OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 GEN('#include "chrome/browser/ui/webui/options/chromeos/shared_options_browserte
st.h"'); |
| 6 |
| 7 /** |
| 8 * Wait for the method specified by |methodName|, on the |object| object, to be |
| 9 * called, then execute |afterFunction|. |
| 10 * @param {*} object Object with callable property named |methodName|. |
| 11 * @param {string} methodName The name of the property on |object| to use as a |
| 12 * callback. |
| 13 * @param {!Function} afterFunction A function to call after object.methodName() |
| 14 * is called. |
| 15 */ |
| 16 function waitForResponse(object, methodName, afterFunction) { |
| 17 var originalCallback = object[methodName]; |
| 18 |
| 19 // Install a wrapper that temporarily replaces the original function. |
| 20 object[methodName] = function() { |
| 21 object[methodName] = originalCallback; |
| 22 originalCallback.apply(this, arguments); |
| 23 afterFunction(); |
| 24 }; |
| 25 } |
| 26 |
| 27 /** |
| 28 * Wait for the global window.onpopstate callback to be called (after a tab |
| 29 * history navigation), then execute |afterFunction|. |
| 30 * @param {!Function} afterFunction A function to call after pop state events. |
| 31 */ |
| 32 function waitForPopstate(afterFunction) { |
| 33 waitForResponse(window, 'onpopstate', afterFunction); |
| 34 } |
| 35 |
| 36 /** |
| 37 * TestFixture for OptionsPage WebUI testing including tab history and support |
| 38 * for preference manipulation. If you don't need the features in the C++ |
| 39 * fixture, use the simpler SharedOptionsWebUITest (above) instead. |
| 40 * @extends {testing.Test} |
| 41 * @constructor |
| 42 */ |
| 43 function SharedOptionsTest() {} |
| 44 |
| 45 SharedOptionsTest.prototype = { |
| 46 __proto__: testing.Test.prototype, |
| 47 |
| 48 /** @override */ |
| 49 browsePreload: 'chrome://settings-frame', |
| 50 |
| 51 /** @override */ |
| 52 typedefCppFixture: 'chromeos::SharedOptionsTest', |
| 53 |
| 54 /** @override */ |
| 55 isAsync: true, |
| 56 |
| 57 /** @override */ |
| 58 setUp: function() { |
| 59 console.log("Setting up SharedOptionsTest.js"); |
| 60 // user-image-stream is a streaming video element used for capturing a |
| 61 // user image during OOBE. |
| 62 this.accessibilityAuditConfig.ignoreSelectors('videoWithoutCaptions', |
| 63 '.user-image-stream'); |
| 64 console.log("Set up SharedOptionsTest.js"); |
| 65 }, |
| 66 |
| 67 /** |
| 68 * Register a mock handler to ensure expectations are met and options pages |
| 69 * behave correctly. |
| 70 */ |
| 71 preLoad: function() { |
| 72 console.log("Preloading SharedOptionsTest.js"); |
| 73 this.makeAndRegisterMockHandler( |
| 74 ['defaultZoomFactorAction', |
| 75 'fetchPrefs', |
| 76 'observePrefs', |
| 77 'setBooleanPref', |
| 78 'setIntegerPref', |
| 79 'setDoublePref', |
| 80 'setStringPref', |
| 81 'setObjectPref', |
| 82 'clearPref', |
| 83 'coreOptionsUserMetricsAction', |
| 84 ]); |
| 85 |
| 86 // Register stubs for methods expected to be called before/during tests. |
| 87 // Specific expectations can be made in the tests themselves. |
| 88 this.mockHandler.stubs().fetchPrefs(ANYTHING); |
| 89 this.mockHandler.stubs().observePrefs(ANYTHING); |
| 90 this.mockHandler.stubs().coreOptionsUserMetricsAction(ANYTHING); |
| 91 console.log("Preloaded SharedOptionsTest.js"); |
| 92 }, |
| 93 |
| 94 /* |
| 95 * Verifies that the correct URLs are listed in the history. Asynchronous. |
| 96 * @param {!Array.<string>} expectedHistory An array of URL paths expected to |
| 97 * be in the tab navigation history, sorted by visit time, including the |
| 98 * current page as the last entry. The base URL (chrome://settings-frame/) |
| 99 * will be prepended to each. An initial 'about:blank' history entry is |
| 100 * assumed and should not be included in this list. |
| 101 * @param {Function=} callback A function to be called after the history has |
| 102 * been verified successfully. May be undefined. |
| 103 * @private |
| 104 */ |
| 105 registerUsers_: function(numUsers, callback) { |
| 106 var self = this; |
| 107 SharedOptionsTest.registerUsersCallback = function() { |
| 108 callback(); |
| 109 }; |
| 110 |
| 111 // The C++ fixture will call registerUsersCallback with the results. |
| 112 chrome.send('sharedOptionsTestRegisterUsers', [numUsers]); |
| 113 }, |
| 114 |
| 115 logInUser_: function(userNum, callback) { |
| 116 var self = this; |
| 117 SharedOptionsTest.logInUserCallback = function() { |
| 118 console.log("logInUserCallback called"); |
| 119 callback(); |
| 120 }; |
| 121 |
| 122 // The C++ fixture will call logInUserCallback with the results. |
| 123 chrome.send('sharedOptionsTestLogInUser', [userNum]); |
| 124 }, |
| 125 |
| 126 addUser_: function(userNum, callback) { |
| 127 console.log("addUSer called"); |
| 128 var self = this; |
| 129 SharedOptionsTest.addUserCallback = function() { |
| 130 console.log("addUserCallback called"); |
| 131 callback(); |
| 132 }; |
| 133 |
| 134 // The C++ fixture will call addUserCallback with the results. |
| 135 chrome.send('sharedOptionsTestAddUser', [userNum]); |
| 136 }, |
| 137 }; |
| 138 |
| 139 SharedOptionsTest.verifyHistoryCallback = null; |
| 140 |
| 141 /** |
| 142 * Set by registerUsers_ to incorporate a followup callback. |
| 143 * @type {Function} |
| 144 */ |
| 145 SharedOptionsTest.registerUsersCallback = null; |
| 146 SharedOptionsTest.logInUserCallback = null; |
| 147 SharedOptionsTest.addUserCallback = null; |
| 148 |
| 149 TEST_F('SharedOptionsTest', 'PRE_Test1', function() { |
| 150 console.log('Starting test!'); |
| 151 // chrome.send('sharedOptionsTestRegisterUsers', [3]); |
| 152 this.registerUsers_(3, testDone);/*function() { |
| 153 testDone(); |
| 154 // Result: Success |
| 155 });*/ |
| 156 }); |
| 157 |
| 158 TEST_F('SharedOptionsTest', 'Test1', function() { |
| 159 console.log('logInUser'); |
| 160 |
| 161 var self = this;t |
| 162 this.logInUser_(0, function() { |
| 163 self.addUser_(1, function() { |
| 164 console.log("Test is done"); |
| 165 testDone(); |
| 166 }); |
| 167 }); |
| 168 |
| 169 // Test fails without an error message. |
| 170 }); |
OLD | NEW |