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

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

Issue 2454023002: MD Settings: Fix <select> search highlighting. (Closed)
Patch Set: Address comments. 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
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 var searchManager = settings.getSearchManager();
7
8 suite('SearchSettingsTest', function() {
9 setup(function() {
10 PolymerTest.clearBody();
11 });
12
13 /**
14 * Test that the DOM of a node is modified as expected when a search hit
15 * occurs within that node.
16 */
17 test('normal highlighting', function() {
18 var textBefore = 'FooSettingsFoo';
Dan Beam 2016/10/27 21:46:09 textBefore -> optionText?
Dan Beam 2016/10/27 22:15:52 ping
dpapad 2016/10/27 22:24:50 Done.
Dan Beam 2016/10/28 22:26:04 thx
19
20 document.body.innerHTML =
21 `<settings-section hidden-by-search>
22 <div id="mydiv">${textBefore}</div>
23 </settings-section>`;
Dan Beam 2016/10/27 21:46:09 indent off?
dpapad 2016/10/27 22:14:22 Done, although I think this is arguable. Is it off
24
25 var section = document.querySelector('settings-section');
26 var div = section.queryEffectiveChildren('#mydiv');
Dan Beam 2016/10/27 21:46:09 why can't this just be $('mydiv')?
dpapad 2016/10/27 22:14:22 Changed to document.querySelector. Not using "$" b
27
28 assertTrue(section.hiddenBySearch);
29 return searchManager.search('settings', section).then(function() {
30 assertFalse(section.hiddenBySearch);
31
32 var highlighWrapper = div.querySelector('.search-highlight-wrapper');
Dan Beam 2016/10/27 21:46:09 highlightWrapper
dpapad 2016/10/27 22:14:22 Done.
33 assertTrue(!!highlighWrapper);
34
35 var originalContent = highlighWrapper.querySelector(
36 '.search-highlight-original-content');
37 assertTrue(!!originalContent);
38 assertEquals(textBefore, originalContent.textContent);
39
40 var searchHits = highlighWrapper.querySelectorAll(
41 '.search-highlight-hit');
42 assertEquals(1, searchHits.length);
43 assertEquals('Settings', searchHits[0].textContent);
44
45 // Check that original DOM structure is restored when search
46 // highlights are cleared.
47 return searchManager.search('', section);
48 }).then(function() {
49 assertEquals(0, div.children.length);
50 assertEquals(textBefore, div.textContent);
51 });
52 });
53
Dan Beam 2016/10/27 21:46:09 remove \n
dpapad 2016/10/27 22:14:22 OK.
54
55 /**
56 * Tests that a search hit within a <select> node causes the parent
57 * settings-section to be shown, but the DOM of the <select> is not
58 * modified.
59 */
60 test('<select> highlighting', function() {
61 document.body.innerHTML =
62 `<settings-section hidden-by-search>
63 <select>
Dan Beam 2016/10/27 21:46:09 indent off?
dpapad 2016/10/27 22:14:22 OK.
64 <option>Foo</option>
65 <option>Settings</option>
66 <option>Baz</option>
67 </select>
68 </settings-section>`;
69
70 var section = document.querySelector('settings-section');
71 var select = section.querySelector('select');
72
73 assertTrue(section.hiddenBySearch);
74 return searchManager.search('settings', section).then(function() {
75 assertFalse(section.hiddenBySearch);
76
77 var highlightWrapper = select.querySelector(
78 '.search-highlight-wrapper');
79 assertFalse(!!highlightWrapper);
80
81 // Check that original DOM structure is present even after search
82 // highlights are cleared.
83 return searchManager.search('', section);
84 }).then(function() {
85 var options = select.querySelectorAll('option');
86 assertEquals(3, options.length);
87 assertEquals('Foo', options[0].textContent);
88 assertEquals('Settings', options[1].textContent);
89 assertEquals('Baz', options[2].textContent);
90 });
91 });
92 });
93 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698