Commit fe3eaf21 authored by rbpotter's avatar rbpotter Committed by Commit Bot

WebUI Polymer2: Fix Extensions tests

Fix failing extensions browser tests for Polymer2.

Bug: 738611
Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: I00cb68204fa3206f29e50d7044e50f1e6b8cc753
Reviewed-on: https://chromium-review.googlesource.com/1109450
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569822}
parent d930f925
...@@ -253,10 +253,11 @@ ...@@ -253,10 +253,11 @@
</div> </div>
</div> </div>
<div id="description" class="multiline-clippable-text" <div id="description" class="multiline-clippable-text"
hidden$="[[hasWarnings_(data.*)]]"> hidden$="[[hasWarnings_(data.disableReasons.*, data.*)]]">
[[data.description]] [[data.description]]
</div> </div>
<template is="dom-if" if="[[hasWarnings_(data.*)]]"> <template is="dom-if"
if="[[hasWarnings_(data.disableReasons.*, data.*)]]">
<div id="warnings"> <div id="warnings">
<iron-icon id="error-icon" icon="error"></iron-icon> <iron-icon id="error-icon" icon="error"></iron-icon>
<span id="runtime-warnings" aria-describedby="a11yAssociation" <span id="runtime-warnings" aria-describedby="a11yAssociation"
......
...@@ -719,25 +719,35 @@ var CrExtensionsErrorConsoleTest = class extends CrExtensionsBrowserTest { ...@@ -719,25 +719,35 @@ var CrExtensionsErrorConsoleTest = class extends CrExtensionsBrowserTest {
}; };
TEST_F('CrExtensionsErrorConsoleTest', 'TestUpDownErrors', function() { TEST_F('CrExtensionsErrorConsoleTest', 'TestUpDownErrors', function() {
const STACK_ERRORS = '* /deep/ li'; const STACK_ERRORS = 'li';
const ACTIVE_ERROR_IN_STACK = '* /deep/ li[tabindex="0"]'; const ACTIVE_ERROR_IN_STACK = 'li[tabindex="0"]';
let initialFocus = document.querySelector(ACTIVE_ERROR_IN_STACK); let initialFocus =
extension_test_util.findMatches(document, ACTIVE_ERROR_IN_STACK)[0];
assertTrue(!!initialFocus); assertTrue(!!initialFocus);
assertEquals(1, document.querySelectorAll(ACTIVE_ERROR_IN_STACK).length); assertEquals(
assertEquals(4, document.querySelectorAll(STACK_ERRORS).length); 1,
extension_test_util.findMatches(document, ACTIVE_ERROR_IN_STACK).length);
assertEquals(
4, extension_test_util.findMatches(document, STACK_ERRORS).length);
// Pressing up when the first item is focused should NOT change focus. // Pressing up when the first item is focused should NOT change focus.
MockInteractions.keyDownOn(initialFocus, 38, '', 'ArrowUp'); MockInteractions.keyDownOn(initialFocus, 38, '', 'ArrowUp');
assertEquals(initialFocus, document.querySelector(ACTIVE_ERROR_IN_STACK)); assertEquals(
initialFocus,
extension_test_util.findMatches(document, ACTIVE_ERROR_IN_STACK)[0]);
// Pressing down when the first item is focused should change focus. // Pressing down when the first item is focused should change focus.
MockInteractions.keyDownOn(initialFocus, 40, '', 'ArrowDown'); MockInteractions.keyDownOn(initialFocus, 40, '', 'ArrowDown');
assertNotEquals(initialFocus, document.querySelector(ACTIVE_ERROR_IN_STACK)); assertNotEquals(
initialFocus,
extension_test_util.findMatches(document, ACTIVE_ERROR_IN_STACK)[0]);
// Pressing up when the second item is focused should focus the first again. // Pressing up when the second item is focused should focus the first again.
MockInteractions.keyDownOn(initialFocus, 38, '', 'ArrowUp'); MockInteractions.keyDownOn(initialFocus, 38, '', 'ArrowUp');
assertEquals(initialFocus, document.querySelector(ACTIVE_ERROR_IN_STACK)); assertEquals(
initialFocus,
extension_test_util.findMatches(document, ACTIVE_ERROR_IN_STACK)[0]);
testDone(); testDone();
}); });
......
...@@ -46,7 +46,7 @@ cr.define('extension_code_section_tests', function() { ...@@ -46,7 +46,7 @@ cr.define('extension_code_section_tests', function() {
expectFalse(testIsVisible('#no-code')); expectFalse(testIsVisible('#no-code'));
let codeSections = let codeSections =
codeSection.querySelectorAll('* /deep/ #source span span'); codeSection.shadowRoot.querySelectorAll('#source span span');
expectEquals(code.beforeHighlight, codeSections[0].textContent); expectEquals(code.beforeHighlight, codeSections[0].textContent);
expectEquals(code.highlight, codeSections[1].textContent); expectEquals(code.highlight, codeSections[1].textContent);
......
...@@ -266,7 +266,7 @@ cr.define('extension_detail_view_tests', function() { ...@@ -266,7 +266,7 @@ cr.define('extension_detail_view_tests', function() {
testWarningVisible('#blacklisted-warning', true); testWarningVisible('#blacklisted-warning', true);
testWarningVisible('#update-required-warning', false); testWarningVisible('#update-required-warning', false);
item.set('data.blacklistText', undefined); item.set('data.blacklistText', null);
Polymer.dom.flush(); Polymer.dom.flush();
testWarningVisible('#runtime-warnings', true); testWarningVisible('#runtime-warnings', true);
testWarningVisible('#corrupted-warning', true); testWarningVisible('#corrupted-warning', true);
......
...@@ -92,7 +92,7 @@ cr.define('extension_error_page_tests', function() { ...@@ -92,7 +92,7 @@ cr.define('extension_error_page_tests', function() {
expectTrue(testIsVisible('#heading')); expectTrue(testIsVisible('#heading'));
expectTrue(testIsVisible('#errorsList')); expectTrue(testIsVisible('#errorsList'));
var errorElements = errorPage.querySelectorAll('* /deep/ .error-item'); var errorElements = errorPage.shadowRoot.querySelectorAll('.error-item');
expectEquals(1, errorElements.length); expectEquals(1, errorElements.length);
var error = errorElements[0]; var error = errorElements[0];
expectEquals( expectEquals(
...@@ -109,7 +109,7 @@ cr.define('extension_error_page_tests', function() { ...@@ -109,7 +109,7 @@ cr.define('extension_error_page_tests', function() {
manifestErrorBase); manifestErrorBase);
errorPage.set('data.manifestErrors', [manifestError]); errorPage.set('data.manifestErrors', [manifestError]);
Polymer.dom.flush(); Polymer.dom.flush();
errorElements = errorPage.querySelectorAll('* /deep/ .error-item'); errorElements = errorPage.shadowRoot.querySelectorAll('.error-item');
expectEquals(2, errorElements.length); expectEquals(2, errorElements.length);
error = errorElements[0]; error = errorElements[0];
expectEquals( expectEquals(
...@@ -165,8 +165,9 @@ cr.define('extension_error_page_tests', function() { ...@@ -165,8 +165,9 @@ cr.define('extension_error_page_tests', function() {
Polymer.dom.flush(); Polymer.dom.flush();
var errorElements = var errorElements =
errorPage.querySelectorAll('* /deep/ .error-item .start'); errorPage.shadowRoot.querySelectorAll('.error-item .start');
var ironCollapses = errorPage.querySelectorAll('* /deep/ iron-collapse'); var ironCollapses =
errorPage.shadowRoot.querySelectorAll('iron-collapse');
expectEquals(2, errorElements.length); expectEquals(2, errorElements.length);
expectEquals(2, ironCollapses.length); expectEquals(2, ironCollapses.length);
......
...@@ -260,7 +260,7 @@ cr.define('extension_item_tests', function() { ...@@ -260,7 +260,7 @@ cr.define('extension_item_tests', function() {
Polymer.dom.flush(); Polymer.dom.flush();
assertWarnings(kCorrupt | kSuspicious | kBlacklisted); assertWarnings(kCorrupt | kSuspicious | kBlacklisted);
item.set('data.blacklistText', undefined); item.set('data.blacklistText', null);
Polymer.dom.flush(); Polymer.dom.flush();
assertWarnings(kCorrupt | kSuspicious); assertWarnings(kCorrupt | kSuspicious);
......
...@@ -30,15 +30,25 @@ cr.define('extension_sidebar_tests', function() { ...@@ -30,15 +30,25 @@ cr.define('extension_sidebar_tests', function() {
PolymerTest.clearBody(); PolymerTest.clearBody();
sidebar = new extensions.Sidebar(); sidebar = new extensions.Sidebar();
document.body.appendChild(sidebar); document.body.appendChild(sidebar);
const whenSelected =
test_util.eventToPromise('iron-select', sidebar.$.sectionMenu);
Polymer.dom.flush(); Polymer.dom.flush();
expectEquals(sidebar.$$(selector).id, 'sections-shortcuts'); return whenSelected
.then(function() {
expectEquals(sidebar.$$(selector).id, 'sections-shortcuts');
window.history.replaceState(undefined, '', '/'); window.history.replaceState(undefined, '', '/');
PolymerTest.clearBody(); PolymerTest.clearBody();
sidebar = new extensions.Sidebar(); sidebar = new extensions.Sidebar();
document.body.appendChild(sidebar); document.body.appendChild(sidebar);
Polymer.dom.flush(); const whenSelected =
expectEquals(sidebar.$$(selector).id, 'sections-extensions'); test_util.eventToPromise('iron-select', sidebar.$.sectionMenu);
Polymer.dom.flush();
return whenSelected;
})
.then(function() {
expectEquals(sidebar.$$(selector).id, 'sections-extensions');
});
}); });
test(assert(TestNames.LayoutAndClickHandlers), function(done) { test(assert(TestNames.LayoutAndClickHandlers), function(done) {
......
...@@ -249,6 +249,35 @@ cr.define('extension_test_util', function() { ...@@ -249,6 +249,35 @@ cr.define('extension_test_util', function() {
}); });
} }
/**
* Finds all nodes matching |query| under |root|, within self and children's
* Shadow DOM.
* @param {!Node} root
* @param {string} query The CSS query
* @return {!Array<!HTMLElement>}
*/
function findMatches(root, query) {
let elements = new Set();
function doSearch(node) {
if (node.nodeType == Node.ELEMENT_NODE) {
const matches = node.querySelectorAll(query);
for (let match of matches)
elements.add(match);
}
let child = node.firstChild;
while (child !== null) {
doSearch(child);
child = child.nextSibling;
}
const shadowRoot = node.shadowRoot;
if (shadowRoot)
doSearch(shadowRoot);
}
doSearch(root);
return Array.from(elements);
}
return { return {
ClickMock: ClickMock, ClickMock: ClickMock,
ListenerMock: ListenerMock, ListenerMock: ListenerMock,
...@@ -258,5 +287,6 @@ cr.define('extension_test_util', function() { ...@@ -258,5 +287,6 @@ cr.define('extension_test_util', function() {
testVisible: testVisible, testVisible: testVisible,
createExtensionInfo: createExtensionInfo, createExtensionInfo: createExtensionInfo,
testIcons: testIcons, testIcons: testIcons,
findMatches: findMatches,
}; };
}); });
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