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

Unified 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 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..1884e9c5d6be73cbad1bd97282875f9fae79e205
--- /dev/null
+++ b/chrome/test/data/webui/settings/search_settings_test.js
@@ -0,0 +1,98 @@
+// 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() {
+
+ suite('SearchSettingsTest', function() {
+ var searchManager;
+
+ suiteSetup(function() {
+ return PolymerTest.loadScript('chrome://md-settings/search_settings.js');
+ });
+
+ setup(function() {
+ searchManager = settings.getSearchManager();
+ PolymerTest.clearBody();
+ });
+
+ /**
+ * Test that the DOM of a node is modified as expected when a search hit
+ * occurs within that node.
+ */
+ test('normal highlighting', function() {
+ var optionText = 'FooSettingsFoo';
+
+ document.body.innerHTML =
+ `<settings-section hidden-by-search>
+ <div id="mydiv">${optionText}</div>
+ </settings-section>`;
+
+ var section = document.querySelector('settings-section');
+ var div = document.querySelector('#mydiv');
+
+ assertTrue(section.hiddenBySearch);
+ return searchManager.search('settings', section).then(function() {
+ assertFalse(section.hiddenBySearch);
+
+ var highlightWrapper = div.querySelector('.search-highlight-wrapper');
+ assertTrue(!!highlightWrapper);
+
+ var originalContent = highlightWrapper.querySelector(
+ '.search-highlight-original-content');
+ assertTrue(!!originalContent);
+ assertEquals(optionText, originalContent.textContent);
+
+ var searchHits = highlightWrapper.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(optionText, div.textContent);
+ });
+ });
+
+ /**
+ * 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() {
+ 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 highlightWrapper = select.querySelector(
+ '.search-highlight-wrapper');
+ assertFalse(!!highlightWrapper);
+
+ // 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