Path: blob/trunk/javascript/webdriver/test/testutil_test.js
2868 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617goog.require('goog.testing.jsunit');18goog.require('webdriver.test.testutil');1920// Aliases for readability.21var callbackHelper = webdriver.test.testutil.callbackHelper,22callbackPair = webdriver.test.testutil.callbackPair;2324function testCallbackHelper_functionCalled() {25var callback = callbackHelper();26callback();27assertNotThrows(callback.assertCalled);28assertThrowsJsUnitException(callback.assertNotCalled);29}3031function testCallbackHelper_functionCalledMoreThanOnce() {32var callback = callbackHelper();33callback();34callback(123, 'abc');35assertThrowsJsUnitException(callback.assertCalled);36assertThrowsJsUnitException(callback.assertNotCalled);37}3839function testCallbackHelper_functionNotCalled() {40var callback = callbackHelper();41assertNotThrows(callback.assertNotCalled);42assertThrowsJsUnitException(callback.assertCalled);43}4445function testCallbackHelper_wrappedFunctionIsCalled() {46var count = 0;47var callback = callbackHelper(function() {48count += 1;49});50callback();51assertNotThrows(callback.assertCalled);52assertThrowsJsUnitException(callback.assertNotCalled);53assertEquals(1, count);54}5556function testCallbackPair_callbackExpected() {57var pair = callbackPair();58assertThrowsJsUnitException(pair.assertCallback);59pair.callback();60assertNotThrows(pair.assertCallback);61pair.errback();62assertThrowsJsUnitException(pair.assertCallback);6364pair.reset();65pair.callback();66assertNotThrows(pair.assertCallback);67pair.callback();68}6970function testCallbackPair_errbackExpected() {71var pair = callbackPair();72assertThrowsJsUnitException(pair.assertErrback);73pair.errback();74assertNotThrows(pair.assertErrback);75pair.callback();76assertThrowsJsUnitException(pair.assertErrback);77}7879function testCallbackPair_eitherExpected() {80var pair = callbackPair();81assertThrowsJsUnitException(pair.assertEither);82pair.errback();83assertNotThrows(pair.assertEither);84pair.reset();85pair.callback();86assertNotThrows(pair.assertEither);87pair.errback();88assertNotThrows(pair.assertEither);89}9091function testCallbackPair_neitherExpected() {92var pair = callbackPair();93assertNotThrows(pair.assertNeither);94pair.errback();95assertThrowsJsUnitException(pair.assertNeither);96pair.reset();97pair.callback();98assertThrowsJsUnitException(pair.assertNeither);99pair.errback();100assertThrowsJsUnitException(pair.assertNeither);101}102103104