Commit 822d830f authored by rbpotter's avatar rbpotter Committed by Commit Bot

Print Preview: Fix flaky tests on Mac

A couple tests:
PrintPreviewSettingsSelectTest.All
PrintPreviewOtherOptionsSettingsTest.All

were flaky on Mac. This is because on Mac, the initial settings
returned from C++ after the print-preview-app was detached and the
new model instance was attached. These tests don't expect
print-preview-app to be running as they are unit tests for the
elements they test, but print preview app still ran
onInitialSettingsSet_ when the new Model instance resolved the
whenReady() promise.

To fix this, get the model whenReady() promise in attached(), and
store it in print-preview-app. Clear it when the app is detached
and check its value before dereferencing. This ensures that the app
only continues to initialize everything if its own model is still
attached.

Also changing settings select test to add binding after setting the
settings property, for consistency with other tests.

Bug: 945846
Change-Id: Id59bd412071af3a88e9e778c61b02bc729234856
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1540072Reviewed-by: default avatarEsmael El-Moslimany <aee@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#644899}
parent 14e8e787
......@@ -89,6 +89,9 @@ Polymer({
/** @private {boolean} */
isInKioskAutoPrintMode_: false,
/** @private {?Promise} */
whenReady_: null,
/** @private {!Array<!CrDialogElement>} */
openDialogs_: [],
......@@ -108,6 +111,7 @@ Polymer({
'print-preset-options', this.onPrintPresetOptions_.bind(this));
this.tracker_.add(window, 'keydown', this.onKeyDown_.bind(this));
this.$.previewArea.setPluginKeyEventCallback(this.onKeyDown_.bind(this));
this.whenReady_ = print_preview.Model.whenReady();
this.nativeLayer_.getInitialSettings().then(
this.onInitialSettingsSet_.bind(this));
},
......@@ -115,6 +119,7 @@ Polymer({
/** @override */
detached: function() {
this.tracker_.removeAll();
this.whenReady_ = null;
},
/**
......@@ -221,7 +226,12 @@ Polymer({
* @private
*/
onInitialSettingsSet_: function(settings) {
print_preview.Model.whenReady().then(() => {
if (!this.whenReady_) {
// This element and its corresponding model were detached while waiting
// for the callback. This can happen in tests; return early.
return;
}
this.whenReady_.then(() => {
this.$.documentInfo.init(
settings.previewModifiable, settings.documentTitle,
settings.documentHasSelection);
......@@ -257,7 +267,12 @@ Polymer({
* @private
*/
onCloudPrintEnable_: function(cloudPrintUrl, appKioskMode) {
print_preview.Model.whenReady().then(() => {
if (!this.whenReady_) {
// This element and its corresponding model were detached while waiting
// for the callback. This can happen in tests; return early.
return;
}
this.whenReady_.then(() => {
assert(!this.cloudPrintInterface_);
this.cloudPrintInterface_ = cloudprint.getCloudPrintInterface(
cloudPrintUrl, assert(this.nativeLayer_), appKioskMode);
......
......@@ -189,13 +189,7 @@ PrintPreviewSettingsSelectTest = class extends NewPrintPreviewTest {
}
};
// TODO(https://crbug.com/945846): Flaky on Mac.
GEN('#if defined(OS_MACOSX)');
GEN('#define MAYBE_All DISABLED_All');
GEN('#else');
GEN('#define MAYBE_All All');
GEN('#endif');
TEST_F('PrintPreviewSettingsSelectTest', 'MAYBE_All', function() {
TEST_F('PrintPreviewSettingsSelectTest', 'All', function() {
mocha.run();
});
......
......@@ -17,9 +17,9 @@ cr.define('settings_select_test', function() {
document.body.appendChild(model);
settingsSelect = document.createElement('print-preview-settings-select');
test_util.fakeDataBind(model, settingsSelect, 'settings');
settingsSelect.settings = model.settings;
settingsSelect.disabled = false;
test_util.fakeDataBind(model, settingsSelect, 'settings');
document.body.appendChild(settingsSelect);
});
......
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