Commit 5e840a17 authored by dpapad's avatar dpapad Committed by Commit bot

MD Settings: Deflake attempt for CrSettingsPrivacyPageTest.PrivacyPage.

In one of the test cases, showModal() was called after the dialog had already
been removed from the DOM from tearDown().

BUG=642574
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2341493003
Cr-Commit-Position: refs/heads/master@{#418953}
parent ce6ea242
......@@ -606,20 +606,6 @@ cr.define('settings_about_page', function() {
}
function registerChannelSwitcherDialogTests() {
/**
* Converts an event occurrence to a promise.
* @param {string} eventType
* @param {!HTMLElement} target
* @return {!Promise} A promise firing once the event occurs.
* TODO(dpapad); Share this code with certificate_manager_page_test.js
* identical helper method.
*/
function eventToPromise(eventType, target) {
return new Promise(function(resolve, reject) {
target.addEventListener(eventType, resolve);
});
}
suite('ChannelSwitcherDialogTest', function() {
var dialog = null;
var radioButtons = null;
......@@ -671,7 +657,7 @@ cr.define('settings_about_page', function() {
assertTrue(dialog.$.changeChannelAndPowerwash.hidden);
assertFalse(dialog.$.changeChannel.hidden);
var whenTargetChannelChangedFired = eventToPromise(
var whenTargetChannelChangedFired = test_util.eventToPromise(
'target-channel-changed', dialog);
MockInteractions.tap(dialog.$.changeChannel);
......@@ -696,7 +682,7 @@ cr.define('settings_about_page', function() {
assertFalse(dialog.$.changeChannelAndPowerwash.hidden);
assertTrue(dialog.$.changeChannel.hidden);
var whenTargetChannelChangedFired = eventToPromise(
var whenTargetChannelChangedFired = test_util.eventToPromise(
'target-channel-changed', dialog);
MockInteractions.tap(dialog.$.changeChannelAndPowerwash);
......
......@@ -182,18 +182,6 @@ cr.define('certificate_manager_page', function() {
MockInteractions.keyEventOn(element, 'input', kSpaceBar);
}
/**
* Converts an event occurrence to a promise.
* @param {string} eventType
* @param {!HTMLElement} target
* @return {!Promise} A promise firing once the event occurs.
*/
function eventToPromise(eventType, target) {
return new Promise(function(resolve, reject) {
target.addEventListener(eventType, resolve);
});
}
function registerCaTrustEditDialogTests() {
/** @type {?SettingsCaTrustEditDialogElement} */
var dialog = null;
......@@ -274,7 +262,8 @@ cr.define('certificate_manager_page', function() {
document.body.appendChild(dialog);
browserProxy.forceCertificatesError();
var whenErrorEventFired = eventToPromise('certificates-error', dialog);
var whenErrorEventFired =
test_util.eventToPromise('certificates-error', dialog);
return browserProxy.whenCalled('getCaCertificateTrust').then(
function() {
......@@ -331,7 +320,8 @@ cr.define('certificate_manager_page', function() {
test('DeleteError', function() {
browserProxy.forceCertificatesError();
var whenErrorEventFired = eventToPromise('certificates-error', dialog);
var whenErrorEventFired =
test_util.eventToPromise('certificates-error', dialog);
// Simulate clicking 'OK'.
MockInteractions.tap(dialog.$.ok);
......@@ -414,7 +404,8 @@ cr.define('certificate_manager_page', function() {
confirmPasswordInputElement.value = passwordInputElement.value;
triggerInputEvent(passwordInputElement);
var whenErrorEventFired = eventToPromise('certificates-error', dialog);
var whenErrorEventFired =
test_util.eventToPromise('certificates-error', dialog);
MockInteractions.tap(dialog.$.ok);
return browserProxy.whenCalled(methodName).then(function() {
......@@ -477,7 +468,8 @@ cr.define('certificate_manager_page', function() {
passwordInputElement.value = 'foopassword';
triggerInputEvent(passwordInputElement);
var whenErrorEventFired = eventToPromise('certificates-error', dialog);
var whenErrorEventFired =
test_util.eventToPromise('certificates-error', dialog);
MockInteractions.tap(dialog.$.ok);
return browserProxy.whenCalled(methodName).then(function() {
return whenErrorEventFired;
......@@ -497,7 +489,8 @@ cr.define('certificate_manager_page', function() {
* |settings.CertificateActionEvent| fires.
*/
var actionEventToPromise = function() {
return eventToPromise(settings.CertificateActionEvent, subentry);
return test_util.eventToPromise(
settings.CertificateActionEvent, subentry);
};
suite('CertificateSubentryTests', function() {
......@@ -722,24 +715,10 @@ cr.define('certificate_manager_page', function() {
var dialog = page.shadowRoot.querySelector(dialogTagName);
assertTrue(!!dialog);
if (dialog.$.dialog.open)
return Promise.resolve();
// Some dialogs are opened after some async operation to fetch initial
// data. Ensure that the underlying cr-dialog is actually opened by
// listening for changes for the 'open' attribute.
return new Promise(function(resolve, reject) {
var observer = new MutationObserver(function(mutations) {
assertEquals(1, mutations.length);
assertEquals('attributes', mutations[0].type);
assertEquals('open', mutations[0].attributeName);
observer.disconnect();
resolve();
});
observer.observe(
dialog.$.dialog,
{attributes: true, childList: false, characterData: false});
});
// data. Ensure that the underlying cr-dialog is actually opened before
// returning.
return test_util.whenAttributeIs(dialog.$.dialog, 'open', true);
}
test('OpensDialog_DeleteConfirmation', function() {
......@@ -830,7 +809,7 @@ cr.define('certificate_manager_page', function() {
assertTrue(!!importButton);
var waitForActionEvent = actionEventExpected ?
eventToPromise(settings.CertificateActionEvent, element) :
test_util.eventToPromise(settings.CertificateActionEvent, element) :
Promise.resolve(null);
MockInteractions.tap(importButton);
......
......@@ -138,6 +138,7 @@ CrSettingsAboutPageTest.prototype = {
/** @override */
extraLibraries: CrSettingsBrowserTest.prototype.extraLibraries.concat([
'test_util.js',
'test_browser_proxy.js',
'test_lifetime_browser_proxy.js',
'about_page_tests.js',
......@@ -438,6 +439,7 @@ CrSettingsCertificateManagerTest.prototype = {
/** @override */
extraLibraries: CrSettingsBrowserTest.prototype.extraLibraries.concat([
'test_util.js',
'test_browser_proxy.js',
'certificate_manager_page_test.js',
]),
......@@ -465,13 +467,13 @@ CrSettingsPrivacyPageTest.prototype = {
/** @override */
extraLibraries: CrSettingsBrowserTest.prototype.extraLibraries.concat([
ROOT_PATH + 'ui/webui/resources/js/promise_resolver.js',
'test_util.js',
'test_browser_proxy.js',
'privacy_page_test.js',
]),
};
// TODO(crbug.com/642574) Disabled because test is flaky.
TEST_F('CrSettingsPrivacyPageTest', 'DISABLED_PrivacyPage', function() {
TEST_F('CrSettingsPrivacyPageTest', 'PrivacyPage', function() {
settings_privacy_page.registerTests();
mocha.run();
});
......
......@@ -105,7 +105,14 @@ cr.define('settings_privacy_page', function() {
assertFalse(!!page.$$('settings-clear-browsing-data-dialog'));
MockInteractions.tap(page.$.clearBrowsingData);
Polymer.dom.flush();
assertTrue(!!page.$$('settings-clear-browsing-data-dialog'));
var dialog = page.$$('settings-clear-browsing-data-dialog');
assertTrue(!!dialog);
// Ensure that the dialog is fully opened before returning from this
// test, otherwise asynchronous code run in attached() can cause flaky
// errors.
return test_util.whenAttributeIs(dialog.$.dialog, 'open', true);
});
});
}
......
// 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('test_util', function() {
/**
* Observes an HTML attribute and fires a promise when it matches a given
* value.
* @param {!HTMLElement} target
* @param {string} attributeName
* @param {*} attributeValue
* @return {!Promise}
*/
function whenAttributeIs(target, attributeName, attributeValue) {
function isDone() { return target[attributeName] === attributeValue; }
return isDone() ? Promise.resolve() : new Promise(function(resolve) {
new MutationObserver(function(mutations, observer) {
for (var mutation of mutations) {
assertEquals('attributes', mutation.type);
if (mutation.attributeName == attributeName && isDone()) {
observer.disconnect();
resolve();
return;
}
}
}).observe(
target, {attributes: true, childList: false, characterData: false});
});
}
/**
* Converts an event occurrence to a promise.
* @param {string} eventType
* @param {!HTMLElement} target
* @return {!Promise} A promise firing once the event occurs.
*/
function eventToPromise(eventType, target) {
return new Promise(function(resolve, reject) {
target.addEventListener(eventType, resolve);
});
}
return {
eventToPromise: eventToPromise,
whenAttributeIs: whenAttributeIs,
};
});
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