Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 /** @fileoverview Tests various settings URLs. */ | |
| 6 | |
| 7 GEN_INCLUDE(['settings_page_browsertest.js']); | |
| 8 | |
| 9 /** | |
| 10 * @constructor | |
| 11 * @extends {SettingsPageBrowserTest} | |
| 12 */ | |
| 13 function SettingsPageURLBrowserTest() {} | |
| 14 | |
| 15 SettingsPageURLBrowserTest.prototype = { | |
| 16 __proto__: SettingsPageBrowserTest.prototype, | |
| 17 | |
| 18 /** @return {number} Height of the cr-toolbar. */ | |
| 19 getToolbarHeight: function() { | |
| 20 var toolbar = assert(document.querySelector('* /deep/ cr-toolbar')); | |
|
dschuyler
2016/10/03 18:29:58
IIRC using /deep/ in a test is ok(?).
michaelpg
2016/10/03 20:28:52
yes: /deep/ inside querySelector is not deprecated
| |
| 21 assertGT(toolbar.offsetHeight, 0); | |
| 22 return toolbar.offsetHeight; | |
| 23 }, | |
| 24 | |
| 25 /** | |
| 26 * Tests that the page opens with the section visible and at the top of the | |
| 27 * scroller. | |
| 28 * @param {string} pageName | |
| 29 * @param {string} sectionName | |
| 30 */ | |
| 31 runSectionTest: function(pageName, sectionName) { | |
| 32 var page = this.getPage(pageName); | |
| 33 var section = assert(this.getSection(page, sectionName)); | |
| 34 | |
| 35 // Section starts at the top of the main page. | |
| 36 assertEquals( | |
| 37 this.getToolbarHeight(), section.getBoundingClientRect().top); | |
| 38 assertGT(section.offsetHeight, 0); | |
| 39 | |
| 40 this.verifySubpagesHidden(section); | |
| 41 }, | |
| 42 | |
| 43 /** | |
| 44 * Tests that the page opens with the subpage visible and filling the page. | |
| 45 * May take several frames to complete. Returns a Promise which resolves on | |
| 46 * success, making this function a suitable parameter for test(). | |
| 47 * @param {string} pageName | |
| 48 * @param {string} sectionName | |
| 49 * @return {!Promise} Test promise. | |
| 50 */ | |
| 51 runSubpageTestAsync: function(pageName, sectionName) { | |
| 52 var page = this.getPage(pageName); | |
| 53 | |
| 54 // Wait for expand animation to complete, leaving the page spanning the | |
| 55 // available vertical space. | |
| 56 var promise = new Promise(function(resolve, reject) { | |
| 57 // Resolves the promise or schedules itself to run again in a rAF. | |
|
dschuyler
2016/10/03 18:29:58
optional:
// Resolves the promise or schedules it
michaelpg
2016/10/03 20:28:52
Done.
| |
| 58 (function keepChecking() { | |
| 59 if (page.getBoundingClientRect().bottom == window.innerHeight) | |
| 60 resolve(); | |
| 61 else | |
| 62 requestAnimationFrame(keepChecking); | |
| 63 })(); | |
| 64 }); | |
| 65 | |
| 66 return promise.then(function() { | |
| 67 assertEquals(page.getBoundingClientRect().bottom, window.innerHeight); | |
| 68 | |
| 69 // Section extends at least to the bottom of the window. | |
| 70 var section = assert(this.getSection(page, sectionName)); | |
| 71 assertGT(section.offsetHeight, 0); | |
| 72 assertEquals( | |
| 73 this.getToolbarHeight(), section.getBoundingClientRect().top); | |
| 74 assertGE(section.getBoundingClientRect().bottom, window.innerHeight); | |
| 75 | |
| 76 // Subpage is stamped. | |
| 77 var pages = section.querySelector('* /deep/ settings-animated-pages'); | |
| 78 assertTrue(!!pages); | |
| 79 var path = this.browsePreload.slice('chrome://md-settings'.length); | |
| 80 var subpage = pages.querySelector( | |
| 81 'settings-subpage[route-path="' + path + '"]'); | |
| 82 assertTrue(!!subpage); | |
| 83 | |
| 84 // Subpage starts at the top of the main page. | |
| 85 assertEquals( | |
| 86 this.getToolbarHeight(), subpage.getBoundingClientRect().top); | |
| 87 assertGT(subpage.offsetHeight, 0); | |
| 88 }.bind(this)); | |
| 89 }, | |
| 90 }; | |
| 91 | |
| 92 // We're loading the whole MD Settings page and running animations, so disable | |
| 93 // problematic builders. See https://crbug.com/558434. | |
| 94 GEN('#if defined(MEMORY_SANITIZER) || !defined(NDEBUG)'); | |
| 95 GEN('#define MAYBE_Load DISABLED_Load'); | |
| 96 GEN('#else'); | |
| 97 GEN('#define MAYBE_Load Load'); | |
| 98 GEN('#endif'); | |
| 99 | |
| 100 // Loads a basic page section. | |
| 101 function SettingsPageURLOnStartupTest() {} | |
| 102 SettingsPageURLOnStartupTest.prototype = { | |
| 103 __proto__: SettingsPageURLBrowserTest.prototype, | |
| 104 | |
| 105 /** @override */ | |
| 106 browsePreload: 'chrome://md-settings/onStartup', | |
| 107 }; | |
| 108 | |
| 109 TEST_F('SettingsPageURLOnStartupTest', 'MAYBE_Load', function() { | |
| 110 test('scrolled to onStartup section', | |
| 111 this.runSectionTest.bind(this, 'basic', 'onStartup')); | |
| 112 mocha.run(); | |
| 113 }); | |
| 114 | |
| 115 // Loads an advanced page section. | |
| 116 function SettingsPageURLResetTest() {} | |
| 117 SettingsPageURLResetTest.prototype = { | |
| 118 __proto__: SettingsPageURLBrowserTest.prototype, | |
| 119 | |
| 120 /** @override */ | |
| 121 browsePreload: 'chrome://md-settings/reset', | |
| 122 }; | |
| 123 | |
| 124 TEST_F('SettingsPageURLResetTest', 'MAYBE_Load', function() { | |
| 125 test('scrolled to reset section', | |
| 126 this.runSectionTest.bind(this, 'advanced', 'reset')); | |
| 127 mocha.run(); | |
| 128 }); | |
| 129 | |
| 130 // Loads a basic page subpage. | |
| 131 function SettingsPageURLSearchEnginesTest() {} | |
| 132 SettingsPageURLSearchEnginesTest.prototype = { | |
| 133 __proto__: SettingsPageURLBrowserTest.prototype, | |
| 134 | |
| 135 /** @override */ | |
| 136 browsePreload: 'chrome://md-settings/searchEngines', | |
| 137 }; | |
| 138 | |
| 139 TEST_F('SettingsPageURLSearchEnginesTest', 'MAYBE_Load', function() { | |
| 140 test('opened searchEngines subpage', | |
| 141 this.runSubpageTestAsync.bind(this, 'basic', 'search')); | |
| 142 mocha.run(); | |
| 143 }); | |
| 144 | |
| 145 // Loads an advanced page subpage. | |
| 146 function SettingsPageURLSiteSettingsTest() {} | |
| 147 SettingsPageURLSiteSettingsTest.prototype = { | |
| 148 __proto__: SettingsPageURLBrowserTest.prototype, | |
| 149 | |
| 150 /** @override */ | |
| 151 browsePreload: 'chrome://md-settings/siteSettings', | |
| 152 }; | |
| 153 | |
| 154 TEST_F('SettingsPageURLSiteSettingsTest', 'MAYBE_Load', function() { | |
| 155 test('opened siteSettings subpage', | |
| 156 this.runSubpageTestAsync.bind( | |
| 157 this, 'advanced', 'privacy')); | |
| 158 mocha.run(); | |
| 159 }); | |
| OLD | NEW |