Commit 3ce36a61 authored by James Cook's avatar James Cook Committed by Commit Bot

Fix settings search when matched text is outside a <settings-section>

There are settings promo banners that contain text that isn't inside
a <settings-section> element (e.g. the Chrome OS settings "If a setting
doesn't show on this page" banner).

If you type search text that matches this string you'll hit a JS
assertion because a "parent" is null while walking up the DOM tree.
The loop in question checks for null parent, but there's an if()
condition that checks parent.nodeName that needs to test for null
as well.

Bug: 1003970
Test: added to browser_tests
Change-Id: I3c5a7367464502461ab3a158c102f4ad246d9f99
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1807777Reviewed-by: default avatarMichael Giuffrida <michaelpg@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697347}
parent c0de3c3c
......@@ -153,7 +153,7 @@ cr.define('settings', function() {
parent = parent.nodeType == Node.DOCUMENT_FRAGMENT_NODE ?
parent.host :
parent.parentNode;
if (parent.nodeName == 'SETTINGS-SUBPAGE') {
if (parent && parent.nodeName == 'SETTINGS-SUBPAGE') {
// TODO(dpapad): Cast to SettingsSubpageElement here.
associatedControl = assert(
parent.associatedControl,
......
......@@ -249,5 +249,24 @@ cr.define('settings_test', function() {
});
});
});
test('match text outside of a settings section', async function() {
document.body.innerHTML = `
<div id="mydiv">Match</div>
<settings-section></settings-section>`;
const section = document.querySelector('settings-section');
const mydiv = document.querySelector('#mydiv');
await searchManager.search('Match', document.body);
assertTrue(section.hiddenBySearch);
const highlight = mydiv.querySelector('.search-highlight-wrapper');
assertTrue(!!highlight);
const searchHits = highlight.querySelectorAll('.search-highlight-hit');
assertEquals(1, searchHits.length);
assertEquals('Match', searchHits[0].textContent);
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment