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')); |
| 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 (function keepChecking() { |
| 58 if (page.getBoundingClientRect().bottom == window.innerHeight) |
| 59 resolve(); |
| 60 else |
| 61 requestAnimationFrame(keepChecking); |
| 62 })(); |
| 63 }); |
| 64 |
| 65 return promise.then(function() { |
| 66 assertEquals(page.getBoundingClientRect().bottom, window.innerHeight); |
| 67 |
| 68 // Section extends at least to the bottom of the window. |
| 69 var section = assert(this.getSection(page, sectionName)); |
| 70 assertGT(section.offsetHeight, 0); |
| 71 assertEquals( |
| 72 this.getToolbarHeight(), section.getBoundingClientRect().top); |
| 73 assertGE(section.getBoundingClientRect().bottom, window.innerHeight); |
| 74 |
| 75 // Subpage is stamped. |
| 76 var pages = section.querySelector('* /deep/ settings-animated-pages'); |
| 77 assertTrue(!!pages); |
| 78 var path = this.browsePreload.slice('chrome://md-settings'.length); |
| 79 var subpage = pages.querySelector( |
| 80 'settings-subpage[route-path="' + path + '"]'); |
| 81 assertTrue(!!subpage); |
| 82 |
| 83 // Subpage starts at the top of the main page. |
| 84 assertEquals( |
| 85 this.getToolbarHeight(), subpage.getBoundingClientRect().top); |
| 86 assertGT(subpage.offsetHeight, 0); |
| 87 }.bind(this)); |
| 88 }, |
| 89 }; |
| 90 |
| 91 // We're loading the whole MD Settings page and running animations, so disable |
| 92 // problematic builders. See https://crbug.com/558434. |
| 93 GEN('#if defined(MEMORY_SANITIZER) || defined(ADDRESS_SANITIZER) || ' + |
| 94 '!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 |