OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 /** | |
6 * @fileoverview Suite of tests to ensure that settings subpages exist and | |
7 * load without errors. Also outputs approximate load times for each subpage. | |
8 */ | |
9 | |
10 GEN_INCLUDE(['settings_page_browsertest.js']); | |
11 | |
12 /** | |
13 * @constructor | |
14 * @extends {SettingsPageBrowserTest} | |
15 */ | |
16 function SettingsSubPageBrowserTest() { | |
17 /** @type {!Array<string>} */ | |
18 this.subPages = []; | |
19 } | |
20 | |
21 SettingsSubPageBrowserTest.prototype = { | |
22 __proto__: SettingsPageBrowserTest.prototype, | |
23 | |
24 /** @override */ | |
25 preLoad: function() { | |
26 SettingsPageBrowserTest.prototype.preLoad.call(this); | |
27 // This will cause all subpages to initially be hidden via dom-if. | |
28 // This allows us to test loading each subpage independently without other | |
29 // subpages affecting load times, etc. | |
30 settingsHidePagesByDefaultForTest = true; | |
31 }, | |
32 | |
33 /* | |
34 * Checks all subpages are hidden first. | |
35 * @private | |
36 */ | |
37 verifySubPagesHidden_: function() { | |
38 var page = this.basicPage; | |
39 assertEquals(0, Object.keys(page.pageVisibility).length); | |
40 | |
41 // Ensure all pages are still hidden after the dom-ifs compute their |if|. | |
42 Polymer.dom.flush(); | |
43 var sections = page.shadowRoot.querySelectorAll('settings-section'); | |
44 assertTrue(!!sections); | |
45 assertEquals(0, sections.length); | |
46 }, | |
47 | |
48 /** | |
49 * Ensures the subpage is initially hidden, then sets it to visible and | |
50 * times the result, outputting a (rough) approximation of load time for the | |
51 * subpage. | |
52 * @param {Node} page | |
53 * @param {string} subpage | |
54 */ | |
55 testSubPage: function(page, subPage) { | |
56 Polymer.dom.flush(); | |
57 assertFalse(!!this.getSection(page, subPage)); | |
58 var startTime = window.performance.now(); | |
59 page.set('pageVisibility.' + subPage, true); | |
60 Polymer.dom.flush(); | |
61 var dtime = window.performance.now() - startTime; | |
62 console.log('Page: ' + subPage + ' Load time: ' + dtime.toFixed(0) + ' ms'); | |
63 assertTrue(!!this.getSection(page, subPage)); | |
64 // Hide the page so that it doesn't interfere with other subPages. | |
65 page.set('pageVisibility.' + subPage, false); | |
66 Polymer.dom.flush(); | |
67 }, | |
68 | |
69 testSubPages: function() { | |
70 this.subPages.forEach(function(subPage) { | |
71 test(subPage, function() { | |
72 this.testSubPage(this.basicPage, subPage); | |
73 }.bind(this)); | |
74 }.bind(this)); | |
75 }, | |
76 }; | |
77 | |
78 /** @constructor @extends {SettingsSubPageBrowserTest} */ | |
79 function SettingsBasicSubPageBrowserTest() { | |
80 SettingsSubPageBrowserTest.call(this, 'basic'); | |
81 | |
82 /** @override */ | |
83 this.subPages = [ | |
84 'people', | |
85 'appearance', | |
86 'onStartup', | |
87 'search', | |
88 ]; | |
89 if (cr.isChromeOS) | |
90 this.subPages.push('internet', 'bluetooth', 'device'); | |
91 else | |
92 this.subPages.push('defaultBrowser'); | |
93 } | |
94 | |
95 SettingsBasicSubPageBrowserTest.prototype = { | |
96 __proto__: SettingsSubPageBrowserTest.prototype, | |
97 }; | |
98 | |
99 // Failing on ChromiumOS dbg. https://crbug.com/709442 | |
100 GEN('#if defined(OS_CHROMEOS) && !defined(NDEBUG)'); | |
101 GEN('#define MAYBE_SubPages DISABLED_SubPages'); | |
102 GEN('#else'); | |
103 GEN('#define MAYBE_SubPages SubPages'); | |
104 GEN('#endif'); | |
105 TEST_F('SettingsBasicSubPageBrowserTest', 'MAYBE_SubPages', function() { | |
106 suiteSetup(this.verifySubPagesHidden_.bind(this)); | |
107 suite('Basic', this.testSubPages.bind(this)); | |
108 mocha.run(); | |
109 }); | |
110 | |
111 /** @constructor @extends {SettingsSubPageBrowserTest} */ | |
112 function SettingsAdvancedSubPageBrowserTest() { | |
113 // "Advanced" sections live in the settings-basic-page. | |
114 SettingsSubPageBrowserTest.call(this, 'basic'); | |
115 | |
116 /** @override */ | |
117 this.subPages = [ | |
118 'privacy', | |
119 'passwordsAndForms', | |
120 'languages', | |
121 'downloads', | |
122 'printing', | |
123 'a11y', | |
124 'reset', | |
125 ]; | |
126 if (cr.isChromeOS) | |
127 this.subPages.push('dateTime'); | |
128 else | |
129 this.subPages.push('system'); | |
130 }; | |
131 | |
132 SettingsAdvancedSubPageBrowserTest.prototype = { | |
133 __proto__: SettingsSubPageBrowserTest.prototype, | |
134 | |
135 /** @override */ | |
136 setUp: function() { | |
137 this.toggleAdvanced(); | |
138 SettingsSubPageBrowserTest.prototype.setUp.call(this); | |
139 }, | |
140 }; | |
141 | |
142 TEST_F('SettingsAdvancedSubPageBrowserTest', 'SubPages', function() { | |
143 suiteSetup(this.verifySubPagesHidden_.bind(this)); | |
144 suite('Advanced', this.testSubPages.bind(this)); | |
145 mocha.run(); | |
146 }); | |
OLD | NEW |