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