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 all targets to be hidden. |
| 86 * @param {Array<Element>} targets |
| 87 */ |
| 88 function waitUntilHidden(targets) { |
| 89 function isHidden(el) { return el.hidden; } |
| 90 function ensureTransition(el) { ensureTransitionEndEvent(el, 500); } |
| 91 |
| 92 document.addEventListener('webkitTransitionEnd', function f(e) { |
| 93 if (targets.indexOf(e.target) >= 0 && targets.every(isHidden)) { |
| 94 document.removeEventListener(f, 'webkitTransitionEnd'); |
| 95 testDone(); |
| 96 } |
| 97 }); |
| 98 |
| 99 targets.forEach(ensureTransition); |
| 100 } |
| 101 |
92 // Crashes on Mac only. See http://crbug.com/79181 | 102 // Crashes on Mac only. See http://crbug.com/79181 |
93 GEN('#if defined(OS_MACOSX)'); | 103 GEN('#if defined(OS_MACOSX)'); |
94 GEN('#define MAYBE_testSetBooleanPrefTriggers ' + | 104 GEN('#define MAYBE_testSetBooleanPrefTriggers ' + |
95 'DISABLED_testSetBooleanPrefTriggers'); | 105 'DISABLED_testSetBooleanPrefTriggers'); |
96 GEN('#else'); | 106 GEN('#else'); |
97 GEN('#define MAYBE_testSetBooleanPrefTriggers testSetBooleanPrefTriggers'); | 107 GEN('#define MAYBE_testSetBooleanPrefTriggers testSetBooleanPrefTriggers'); |
98 GEN('#endif // defined(OS_MACOSX)'); | 108 GEN('#endif // defined(OS_MACOSX)'); |
99 | 109 |
100 TEST_F('OptionsWebUITest', 'MAYBE_testSetBooleanPrefTriggers', function() { | 110 TEST_F('OptionsWebUITest', 'MAYBE_testSetBooleanPrefTriggers', function() { |
101 // TODO(dtseng): make generic to click all buttons. | 111 // TODO(dtseng): make generic to click all buttons. |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 /** | 366 /** |
357 * TestFixture for OptionsPage WebUI testing including tab history and support | 367 * TestFixture for OptionsPage WebUI testing including tab history and support |
358 * for preference manipulation. If you don't need the features in the C++ | 368 * for preference manipulation. If you don't need the features in the C++ |
359 * fixture, use the simpler OptionsWebUITest (above) instead. | 369 * fixture, use the simpler OptionsWebUITest (above) instead. |
360 * @extends {testing.Test} | 370 * @extends {testing.Test} |
361 * @constructor | 371 * @constructor |
362 */ | 372 */ |
363 function OptionsWebUIExtendedTest() {} | 373 function OptionsWebUIExtendedTest() {} |
364 | 374 |
365 OptionsWebUIExtendedTest.prototype = { | 375 OptionsWebUIExtendedTest.prototype = { |
366 __proto__: testing.Test.prototype, | 376 __proto__: OptionsWebUITest.prototype, |
367 | |
368 /** @override */ | |
369 browsePreload: 'chrome://settings-frame', | |
370 | 377 |
371 /** @override */ | 378 /** @override */ |
372 typedefCppFixture: 'OptionsBrowserTest', | 379 typedefCppFixture: 'OptionsBrowserTest', |
373 | 380 |
374 testGenPreamble: function() { | 381 testGenPreamble: function() { |
375 // Start with no supervised users managed by this profile. | 382 // Start with no supervised users managed by this profile. |
376 GEN(' ClearPref("' + SUPERVISED_USERS_PREF + '");'); | 383 GEN(' ClearPref("' + SUPERVISED_USERS_PREF + '");'); |
377 }, | 384 }, |
378 | 385 |
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 /** | 386 /** |
391 * Asserts that two non-nested arrays are equal. The arrays must contain only | 387 * Asserts that two non-nested arrays are equal. The arrays must contain only |
392 * plain data types, no nested arrays or other objects. | 388 * plain data types, no nested arrays or other objects. |
393 * @param {Array} expected An array of expected values. | 389 * @param {Array} expected An array of expected values. |
394 * @param {Array} result An array of actual values. | 390 * @param {Array} result An array of actual values. |
395 * @param {boolean} doSort If true, the arrays will be sorted before being | 391 * @param {boolean} doSort If true, the arrays will be sorted before being |
396 * compared. | 392 * compared. |
397 * @param {string} description A brief description for the array of actual | 393 * @param {string} description A brief description for the array of actual |
398 * values, to use in an error message if the arrays differ. | 394 * values, to use in an error message if the arrays differ. |
399 * @private | 395 * @private |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 PageManager.closeOverlay(); | 665 PageManager.closeOverlay(); |
670 self.verifyOpenPages_(['settings', 'languages']); | 666 self.verifyOpenPages_(['settings', 'languages']); |
671 self.verifyHistory_( | 667 self.verifyHistory_( |
672 ['', 'languages', 'addLanguage', 'languages'], | 668 ['', 'languages', 'addLanguage', 'languages'], |
673 function() { | 669 function() { |
674 // Close the layer-1 overlay. | 670 // Close the layer-1 overlay. |
675 PageManager.closeOverlay(); | 671 PageManager.closeOverlay(); |
676 self.verifyOpenPages_(['settings'], ''); | 672 self.verifyOpenPages_(['settings'], ''); |
677 self.verifyHistory_( | 673 self.verifyHistory_( |
678 ['', 'languages', 'addLanguage', 'languages', ''], | 674 ['', 'languages', 'addLanguage', 'languages', ''], |
679 testDone); | 675 function noop() {}); |
| 676 waitUntilHidden([$('overlay-container-1'), $('overlay-container-2')]); |
680 }); | 677 }); |
681 }); | 678 }); |
682 }); | 679 }); |
683 | 680 |
684 // Hashes are maintained separately for each page and are preserved when | 681 // Hashes are maintained separately for each page and are preserved when |
685 // overlays close. | 682 // overlays close. |
686 TEST_F('OptionsWebUIExtendedTest', 'CloseOverlayWithHashes', function() { | 683 TEST_F('OptionsWebUIExtendedTest', 'CloseOverlayWithHashes', function() { |
687 // Open an overlay on top of the search page. | 684 // Open an overlay on top of the search page. |
688 PageManager.showPageByName('search', true, {hash: '#1'}); | 685 PageManager.showPageByName('search', true, {hash: '#1'}); |
689 this.verifyOpenPages_(['settings', 'search'], 'search#1'); | 686 this.verifyOpenPages_(['settings', 'search'], 'search#1'); |
(...skipping 11 matching lines...) Expand all Loading... |
701 this.verifyOpenPages_(['settings', 'search', 'languages'], 'languages#2'); | 698 this.verifyOpenPages_(['settings', 'search', 'languages'], 'languages#2'); |
702 this.verifyHistory_( | 699 this.verifyHistory_( |
703 ['', 'search#1', 'languages#2', 'addLanguage#3', 'languages#2'], | 700 ['', 'search#1', 'languages#2', 'addLanguage#3', 'languages#2'], |
704 function() { | 701 function() { |
705 // Close the layer-1 overlay. | 702 // Close the layer-1 overlay. |
706 PageManager.closeOverlay(); | 703 PageManager.closeOverlay(); |
707 this.verifyOpenPages_(['settings', 'search'], 'search#1'); | 704 this.verifyOpenPages_(['settings', 'search'], 'search#1'); |
708 this.verifyHistory_( | 705 this.verifyHistory_( |
709 ['', 'search#1', 'languages#2', 'addLanguage#3', 'languages#2', | 706 ['', 'search#1', 'languages#2', 'addLanguage#3', 'languages#2', |
710 'search#1'], | 707 'search#1'], |
711 testDone); | 708 function noop() {}); |
| 709 waitUntilHidden([$('overlay-container-1'), $('overlay-container-2')]); |
712 }.bind(this)); | 710 }.bind(this)); |
713 }.bind(this)); | 711 }.bind(this)); |
714 }); | 712 }); |
715 | 713 |
716 // Test that closing an overlay that did not push history when opening does not | 714 // Test that closing an overlay that did not push history when opening does not |
717 // again push history. | 715 // again push history. |
718 TEST_F('OptionsWebUIExtendedTest', 'CloseOverlayNoHistory', function() { | 716 TEST_F('OptionsWebUIExtendedTest', 'CloseOverlayNoHistory', function() { |
719 // Open the do not track confirmation prompt. | 717 // Open the do not track confirmation prompt. |
720 PageManager.showPageByName('doNotTrackConfirm', false); | 718 PageManager.showPageByName('doNotTrackConfirm', false); |
721 | 719 |
722 // Opening the prompt does not add to the history. | 720 // Opening the prompt does not add to the history. |
723 this.verifyHistory_([''], function() { | 721 this.verifyHistory_([''], function() { |
724 // Close the overlay. | 722 // Close the overlay. |
725 PageManager.closeOverlay(); | 723 PageManager.closeOverlay(); |
726 // Still no history changes. | 724 // Still no history changes. |
727 this.verifyHistory_([''], testDone); | 725 this.verifyHistory_([''], function noop() {}); |
| 726 waitUntilHidden([$('overlay-container-1')]); |
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 |