Commit d33d841b authored by dpapad's avatar dpapad Committed by Commit Bot

WebUI Polymer 2: Fixing some Settings tests to work with Polymer 2, part 1.

CrElementsLazyRenderTest.All
CrElementsPolicyIndicatorBehaviorTest.All
CrSettingsDropdownMenuTest.All
CrSettingsPeoplePageTest.All
CrSettingsPrefsTest.All
CrSettingsSystemPageTest.All

Note that in Polymer 2 (unlike Polymer 1), an element's local DOM is not ready,
until after the element is attached to the document. Several tests currently:

 - Either test UI elements not in the document, or
 - Interact with UI elements before they are appended to the document.

which leads to failures.

Bug: 738611
Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: If8b05c283afa18b0e08b16365d1a8f53352765e6
Reviewed-on: https://chromium-review.googlesource.com/1098299Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568255}
parent b919acfe
...@@ -20,11 +20,14 @@ Polymer({ ...@@ -20,11 +20,14 @@ Polymer({
* @private * @private
*/ */
getLabel_: function(extensionId, extensionName) { getLabel_: function(extensionId, extensionName) {
const manageUrl = 'chrome://extensions/?id=' + assert(this.extensionId); if (this.extensionId == undefined || this.extensionName == undefined)
return '';
const manageUrl = 'chrome://extensions/?id=' + this.extensionId;
return this.i18nAdvanced('controlledByExtension', { return this.i18nAdvanced('controlledByExtension', {
substitutions: substitutions:
['<a href="' + manageUrl + '" target="_blank">' + ['<a href="' + manageUrl + '" target="_blank">' + this.extensionName +
assert(this.extensionName) + '</a>'], '</a>'],
}); });
}, },
......
...@@ -456,7 +456,10 @@ Polymer({ ...@@ -456,7 +456,10 @@ Polymer({
* @private * @private
*/ */
shouldShowSyncAccountControl_: function() { shouldShowSyncAccountControl_: function() {
return !!this.diceEnabled_ && !!this.syncStatus.syncSystemEnabled && if (this.syncStatus == undefined)
return false;
return this.diceEnabled_ && !!this.syncStatus.syncSystemEnabled &&
!!this.syncStatus.signinAllowed; !!this.syncStatus.signinAllowed;
}, },
// </if> // </if>
......
...@@ -231,6 +231,9 @@ Polymer({ ...@@ -231,6 +231,9 @@ Polymer({
* @private * @private
*/ */
computeShouldShowAvatarRow_: function() { computeShouldShowAvatarRow_: function() {
if (this.storedAccounts_ == undefined)
return false;
return this.syncStatus.signedIn || this.storedAccounts_.length > 0; return this.syncStatus.signedIn || this.storedAccounts_.length > 0;
}, },
...@@ -290,6 +293,9 @@ Polymer({ ...@@ -290,6 +293,9 @@ Polymer({
/** @private */ /** @private */
onShownAccountShouldChange_: function() { onShownAccountShouldChange_: function() {
if (this.storedAccounts_ == undefined)
return;
if (this.syncStatus.signedIn) { if (this.syncStatus.signedIn) {
for (let i = 0; i < this.storedAccounts_.length; i++) { for (let i = 0; i < this.storedAccounts_.length; i++) {
if (this.storedAccounts_[i].email == this.syncStatus.signedInUsername) { if (this.storedAccounts_[i].email == this.syncStatus.signedInUsername) {
......
...@@ -14,19 +14,23 @@ suite('cr-lazy-render', function() { ...@@ -14,19 +14,23 @@ suite('cr-lazy-render', function() {
setup(function() { setup(function() {
PolymerTest.clearBody(); PolymerTest.clearBody();
const template = ` const template = `
<template is="dom-bind" id="bind"> <dom-bind>
<cr-lazy-render id="lazy"> <template is="dom-bind">
<template> <cr-lazy-render id="lazy">
<h1> <template>
<cr-checkbox checked="{{checked}}"></cr-checkbox> <h1>
{{name}} <cr-checkbox checked="{{checked}}"></cr-checkbox>
</h1> {{name}}
</template> </h1>
</cr-lazy-render> </template>
</template>`; </cr-lazy-render>
</template>
</dom-bind>`;
document.body.innerHTML = template; document.body.innerHTML = template;
lazy = document.getElementById('lazy'); lazy = document.getElementById('lazy');
bind = document.getElementById('bind'); // TODO(dpapad): Remove conditional when Polymer 2 migration has completed.
bind = document.querySelector(
Polymer.DomBind ? 'dom-bind' : 'template[is=\'dom-bind\']');
}); });
test('stamps after get()', function() { test('stamps after get()', function() {
......
...@@ -4,9 +4,8 @@ ...@@ -4,9 +4,8 @@
/** @fileoverview Suite of tests for CrPolicyIndicatorBehavior. */ /** @fileoverview Suite of tests for CrPolicyIndicatorBehavior. */
suite('CrPolicyIndicatorBehavior', function() { suite('CrPolicyIndicatorBehavior', function() {
let TestIndicator;
suiteSetup(function() { suiteSetup(function() {
TestIndicator = Polymer({ Polymer({
is: 'test-indicator', is: 'test-indicator',
behaviors: [CrPolicyIndicatorBehavior], behaviors: [CrPolicyIndicatorBehavior],
...@@ -15,7 +14,9 @@ suite('CrPolicyIndicatorBehavior', function() { ...@@ -15,7 +14,9 @@ suite('CrPolicyIndicatorBehavior', function() {
let indicator; let indicator;
setup(function() { setup(function() {
indicator = new TestIndicator; PolymerTest.clearBody();
indicator = document.createElement('test-indicator');
document.body.appendChild(indicator);
}); });
test('default indicator is blank', function() { test('default indicator is blank', function() {
......
...@@ -35,10 +35,10 @@ cr.define('settings_dropdown_menu', function() { ...@@ -35,10 +35,10 @@ cr.define('settings_dropdown_menu', function() {
setup(function() { setup(function() {
PolymerTest.clearBody(); PolymerTest.clearBody();
dropdown = document.createElement('settings-dropdown-menu'); dropdown = document.createElement('settings-dropdown-menu');
document.body.appendChild(dropdown);
selectElement = assert(dropdown.$$('select')); selectElement = assert(dropdown.$$('select'));
const options = selectElement.options; const options = selectElement.options;
customOption = assert(options[options.length - 1]); customOption = assert(options[options.length - 1]);
document.body.appendChild(dropdown);
}); });
test('with number options', function testNumberOptions() { test('with number options', function testNumberOptions() {
......
...@@ -81,6 +81,7 @@ cr.define('settings_prefs', function() { ...@@ -81,6 +81,7 @@ cr.define('settings_prefs', function() {
CrSettingsPrefs.deferInitialization = true; CrSettingsPrefs.deferInitialization = true;
prefs = document.createElement('settings-prefs'); prefs = document.createElement('settings-prefs');
document.body.appendChild(prefs);
prefs.initialize(fakeApi); prefs.initialize(fakeApi);
// getAllPrefs is asynchronous, so return the prefs promise. // getAllPrefs is asynchronous, so return the prefs promise.
......
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