Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/webdriver/test/testutil_test.js
2868 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
goog.require('goog.testing.jsunit');
19
goog.require('webdriver.test.testutil');
20
21
// Aliases for readability.
22
var callbackHelper = webdriver.test.testutil.callbackHelper,
23
callbackPair = webdriver.test.testutil.callbackPair;
24
25
function testCallbackHelper_functionCalled() {
26
var callback = callbackHelper();
27
callback();
28
assertNotThrows(callback.assertCalled);
29
assertThrowsJsUnitException(callback.assertNotCalled);
30
}
31
32
function testCallbackHelper_functionCalledMoreThanOnce() {
33
var callback = callbackHelper();
34
callback();
35
callback(123, 'abc');
36
assertThrowsJsUnitException(callback.assertCalled);
37
assertThrowsJsUnitException(callback.assertNotCalled);
38
}
39
40
function testCallbackHelper_functionNotCalled() {
41
var callback = callbackHelper();
42
assertNotThrows(callback.assertNotCalled);
43
assertThrowsJsUnitException(callback.assertCalled);
44
}
45
46
function testCallbackHelper_wrappedFunctionIsCalled() {
47
var count = 0;
48
var callback = callbackHelper(function() {
49
count += 1;
50
});
51
callback();
52
assertNotThrows(callback.assertCalled);
53
assertThrowsJsUnitException(callback.assertNotCalled);
54
assertEquals(1, count);
55
}
56
57
function testCallbackPair_callbackExpected() {
58
var pair = callbackPair();
59
assertThrowsJsUnitException(pair.assertCallback);
60
pair.callback();
61
assertNotThrows(pair.assertCallback);
62
pair.errback();
63
assertThrowsJsUnitException(pair.assertCallback);
64
65
pair.reset();
66
pair.callback();
67
assertNotThrows(pair.assertCallback);
68
pair.callback();
69
}
70
71
function testCallbackPair_errbackExpected() {
72
var pair = callbackPair();
73
assertThrowsJsUnitException(pair.assertErrback);
74
pair.errback();
75
assertNotThrows(pair.assertErrback);
76
pair.callback();
77
assertThrowsJsUnitException(pair.assertErrback);
78
}
79
80
function testCallbackPair_eitherExpected() {
81
var pair = callbackPair();
82
assertThrowsJsUnitException(pair.assertEither);
83
pair.errback();
84
assertNotThrows(pair.assertEither);
85
pair.reset();
86
pair.callback();
87
assertNotThrows(pair.assertEither);
88
pair.errback();
89
assertNotThrows(pair.assertEither);
90
}
91
92
function testCallbackPair_neitherExpected() {
93
var pair = callbackPair();
94
assertNotThrows(pair.assertNeither);
95
pair.errback();
96
assertThrowsJsUnitException(pair.assertNeither);
97
pair.reset();
98
pair.callback();
99
assertThrowsJsUnitException(pair.assertNeither);
100
pair.errback();
101
assertThrowsJsUnitException(pair.assertNeither);
102
}
103
104