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 to be hidden. | |
86 */ | |
87 function waitForSingleOverlayToHide() { | |
88 var overlay1 = $('overlay-container-1'); | |
89 | |
90 document.addEventListener('webkitTransitionEnd', function f(e) { | |
91 if (e.target.id == overlay1.id && overlay1.hidden) { | |
92 document.removeEventListener(f, 'webkitTransitionEnd'); | |
93 testDone(); | |
94 } | |
95 }); | |
96 | |
97 ensureTransitionEndEvent(overlay1, 500); | |
98 } | |
99 | |
100 /** | |
101 * Wait for overlay-container-1 and overlay-container-2 to be hidden. | |
102 */ | |
103 function waitForBothOverlaysToHide() { | |
104 var overlay1 = $('overlay-container-1'); | |
105 var overlay2 = $('overlay-container-2'); | |
106 | |
107 document.addEventListener('webkitTransitionEnd', function f(e) { | |
108 if ((e.target.id == overlay1.id || e.target.id == overlay2.id) && | |
109 overlay1.hidden && overlay2.hidden) { | |
110 document.removeEventListener(f, 'webkitTransitionEnd'); | |
111 testDone(); | |
112 } | |
113 }); | |
114 | |
115 ensureTransitionEndEvent(overlay1, 500); | |
116 ensureTransitionEndEvent(overlay2, 500); | |
117 } | |
Dan Beam
2014/12/03 00:55:22
dedupe the cotents of these 2 methods, e.g.:
/**
Dan Beam
2014/12/03 00:55:42
contents
hcarmona
2014/12/04 00:12:34
Done.
| |
118 | |
92 // Crashes on Mac only. See http://crbug.com/79181 | 119 // Crashes on Mac only. See http://crbug.com/79181 |
93 GEN('#if defined(OS_MACOSX)'); | 120 GEN('#if defined(OS_MACOSX)'); |
94 GEN('#define MAYBE_testSetBooleanPrefTriggers ' + | 121 GEN('#define MAYBE_testSetBooleanPrefTriggers ' + |
95 'DISABLED_testSetBooleanPrefTriggers'); | 122 'DISABLED_testSetBooleanPrefTriggers'); |
96 GEN('#else'); | 123 GEN('#else'); |
97 GEN('#define MAYBE_testSetBooleanPrefTriggers testSetBooleanPrefTriggers'); | 124 GEN('#define MAYBE_testSetBooleanPrefTriggers testSetBooleanPrefTriggers'); |
98 GEN('#endif // defined(OS_MACOSX)'); | 125 GEN('#endif // defined(OS_MACOSX)'); |
99 | 126 |
100 TEST_F('OptionsWebUITest', 'MAYBE_testSetBooleanPrefTriggers', function() { | 127 TEST_F('OptionsWebUITest', 'MAYBE_testSetBooleanPrefTriggers', function() { |
101 // TODO(dtseng): make generic to click all buttons. | 128 // TODO(dtseng): make generic to click all buttons. |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 /** | 383 /** |
357 * TestFixture for OptionsPage WebUI testing including tab history and support | 384 * TestFixture for OptionsPage WebUI testing including tab history and support |
358 * for preference manipulation. If you don't need the features in the C++ | 385 * for preference manipulation. If you don't need the features in the C++ |
359 * fixture, use the simpler OptionsWebUITest (above) instead. | 386 * fixture, use the simpler OptionsWebUITest (above) instead. |
360 * @extends {testing.Test} | 387 * @extends {testing.Test} |
361 * @constructor | 388 * @constructor |
362 */ | 389 */ |
363 function OptionsWebUIExtendedTest() {} | 390 function OptionsWebUIExtendedTest() {} |
364 | 391 |
365 OptionsWebUIExtendedTest.prototype = { | 392 OptionsWebUIExtendedTest.prototype = { |
366 __proto__: testing.Test.prototype, | 393 __proto__: OptionsWebUITest.prototype, |
367 | |
368 /** @override */ | |
369 browsePreload: 'chrome://settings-frame', | |
370 | 394 |
371 /** @override */ | 395 /** @override */ |
372 typedefCppFixture: 'OptionsBrowserTest', | 396 typedefCppFixture: 'OptionsBrowserTest', |
373 | 397 |
374 testGenPreamble: function() { | 398 testGenPreamble: function() { |
375 // Start with no supervised users managed by this profile. | 399 // Start with no supervised users managed by this profile. |
376 GEN(' ClearPref("' + SUPERVISED_USERS_PREF + '");'); | 400 GEN(' ClearPref("' + SUPERVISED_USERS_PREF + '");'); |
377 }, | 401 }, |
378 | 402 |
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 /** | 403 /** |
391 * Asserts that two non-nested arrays are equal. The arrays must contain only | 404 * Asserts that two non-nested arrays are equal. The arrays must contain only |
392 * plain data types, no nested arrays or other objects. | 405 * plain data types, no nested arrays or other objects. |
393 * @param {Array} expected An array of expected values. | 406 * @param {Array} expected An array of expected values. |
394 * @param {Array} result An array of actual values. | 407 * @param {Array} result An array of actual values. |
395 * @param {boolean} doSort If true, the arrays will be sorted before being | 408 * @param {boolean} doSort If true, the arrays will be sorted before being |
396 * compared. | 409 * compared. |
397 * @param {string} description A brief description for the array of actual | 410 * @param {string} description A brief description for the array of actual |
398 * values, to use in an error message if the arrays differ. | 411 * values, to use in an error message if the arrays differ. |
399 * @private | 412 * @private |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
669 PageManager.closeOverlay(); | 682 PageManager.closeOverlay(); |
670 self.verifyOpenPages_(['settings', 'languages']); | 683 self.verifyOpenPages_(['settings', 'languages']); |
671 self.verifyHistory_( | 684 self.verifyHistory_( |
672 ['', 'languages', 'addLanguage', 'languages'], | 685 ['', 'languages', 'addLanguage', 'languages'], |
673 function() { | 686 function() { |
674 // Close the layer-1 overlay. | 687 // Close the layer-1 overlay. |
675 PageManager.closeOverlay(); | 688 PageManager.closeOverlay(); |
676 self.verifyOpenPages_(['settings'], ''); | 689 self.verifyOpenPages_(['settings'], ''); |
677 self.verifyHistory_( | 690 self.verifyHistory_( |
678 ['', 'languages', 'addLanguage', 'languages', ''], | 691 ['', 'languages', 'addLanguage', 'languages', ''], |
679 testDone); | 692 waitForBothOverlaysToHide); |
680 }); | 693 }); |
681 }); | 694 }); |
682 }); | 695 }); |
683 | 696 |
684 // Hashes are maintained separately for each page and are preserved when | 697 // Hashes are maintained separately for each page and are preserved when |
685 // overlays close. | 698 // overlays close. |
686 TEST_F('OptionsWebUIExtendedTest', 'CloseOverlayWithHashes', function() { | 699 TEST_F('OptionsWebUIExtendedTest', 'CloseOverlayWithHashes', function() { |
687 // Open an overlay on top of the search page. | 700 // Open an overlay on top of the search page. |
688 PageManager.showPageByName('search', true, {hash: '#1'}); | 701 PageManager.showPageByName('search', true, {hash: '#1'}); |
689 this.verifyOpenPages_(['settings', 'search'], 'search#1'); | 702 this.verifyOpenPages_(['settings', 'search'], 'search#1'); |
(...skipping 11 matching lines...) Expand all Loading... | |
701 this.verifyOpenPages_(['settings', 'search', 'languages'], 'languages#2'); | 714 this.verifyOpenPages_(['settings', 'search', 'languages'], 'languages#2'); |
702 this.verifyHistory_( | 715 this.verifyHistory_( |
703 ['', 'search#1', 'languages#2', 'addLanguage#3', 'languages#2'], | 716 ['', 'search#1', 'languages#2', 'addLanguage#3', 'languages#2'], |
704 function() { | 717 function() { |
705 // Close the layer-1 overlay. | 718 // Close the layer-1 overlay. |
706 PageManager.closeOverlay(); | 719 PageManager.closeOverlay(); |
707 this.verifyOpenPages_(['settings', 'search'], 'search#1'); | 720 this.verifyOpenPages_(['settings', 'search'], 'search#1'); |
708 this.verifyHistory_( | 721 this.verifyHistory_( |
709 ['', 'search#1', 'languages#2', 'addLanguage#3', 'languages#2', | 722 ['', 'search#1', 'languages#2', 'addLanguage#3', 'languages#2', |
710 'search#1'], | 723 'search#1'], |
711 testDone); | 724 waitForBothOverlaysToHide); |
712 }.bind(this)); | 725 }.bind(this)); |
713 }.bind(this)); | 726 }.bind(this)); |
714 }); | 727 }); |
715 | 728 |
716 // Test that closing an overlay that did not push history when opening does not | 729 // Test that closing an overlay that did not push history when opening does not |
717 // again push history. | 730 // again push history. |
718 TEST_F('OptionsWebUIExtendedTest', 'CloseOverlayNoHistory', function() { | 731 TEST_F('OptionsWebUIExtendedTest', 'CloseOverlayNoHistory', function() { |
719 // Open the do not track confirmation prompt. | 732 // Open the do not track confirmation prompt. |
720 PageManager.showPageByName('doNotTrackConfirm', false); | 733 PageManager.showPageByName('doNotTrackConfirm', false); |
721 | 734 |
722 // Opening the prompt does not add to the history. | 735 // Opening the prompt does not add to the history. |
723 this.verifyHistory_([''], function() { | 736 this.verifyHistory_([''], function() { |
724 // Close the overlay. | 737 // Close the overlay. |
725 PageManager.closeOverlay(); | 738 PageManager.closeOverlay(); |
726 // Still no history changes. | 739 // Still no history changes. |
727 this.verifyHistory_([''], testDone); | 740 this.verifyHistory_([''], waitForSingleOverlayToHide); |
728 }.bind(this)); | 741 }.bind(this)); |
729 }); | 742 }); |
730 | 743 |
731 // Make sure an overlay isn't closed (even temporarily) when another overlay is | 744 // Make sure an overlay isn't closed (even temporarily) when another overlay is |
732 // opened on top. | 745 // opened on top. |
733 TEST_F('OptionsWebUIExtendedTest', 'OverlayAboveNoReset', function() { | 746 TEST_F('OptionsWebUIExtendedTest', 'OverlayAboveNoReset', function() { |
734 // Open a layer-1 overlay. | 747 // Open a layer-1 overlay. |
735 PageManager.showPageByName('languages', true); | 748 PageManager.showPageByName('languages', true); |
736 this.verifyOpenPages_(['settings', 'languages']); | 749 this.verifyOpenPages_(['settings', 'languages']); |
737 | 750 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
873 __proto__: OptionsWebUIExtendedTest.prototype, | 886 __proto__: OptionsWebUIExtendedTest.prototype, |
874 | 887 |
875 /** @override */ | 888 /** @override */ |
876 browsePreload: 'chrome://settings-frame/nonexistantPage', | 889 browsePreload: 'chrome://settings-frame/nonexistantPage', |
877 }; | 890 }; |
878 | 891 |
879 TEST_F('OptionsWebUIRedirectTest', 'TestURL', function() { | 892 TEST_F('OptionsWebUIRedirectTest', 'TestURL', function() { |
880 assertEquals('chrome://settings-frame/', document.location.href); | 893 assertEquals('chrome://settings-frame/', document.location.href); |
881 this.verifyHistory_([''], testDone); | 894 this.verifyHistory_([''], testDone); |
882 }); | 895 }); |
OLD | NEW |