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 /** @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. | |
dpapad
2016/12/08 01:33:54
Perhaps update the comment to mention that the sec
tommycli
2016/12/08 01:54:46
Done.
| |
65 setTimeout(function() { | |
66 var sections = | |
67 Polymer.dom().querySelectorAll('* /deep/ settings-section'); | |
68 for (var i = 0; i < sections.length; i++) | |
69 sections[i].hiddenBySearch = !!text; | |
70 | |
71 this.searchRequest_.resolver.resolve(this.searchRequest_); | |
72 this.methodCalled('search', text); | |
73 }.bind(this), 0); | |
74 } | |
75 return this.searchRequest_.resolver.promise; | |
76 }, | |
77 }; | |
78 | |
33 // Register mocha tests. | 79 // Register mocha tests. |
34 suite('SettingsPage', function() { | 80 suite('SettingsPage', function() { |
35 test('load page', function() { | 81 test('load page', function() { |
36 // This will fail if there are any asserts or errors in the Settings page. | 82 // This will fail if there are any asserts or errors in the Settings page. |
37 }); | 83 }); |
38 | 84 |
39 test('basic pages', function() { | 85 test('basic pages', function() { |
40 var page = self.getPage('basic'); | 86 var page = self.getPage('basic'); |
41 var sections = ['appearance', 'onStartup', 'people', 'search']; | 87 var sections = ['appearance', 'onStartup', 'people', 'search']; |
42 expectTrue(!!self.getSection(page, 'appearance')); | 88 expectTrue(!!self.getSection(page, 'appearance')); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 | 120 |
75 return new Promise(function(resolve) { | 121 return new Promise(function(resolve) { |
76 listenOnce(window, 'popstate', resolve); | 122 listenOnce(window, 'popstate', resolve); |
77 settings.navigateToPreviousRoute(); | 123 settings.navigateToPreviousRoute(); |
78 }); | 124 }); |
79 }).then(function() { | 125 }).then(function() { |
80 // Should be at the top of the page after going Back from the section. | 126 // Should be at the top of the page after going Back from the section. |
81 assertEquals(0, page.scroller.scrollTop); | 127 assertEquals(0, page.scroller.scrollTop); |
82 }); | 128 }); |
83 }); | 129 }); |
130 | |
131 test('scroll to section after exiting search', function() { | |
132 var searchManager = new TestSearchManager(); | |
133 settings.setSearchManagerForTesting(searchManager); | |
134 | |
135 settings.navigateTo(settings.Route.BASIC, | |
136 new URLSearchParams(`search=foobar`), | |
137 /* removeSearch */ false); | |
138 return searchManager.whenCalled('search').then(function() { | |
139 return new Promise(function(resolve) { | |
140 settings.navigateTo(settings.Route.ON_STARTUP, | |
141 /* dynamicParams */ null, | |
142 /* removeSearch */ true); | |
143 | |
144 var page = self.getPage('basic'); | |
145 assertTrue(!!page); | |
146 | |
147 // Should (after some time) be scrolled to the On Startup section. | |
148 var intervalId = window.setInterval(function() { | |
149 if (page.scroller.scrollTop != 0) { | |
150 window.clearInterval(intervalId); | |
151 resolve(); | |
152 } | |
dpapad
2016/12/08 01:33:54
If this test was to fail, it would only manifest t
tommycli
2016/12/08 01:54:46
This test requires the setInterval because sometim
dpapad
2016/12/08 02:01:16
Ah, I had not noticed that it calls setInterval an
| |
153 }, 55); | |
154 }); | |
155 }); | |
156 }); | |
84 }); | 157 }); |
85 | 158 |
86 // Run all registered tests. | 159 // Run all registered tests. |
87 mocha.run(); | 160 mocha.run(); |
88 }); | 161 }); |
OLD | NEW |