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

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

Issue 2454023002: MD Settings: Fix <select> search highlighting. (Closed)
Patch Set: Use loadScript. Created 4 years, 1 month 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/test/data/webui/settings/cr_settings_browsertest.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
(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 cr.define('settings_test', function() {
6
7 suite('SearchSettingsTest', function() {
8 var searchManager;
9
10 suiteSetup(function() {
11 return PolymerTest.loadScript('chrome://md-settings/search_settings.js');
12 });
13
14 setup(function() {
15 searchManager = settings.getSearchManager();
16 PolymerTest.clearBody();
17 });
18
19 /**
20 * Test that the DOM of a node is modified as expected when a search hit
21 * occurs within that node.
22 */
23 test('normal highlighting', function() {
24 var optionText = 'FooSettingsFoo';
25
26 document.body.innerHTML =
27 `<settings-section hidden-by-search>
28 <div id="mydiv">${optionText}</div>
29 </settings-section>`;
30
31 var section = document.querySelector('settings-section');
32 var div = document.querySelector('#mydiv');
33
34 assertTrue(section.hiddenBySearch);
35 return searchManager.search('settings', section).then(function() {
36 assertFalse(section.hiddenBySearch);
37
38 var highlightWrapper = div.querySelector('.search-highlight-wrapper');
39 assertTrue(!!highlightWrapper);
40
41 var originalContent = highlightWrapper.querySelector(
42 '.search-highlight-original-content');
43 assertTrue(!!originalContent);
44 assertEquals(optionText, originalContent.textContent);
45
46 var searchHits = highlightWrapper.querySelectorAll(
47 '.search-highlight-hit');
48 assertEquals(1, searchHits.length);
49 assertEquals('Settings', searchHits[0].textContent);
50
51 // Check that original DOM structure is restored when search
52 // highlights are cleared.
53 return searchManager.search('', section);
54 }).then(function() {
55 assertEquals(0, div.children.length);
56 assertEquals(optionText, div.textContent);
57 });
58 });
59
60 /**
61 * Tests that a search hit within a <select> node causes the parent
62 * settings-section to be shown, but the DOM of the <select> is not
63 * modified.
64 */
65 test('<select> highlighting', function() {
66 document.body.innerHTML =
67 `<settings-section hidden-by-search>
68 <select>
69 <option>Foo</option>
70 <option>Settings</option>
71 <option>Baz</option>
72 </select>
73 </settings-section>`;
74
75 var section = document.querySelector('settings-section');
76 var select = section.querySelector('select');
77
78 assertTrue(section.hiddenBySearch);
79 return searchManager.search('settings', section).then(function() {
80 assertFalse(section.hiddenBySearch);
81
82 var highlightWrapper = select.querySelector(
83 '.search-highlight-wrapper');
84 assertFalse(!!highlightWrapper);
85
86 // Check that original DOM structure is present even after search
87 // highlights are cleared.
88 return searchManager.search('', section);
89 }).then(function() {
90 var options = select.querySelectorAll('option');
91 assertEquals(3, options.length);
92 assertEquals('Foo', options[0].textContent);
93 assertEquals('Settings', options[1].textContent);
94 assertEquals('Baz', options[2].textContent);
95 });
96 });
97 });
98 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/settings/cr_settings_browsertest.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698