1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 * @fileoverview Library providing basic test framework functionality.
10 * Namespace for |Test|.
16 * Holds the original version of the |chrome| object.
18 var originalChrome
= null;
21 * Hold the currentTestCase across between preLoad and run.
24 var currentTestCase
= null;
27 * The string representation of the currently running test function.
30 var currentTestFunction
= null;
33 * The arguments of the currently running test.
36 var currentTestArguments
= [];
39 * This class will be exported as testing.Test, and is provided to hold the
40 * fixture's configuration and callback methods for the various phases of
41 * invoking a test. It is called "Test" rather than TestFixture to roughly
42 * mimic the gtest's class names.
49 * The name of the test.
54 * When set to a string value representing a url, generate BrowsePreload
55 * call, which will browse to the url and call fixture.preLoad of the
62 * When set to a string value representing an html page in the test
63 * directory, generate BrowsePrintPreload call, which will browse to a url
64 * representing the file, cause print, and call fixture.preLoad of the
68 browsePrintPreload
: null,
71 * When set to a function, will be called in the context of the test
72 * generation inside the function, after AddLibrary calls and before
74 * @type {function(string,string)}
76 testGenPreamble
: null,
79 * When set to a function, will be called in the context of the test
80 * generation inside the function, and after any generated C++.
81 * @type {function(string,string)}
83 testGenPostamble
: null,
86 * When set to a non-null string, auto-generate typedef before generating
87 * TEST*: {@code typedef typedefCppFixture testFixture}.
90 typedefCppFixture
: 'WebUIBrowserTest',
93 * This should be initialized by the test fixture and can be referenced
94 * during the test run. It holds any mocked handler methods.
95 * @type {?Mock4JS.Mock}
100 * This should be initialized by the test fixture and can be referenced
101 * during the test run. It holds any mocked global functions.
102 * @type {?Mock4JS.Mock}
107 * Value is passed through call to C++ RunJavascriptF to invoke this test.
113 * True when the test is expected to fail for testing the test framework.
116 testShouldFail
: false,
119 * Extra libraries to add before loading this test file.
120 * @type {Array.<string>}
125 * Extra libraries to add before loading this test file.
126 * This list is in the form of Closure library style object
127 * names. To support this, a closure deps.js file must
128 * be specified when generating the test C++ source.
129 * The specified libraries will be included with their transitive
130 * dependencies according to the deps file.
131 * @type {Array.<string>}
133 closureModuleDeps
: [],
136 * Whether to run the accessibility checks.
139 runAccessibilityChecks
: true,
142 * Configuration for the accessibility audit.
143 * @type {axs.AuditConfiguration}
145 accessibilityAuditConfig_
: null,
148 * Returns the configuration for the accessibility audit, creating it
150 * @return {axs.AuditConfiguration}
152 get accessibilityAuditConfig() {
153 // The axs namespace is not available in chromevox tests.
154 // Further, 'window' is not available in unit tests, but since the
155 // accessibility audit library pulls in the closure library,
156 // 'goog.global' has to be present if axs is, so we use that here.
157 if (!this.accessibilityAuditConfig_
&&
158 goog
&& goog
.global
&& goog
.global
.axs
) {
159 this.accessibilityAuditConfig_
= new axs
.AuditConfiguration();
161 this.accessibilityAuditConfig_
.showUnsupportedRulesWarning
= false;
163 this.accessibilityAuditConfig_
.auditRulesToIgnore
= [
164 // The "elements with meaningful background image" accessibility
165 // audit (AX_IMAGE_01) does not apply, since Chrome doesn't
166 // disable background images in high-contrast mode like some
168 "elementsWithMeaningfulBackgroundImage",
170 // Most WebUI pages are inside an IFrame, so the "web page should
171 // have a title that describes topic or purpose" test (AX_TITLE_01)
172 // generally does not apply.
175 // TODO(aboxhall): re-enable when crbug.com/267035 is fixed.
176 // Until then it's just noise.
177 "lowContrastElements",
180 return this.accessibilityAuditConfig_
;
184 * Whether to treat accessibility issues (errors or warnings) as test
185 * failures. If true, any accessibility issues will cause the test to fail.
186 * If false, accessibility issues will cause a console.warn.
187 * Off by default to begin with; as we add the ability to suppress false
188 * positives, we will transition this to true.
191 accessibilityIssuesAreErrors
: false,
194 * Holds any accessibility results found during the accessibility audit.
195 * @type {Array.<Object>}
200 * Gets the list of accessibility errors found during the accessibility
201 * audit. Only for use in testing.
202 * @return {Array.<Object>}
204 getAccessibilityResults: function() {
205 return this.a11yResults_
;
209 * Run accessibility checks after this test completes.
211 enableAccessibilityChecks: function() {
212 this.runAccessibilityChecks
= true;
216 * Don't run accessibility checks after this test completes.
218 disableAccessibilityChecks: function() {
219 this.runAccessibilityChecks
= false;
223 * Create a new class to handle |messageNames|, assign it to
224 * |this.mockHandler|, register its messages and return it.
225 * @return {Mock} Mock handler class assigned to |this.mockHandler|.
227 makeAndRegisterMockHandler: function(messageNames
) {
228 var MockClass
= makeMockClass(messageNames
);
229 this.mockHandler
= mock(MockClass
);
230 registerMockMessageCallbacks(this.mockHandler
, MockClass
);
231 return this.mockHandler
;
235 * Create a new class to handle |functionNames|, assign it to
236 * |this.mockGlobals|, register its global overrides, and return it.
237 * @return {Mock} Mock handler class assigned to |this.mockGlobals|.
238 * @see registerMockGlobals
240 makeAndRegisterMockGlobals: function(functionNames
) {
241 var MockClass
= makeMockClass(functionNames
);
242 this.mockGlobals
= mock(MockClass
);
243 registerMockGlobals(this.mockGlobals
, MockClass
);
244 return this.mockGlobals
;
248 * Create a container of mocked standalone functions to handle
249 * '.'-separated |apiNames|, assign it to |this.mockApis|, register its API
250 * overrides and return it.
251 * @return {Mock} Mock handler class.
252 * @see makeMockFunctions
253 * @see registerMockApis
255 makeAndRegisterMockApis: function (apiNames
) {
256 var apiMockNames
= apiNames
.map(function(name
) {
257 return name
.replace(/\./g, '_');
260 this.mockApis
= makeMockFunctions(apiMockNames
);
261 registerMockApis(this.mockApis
);
262 return this.mockApis
;
266 * Create a container of mocked standalone functions to handle
267 * |functionNames|, assign it to |this.mockLocalFunctions| and return it.
268 * @param {!Array.<string>} functionNames
269 * @return {Mock} Mock handler class.
270 * @see makeMockFunctions
272 makeMockLocalFunctions: function(functionNames
) {
273 this.mockLocalFunctions
= makeMockFunctions(functionNames
);
274 return this.mockLocalFunctions
;
278 * Override this method to perform initialization during preload (such as
279 * creating mocks and registering handlers).
282 preLoad: function() {},
285 * Override this method to perform tasks before running your test.
289 var auditConfig
= this.accessibilityAuditConfig
;
291 // These should be ignored in many of the web UI tests.
292 // user-image-stream and supervised-user-creation-image-stream are
293 // streaming video elements used for capturing a user image so they
294 // won't have captions and should be ignored everywhere.
295 auditConfig
.ignoreSelectors('videoWithoutCaptions',
296 '.user-image-stream');
297 auditConfig
.ignoreSelectors(
298 'videoWithoutCaptions', '.supervised-user-creation-image-stream');
303 * Override this method to perform tasks after running your test. If you
304 * create a mock class, you must call Mock4JS.verifyAllMocks() in this
308 tearDown: function() {
309 Mock4JS
.verifyAllMocks();
313 * Called to run the body from the perspective of this fixture.
316 runTest: function(testBody
) {
321 * Called to run the accessibility audit from the perspective of this
324 runAccessibilityAudit: function() {
325 if (!this.runAccessibilityChecks
|| typeof document
=== 'undefined')
328 var auditConfig
= this.accessibilityAuditConfig
;
329 if (!runAccessibilityAudit(this.a11yResults_
, auditConfig
)) {
330 var report
= accessibilityAuditReport(this.a11yResults_
);
331 if (this.accessibilityIssuesAreErrors
)
332 throw new Error(report
);
334 console
.warn(report
);
339 * Create a closure function for continuing the test at a later time. May be
340 * used as a listener function.
341 * @param {WhenTestDone} whenTestDone Call testDone() at the appropriate
343 * @param {Function} completion The function to call to complete the test.
344 * @param {...*} var_args Arguments to pass when calling completionAction.
345 * @return {function(): void} Return a function, bound to this test fixture,
346 * which continues the test.
348 continueTest: function(whenTestDone
, completion
) {
349 var savedArgs
= new SaveMockArguments();
350 var completionAction
= new CallFunctionAction(
351 this, savedArgs
, completion
,
352 Array
.prototype.slice
.call(arguments
, 2));
353 if (whenTestDone
=== WhenTestDone
.DEFAULT
)
354 whenTestDone
= WhenTestDone
.ASSERT
;
355 var runAll
= new RunAllAction(
356 true, whenTestDone
, [completionAction
]);
358 savedArgs
.arguments
= Array
.prototype.slice
.call(arguments
);
364 * Call this during setUp to defer the call to runTest() until later. The
365 * caller must call the returned function at some point to run the test.
367 * @param {WhenTestDone} whenTestDone Call testDone() at the appropriate
369 * @param {...*} var_args Arguments to pass when running the
371 * @return {function(): void} A function which will run the current body of
372 * the currentTestCase.
374 deferRunTest: function(whenTestDone
) {
375 if (whenTestDone
=== WhenTestDone
.DEFAULT
)
376 whenTestDone
= WhenTestDone
.ALWAYS
;
378 return currentTestCase
.deferRunTest
.apply(
379 currentTestCase
, [whenTestDone
].concat(
380 Array
.prototype.slice
.call(arguments
, 1)));
385 * This class is not exported and is available to hold the state of the
386 * |currentTestCase| throughout preload and test run.
387 * @param {string} name The name of the test case.
388 * @param {Test} fixture The fixture object for this test case.
389 * @param {Function} body The code to run for the test.
392 function TestCase(name
, fixture
, body
) {
394 this.fixture
= fixture
;
398 TestCase
.prototype = {
400 * The name of this test.
406 * The test fixture to set |this| to when running the test |body|.
407 * @type {testing.Test}
412 * The test body to execute in runTest().
418 * True when the test fixture will run the test later.
425 * Called at preload time, proxies to the fixture.
428 preLoad: function(name
) {
430 this.fixture
.preLoad();
434 * Called before a test runs.
438 this.fixture
.setUp();
442 * Called before a test is torn down (by testDone()).
444 tearDown: function() {
446 this.fixture
.tearDown();
450 * Called to run this test's body.
452 runTest: function() {
453 if (this.body
&& this.fixture
)
454 this.fixture
.runTest(this.body
);
458 * Called after a test is run (in testDone) to test accessibility.
460 runAccessibilityAudit: function() {
462 this.fixture
.runAccessibilityAudit();
466 * Runs this test case with |this| set to the |fixture|.
468 * Note: Tests created with TEST_F may depend upon |this| being set to an
469 * instance of this.fixture. The current implementation of TEST creates a
470 * dummy constructor, but tests created with TEST should not rely on |this|
478 // Mock4JSException doesn't inherit from Error, so fall back on
480 console
.error(e
.stack
|| e
.toString());
486 // tearDown called by testDone().
490 * Cause this TestCase to be deferred (don't call runTest()) until the
491 * returned function is called.
493 * @param {WhenTestDone} whenTestDone Call testDone() at the appropriate
495 * @param {...*} var_args Arguments to pass when running the
497 * @return {function(): void} A function thatwill run this TestCase when
500 deferRunTest: function(whenTestDone
) {
501 this.deferred_
= true;
502 var savedArgs
= new SaveMockArguments();
503 var completionAction
= new CallFunctionAction(
504 this, savedArgs
, this.runTest
,
505 Array
.prototype.slice
.call(arguments
, 1));
506 var runAll
= new RunAllAction(
507 true, whenTestDone
, [completionAction
]);
509 savedArgs
.arguments
= Array
.prototype.slice
.call(arguments
);
517 * Registry of javascript-defined callbacks for {@code chrome.send}.
520 var sendCallbacks
= {};
523 * Registers the message, object and callback for {@code chrome.send}
524 * @param {string} name The name of the message to route to this |callback|.
525 * @param {Object} messageHandler Pass as |this| when calling the |callback|.
526 * @param {function(...)} callback Called by {@code chrome.send}.
529 function registerMessageCallback(name
, messageHandler
, callback
) {
530 sendCallbacks
[name
] = [messageHandler
, callback
];
534 * Register all methods of {@code mockClass.prototype} with messages of the
535 * same name as the method, using the proxy of the |mockObject| as the
536 * |messageHandler| when registering.
537 * @param {Mock4JS.Mock} mockObject The mock to register callbacks against.
538 * @param {function(new:Object)} mockClAss Constructor for the mocked class.
539 * @see registerMessageCallback
540 * @see overrideChrome
542 function registerMockMessageCallbacks(mockObject
, mockClass
) {
543 if (!deferGlobalOverrides
&& !originalChrome
)
545 var mockProxy
= mockObject
.proxy();
546 for (var func
in mockClass
.prototype) {
547 if (typeof mockClass
.prototype[func
] === 'function') {
548 registerMessageCallback(func
, mockProxy
, mockProxy
[func
]);
554 * Holds the mapping of name -> global override information.
557 var globalOverrides
= {};
560 * When preloading JavaScript libraries, this is true until the
561 * DOMContentLoaded event has been received as globals cannot be overridden
562 * until the page has loaded its JavaScript.
565 var deferGlobalOverrides
= false;
568 * Override the global function |funcName| with its registered mock. This
569 * should not be called twice for the same |funcName|.
570 * @param {string} funcName The name of the global function to override.
572 function overrideGlobal(funcName
) {
573 assertNotEquals(undefined, this[funcName
]);
574 var globalOverride
= globalOverrides
[funcName
];
575 assertNotEquals(undefined, globalOverride
);
576 assertEquals(undefined, globalOverride
.original
);
577 globalOverride
.original
= this[funcName
];
578 this[funcName
] = globalOverride
.callback
.bind(globalOverride
.object
);
582 * Registers the global function name, object and callback.
583 * @param {string} name The name of the message to route to this |callback|.
584 * @param {Object} object Pass as |this| when calling the |callback|.
585 * @param {function(...)} callback Called by {@code chrome.send}.
586 * @see overrideGlobal
588 function registerMockGlobal(name
, object
, callback
) {
589 assertEquals(undefined, globalOverrides
[name
]);
590 globalOverrides
[name
] = {
595 if (!deferGlobalOverrides
)
596 overrideGlobal(name
);
600 * Registers the mock API call and its function.
601 * @param {string} name The '_'-separated name of the API call.
602 * @param {function(...)} theFunction Mock function for this API call.
604 function registerMockApi(name
, theFunction
) {
605 var path
= name
.split('_');
607 var namespace = this;
608 for(var i
= 0; i
< path
.length
- 1; i
++) {
609 var fieldName
= path
[i
];
610 if(!namespace[fieldName
])
611 namespace[fieldName
] = {};
613 namespace = namespace[fieldName
];
616 var fieldName
= path
[path
.length
-1];
617 namespace[fieldName
] = theFunction
;
621 * Empty function for use in making mocks.
624 function emptyFunction() {}
627 * Make a mock from the supplied |methodNames| array.
628 * @param {Array.<string>} methodNames Array of names of methods to mock.
629 * @return {Function} Constructor with prototype filled in with methods
630 * matching |methodNames|.
632 function makeMockClass(methodNames
) {
633 function MockConstructor() {}
634 for(var i
= 0; i
< methodNames
.length
; i
++)
635 MockConstructor
.prototype[methodNames
[i
]] = emptyFunction
;
636 return MockConstructor
;
640 * Create a new class to handle |functionNames|, add method 'functions()'
641 * that returns a container of standalone functions based on the mock class
642 * members, and return it.
643 * @return {Mock} Mock handler class.
645 function makeMockFunctions(functionNames
) {
646 var MockClass
= makeMockClass(functionNames
);
647 var mockFunctions
= mock(MockClass
);
648 var mockProxy
= mockFunctions
.proxy();
650 mockFunctions
.functions_
= {};
652 for (var func
in MockClass
.prototype) {
653 if (typeof MockClass
.prototype[func
] === 'function')
654 mockFunctions
.functions_
[func
] = mockProxy
[func
].bind(mockProxy
);
657 mockFunctions
.functions = function () {
658 return this.functions_
;
661 return mockFunctions
;
665 * Register all methods of {@code mockClass.prototype} as overrides to global
666 * functions of the same name as the method, using the proxy of the
667 * |mockObject| to handle the functions.
668 * @param {Mock4JS.Mock} mockObject The mock to register callbacks against.
669 * @param {function(new:Object)} mockClass Constructor for the mocked class.
670 * @see registerMockGlobal
672 function registerMockGlobals(mockObject
, mockClass
) {
673 var mockProxy
= mockObject
.proxy();
674 for (var func
in mockClass
.prototype) {
675 if (typeof mockClass
.prototype[func
] === 'function')
676 registerMockGlobal(func
, mockProxy
, mockProxy
[func
]);
681 * Register all functions in |mockObject.functions()| as global API calls.
682 * @param {Mock4JS.Mock} mockObject The mock to register callbacks against.
683 * @see registerMockApi
685 function registerMockApis(mockObject
) {
686 var functions
= mockObject
.functions();
687 for (var func
in functions
) {
688 if (typeof functions
[func
] === 'function')
689 registerMockApi(func
, functions
[func
]);
694 * Overrides {@code chrome.send} for routing messages to javascript
695 * functions. Also falls back to sending with the original chrome object.
696 * @param {string} messageName The message to route.
698 function send(messageName
) {
699 var callback
= sendCallbacks
[messageName
];
700 if (callback
!= undefined)
701 callback
[1].apply(callback
[0], Array
.prototype.slice
.call(arguments
, 1));
703 this.__proto__
.send
.apply(this.__proto__
, arguments
);
707 * Provides a mechanism for assert* and expect* methods to fetch the signature
708 * of their caller. Assert* methods should |registerCall| and expect* methods
709 * should set |isExpect| and |expectName| properties to indicate that the
710 * interesting caller is one more level up the stack.
712 function CallHelper() {
713 this.__proto__
= CallHelper
.prototype;
716 CallHelper
.prototype = {
718 * Holds the mapping of (callerCallerString, callerName) -> count of times
720 * @type {Object.<string, Object.<string, number>>}
725 * This information about the caller is needed from most of the following
727 * @param {Function} caller the caller of the assert* routine.
728 * @return {{callerName: string, callercallerString: string}} stackInfo
731 getCallerInfo_: function(caller
) {
732 var callerName
= caller
.name
;
733 var callerCaller
= caller
.caller
;
734 if (callerCaller
['isExpect']) {
735 callerName
= callerCaller
.expectName
;
736 callerCaller
= callerCaller
.caller
;
738 var callerCallerString
= callerCaller
.toString();
740 callerName
: callerName
,
741 callerCallerString
: callerCallerString
,
746 * Register a call to an assertion class.
748 registerCall: function() {
749 var stackInfo
= this.getCallerInfo_(arguments
.callee
.caller
);
750 if (!(stackInfo
.callerCallerString
in this.counts_
))
751 this.counts_
[stackInfo
.callerCallerString
] = {};
752 if (!(stackInfo
.callerName
in this.counts_
[stackInfo
.callerCallerString
]))
753 this.counts_
[stackInfo
.callerCallerString
][stackInfo
.callerName
] = 0;
754 ++this.counts_
[stackInfo
.callerCallerString
][stackInfo
.callerName
];
758 * Get the call signature of this instance of the caller's call to this
760 * @param {Function} caller The caller of the assert* routine.
761 * @return {String} Call signature.
764 getCall_: function(caller
) {
765 var stackInfo
= this.getCallerInfo_(caller
);
767 this.counts_
[stackInfo
.callerCallerString
][stackInfo
.callerName
];
769 // Allow pattern to match multiple lines for text wrapping.
771 new RegExp(stackInfo
.callerName
+ '\\((.|\\n|\\r)*?\\);', 'g');
773 // Find all matches allowing wrap around such as when a helper function
774 // calls assert/expect calls and that helper function is called multiple
776 var matches
= stackInfo
.callerCallerString
.match(callerRegExp
);
777 var match
= matches
[(count
- 1) % matches
.length
];
779 // Chop off the trailing ';'.
780 return match
.substring(0, match
.length
-1);
784 * Returns the text of the call signature and any |message|.
785 * @param {string=} message Addtional message text from caller.
787 getCallMessage: function(message
) {
788 var callMessage
= this.getCall_(arguments
.callee
.caller
);
790 callMessage
+= ': ' + message
;
796 * Help register calls for better error reporting.
799 var helper
= new CallHelper();
802 * true when testDone has been called.
805 var testIsDone
= false;
808 * Holds the errors, if any, caught by expects so that the test case can
809 * fail. Cleared when results are reported from runTest() or testDone().
810 * @type {Array.<Error>}
815 * URL to dummy WebUI page for testing framework.
818 var DUMMY_URL
= 'chrome://DummyURL';
821 * Resets test state by clearing |errors| and |testIsDone| flags.
823 function resetTestState() {
824 errors
.splice(0, errors
.length
);
829 * Notifies the running browser test of the test results. Clears |errors|.
830 * @param {Array.<boolean, string>=} result When passed, this is used for the
831 * testResult message.
833 function testDone(result
) {
836 if (currentTestCase
) {
838 ok
= createExpect(currentTestCase
.runAccessibilityAudit
.bind(
839 currentTestCase
)).call(null) && ok
;
840 ok
= createExpect(currentTestCase
.tearDown
.bind(
841 currentTestCase
)).call(null) && ok
;
844 result
= [false, errorsToMessage(errors
, result
[1])];
846 currentTestCase
= null;
849 result
= testResult();
852 chrome
.send('testResult', result
);
853 } else if (window
.domAutomationController
.send
) {
854 // For extension tests.
855 valueResult
= { 'result': result
[0], message
: result
[1] };
856 window
.domAutomationController
.send(JSON
.stringify(valueResult
));
858 errors
.splice(0, errors
.length
);
860 console
.warn('testIsDone already');
865 * Converts each Error in |errors| to a suitable message, adding them to
866 * |message|, and returns the message string.
867 * @param {Array.<Error>} errors Array of errors to add to |message|.
868 * @param {string?} message When supplied, error messages are appended to it.
869 * @return {string} |message| + messages of all |errors|.
871 function errorsToMessage(errors
, message
) {
872 for (var i
= 0; i
< errors
.length
; ++i
) {
873 var errorMessage
= errors
[i
].stack
|| errors
[i
].message
;
877 message
+= 'Failed: ' + currentTestFunction
+ '(' +
878 currentTestArguments
.map(JSON
.stringify
) +
879 ')\n' + errorMessage
;
885 * Returns [success, message] & clears |errors|.
886 * @param {boolean} errorsOk When true, errors are ok.
887 * @return {Array.<boolean, string>}
889 function testResult(errorsOk
) {
890 var result
= [true, ''];
892 result
= [!!errorsOk
, errorsToMessage(errors
)];
898 // Use the following assertions to verify a condition within a test.
899 // If assertion fails, throw an Error with information pertinent to the test.
902 * When |test| !== true, aborts the current test.
903 * @param {boolean} test The predicate to check against |expected|.
904 * @param {string=} message The message to include in the Error thrown.
905 * @throws {Error} upon failure.
907 function assertTrue(test
, message
) {
908 helper
.registerCall();
911 'Test Error ' + helper
.getCallMessage(message
) + ': ' + test
);
915 * When |test| !== false, aborts the current test.
916 * @param {boolean} test The predicate to check against |expected|.
917 * @param {string=} message The message to include in the Error thrown.
918 * @throws {Error} upon failure.
920 function assertFalse(test
, message
) {
921 helper
.registerCall();
924 'Test Error ' + helper
.getCallMessage(message
) + ': ' + test
);
928 * When |val1| < |val2|, aborts the current test.
929 * @param {number} val1 The number expected to be >= |val2|.
930 * @param {number} val2 The number expected to be < |val1|.
931 * @param {string=} message The message to include in the Error thrown.
933 function assertGE(val1
, val2
, message
) {
934 helper
.registerCall();
937 'Test Error ' + helper
.getCallMessage(message
) + val1
+ '<' + val2
);
942 * When |val1| <= |val2|, aborts the current test.
943 * @param {number} val1 The number expected to be > |val2|.
944 * @param {number} val2 The number expected to be <= |val1|.
945 * @param {string=} message The message to include in the Error thrown.
947 function assertGT(val1
, val2
, message
) {
948 helper
.registerCall();
951 'Test Error ' + helper
.getCallMessage(message
) + val1
+ '<=' + val2
);
956 * When |expected| !== |actual|, aborts the current test.
957 * @param {*} expected The expected value of |actual|.
958 * @param {*} actual The predicate to check against |expected|.
959 * @param {string=} message The message to include in the Error thrown.
960 * @throws {Error} upon failure.
962 function assertEquals(expected
, actual
, message
) {
963 helper
.registerCall();
964 if (expected
!= actual
) {
966 'Test Error ' + helper
.getCallMessage(message
) +
967 '\nActual: ' + actual
+ '\nExpected: ' + expected
);
969 if (typeof expected
!== typeof actual
) {
971 'Test Error (type mismatch) ' + helper
.getCallMessage(message
) +
972 '\nActual Type: ' + typeof actual
+
973 '\nExpected Type:' + typeof expected
);
978 * When |val1| > |val2|, aborts the current test.
979 * @param {number} val1 The number expected to be <= |val2|.
980 * @param {number} val2 The number expected to be > |val1|.
981 * @param {string=} message The message to include in the Error thrown.
983 function assertLE(val1
, val2
, message
) {
984 helper
.registerCall();
987 'Test Error ' + helper
.getCallMessage(message
) + val1
+ '>' + val2
);
992 * When |val1| >= |val2|, aborts the current test.
993 * @param {number} val1 The number expected to be < |val2|.
994 * @param {number} val2 The number expected to be >= |val1|.
995 * @param {string=} message The message to include in the Error thrown.
997 function assertLT(val1
, val2
, message
) {
998 helper
.registerCall();
1001 'Test Error ' + helper
.getCallMessage(message
) + val1
+ '>=' + val2
);
1006 * When |notExpected| === |actual|, aborts the current test.
1007 * @param {*} notExpected The expected value of |actual|.
1008 * @param {*} actual The predicate to check against |notExpected|.
1009 * @param {string=} message The message to include in the Error thrown.
1010 * @throws {Error} upon failure.
1012 function assertNotEquals(notExpected
, actual
, message
) {
1013 helper
.registerCall();
1014 if (notExpected
=== actual
) {
1016 'Test Error ' + helper
.getCallMessage(message
) +
1017 '\nActual: ' + actual
+ '\nnotExpected: ' + notExpected
);
1022 * Always aborts the current test.
1023 * @param {string=} message The message to include in the Error thrown.
1024 * @throws {Error} always.
1026 function assertNotReached(message
) {
1027 helper
.registerCall();
1028 throw new Error(helper
.getCallMessage(message
));
1032 * Run an accessibility audit on the current page state.
1034 * @param {Array} a11yResults
1035 * @param {axs.AuditConfigutarion=} opt_config
1036 * @return {boolean} Whether there were any errors or warnings
1039 function runAccessibilityAudit(a11yResults
, opt_config
) {
1040 var auditResults
= axs
.Audit
.run(opt_config
);
1041 for (var i
= 0; i
< auditResults
.length
; i
++) {
1042 var auditResult
= auditResults
[i
];
1043 if (auditResult
.result
== axs
.constants
.AuditResult
.FAIL
) {
1044 var auditRule
= auditResult
.rule
;
1045 // TODO(aboxhall): more useful error messages (sadly non-trivial)
1046 a11yResults
.push(auditResult
);
1049 // TODO(aboxhall): have strict (no errors or warnings) vs non-strict
1051 // TODO(aboxhall): some kind of info logging for warnings only??
1052 return (a11yResults
.length
== 0);
1056 * Concatenates the accessibility error messages for each result in
1058 * |a11yWarnings| in to an accessibility report, appends it to the given
1059 * |message| and returns the resulting message string.
1060 * @param {Array.<string>} a11yResults The list of accessibility results
1061 * @return {string} |message| + accessibility report.
1063 function accessibilityAuditReport(a11yResults
, message
) {
1064 message
= message
? message
+ '\n\n' : '\n';
1065 message
+= 'Accessibility issues found on ' + window
.location
.href
+ '\n';
1066 message
+= axs
.Audit
.createReport(a11yResults
);
1071 * Asserts that the current page state passes the accessibility audit.
1072 * @param {Array=} opt_results Array to fill with results, if desired.
1074 function assertAccessibilityOk(opt_results
) {
1075 helper
.registerCall();
1076 var a11yResults
= opt_results
|| [];
1077 var auditConfig
= currentTestCase
.fixture
.accessibilityAuditConfig
;
1078 if (!runAccessibilityAudit(a11yResults
, auditConfig
))
1079 throw new Error(accessibilityAuditReport(a11yResults
));
1083 * Creates a function based upon a function that thows an exception on
1084 * failure. The new function stuffs any errors into the |errors| array for
1085 * checking by runTest. This allows tests to continue running other checks,
1086 * while failing the overall test if any errors occurrred.
1087 * @param {Function} assertFunc The function which may throw an Error.
1088 * @return {function(...*):bool} A function that applies its arguments to
1089 * |assertFunc| and returns true if |assertFunc| passes.
1091 * @see runTestFunction
1093 function createExpect(assertFunc
) {
1094 var expectFunc = function() {
1096 assertFunc
.apply(null, arguments
);
1103 expectFunc
.isExpect
= true;
1104 expectFunc
.expectName
= assertFunc
.name
.replace(/^assert/, 'expect');
1109 * This is the starting point for tests run by WebUIBrowserTest. If an error
1110 * occurs, it reports a failure and a message created by joining individual
1111 * error messages. This supports sync tests and async tests by calling
1112 * testDone() when |isAsync| is not true, relying on async tests to call
1113 * testDone() when they complete.
1114 * @param {boolean} isAsync When false, call testDone() with the test result
1115 * otherwise only when assertions are caught.
1116 * @param {string} testFunction The function name to call.
1117 * @param {Array} testArguments The arguments to call |testFunction| with.
1118 * @return {boolean} true always to signal successful execution (but not
1119 * necessarily successful results) of this test.
1121 * @see runTestFunction
1123 function runTest(isAsync
, testFunction
, testArguments
) {
1124 // Avoid eval() if at all possible, since it will not work on pages
1125 // that have enabled content-security-policy.
1126 var testBody
= this[testFunction
]; // global object -- not a method.
1127 var testName
= testFunction
;
1129 // Depending on how we were called, |this| might not resolve to the global
1131 if (testName
== 'RUN_TEST_F' && testBody
=== undefined)
1132 testBody
= RUN_TEST_F
;
1134 if (typeof testBody
=== "undefined") {
1135 testBody
= eval(testFunction
);
1136 testName
= testBody
.toString();
1138 if (testBody
!= RUN_TEST_F
) {
1139 console
.log('Running test ' + testName
);
1142 // Async allow expect errors, but not assert errors.
1143 var result
= runTestFunction(testFunction
, testBody
, testArguments
,
1145 if (!isAsync
|| !result
[0])
1151 * This is the guts of WebUIBrowserTest. It runs the test surrounded by an
1152 * expect to catch Errors. If |errors| is non-empty, it reports a failure and
1153 * a message by joining |errors|. Consumers can use this to use assert/expect
1154 * functions asynchronously, but are then responsible for reporting errors to
1155 * the browser themselves through testDone().
1156 * @param {string} testFunction The function name to report on failure.
1157 * @param {Function} testBody The function to call.
1158 * @param {Array} testArguments The arguments to call |testBody| with.
1159 * @param {boolean} onlyAssertFails When true, only assertions cause failing
1161 * @return {Array.<boolean, string>} [test-succeeded, message-if-failed]
1165 function runTestFunction(testFunction
, testBody
, testArguments
,
1167 currentTestFunction
= testFunction
;
1168 currentTestArguments
= testArguments
;
1169 var ok
= createExpect(testBody
).apply(null, testArguments
);
1170 return testResult(onlyAssertFails
&& ok
);
1174 * Creates a new test case for the given |testFixture| and |testName|. Assumes
1175 * |testFixture| describes a globally available subclass of type Test.
1176 * @param {string} testFixture The fixture for this test case.
1177 * @param {string} testName The name for this test case.
1178 * @return {TestCase} A newly created TestCase.
1180 function createTestCase(testFixture
, testName
) {
1181 var fixtureConstructor
= this[testFixture
];
1182 var testBody
= fixtureConstructor
.testCaseBodies
[testName
];
1183 var fixture
= new fixtureConstructor();
1184 fixture
.name
= testFixture
;
1185 return new TestCase(testName
, fixture
, testBody
);
1189 * Overrides the |chrome| object to enable mocking calls to chrome.send().
1191 function overrideChrome() {
1192 if (originalChrome
) {
1193 console
.error('chrome object already overridden');
1197 originalChrome
= chrome
;
1199 __proto__
: originalChrome
,
1201 originalSend
: originalChrome
.send
.bind(originalChrome
),
1206 * Used by WebUIBrowserTest to preload the javascript libraries at the
1207 * appropriate time for javascript injection into the current page. This
1208 * creates a test case and calls its preLoad for any early initialization such
1209 * as registering handlers before the page's javascript runs it's OnLoad
1210 * method. This is called before the page is loaded, so the |chrome| object is
1211 * not yet bound and this DOMContentLoaded listener will be called first to
1212 * override |chrome| in order to route messages registered in |sendCallbacks|.
1213 * @param {string} testFixture The test fixture name.
1214 * @param {string} testName The test name.
1215 * @see sendCallbacks
1217 function preloadJavascriptLibraries(testFixture
, testName
) {
1218 deferGlobalOverrides
= true;
1220 // The document seems to change from the point of preloading to the point of
1221 // events (and doesn't fire), whereas the window does not. Listening to the
1222 // capture phase allows this event to fire first.
1223 window
.addEventListener('DOMContentLoaded', function() {
1226 // Override globals at load time so they will be defined.
1227 assertTrue(deferGlobalOverrides
);
1228 deferGlobalOverrides
= false;
1229 for (var funcName
in globalOverrides
)
1230 overrideGlobal(funcName
);
1232 currentTestCase
= createTestCase(testFixture
, testName
);
1233 currentTestCase
.preLoad();
1237 * During generation phase, this outputs; do nothing at runtime.
1242 * During generation phase, this outputs; do nothing at runtime.
1244 function GEN_INCLUDE() {}
1247 * At runtime, register the testName with a test fixture. Since this method
1248 * doesn't have a test fixture, create a dummy fixture to hold its |name|
1249 * and |testCaseBodies|.
1250 * @param {string} testCaseName The name of the test case.
1251 * @param {string} testName The name of the test function.
1252 * @param {Function} testBody The body to execute when running this test.
1254 function TEST(testCaseName
, testName
, testBody
) {
1255 var fixtureConstructor
= this[testCaseName
];
1256 if (fixtureConstructor
=== undefined) {
1257 fixtureConstructor = function() {};
1258 this[testCaseName
] = fixtureConstructor
;
1259 fixtureConstructor
.prototype = {
1260 __proto__
: Test
.prototype,
1263 fixtureConstructor
.testCaseBodies
= {};
1265 fixtureConstructor
.testCaseBodies
[testName
] = testBody
;
1269 * At runtime, register the testName with its fixture. Stuff the |name| into
1270 * the |testFixture|'s prototype, if needed, and the |testCaseBodies| into its
1272 * @param {string} testFixture The name of the test fixture class.
1273 * @param {string} testName The name of the test function.
1274 * @param {Function} testBody The body to execute when running this test.
1276 function TEST_F(testFixture
, testName
, testBody
) {
1277 var fixtureConstructor
= this[testFixture
];
1278 if (!fixtureConstructor
.prototype.name
)
1279 fixtureConstructor
.prototype.name
= testFixture
;
1280 if (fixtureConstructor
['testCaseBodies'] === undefined)
1281 fixtureConstructor
.testCaseBodies
= {};
1282 fixtureConstructor
.testCaseBodies
[testName
] = testBody
;
1286 * RunJavascriptTestF uses this as the |testFunction| when invoking
1287 * runTest. If |currentTestCase| is non-null at this point, verify that
1288 * |testFixture| and |testName| agree with the preloaded values. Create
1289 * |currentTestCase|, if needed, run it, and clear the |currentTestCase|.
1290 * @param {string} testFixture The name of the test fixture class.
1291 * @param {string} testName The name of the test function.
1292 * @see preloadJavascriptLibraries
1295 function RUN_TEST_F(testFixture
, testName
) {
1296 if (!currentTestCase
)
1297 currentTestCase
= createTestCase(testFixture
, testName
);
1298 assertEquals(currentTestCase
.name
, testName
);
1299 assertEquals(currentTestCase
.fixture
.name
, testFixture
);
1300 console
.log('Running TestCase ' + testFixture
+ '.' + testName
);
1301 currentTestCase
.run();
1305 * This Mock4JS matcher object pushes each |actualArgument| parameter to
1306 * match() calls onto |args|.
1307 * @param {Array} args The array to push |actualArgument| onto.
1308 * @param {Object} realMatcher The real matcher check arguments with.
1310 * @extends {realMatcher}
1312 function SaveMockArgumentMatcher(args
, realMatcher
) {
1313 this.arguments_
= args
;
1314 this.realMatcher_
= realMatcher
;
1317 SaveMockArgumentMatcher
.prototype = {
1319 * Holds the arguments to push each |actualArgument| onto.
1326 * The real Mock4JS matcher object to check arguments with.
1332 * Pushes |actualArgument| onto |arguments_| and call |realMatcher_|. Clears
1333 * |arguments_| on non-match.
1334 * @param {*} actualArgument The argument to match and save.
1335 * @return {boolean} Result of calling the |realMatcher|.
1337 argumentMatches: function(actualArgument
) {
1338 this.arguments_
.push(actualArgument
);
1339 var match
= this.realMatcher_
.argumentMatches(actualArgument
);
1341 this.arguments_
.splice(0, this.arguments_
.length
);
1347 * Proxy to |realMatcher_| for description.
1348 * @return {string} Description of this Mock4JS matcher.
1350 describe: function() {
1351 return this.realMatcher_
.describe();
1356 * Actions invoked by Mock4JS's "will()" syntax do not receive arguments from
1357 * the mocked method. This class works with SaveMockArgumentMatcher to save
1358 * arguments so that the invoked Action can pass arguments through to the
1360 * @param {!Object} realMatcher The real matcher to perform matching with.
1363 function SaveMockArguments() {
1364 this.arguments
= [];
1367 SaveMockArguments
.prototype = {
1369 * Wraps the |realMatcher| with an object which will push its argument onto
1370 * |arguments| and call realMatcher.
1371 * @param {Object} realMatcher A Mock4JS matcher object for this argument.
1372 * @return {SaveMockArgumentMatcher} A new matcher which will push its
1373 * argument onto |arguments|.
1375 match: function(realMatcher
) {
1376 return new SaveMockArgumentMatcher(this.arguments
, realMatcher
);
1380 * Remember the argument passed to this stub invocation.
1387 * CallFunctionAction is provided to allow mocks to have side effects.
1388 * @param {Object} obj The object to set |this| to when calling |func_|.
1389 * @param {?SaveMockArguments} savedArgs when non-null, saved arguments are
1391 * @param {Function} func The function to call.
1392 * @param {Array=} args Any arguments to pass to func.
1395 function CallFunctionAction(obj
, savedArgs
, func
, args
) {
1397 this.savedArgs_
= savedArgs
;
1399 this.args_
= args
? args
: [];
1402 CallFunctionAction
.prototype = {
1404 * Set |this| to |obj_| when calling |func_|.
1410 * The SaveMockArguments to hold arguments when invoking |func_|.
1411 * @type {?SaveMockArguments}
1417 * The function to call when invoked.
1424 * Arguments to pass to |func_| when invoked.
1430 * Accessor for |func_|.
1431 * @return {Function} The function to invoke.
1438 * Called by Mock4JS when using .will() to specify actions for stubs() or
1439 * expects(). Clears |savedArgs_| so it can be reused.
1440 * @return The results of calling |func_| with the concatenation of
1441 * |savedArgs_| and |args_|.
1443 invoke: function() {
1444 var prependArgs
= [];
1445 if (this.savedArgs_
) {
1446 prependArgs
= this.savedArgs_
.arguments
.splice(
1447 0, this.savedArgs_
.arguments
.length
);
1449 return this.func
.apply(this.obj_
, prependArgs
.concat(this.args_
));
1453 * Describe this action to Mock4JS.
1454 * @return {string} A description of this action.
1456 describe: function() {
1457 return 'calls the given function with saved arguments and ' + this.args_
;
1462 * Syntactic sugar for use with will() on a Mock4JS.Mock.
1463 * @param {Function} func The function to call when the method is invoked.
1464 * @param {...*} var_args Arguments to pass when calling func.
1465 * @return {CallFunctionAction} Action for use in will.
1467 function callFunction(func
) {
1468 return new CallFunctionAction(
1469 null, null, func
, Array
.prototype.slice
.call(arguments
, 1));
1473 * Syntactic sugar for use with will() on a Mock4JS.Mock.
1474 * @param {SaveMockArguments} savedArgs Arguments saved with this object
1475 * are passed to |func|.
1476 * @param {Function} func The function to call when the method is invoked.
1477 * @param {...*} var_args Arguments to pass when calling func.
1478 * @return {CallFunctionAction} Action for use in will.
1480 function callFunctionWithSavedArgs(savedArgs
, func
) {
1481 return new CallFunctionAction(
1482 null, savedArgs
, func
, Array
.prototype.slice
.call(arguments
, 2));
1486 * CallGlobalAction as a subclass of CallFunctionAction looks up the original
1487 * global object in |globalOverrides| using |funcName| as the key. This allows
1488 * tests, which need to wait until a global function to be called in order to
1489 * start the test to run the original function. When used with runAllActions
1490 * or runAllActionsAsync, Mock4JS expectations may call start or continue the
1491 * test after calling the original function.
1492 * @param {?SaveMockArguments} savedArgs when non-null, saved arguments are
1493 * passed to the global function |funcName|.
1494 * @param {string} funcName The name of the global function to call.
1495 * @param {Array} args Any arguments to pass to func.
1497 * @extends {CallFunctionAction}
1498 * @see globalOverrides
1500 function CallGlobalAction(savedArgs
, funcName
, args
) {
1501 CallFunctionAction
.call(this, null, savedArgs
, funcName
, args
);
1504 CallGlobalAction
.prototype = {
1505 __proto__
: CallFunctionAction
.prototype,
1508 * Fetch and return the original global function to call.
1509 * @return {Function} The global function to invoke.
1513 var func
= globalOverrides
[this.func_
].original
;
1514 assertNotEquals(undefined, func
);
1520 * Syntactic sugar for use with will() on a Mock4JS.Mock.
1521 * @param {SaveMockArguments} savedArgs Arguments saved with this object
1522 * are passed to the global function |funcName|.
1523 * @param {string} funcName The name of a registered mock global function to
1524 * call when the method is invoked.
1525 * @param {...*} var_args Arguments to pass when calling func.
1526 * @return {CallGlobalAction} Action for use in Mock4JS will().
1528 function callGlobalWithSavedArgs(savedArgs
, funcName
) {
1529 return new CallGlobalAction(
1530 savedArgs
, funcName
, Array
.prototype.slice
.call(arguments
, 2));
1534 * When to call testDone().
1537 var WhenTestDone
= {
1539 * Default for the method called.
1544 * Never call testDone().
1549 * Call testDone() on assert failure.
1554 * Call testDone() if there are any assert or expect failures.
1559 * Always call testDone().
1565 * Runs all |actions|.
1566 * @param {boolean} isAsync When true, call testDone() on Errors.
1567 * @param {WhenTestDone} whenTestDone Call testDone() at the appropriate
1569 * @param {Array.<Object>} actions Actions to run.
1572 function RunAllAction(isAsync
, whenTestDone
, actions
) {
1573 this.isAsync_
= isAsync
;
1574 this.whenTestDone_
= whenTestDone
;
1575 this.actions_
= actions
;
1578 RunAllAction
.prototype = {
1580 * When true, call testDone() on Errors.
1587 * Call testDone() at appropriate time.
1588 * @type {WhenTestDone}
1592 whenTestDone_
: WhenTestDone
.ASSERT
,
1595 * Holds the actions to execute when invoked.
1602 * Runs all |actions_|, returning the last one. When running in sync mode,
1603 * throws any exceptions to be caught by runTest() or
1604 * runTestFunction(). Call testDone() according to |whenTestDone_| setting.
1606 invoke: function() {
1609 for(var i
= 0; i
< this.actions_
.length
; ++i
)
1610 result
= this.actions_
[i
].invoke();
1612 if ((this.whenTestDone_
== WhenTestDone
.EXPECT
&& errors
.length
) ||
1613 this.whenTestDone_
== WhenTestDone
.ALWAYS
)
1618 if (!(e
instanceof Error
))
1619 e
= new Error(e
.toString());
1625 if (this.whenTestDone_
!= WhenTestDone
.NEVER
)
1631 * Describe this action to Mock4JS.
1632 * @return {string} A description of this action.
1634 describe: function() {
1635 return 'Calls all actions: ' + this.actions_
;
1640 * Syntactic sugar for use with will() on a Mock4JS.Mock.
1641 * @param {...Object} var_actions Actions to run.
1642 * @return {RunAllAction} Action for use in will.
1644 function runAllActions() {
1645 return new RunAllAction(false, WhenTestDone
.NEVER
,
1646 Array
.prototype.slice
.call(arguments
));
1650 * Syntactic sugar for use with will() on a Mock4JS.Mock.
1651 * @param {WhenTestDone} whenTestDone Call testDone() at the appropriate
1653 * @param {...Object} var_actions Actions to run.
1654 * @return {RunAllAction} Action for use in will.
1656 function runAllActionsAsync(whenTestDone
) {
1657 return new RunAllAction(true, whenTestDone
,
1658 Array
.prototype.slice
.call(arguments
, 1));
1662 * Syntactic sugar for use with will() on a Mock4JS.Mock.
1663 * Creates an action for will() that invokes a callback that the tested code
1664 * passes to a mocked function.
1665 * @param {SaveMockArguments} savedArgs Arguments that will contain the
1666 * callback once the mocked function is called.
1667 * @param {number} callbackParameter Index of the callback parameter in
1669 * @param {...Object} var_args Arguments to pass to the callback.
1670 * @return {CallFunctionAction} Action for use in will().
1672 function invokeCallback(savedArgs
, callbackParameter
, var_args
) {
1673 var callbackArguments
= Array
.prototype.slice
.call(arguments
, 2);
1674 return callFunction(function() {
1675 savedArgs
.arguments
[callbackParameter
].apply(null, callbackArguments
);
1677 // Mock4JS does not clear the saved args after invocation.
1678 // To allow reuse of the same SaveMockArguments for multiple
1679 // invocations with similar arguments, clear them here.
1680 savedArgs
.arguments
.splice(0, savedArgs
.arguments
.length
);
1685 * Mock4JS matcher object that matches the actual argument and the expected
1686 * value iff their JSON represenations are same.
1687 * @param {Object} expectedValue
1690 function MatchJSON(expectedValue
) {
1691 this.expectedValue_
= expectedValue
;
1694 MatchJSON
.prototype = {
1696 * Checks that JSON represenation of the actual and expected arguments are
1698 * @param {Object} actualArgument The argument to match.
1699 * @return {boolean} Result of the comparison.
1701 argumentMatches: function(actualArgument
) {
1702 return JSON
.stringify(this.expectedValue_
) ===
1703 JSON
.stringify(actualArgument
);
1707 * Describes the matcher.
1708 * @return {string} Description of this Mock4JS matcher.
1710 describe: function() {
1711 return 'eqJSON(' + JSON
.stringify(this.expectedValue_
) + ')';
1716 * Builds a MatchJSON argument matcher for a given expected value.
1717 * @param {Object} expectedValue
1718 * @return {MatchJSON} Resulting Mock4JS matcher.
1720 function eqJSON(expectedValue
) {
1721 return new MatchJSON(expectedValue
);
1725 * Mock4JS matcher object that matches the actual argument and the expected
1726 * value iff the the string representation of the actual argument is equal to
1727 * the expected value.
1728 * @param {string} expectedValue
1731 function MatchToString(expectedValue
) {
1732 this.expectedValue_
= expectedValue
;
1735 MatchToString
.prototype = {
1737 * Checks that the the string representation of the actual argument matches
1738 * the expected value.
1739 * @param {*} actualArgument The argument to match.
1740 * @return {boolean} Result of the comparison.
1742 argumentMatches: function(actualArgument
) {
1743 return this.expectedValue_
=== String(actualArgument
);
1747 * Describes the matcher.
1748 * @return {string} Description of this Mock4JS matcher.
1750 describe: function() {
1751 return 'eqToString("' + this.expectedValue_
+ '")';
1756 * Builds a MatchToString argument matcher for a given expected value.
1757 * @param {Object} expectedValue
1758 * @return {MatchToString} Resulting Mock4JS matcher.
1760 function eqToString(expectedValue
) {
1761 return new MatchToString(expectedValue
);
1765 testing
.Test
= Test
;
1766 exports
.testDone
= testDone
;
1767 exports
.assertTrue
= assertTrue
;
1768 exports
.assertFalse
= assertFalse
;
1769 exports
.assertGE
= assertGE
;
1770 exports
.assertGT
= assertGT
;
1771 exports
.assertEquals
= assertEquals
;
1772 exports
.assertLE
= assertLE
;
1773 exports
.assertLT
= assertLT
;
1774 exports
.assertNotEquals
= assertNotEquals
;
1775 exports
.assertNotReached
= assertNotReached
;
1776 exports
.assertAccessibilityOk
= assertAccessibilityOk
;
1777 exports
.callFunction
= callFunction
;
1778 exports
.callFunctionWithSavedArgs
= callFunctionWithSavedArgs
;
1779 exports
.callGlobalWithSavedArgs
= callGlobalWithSavedArgs
;
1780 exports
.eqJSON
= eqJSON
;
1781 exports
.eqToString
= eqToString
;
1782 exports
.expectTrue
= createExpect(assertTrue
);
1783 exports
.expectFalse
= createExpect(assertFalse
);
1784 exports
.expectGE
= createExpect(assertGE
);
1785 exports
.expectGT
= createExpect(assertGT
);
1786 exports
.expectEquals
= createExpect(assertEquals
);
1787 exports
.expectLE
= createExpect(assertLE
);
1788 exports
.expectLT
= createExpect(assertLT
);
1789 exports
.expectNotEquals
= createExpect(assertNotEquals
);
1790 exports
.expectNotReached
= createExpect(assertNotReached
);
1791 exports
.expectAccessibilityOk
= createExpect(assertAccessibilityOk
);
1792 exports
.invokeCallback
= invokeCallback
;
1793 exports
.preloadJavascriptLibraries
= preloadJavascriptLibraries
;
1794 exports
.registerMessageCallback
= registerMessageCallback
;
1795 exports
.registerMockGlobals
= registerMockGlobals
;
1796 exports
.registerMockMessageCallbacks
= registerMockMessageCallbacks
;
1797 exports
.resetTestState
= resetTestState
;
1798 exports
.runAccessibilityAudit
= runAccessibilityAudit
;
1799 exports
.runAllActions
= runAllActions
;
1800 exports
.runAllActionsAsync
= runAllActionsAsync
;
1801 exports
.runTest
= runTest
;
1802 exports
.runTestFunction
= runTestFunction
;
1803 exports
.SaveMockArguments
= SaveMockArguments
;
1804 exports
.DUMMY_URL
= DUMMY_URL
;
1805 exports
.TEST
= TEST
;
1806 exports
.TEST_F
= TEST_F
;
1807 exports
.RUNTIME_TEST_F
= TEST_F
;
1809 exports
.GEN_INCLUDE
= GEN_INCLUDE
;
1810 exports
.WhenTestDone
= WhenTestDone
;
1812 // Import the Mock4JS helpers.
1813 Mock4JS
.addMockSupport(exports
);