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

Unified Diff: chrome/test/data/webui/settings/search_settings_test.js

Issue 2454023002: MD Settings: Fix <select> search highlighting. (Closed)
Patch Set: Fix browserPreload path. Created 4 years, 2 months 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/webui/settings/search_settings_test.js
diff --git a/chrome/test/data/webui/settings/search_settings_test.js b/chrome/test/data/webui/settings/search_settings_test.js
new file mode 100644
index 0000000000000000000000000000000000000000..7dde2509f661d32950af896040c9aa52ab08e65d
--- /dev/null
+++ b/chrome/test/data/webui/settings/search_settings_test.js
@@ -0,0 +1,95 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+cr.define('settings_test', function() {
+ var searchManager = settings.getSearchManager();
+
+ suite('SearchSettingsTest', function() {
+ setup(function() {
+ PolymerTest.clearBody();
+ });
+
+ /*
Dan Beam 2016/10/27 21:24:53 /**
dpapad 2016/10/27 21:35:37 Done. Technically this is only needed if you have
+ * Test that the DOM of a node is modified as expected when a search hit
+ * occurs within that node.
+ */
+ test('normal highlighting', function() {
+ var textBefore = 'FooSettingsFoo';
+ var htmlBefore = document.body.innerHTML =
Dan Beam 2016/10/27 21:24:53 why are you changing document.body's innerHTML rat
dpapad 2016/10/27 21:35:37 Removed. It was an accidental leftover of a previo
+ `<settings-section hidden-by-search>
Dan Beam 2016/10/27 21:24:53 why are you adding hidden-by-search and checking i
dpapad 2016/10/27 21:35:37 Well, for two reasons. a) If I don't add it, then
+ <div id="mydiv">${textBefore}</div>
+ </settings-section>`;
+
+ document.body.innerHTML = htmlBefore;
Dan Beam 2016/10/27 21:24:53 what is all this assignment devilry?
dpapad 2016/10/27 21:35:37 Fixed.
+
+ var section = document.querySelector('settings-section');
+ var div = section.queryEffectiveChildren('#mydiv');
+
+ assertTrue(section.hiddenBySearch);
+ return searchManager.search('settings', section).then(function() {
+ assertFalse(section.hiddenBySearch);
+
+ var highlighWrapper = div.querySelector('.search-highlight-wrapper');
+ assertTrue(!!highlighWrapper);
+
+ var originalContent = highlighWrapper.querySelector(
+ '.search-highlight-original-content');
+ assertTrue(!!originalContent);
+ assertEquals(textBefore, originalContent.textContent);
+
+ var searchHits = highlighWrapper.querySelectorAll(
+ '.search-highlight-hit');
+ assertEquals(1, searchHits.length);
+ assertEquals('Settings', searchHits[0].textContent);
+
+ // Check that original DOM structure is restored when search
+ // highlights are cleared.
+ return searchManager.search('', section);
+ }).then(function() {
+ assertEquals(0, div.children.length);
+ assertEquals(textBefore, div.textContent);
+ });
+ });
+
+
+ /*
Dan Beam 2016/10/27 21:24:53 same
dpapad 2016/10/27 21:35:37 Done.
+ * Tests that a search hit within a <select> node causes the parent
+ * settings-section to be shown, but the DOM of the <select> is not
+ * modified.
+ */
+ test('<select> highlighting', function() {
+ PolymerTest.clearBody();
Dan Beam 2016/10/27 21:24:53 why do this if it's already done in setup?
dpapad 2016/10/27 21:35:37 Removed.
+ document.body.innerHTML =
+ `<settings-section hidden-by-search>
+ <select>
+ <option>Foo</option>
+ <option>Settings</option>
+ <option>Baz</option>
+ </select>
+ </settings-section>`;
+
+ var section = document.querySelector('settings-section');
+ var select = section.querySelector('select');
+
+ assertTrue(section.hiddenBySearch);
+ return searchManager.search('settings', section).then(function() {
+ assertFalse(section.hiddenBySearch);
+
+ var highlighWrapper = select.querySelector(
Dan Beam 2016/10/27 21:24:53 highlightWrapper
+ '.search-highlight-wrapper');
+ assertFalse(!!highlighWrapper);
+
+ // Check that original DOM structure is present even after search
+ // highlights are cleared.
+ return searchManager.search('', section);
+ }).then(function() {
+ var options = select.querySelectorAll('option');
+ assertEquals(3, options.length);
+ assertEquals('Foo', options[0].textContent);
+ assertEquals('Settings', options[1].textContent);
+ assertEquals('Baz', options[2].textContent);
+ });
+ });
+ });
+});
« 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