Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_main_page', function() { | |
| 6 | |
| 7 function registerSearchTests() { | |
| 8 var searchManager = settings.getSearchManager(); | |
| 9 | |
| 10 suite('SearchSettingsTest', function() { | |
| 11 setup(function() { | |
| 12 PolymerTest.clearBody(); | |
| 13 }); | |
| 14 | |
| 15 /* | |
| 16 * Test that the DOM of a node is modified as expected when a search hit | |
| 17 * occurs within that node. | |
| 18 */ | |
| 19 test('normal highlighting', function() { | |
| 20 var textBefore = 'FooSettingsFoo'; | |
| 21 var htmlBefore = document.body.innerHTML = | |
| 22 `<settings-section hidden-by-search> | |
| 23 <div id="mydiv">${textBefore}</div> | |
| 24 </settings-section>`; | |
| 25 | |
| 26 document.body.innerHTML = htmlBefore; | |
| 27 | |
| 28 var section = document.querySelector('settings-section'); | |
| 29 var div = section.queryEffectiveChildren('#mydiv'); | |
| 30 | |
| 31 return searchManager.search('settings', section).then(function() { | |
| 32 assertFalse(section.hiddenBySearch); | |
|
dpapad
2016/10/27 01:24:48
I believe this is the assertion you were talking a
| |
| 33 | |
| 34 var highlighWrapper = div.querySelector('.search-highlight-wrapper'); | |
| 35 assertTrue(!!highlighWrapper); | |
| 36 | |
| 37 var originalContent = highlighWrapper.querySelector( | |
| 38 '.search-highlight-original-content'); | |
| 39 assertTrue(!!originalContent); | |
| 40 assertEquals(textBefore, originalContent.textContent); | |
| 41 | |
| 42 var searchHits = highlighWrapper.querySelectorAll( | |
| 43 '.search-highlight-hit'); | |
| 44 assertEquals(1, searchHits.length); | |
| 45 assertEquals('Settings', searchHits[0].textContent); | |
| 46 | |
| 47 // Check that original DOM structure is restored when search | |
| 48 // highlights are cleared. | |
| 49 return searchManager.search('', section); | |
| 50 }).then(function() { | |
| 51 assertEquals(0, div.children.length); | |
| 52 assertEquals(textBefore, div.textContent); | |
| 53 }); | |
| 54 }); | |
| 55 | |
| 56 | |
| 57 /* | |
| 58 * Tests that a search hit within a <select> node causes the parent | |
| 59 * settings-section to be shown, but the DOM of the <select> is not | |
| 60 * modified. | |
| 61 */ | |
| 62 test('<select> highlighting', function() { | |
| 63 PolymerTest.clearBody(); | |
| 64 document.body.innerHTML = | |
| 65 `<settings-section hidden-by-search> | |
| 66 <select> | |
| 67 <option>Foo</option> | |
| 68 <option>Settings</option> | |
| 69 <option>Baz</option> | |
| 70 </select> | |
| 71 </settings-section>`; | |
| 72 | |
| 73 var section = document.querySelector('settings-section'); | |
| 74 var select = section.querySelector('select'); | |
| 75 | |
| 76 return searchManager.search('settings', section).then(function() { | |
| 77 assertFalse(section.hiddenBySearch); | |
| 78 | |
| 79 var highlighWrapper = select.querySelector( | |
| 80 '.search-highlight-wrapper'); | |
| 81 assertFalse(!!highlighWrapper); | |
| 82 | |
| 83 // Check that original DOM structure is present even after search | |
| 84 // highlights are cleared. | |
| 85 return searchManager.search('', section); | |
| 86 }).then(function() { | |
| 87 var options = select.querySelectorAll('option'); | |
| 88 assertEquals(3, options.length); | |
| 89 assertEquals('Foo', options[0].textContent); | |
| 90 assertEquals('Settings', options[1].textContent); | |
| 91 assertEquals('Baz', options[2].textContent); | |
| 92 }); | |
| 93 }); | |
| 94 }); | |
| 95 } | |
| 96 | |
| 97 return { | |
| 98 registerSearchTests: registerSearchTests, | |
| 99 }; | |
| 100 }); | |
| OLD | NEW |