Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: chrome/test/data/webui/settings/basic_page_browsertest.js

Issue 2552393002: MD Settings: Scroll correctly for navigations that exit search mode. (Closed)
Patch Set: update Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/resources/settings/settings_page/main_page_behavior.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /** @fileoverview Suite of tests for the Settings basic page. */ 5 /** @fileoverview Suite of tests for the Settings basic page. */
6 6
7 GEN_INCLUDE(['settings_page_browsertest.js']); 7 GEN_INCLUDE(['settings_page_browsertest.js']);
8 8
9 /** 9 /**
10 * @constructor 10 * @constructor
11 * @extends {SettingsPageBrowserTest} 11 * @extends {SettingsPageBrowserTest}
12 */ 12 */
13 function SettingsBasicPageBrowserTest() {} 13 function SettingsBasicPageBrowserTest() {}
14 14
15 SettingsBasicPageBrowserTest.prototype = { 15 SettingsBasicPageBrowserTest.prototype = {
16 __proto__: SettingsPageBrowserTest.prototype 16 __proto__: SettingsPageBrowserTest.prototype,
17
18 /** @override */
19 extraLibraries: SettingsPageBrowserTest.prototype.extraLibraries.concat([
20 'test_browser_proxy.js',
21 ]),
17 }; 22 };
18 23
19 // Times out on debug builders and may time out on memory bots because 24 // Times out on debug builders and may time out on memory bots because
20 // the Settings page can take several seconds to load in a Release build 25 // the Settings page can take several seconds to load in a Release build
21 // and several times that in a Debug build. See https://crbug.com/558434. 26 // and several times that in a Debug build. See https://crbug.com/558434.
22 GEN('#if defined(MEMORY_SANITIZER) || !defined(NDEBUG)'); 27 GEN('#if defined(MEMORY_SANITIZER) || !defined(NDEBUG)');
23 GEN('#define MAYBE_Load DISABLED_Load'); 28 GEN('#define MAYBE_Load DISABLED_Load');
24 GEN('#else'); 29 GEN('#else');
25 GEN('#define MAYBE_Load Load'); 30 GEN('#define MAYBE_Load Load');
26 GEN('#endif'); 31 GEN('#endif');
27 32
28 TEST_F('SettingsBasicPageBrowserTest', 'MAYBE_Load', function() { 33 TEST_F('SettingsBasicPageBrowserTest', 'MAYBE_Load', function() {
29 // Assign |self| to |this| instead of binding since 'this' in suite() 34 // Assign |self| to |this| instead of binding since 'this' in suite()
30 // and test() will be a Mocha 'Suite' or 'Test' instance. 35 // and test() will be a Mocha 'Suite' or 'Test' instance.
31 var self = this; 36 var self = this;
32 37
38 /**
39 * This fake SearchManager just hides and re-displays the sections on search.
40 *
41 * @implements {SearchManager}
42 * @extends {settings.TestBrowserProxy}
43 */
44 var TestSearchManager = function() {
45 settings.TestBrowserProxy.call(this, [
46 'search',
47 ]);
48
49 /** @private {?settings.SearchRequest} */
50 this.searchRequest_ = null;
51 }
52
53 TestSearchManager.prototype = {
54 __proto__: settings.TestBrowserProxy.prototype,
55
56 /** @override */
57 search: function(text, page) {
58 if (this.searchRequest_ == null || !this.searchRequest_.isSame(text)) {
59 this.searchRequest_ = new settings.SearchRequest(text);
60 this.searchRequest_.finished = true;
61 this.searchRequest_.updateMatches(false);
62
63 // The search much be resolved asynchronously just like the real
64 // SearchManager. Otherwise, the race condition doesn't manifest.
65 setTimeout(function() {
66 // All the sections must be hidden by the TestSearchManager, just like
67 // the real SearchManager. Otherwise, the bug doesn't manifest.
68 var sections =
69 Polymer.dom().querySelectorAll('* /deep/ settings-section');
70 for (var i = 0; i < sections.length; i++)
71 sections[i].hiddenBySearch = !!text;
72
73 this.searchRequest_.resolver.resolve(this.searchRequest_);
74 this.methodCalled('search', text);
75 }.bind(this), 0);
76 }
77 return this.searchRequest_.resolver.promise;
78 },
79 };
80
33 // Register mocha tests. 81 // Register mocha tests.
34 suite('SettingsPage', function() { 82 suite('SettingsPage', function() {
35 test('load page', function() { 83 test('load page', function() {
36 // This will fail if there are any asserts or errors in the Settings page. 84 // This will fail if there are any asserts or errors in the Settings page.
37 }); 85 });
38 86
39 test('basic pages', function() { 87 test('basic pages', function() {
40 var page = self.getPage('basic'); 88 var page = self.getPage('basic');
41 var sections = ['appearance', 'onStartup', 'people', 'search']; 89 var sections = ['appearance', 'onStartup', 'people', 'search'];
42 expectTrue(!!self.getSection(page, 'appearance')); 90 expectTrue(!!self.getSection(page, 'appearance'));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 122
75 return new Promise(function(resolve) { 123 return new Promise(function(resolve) {
76 listenOnce(window, 'popstate', resolve); 124 listenOnce(window, 'popstate', resolve);
77 settings.navigateToPreviousRoute(); 125 settings.navigateToPreviousRoute();
78 }); 126 });
79 }).then(function() { 127 }).then(function() {
80 // Should be at the top of the page after going Back from the section. 128 // Should be at the top of the page after going Back from the section.
81 assertEquals(0, page.scroller.scrollTop); 129 assertEquals(0, page.scroller.scrollTop);
82 }); 130 });
83 }); 131 });
132
133 test('scroll to section after exiting search', function() {
134 var searchManager = new TestSearchManager();
135 settings.setSearchManagerForTesting(searchManager);
136
137 settings.navigateTo(settings.Route.BASIC,
138 new URLSearchParams(`search=foobar`),
139 /* removeSearch */ false);
140 return searchManager.whenCalled('search').then(function() {
141 return new Promise(function(resolve) {
142 settings.navigateTo(settings.Route.ON_STARTUP,
143 /* dynamicParams */ null,
144 /* removeSearch */ true);
145
146 var page = self.getPage('basic');
147 assertTrue(!!page);
148
149 // Should (after some time) be scrolled to the On Startup section.
150 var intervalId = window.setInterval(function() {
151 if (page.scroller.scrollTop != 0) {
152 window.clearInterval(intervalId);
153 resolve();
154 }
155 }, 55);
156 });
157 });
158 });
84 }); 159 });
85 160
86 // Run all registered tests. 161 // Run all registered tests.
87 mocha.run(); 162 mocha.run();
88 }); 163 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/settings_page/main_page_behavior.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698