| Index: chrome/browser/ui/webui/options/chromeos/shared_options_browsertest.js
|
| diff --git a/chrome/browser/ui/webui/options/chromeos/shared_options_browsertest.js b/chrome/browser/ui/webui/options/chromeos/shared_options_browsertest.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..58496dd73c58eb668932122dec43d2fddd33644d
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/webui/options/chromeos/shared_options_browsertest.js
|
| @@ -0,0 +1,170 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +GEN('#include "chrome/browser/ui/webui/options/chromeos/shared_options_browsertest.h"');
|
| +
|
| +/**
|
| + * Wait for the method specified by |methodName|, on the |object| object, to be
|
| + * called, then execute |afterFunction|.
|
| + * @param {*} object Object with callable property named |methodName|.
|
| + * @param {string} methodName The name of the property on |object| to use as a
|
| + * callback.
|
| + * @param {!Function} afterFunction A function to call after object.methodName()
|
| + * is called.
|
| + */
|
| +function waitForResponse(object, methodName, afterFunction) {
|
| + var originalCallback = object[methodName];
|
| +
|
| + // Install a wrapper that temporarily replaces the original function.
|
| + object[methodName] = function() {
|
| + object[methodName] = originalCallback;
|
| + originalCallback.apply(this, arguments);
|
| + afterFunction();
|
| + };
|
| +}
|
| +
|
| +/**
|
| + * Wait for the global window.onpopstate callback to be called (after a tab
|
| + * history navigation), then execute |afterFunction|.
|
| + * @param {!Function} afterFunction A function to call after pop state events.
|
| + */
|
| +function waitForPopstate(afterFunction) {
|
| + waitForResponse(window, 'onpopstate', afterFunction);
|
| +}
|
| +
|
| +/**
|
| + * TestFixture for OptionsPage WebUI testing including tab history and support
|
| + * for preference manipulation. If you don't need the features in the C++
|
| + * fixture, use the simpler SharedOptionsWebUITest (above) instead.
|
| + * @extends {testing.Test}
|
| + * @constructor
|
| + */
|
| +function SharedOptionsTest() {}
|
| +
|
| +SharedOptionsTest.prototype = {
|
| + __proto__: testing.Test.prototype,
|
| +
|
| + /** @override */
|
| + browsePreload: 'chrome://settings-frame',
|
| +
|
| + /** @override */
|
| + typedefCppFixture: 'chromeos::SharedOptionsTest',
|
| +
|
| + /** @override */
|
| + isAsync: true,
|
| +
|
| + /** @override */
|
| + setUp: function() {
|
| + console.log("Setting up SharedOptionsTest.js");
|
| + // user-image-stream is a streaming video element used for capturing a
|
| + // user image during OOBE.
|
| + this.accessibilityAuditConfig.ignoreSelectors('videoWithoutCaptions',
|
| + '.user-image-stream');
|
| + console.log("Set up SharedOptionsTest.js");
|
| + },
|
| +
|
| + /**
|
| + * Register a mock handler to ensure expectations are met and options pages
|
| + * behave correctly.
|
| + */
|
| + preLoad: function() {
|
| + console.log("Preloading SharedOptionsTest.js");
|
| + this.makeAndRegisterMockHandler(
|
| + ['defaultZoomFactorAction',
|
| + 'fetchPrefs',
|
| + 'observePrefs',
|
| + 'setBooleanPref',
|
| + 'setIntegerPref',
|
| + 'setDoublePref',
|
| + 'setStringPref',
|
| + 'setObjectPref',
|
| + 'clearPref',
|
| + 'coreOptionsUserMetricsAction',
|
| + ]);
|
| +
|
| + // Register stubs for methods expected to be called before/during tests.
|
| + // Specific expectations can be made in the tests themselves.
|
| + this.mockHandler.stubs().fetchPrefs(ANYTHING);
|
| + this.mockHandler.stubs().observePrefs(ANYTHING);
|
| + this.mockHandler.stubs().coreOptionsUserMetricsAction(ANYTHING);
|
| + console.log("Preloaded SharedOptionsTest.js");
|
| + },
|
| +
|
| + /*
|
| + * Verifies that the correct URLs are listed in the history. Asynchronous.
|
| + * @param {!Array.<string>} expectedHistory An array of URL paths expected to
|
| + * be in the tab navigation history, sorted by visit time, including the
|
| + * current page as the last entry. The base URL (chrome://settings-frame/)
|
| + * will be prepended to each. An initial 'about:blank' history entry is
|
| + * assumed and should not be included in this list.
|
| + * @param {Function=} callback A function to be called after the history has
|
| + * been verified successfully. May be undefined.
|
| + * @private
|
| + */
|
| + registerUsers_: function(numUsers, callback) {
|
| + var self = this;
|
| + SharedOptionsTest.registerUsersCallback = function() {
|
| + callback();
|
| + };
|
| +
|
| + // The C++ fixture will call registerUsersCallback with the results.
|
| + chrome.send('sharedOptionsTestRegisterUsers', [numUsers]);
|
| + },
|
| +
|
| + logInUser_: function(userNum, callback) {
|
| + var self = this;
|
| + SharedOptionsTest.logInUserCallback = function() {
|
| + console.log("logInUserCallback called");
|
| + callback();
|
| + };
|
| +
|
| + // The C++ fixture will call logInUserCallback with the results.
|
| + chrome.send('sharedOptionsTestLogInUser', [userNum]);
|
| + },
|
| +
|
| + addUser_: function(userNum, callback) {
|
| + console.log("addUSer called");
|
| + var self = this;
|
| + SharedOptionsTest.addUserCallback = function() {
|
| + console.log("addUserCallback called");
|
| + callback();
|
| + };
|
| +
|
| + // The C++ fixture will call addUserCallback with the results.
|
| + chrome.send('sharedOptionsTestAddUser', [userNum]);
|
| + },
|
| +};
|
| +
|
| +SharedOptionsTest.verifyHistoryCallback = null;
|
| +
|
| +/**
|
| + * Set by registerUsers_ to incorporate a followup callback.
|
| + * @type {Function}
|
| + */
|
| +SharedOptionsTest.registerUsersCallback = null;
|
| +SharedOptionsTest.logInUserCallback = null;
|
| +SharedOptionsTest.addUserCallback = null;
|
| +
|
| +TEST_F('SharedOptionsTest', 'PRE_Test1', function() {
|
| + console.log('Starting test!');
|
| +// chrome.send('sharedOptionsTestRegisterUsers', [3]);
|
| + this.registerUsers_(3, testDone);/*function() {
|
| + testDone();
|
| + // Result: Success
|
| + });*/
|
| +});
|
| +
|
| +TEST_F('SharedOptionsTest', 'Test1', function() {
|
| + console.log('logInUser');
|
| +
|
| + var self = this;t
|
| + this.logInUser_(0, function() {
|
| + self.addUser_(1, function() {
|
| + console.log("Test is done");
|
| + testDone();
|
| + });
|
| + });
|
| +
|
| + // Test fails without an error message.
|
| +});
|
|
|