| 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 * | |
| 16 * @param {string} pageId Just 'basic'. TODO(michaelpg): Add 'about' if we want | |
| 17 * to, but that requires wrapping its sole <settings-section> in a dom-if. | |
| 18 */ | 15 */ |
| 19 function SettingsSubPageBrowserTest(pageId) { | 16 function SettingsSubPageBrowserTest() { |
| 20 /** @type {string} */ | |
| 21 this.pageId = pageId; | |
| 22 | |
| 23 /** @type {!Array<string>} */ | 17 /** @type {!Array<string>} */ |
| 24 this.subPages = []; | 18 this.subPages = []; |
| 25 } | 19 } |
| 26 | 20 |
| 27 SettingsSubPageBrowserTest.prototype = { | 21 SettingsSubPageBrowserTest.prototype = { |
| 28 __proto__: SettingsPageBrowserTest.prototype, | 22 __proto__: SettingsPageBrowserTest.prototype, |
| 29 | 23 |
| 30 /** @override */ | 24 /** @override */ |
| 31 preLoad: function() { | 25 preLoad: function() { |
| 32 SettingsPageBrowserTest.prototype.preLoad.call(this); | 26 SettingsPageBrowserTest.prototype.preLoad.call(this); |
| 33 // This will cause all subpages to initially be hidden via dom-if. | 27 // This will cause all subpages to initially be hidden via dom-if. |
| 34 // This allows us to test loading each subpage independently without other | 28 // This allows us to test loading each subpage independently without other |
| 35 // subpages affecting load times, etc. | 29 // subpages affecting load times, etc. |
| 36 settingsHidePagesByDefaultForTest = true; | 30 settingsHidePagesByDefaultForTest = true; |
| 37 }, | 31 }, |
| 38 | 32 |
| 39 /** @override */ | |
| 40 setUp: function() { | |
| 41 SettingsPageBrowserTest.prototype.setUp.call(this); | |
| 42 this.verifySubPagesHidden_(); | |
| 43 }, | |
| 44 | |
| 45 /* | 33 /* |
| 46 * Checks all subpages are hidden first. | 34 * Checks all subpages are hidden first. |
| 47 * @private | 35 * @private |
| 48 */ | 36 */ |
| 49 verifySubPagesHidden_: function() { | 37 verifySubPagesHidden_: function() { |
| 50 var page = this.getPage(this.pageId); | 38 var page = this.basicPage; |
| 51 assertEquals(0, Object.keys(page.pageVisibility).length); | 39 assertEquals(0, Object.keys(page.pageVisibility).length); |
| 52 | 40 |
| 53 // Ensure all pages are still hidden after the dom-ifs compute their |if|. | 41 // Ensure all pages are still hidden after the dom-ifs compute their |if|. |
| 54 Polymer.dom.flush(); | 42 Polymer.dom.flush(); |
| 55 var sections = page.shadowRoot.querySelectorAll('settings-section'); | 43 var sections = page.shadowRoot.querySelectorAll('settings-section'); |
| 56 assertTrue(!!sections); | 44 assertTrue(!!sections); |
| 57 assertEquals(0, sections.length); | 45 assertEquals(0, sections.length); |
| 58 }, | 46 }, |
| 59 | 47 |
| 60 /** | 48 /** |
| (...skipping 11 matching lines...) Expand all Loading... |
| 72 Polymer.dom.flush(); | 60 Polymer.dom.flush(); |
| 73 var dtime = window.performance.now() - startTime; | 61 var dtime = window.performance.now() - startTime; |
| 74 console.log('Page: ' + subPage + ' Load time: ' + dtime.toFixed(0) + ' ms'); | 62 console.log('Page: ' + subPage + ' Load time: ' + dtime.toFixed(0) + ' ms'); |
| 75 assertTrue(!!this.getSection(page, subPage)); | 63 assertTrue(!!this.getSection(page, subPage)); |
| 76 // Hide the page so that it doesn't interfere with other subPages. | 64 // Hide the page so that it doesn't interfere with other subPages. |
| 77 page.set('pageVisibility.' + subPage, false); | 65 page.set('pageVisibility.' + subPage, false); |
| 78 Polymer.dom.flush(); | 66 Polymer.dom.flush(); |
| 79 }, | 67 }, |
| 80 | 68 |
| 81 testSubPages: function() { | 69 testSubPages: function() { |
| 82 var page = this.getPage(this.pageId); | |
| 83 this.subPages.forEach(function(subPage) { | 70 this.subPages.forEach(function(subPage) { |
| 84 test(subPage, this.testSubPage.bind(this, page, subPage)); | 71 test(subPage, function() { |
| 72 this.testSubPage(this.basicPage, subPage); |
| 73 }.bind(this)); |
| 85 }.bind(this)); | 74 }.bind(this)); |
| 86 }, | 75 }, |
| 87 }; | 76 }; |
| 88 | 77 |
| 89 /** @constructor @extends {SettingsSubPageBrowserTest} */ | 78 /** @constructor @extends {SettingsSubPageBrowserTest} */ |
| 90 function SettingsBasicSubPageBrowserTest() { | 79 function SettingsBasicSubPageBrowserTest() { |
| 91 SettingsSubPageBrowserTest.call(this, 'basic'); | 80 SettingsSubPageBrowserTest.call(this, 'basic'); |
| 92 | 81 |
| 93 /** @override */ | 82 /** @override */ |
| 94 this.subPages = [ | 83 this.subPages = [ |
| 95 'people', | 84 'people', |
| 96 'appearance', | 85 'appearance', |
| 97 'onStartup', | 86 'onStartup', |
| 98 'search', | 87 'search', |
| 99 ]; | 88 ]; |
| 100 if (cr.isChromeOS) | 89 if (cr.isChromeOS) |
| 101 this.subPages.push('internet', 'bluetooth', 'device'); | 90 this.subPages.push('internet', 'bluetooth', 'device'); |
| 102 else | 91 else |
| 103 this.subPages.push('defaultBrowser'); | 92 this.subPages.push('defaultBrowser'); |
| 104 } | 93 } |
| 105 | 94 |
| 106 SettingsBasicSubPageBrowserTest.prototype = { | 95 SettingsBasicSubPageBrowserTest.prototype = { |
| 107 __proto__: SettingsSubPageBrowserTest.prototype, | 96 __proto__: SettingsSubPageBrowserTest.prototype, |
| 108 }; | 97 }; |
| 109 | 98 |
| 110 TEST_F('SettingsBasicSubPageBrowserTest', 'SubPages', function() { | 99 TEST_F('SettingsBasicSubPageBrowserTest', 'SubPages', function() { |
| 100 suiteSetup(this.verifySubPagesHidden_.bind(this)); |
| 111 suite('Basic', this.testSubPages.bind(this)); | 101 suite('Basic', this.testSubPages.bind(this)); |
| 112 mocha.run(); | 102 mocha.run(); |
| 113 }); | 103 }); |
| 114 | 104 |
| 115 /** @constructor @extends {SettingsSubPageBrowserTest} */ | 105 /** @constructor @extends {SettingsSubPageBrowserTest} */ |
| 116 function SettingsAdvancedSubPageBrowserTest() { | 106 function SettingsAdvancedSubPageBrowserTest() { |
| 117 // "Advanced" sections live in the settings-basic-page. | 107 // "Advanced" sections live in the settings-basic-page. |
| 118 SettingsSubPageBrowserTest.call(this, 'basic'); | 108 SettingsSubPageBrowserTest.call(this, 'basic'); |
| 119 | 109 |
| 120 /** @override */ | 110 /** @override */ |
| (...skipping 16 matching lines...) Expand all Loading... |
| 137 __proto__: SettingsSubPageBrowserTest.prototype, | 127 __proto__: SettingsSubPageBrowserTest.prototype, |
| 138 | 128 |
| 139 /** @override */ | 129 /** @override */ |
| 140 setUp: function() { | 130 setUp: function() { |
| 141 this.toggleAdvanced(); | 131 this.toggleAdvanced(); |
| 142 SettingsSubPageBrowserTest.prototype.setUp.call(this); | 132 SettingsSubPageBrowserTest.prototype.setUp.call(this); |
| 143 }, | 133 }, |
| 144 }; | 134 }; |
| 145 | 135 |
| 146 TEST_F('SettingsAdvancedSubPageBrowserTest', 'SubPages', function() { | 136 TEST_F('SettingsAdvancedSubPageBrowserTest', 'SubPages', function() { |
| 137 suiteSetup(this.verifySubPagesHidden_.bind(this)); |
| 147 suite('Advanced', this.testSubPages.bind(this)); | 138 suite('Advanced', this.testSubPages.bind(this)); |
| 148 mocha.run(); | 139 mocha.run(); |
| 149 }); | 140 }); |
| OLD | NEW |