| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 GEN_INCLUDE(['options_browsertest_base.js']); |
| 5 GEN('#include "chrome/browser/ui/webui/options/options_browsertest.h"'); | 6 GEN('#include "chrome/browser/ui/webui/options/options_browsertest.h"'); |
| 6 | 7 |
| 7 /** @const */ var SUPERVISED_USERS_PREF = 'profile.managed_users'; | 8 /** @const */ var SUPERVISED_USERS_PREF = 'profile.managed_users'; |
| 8 | 9 |
| 9 /** | 10 /** |
| 10 * Wait for the method specified by |methodName|, on the |object| object, to be | 11 * Wait for the method specified by |methodName|, on the |object| object, to be |
| 11 * called, then execute |afterFunction|. | 12 * called, then execute |afterFunction|. |
| 12 * @param {*} object Object with callable property named |methodName|. | 13 * @param {*} object Object with callable property named |methodName|. |
| 13 * @param {string} methodName The name of the property on |object| to use as a | 14 * @param {string} methodName The name of the property on |object| to use as a |
| 14 * callback. | 15 * callback. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 36 } | 37 } |
| 37 | 38 |
| 38 /** | 39 /** |
| 39 * TestFixture for OptionsPage WebUI testing. | 40 * TestFixture for OptionsPage WebUI testing. |
| 40 * @extends {testing.Test} | 41 * @extends {testing.Test} |
| 41 * @constructor | 42 * @constructor |
| 42 */ | 43 */ |
| 43 function OptionsWebUITest() {} | 44 function OptionsWebUITest() {} |
| 44 | 45 |
| 45 OptionsWebUITest.prototype = { | 46 OptionsWebUITest.prototype = { |
| 46 __proto__: testing.Test.prototype, | 47 __proto__: OptionsBrowsertestBase.prototype, |
| 47 | |
| 48 /** @override */ | |
| 49 accessibilityIssuesAreErrors: true, | |
| 50 | |
| 51 /** @override */ | |
| 52 setUp: function() { | |
| 53 // user-image-stream is a streaming video element used for capturing a | |
| 54 // user image during OOBE. | |
| 55 this.accessibilityAuditConfig.ignoreSelectors('videoWithoutCaptions', | |
| 56 '.user-image-stream'); | |
| 57 }, | |
| 58 | 48 |
| 59 /** | 49 /** |
| 60 * Browse to the options page & call our preLoad(). | 50 * Browse to the options page & call our preLoad(). |
| 51 * @override |
| 61 */ | 52 */ |
| 62 browsePreload: 'chrome://settings-frame', | 53 browsePreload: 'chrome://settings-frame', |
| 63 | 54 |
| 55 /** @override */ |
| 64 isAsync: true, | 56 isAsync: true, |
| 65 | 57 |
| 66 /** | 58 /** |
| 67 * Register a mock handler to ensure expectations are met and options pages | 59 * Register a mock handler to ensure expectations are met and options pages |
| 68 * behave correctly. | 60 * behave correctly. |
| 69 */ | 61 */ |
| 70 preLoad: function() { | 62 preLoad: function() { |
| 71 this.makeAndRegisterMockHandler( | 63 this.makeAndRegisterMockHandler( |
| 72 ['defaultZoomFactorAction', | 64 ['defaultZoomFactorAction', |
| 73 'fetchPrefs', | 65 'fetchPrefs', |
| 74 'observePrefs', | 66 'observePrefs', |
| 75 'setBooleanPref', | 67 'setBooleanPref', |
| 76 'setIntegerPref', | 68 'setIntegerPref', |
| 77 'setDoublePref', | 69 'setDoublePref', |
| 78 'setStringPref', | 70 'setStringPref', |
| 79 'setObjectPref', | 71 'setObjectPref', |
| 80 'clearPref', | 72 'clearPref', |
| 81 'coreOptionsUserMetricsAction', | 73 'coreOptionsUserMetricsAction', |
| 82 ]); | 74 ]); |
| 83 | 75 |
| 84 // Register stubs for methods expected to be called before/during tests. | 76 // Register stubs for methods expected to be called before/during tests. |
| 85 // Specific expectations can be made in the tests themselves. | 77 // Specific expectations can be made in the tests themselves. |
| 86 this.mockHandler.stubs().fetchPrefs(ANYTHING); | 78 this.mockHandler.stubs().fetchPrefs(ANYTHING); |
| 87 this.mockHandler.stubs().observePrefs(ANYTHING); | 79 this.mockHandler.stubs().observePrefs(ANYTHING); |
| 88 this.mockHandler.stubs().coreOptionsUserMetricsAction(ANYTHING); | 80 this.mockHandler.stubs().coreOptionsUserMetricsAction(ANYTHING); |
| 89 }, | 81 }, |
| 90 }; | 82 }; |
| 91 | 83 |
| 84 /** |
| 85 * Wait for overlay-container-1 and overlay-container-2 to be hidden. |
| 86 */ |
| 87 function waitForOverlaysToHide() { |
| 88 var overlay1 = $('overlay-container-1'); |
| 89 var overlay2 = $('overlay-container-2'); |
| 90 |
| 91 document.addEventListener('webkitTransitionEnd', function f(e) { |
| 92 if ((e.target.id == overlay1.id || e.target.id == overlay2.id) && |
| 93 overlay1.hidden && overlay2.hidden) { |
| 94 document.removeEventListener(f, 'webkitTransitionEnd'); |
| 95 testDone(); |
| 96 } |
| 97 }); |
| 98 |
| 99 if (!overlay1.hidden) |
| 100 ensureTransitionEndEvent(overlay1, 500); |
| 101 if (!overlay2.hidden) |
| 102 ensureTransitionEndEvent(overlay2, 500); |
| 103 } |
| 104 |
| 92 // Crashes on Mac only. See http://crbug.com/79181 | 105 // Crashes on Mac only. See http://crbug.com/79181 |
| 93 GEN('#if defined(OS_MACOSX)'); | 106 GEN('#if defined(OS_MACOSX)'); |
| 94 GEN('#define MAYBE_testSetBooleanPrefTriggers ' + | 107 GEN('#define MAYBE_testSetBooleanPrefTriggers ' + |
| 95 'DISABLED_testSetBooleanPrefTriggers'); | 108 'DISABLED_testSetBooleanPrefTriggers'); |
| 96 GEN('#else'); | 109 GEN('#else'); |
| 97 GEN('#define MAYBE_testSetBooleanPrefTriggers testSetBooleanPrefTriggers'); | 110 GEN('#define MAYBE_testSetBooleanPrefTriggers testSetBooleanPrefTriggers'); |
| 98 GEN('#endif // defined(OS_MACOSX)'); | 111 GEN('#endif // defined(OS_MACOSX)'); |
| 99 | 112 |
| 100 TEST_F('OptionsWebUITest', 'MAYBE_testSetBooleanPrefTriggers', function() { | 113 TEST_F('OptionsWebUITest', 'MAYBE_testSetBooleanPrefTriggers', function() { |
| 101 // TODO(dtseng): make generic to click all buttons. | 114 // TODO(dtseng): make generic to click all buttons. |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 /** | 369 /** |
| 357 * TestFixture for OptionsPage WebUI testing including tab history and support | 370 * TestFixture for OptionsPage WebUI testing including tab history and support |
| 358 * for preference manipulation. If you don't need the features in the C++ | 371 * for preference manipulation. If you don't need the features in the C++ |
| 359 * fixture, use the simpler OptionsWebUITest (above) instead. | 372 * fixture, use the simpler OptionsWebUITest (above) instead. |
| 360 * @extends {testing.Test} | 373 * @extends {testing.Test} |
| 361 * @constructor | 374 * @constructor |
| 362 */ | 375 */ |
| 363 function OptionsWebUIExtendedTest() {} | 376 function OptionsWebUIExtendedTest() {} |
| 364 | 377 |
| 365 OptionsWebUIExtendedTest.prototype = { | 378 OptionsWebUIExtendedTest.prototype = { |
| 366 __proto__: testing.Test.prototype, | 379 __proto__: OptionsWebUITest.prototype, |
| 367 | |
| 368 /** @override */ | |
| 369 browsePreload: 'chrome://settings-frame', | |
| 370 | 380 |
| 371 /** @override */ | 381 /** @override */ |
| 372 typedefCppFixture: 'OptionsBrowserTest', | 382 typedefCppFixture: 'OptionsBrowserTest', |
| 373 | 383 |
| 374 testGenPreamble: function() { | 384 testGenPreamble: function() { |
| 375 // Start with no supervised users managed by this profile. | 385 // Start with no supervised users managed by this profile. |
| 376 GEN(' ClearPref("' + SUPERVISED_USERS_PREF + '");'); | 386 GEN(' ClearPref("' + SUPERVISED_USERS_PREF + '");'); |
| 377 }, | 387 }, |
| 378 | 388 |
| 379 /** @override */ | |
| 380 isAsync: true, | |
| 381 | |
| 382 /** @override */ | |
| 383 setUp: function() { | |
| 384 // user-image-stream is a streaming video element used for capturing a | |
| 385 // user image during OOBE. | |
| 386 this.accessibilityAuditConfig.ignoreSelectors('videoWithoutCaptions', | |
| 387 '.user-image-stream'); | |
| 388 }, | |
| 389 | |
| 390 /** | 389 /** |
| 391 * Asserts that two non-nested arrays are equal. The arrays must contain only | 390 * Asserts that two non-nested arrays are equal. The arrays must contain only |
| 392 * plain data types, no nested arrays or other objects. | 391 * plain data types, no nested arrays or other objects. |
| 393 * @param {Array} expected An array of expected values. | 392 * @param {Array} expected An array of expected values. |
| 394 * @param {Array} result An array of actual values. | 393 * @param {Array} result An array of actual values. |
| 395 * @param {boolean} doSort If true, the arrays will be sorted before being | 394 * @param {boolean} doSort If true, the arrays will be sorted before being |
| 396 * compared. | 395 * compared. |
| 397 * @param {string} description A brief description for the array of actual | 396 * @param {string} description A brief description for the array of actual |
| 398 * values, to use in an error message if the arrays differ. | 397 * values, to use in an error message if the arrays differ. |
| 399 * @private | 398 * @private |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 PageManager.closeOverlay(); | 668 PageManager.closeOverlay(); |
| 670 self.verifyOpenPages_(['settings', 'languages']); | 669 self.verifyOpenPages_(['settings', 'languages']); |
| 671 self.verifyHistory_( | 670 self.verifyHistory_( |
| 672 ['', 'languages', 'addLanguage', 'languages'], | 671 ['', 'languages', 'addLanguage', 'languages'], |
| 673 function() { | 672 function() { |
| 674 // Close the layer-1 overlay. | 673 // Close the layer-1 overlay. |
| 675 PageManager.closeOverlay(); | 674 PageManager.closeOverlay(); |
| 676 self.verifyOpenPages_(['settings'], ''); | 675 self.verifyOpenPages_(['settings'], ''); |
| 677 self.verifyHistory_( | 676 self.verifyHistory_( |
| 678 ['', 'languages', 'addLanguage', 'languages', ''], | 677 ['', 'languages', 'addLanguage', 'languages', ''], |
| 679 testDone); | 678 waitForOverlaysToHide); |
| 680 }); | 679 }); |
| 681 }); | 680 }); |
| 682 }); | 681 }); |
| 683 | 682 |
| 684 // Hashes are maintained separately for each page and are preserved when | 683 // Hashes are maintained separately for each page and are preserved when |
| 685 // overlays close. | 684 // overlays close. |
| 686 TEST_F('OptionsWebUIExtendedTest', 'CloseOverlayWithHashes', function() { | 685 TEST_F('OptionsWebUIExtendedTest', 'CloseOverlayWithHashes', function() { |
| 687 // Open an overlay on top of the search page. | 686 // Open an overlay on top of the search page. |
| 688 PageManager.showPageByName('search', true, {hash: '#1'}); | 687 PageManager.showPageByName('search', true, {hash: '#1'}); |
| 689 this.verifyOpenPages_(['settings', 'search'], 'search#1'); | 688 this.verifyOpenPages_(['settings', 'search'], 'search#1'); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 701 this.verifyOpenPages_(['settings', 'search', 'languages'], 'languages#2'); | 700 this.verifyOpenPages_(['settings', 'search', 'languages'], 'languages#2'); |
| 702 this.verifyHistory_( | 701 this.verifyHistory_( |
| 703 ['', 'search#1', 'languages#2', 'addLanguage#3', 'languages#2'], | 702 ['', 'search#1', 'languages#2', 'addLanguage#3', 'languages#2'], |
| 704 function() { | 703 function() { |
| 705 // Close the layer-1 overlay. | 704 // Close the layer-1 overlay. |
| 706 PageManager.closeOverlay(); | 705 PageManager.closeOverlay(); |
| 707 this.verifyOpenPages_(['settings', 'search'], 'search#1'); | 706 this.verifyOpenPages_(['settings', 'search'], 'search#1'); |
| 708 this.verifyHistory_( | 707 this.verifyHistory_( |
| 709 ['', 'search#1', 'languages#2', 'addLanguage#3', 'languages#2', | 708 ['', 'search#1', 'languages#2', 'addLanguage#3', 'languages#2', |
| 710 'search#1'], | 709 'search#1'], |
| 711 testDone); | 710 waitForOverlaysToHide); |
| 712 }.bind(this)); | 711 }.bind(this)); |
| 713 }.bind(this)); | 712 }.bind(this)); |
| 714 }); | 713 }); |
| 715 | 714 |
| 716 // Test that closing an overlay that did not push history when opening does not | 715 // Test that closing an overlay that did not push history when opening does not |
| 717 // again push history. | 716 // again push history. |
| 718 TEST_F('OptionsWebUIExtendedTest', 'CloseOverlayNoHistory', function() { | 717 TEST_F('OptionsWebUIExtendedTest', 'CloseOverlayNoHistory', function() { |
| 719 // Open the do not track confirmation prompt. | 718 // Open the do not track confirmation prompt. |
| 720 PageManager.showPageByName('doNotTrackConfirm', false); | 719 PageManager.showPageByName('doNotTrackConfirm', false); |
| 721 | 720 |
| 722 // Opening the prompt does not add to the history. | 721 // Opening the prompt does not add to the history. |
| 723 this.verifyHistory_([''], function() { | 722 this.verifyHistory_([''], function() { |
| 724 // Close the overlay. | 723 // Close the overlay. |
| 725 PageManager.closeOverlay(); | 724 PageManager.closeOverlay(); |
| 726 // Still no history changes. | 725 // Still no history changes. |
| 727 this.verifyHistory_([''], testDone); | 726 this.verifyHistory_([''], waitForOverlaysToHide); |
| 728 }.bind(this)); | 727 }.bind(this)); |
| 729 }); | 728 }); |
| 730 | 729 |
| 731 // Make sure an overlay isn't closed (even temporarily) when another overlay is | 730 // Make sure an overlay isn't closed (even temporarily) when another overlay is |
| 732 // opened on top. | 731 // opened on top. |
| 733 TEST_F('OptionsWebUIExtendedTest', 'OverlayAboveNoReset', function() { | 732 TEST_F('OptionsWebUIExtendedTest', 'OverlayAboveNoReset', function() { |
| 734 // Open a layer-1 overlay. | 733 // Open a layer-1 overlay. |
| 735 PageManager.showPageByName('languages', true); | 734 PageManager.showPageByName('languages', true); |
| 736 this.verifyOpenPages_(['settings', 'languages']); | 735 this.verifyOpenPages_(['settings', 'languages']); |
| 737 | 736 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 __proto__: OptionsWebUIExtendedTest.prototype, | 872 __proto__: OptionsWebUIExtendedTest.prototype, |
| 874 | 873 |
| 875 /** @override */ | 874 /** @override */ |
| 876 browsePreload: 'chrome://settings-frame/nonexistantPage', | 875 browsePreload: 'chrome://settings-frame/nonexistantPage', |
| 877 }; | 876 }; |
| 878 | 877 |
| 879 TEST_F('OptionsWebUIRedirectTest', 'TestURL', function() { | 878 TEST_F('OptionsWebUIRedirectTest', 'TestURL', function() { |
| 880 assertEquals('chrome://settings-frame/', document.location.href); | 879 assertEquals('chrome://settings-frame/', document.location.href); |
| 881 this.verifyHistory_([''], testDone); | 880 this.verifyHistory_([''], testDone); |
| 882 }); | 881 }); |
| OLD | NEW |