Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / chrome / test / chromedriver / js / test.js
blob6187176ed10dc08304e95fb9b8c7459b4f0c207a
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.
5 /**
6 * Asserts the value is true.
7 * @param {*} x The value to assert.
8 */
9 function assert(x) {
10 if (!x)
11 throw new Error();
14 /**
15 * Asserts the values are equal.
16 * @param {*} x The value to assert.
18 function assertEquals(x, y) {
19 if (x != y)
20 throw new Error(x + ' != ' + y);
23 /**
24 * Runs the given test.
25 * @param {function()} test The test to run.
26 * @param {function()} onPass The function to call if and when the
27 * function passes.
29 function runTest(test, onPass) {
30 var shouldContinue = true;
31 var runner = {
32 waitForAsync: function(description) {
33 shouldContinue = false;
34 console.log('Waiting for ', description);
37 continueTesting: function() {
38 shouldContinue = true;
39 window.setTimeout(function() {
40 if (shouldContinue)
41 onPass();
42 }, 0);
46 test(runner);
47 if (shouldContinue)
48 onPass();
51 /**
52 * Runs all tests and reports the results via the console.
54 function runTests() {
55 var tests = [];
56 for (var i in window) {
57 if (i.indexOf('test') == 0)
58 tests.push(window[i]);
60 console.log('Running %d tests...', tests.length);
62 var testNo = 0;
63 function runNextTest() {
64 if (testNo >= tests.length) {
65 console.log('All tests passed');
66 return;
69 function onPass() {
70 testNo++;
71 runNextTest();
74 var test = tests[testNo];
75 console.log('Running (%d/%d) -- %s', testNo + 1, tests.length, test.name);
76 runTest(test, onPass);
78 runNextTest();
81 window.addEventListener('load', function() {
82 runTests();
83 });