Index: chrome/test/data/webui/print_preview.js |
diff --git a/chrome/test/data/webui/print_preview.js b/chrome/test/data/webui/print_preview.js |
index d5dc8dac97af6b3e95348be078f579f1c4dfed20..df28e9ec52209296dcbfb9eaad9fb9b0e764fe50 100644 |
--- a/chrome/test/data/webui/print_preview.js |
+++ b/chrome/test/data/webui/print_preview.js |
@@ -35,6 +35,8 @@ PrintPreviewWebUITest.FOO_INDEX = 1; |
*/ |
PrintPreviewWebUITest.BAR_INDEX = 2; |
+PrintPreviewWebUITest.TIMEOUT = 500; |
+ |
PrintPreviewWebUITest.prototype = { |
__proto__: testing.Test.prototype, |
@@ -45,6 +47,15 @@ PrintPreviewWebUITest.prototype = { |
*/ |
browsePrintPreload: 'print_preview_hello_world_test.html', |
+ /** @override */ |
+ runAccessibilityChecks: true, |
+ |
+ /** @override */ |
+ accessibilityIssuesAreErrors: true, |
+ |
+ /** @override */ |
+ isAsync: true, |
+ |
/** |
* Stub out low-level functionality like the NativeLayer and |
* CloudPrintInterface. |
@@ -99,6 +110,27 @@ PrintPreviewWebUITest.prototype = { |
this.nativeLayer_.dispatchEvent(localDestsSetEvent); |
}, |
+ waitForTransitionEvents: function(expectedTransitions) { |
+ // add a listener for the transition end event |
+ document.addEventListener('webkitTransitionEnd', function finishTest(e) { |
+ if (--expectedTransitions <= 0) { |
+ // end the test once all expected transitions are done |
Dan Beam
2014/10/15 21:37:31
why not when a specific transition ends, e.g.
e
hcarmona
2014/10/17 01:35:53
Done.
|
+ console.log('transitions done'); |
+ testDone(); |
+ } |
+ else { |
+ // If more transitions are expected, make sure they will happen |
+ // because the webkitTransitionEnd event is sometimes flaky. |
+ console.log('transitions remain: ' + expectedTransitions); |
+ ensureTransitionEndEvent(document, PrintPreviewWebUITest.TIMEOUT); |
Dan Beam
2014/10/15 21:39:19
we should not have to do this
hcarmona
2014/10/17 01:35:53
Acknowledged.
|
+ } |
+ }); |
+ |
+ // Event is not thrown if there is no draw event. This will ensure that |
+ // the event is thrown to keep test from waiting forever. |
+ ensureTransitionEndEvent(document, PrintPreviewWebUITest.TIMEOUT); |
+ }, |
+ |
/** |
* Generate a real C++ class; don't typedef. |
* @type {?string} |
@@ -139,15 +171,7 @@ GEN('#include "chrome/test/data/webui/print_preview.h"'); |
// Test some basic assumptions about the print preview WebUI. |
TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() { |
- var initialSettingsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); |
- initialSettingsSetEvent.initialSettings = this.initialSettings_; |
- this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); |
- |
- var localDestsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); |
- localDestsSetEvent.destinationInfos = this.localDestinationInfos_; |
- this.nativeLayer_.dispatchEvent(localDestsSetEvent); |
+ this.setUpPreview(); |
var recentList = $('destination-search').querySelector('.recent-list ul'); |
var localList = $('destination-search').querySelector('.local-list ul'); |
@@ -168,20 +192,13 @@ TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() { |
assertEquals('BarName', |
localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX). |
querySelector('.destination-list-item-name').textContent); |
+ testDone(); |
}); |
// Test that the printer list is structured correctly after calling |
// addCloudPrinters with an empty list. |
TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() { |
- var initialSettingsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); |
- initialSettingsSetEvent.initialSettings = this.initialSettings_; |
- this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); |
- |
- var localDestsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); |
- localDestsSetEvent.destinationInfos = this.localDestinationInfos_; |
- this.nativeLayer_.dispatchEvent(localDestsSetEvent); |
+ this.setUpPreview(); |
var cloudPrintEnableEvent = |
new Event(print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE); |
@@ -219,6 +236,7 @@ TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() { |
assertNotEquals(null, cloudList); |
assertEquals(0, cloudList.childNodes.length); |
+ testDone(); |
}); |
/** |
@@ -292,6 +310,7 @@ TEST_F('PrintPreviewWebUITest', 'TestSystemDialogLinkIsHiddenInAppKiosMode', |
this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); |
checkElementDisplayed($('system-dialog-link'), false); |
+ testDone(); |
}); |
// Test that disabled settings hide the disabled sections. |
@@ -299,16 +318,7 @@ TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() { |
checkSectionVisible($('layout-settings'), false); |
checkSectionVisible($('color-settings'), false); |
checkSectionVisible($('copies-settings'), false); |
- |
- var initialSettingsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); |
- initialSettingsSetEvent.initialSettings = this.initialSettings_; |
- this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); |
- |
- var localDestsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); |
- localDestsSetEvent.destinationInfos = this.localDestinationInfos_; |
- this.nativeLayer_.dispatchEvent(localDestsSetEvent); |
+ this.setUpPreview(); |
var capsSetEvent = |
new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); |
@@ -324,6 +334,7 @@ TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() { |
checkSectionVisible($('layout-settings'), true); |
checkSectionVisible($('color-settings'), false); |
checkSectionVisible($('copies-settings'), false); |
+ testDone(); |
}); |
// When the source is 'PDF' and 'Save as PDF' option is selected, we hide the |
@@ -373,20 +384,13 @@ TEST_F('PrintPreviewWebUITest', 'PrintToPDFSelectedCapabilities', function() { |
checkSectionVisible($('other-options-settings'), false); |
checkSectionVisible($('media-size-settings'), false); |
+ testDone(); |
}); |
// When the source is 'HTML', we always hide the fit to page option and show |
// media size option. |
TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLCapabilities', function() { |
- var initialSettingsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); |
- initialSettingsSetEvent.initialSettings = this.initialSettings_; |
- this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); |
- |
- var localDestsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); |
- localDestsSetEvent.destinationInfos = this.localDestinationInfos_; |
- this.nativeLayer_.dispatchEvent(localDestsSetEvent); |
+ this.setUpPreview(); |
var capsSetEvent = |
new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); |
@@ -409,22 +413,15 @@ TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLCapabilities', function() { |
checkElementDisplayed(fitToPageEl, false); |
checkSectionVisible(mediaSizeDiv, true); |
+ |
+ this.waitForTransitionEvents(1); |
}); |
// When the source is "PDF", depending on the selected destination printer, we |
// show/hide the fit to page option and hide media size selection. |
TEST_F('PrintPreviewWebUITest', 'SourceIsPDFCapabilities', function() { |
this.initialSettings_.isDocumentModifiable_ = false; |
- |
- var initialSettingsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); |
- initialSettingsSetEvent.initialSettings = this.initialSettings_; |
- this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); |
- |
- var localDestsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); |
- localDestsSetEvent.destinationInfos = this.localDestinationInfos_; |
- this.nativeLayer_.dispatchEvent(localDestsSetEvent); |
+ this.setUpPreview(); |
var capsSetEvent = |
new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); |
@@ -439,22 +436,14 @@ TEST_F('PrintPreviewWebUITest', 'SourceIsPDFCapabilities', function() { |
expectTrue( |
otherOptionsDiv.querySelector('.fit-to-page-checkbox').checked); |
checkSectionVisible($('media-size-settings'), true); |
+ testDone(); |
Dan Beam
2014/10/15 21:37:31
function PrintPreviewWebUIAsyncTest() {}
PrintPre
Dan Beam
2014/10/15 21:39:18
(so you don't have to put all these useless testDo
hcarmona
2014/10/17 01:35:53
Acknowledged.
hcarmona
2014/10/17 01:35:53
Done.
|
}); |
// When the print scaling is disabled for the source "PDF", we show the fit |
// to page option but the state is unchecked by default. |
TEST_F('PrintPreviewWebUITest', 'PrintScalingDisabledForPlugin', function() { |
this.initialSettings_.isDocumentModifiable_ = false; |
- |
- var initialSettingsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); |
- initialSettingsSetEvent.initialSettings = this.initialSettings_; |
- this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); |
- |
- var localDestsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); |
- localDestsSetEvent.destinationInfos = this.localDestinationInfos_; |
- this.nativeLayer_.dispatchEvent(localDestsSetEvent); |
+ this.setUpPreview(); |
var capsSetEvent = |
new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); |
@@ -473,19 +462,12 @@ TEST_F('PrintPreviewWebUITest', 'PrintScalingDisabledForPlugin', function() { |
otherOptionsDiv.querySelector('.fit-to-page-container'), true); |
expectFalse( |
otherOptionsDiv.querySelector('.fit-to-page-checkbox').checked); |
+ testDone(); |
}); |
// Make sure that custom margins controls are properly set up. |
TEST_F('PrintPreviewWebUITest', 'CustomMarginsControlsCheck', function() { |
- var initialSettingsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); |
- initialSettingsSetEvent.initialSettings = this.initialSettings_; |
- this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); |
- |
- var localDestsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); |
- localDestsSetEvent.destinationInfos = this.localDestinationInfos_; |
- this.nativeLayer_.dispatchEvent(localDestsSetEvent); |
+ this.setUpPreview(); |
var capsSetEvent = |
new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); |
@@ -502,20 +484,13 @@ TEST_F('PrintPreviewWebUITest', 'CustomMarginsControlsCheck', function() { |
assertTrue(input.hasAttribute('aria-label')); |
assertNotEquals('undefined', input.getAttribute('aria-label')); |
}); |
+ testDone(); |
}); |
// Page layout has zero margins. Hide header and footer option. |
TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter', |
function() { |
- var initialSettingsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); |
- initialSettingsSetEvent.initialSettings = this.initialSettings_; |
- this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); |
- |
- var localDestsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); |
- localDestsSetEvent.destinationInfos = this.localDestinationInfos_; |
- this.nativeLayer_.dispatchEvent(localDestsSetEvent); |
+ this.setUpPreview(); |
var capsSetEvent = |
new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); |
@@ -543,21 +518,14 @@ TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter', |
new print_preview.Margins(0, 0, 0, 0)); |
checkElementDisplayed(headerFooterEl, false); |
+ |
+ this.waitForTransitionEvents(4); |
}); |
// Page layout has half-inch margins. Show header and footer option. |
TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter', |
function() { |
- var initialSettingsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); |
- initialSettingsSetEvent.initialSettings = this.initialSettings_; |
- this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); |
- |
- var localDestsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); |
- localDestsSetEvent.destinationInfos = this.localDestinationInfos_; |
- this.nativeLayer_.dispatchEvent(localDestsSetEvent); |
- |
+ this.setUpPreview(); |
var capsSetEvent = |
new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); |
capsSetEvent.settingsInfo = getCddTemplate("FooDevice"); |
@@ -584,21 +552,15 @@ TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter', |
new print_preview.Margins(36, 36, 36, 36)); |
checkElementDisplayed(headerFooterEl, true); |
+ |
+ this.waitForTransitionEvents(4); |
}); |
// Page layout has zero top and bottom margins. Hide header and footer option. |
TEST_F('PrintPreviewWebUITest', |
'ZeroTopAndBottomMarginsHideHeaderFooter', |
function() { |
- var initialSettingsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); |
- initialSettingsSetEvent.initialSettings = this.initialSettings_; |
- this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); |
- |
- var localDestsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); |
- localDestsSetEvent.destinationInfos = this.localDestinationInfos_; |
- this.nativeLayer_.dispatchEvent(localDestsSetEvent); |
+ this.setUpPreview(); |
var capsSetEvent = |
new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); |
@@ -626,6 +588,8 @@ TEST_F('PrintPreviewWebUITest', |
new print_preview.Margins(0, 36, 0, 36)); |
checkElementDisplayed(headerFooterEl, false); |
+ |
+ this.waitForTransitionEvents(4); |
}); |
// Page layout has zero top and half-inch bottom margin. Show header and footer |
@@ -633,15 +597,7 @@ TEST_F('PrintPreviewWebUITest', |
TEST_F('PrintPreviewWebUITest', |
'ZeroTopAndNonZeroBottomMarginShowHeaderFooter', |
function() { |
- var initialSettingsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); |
- initialSettingsSetEvent.initialSettings = this.initialSettings_; |
- this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); |
- |
- var localDestsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); |
- localDestsSetEvent.destinationInfos = this.localDestinationInfos_; |
- this.nativeLayer_.dispatchEvent(localDestsSetEvent); |
+ this.setUpPreview(); |
var capsSetEvent = |
new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); |
@@ -669,6 +625,7 @@ TEST_F('PrintPreviewWebUITest', |
new print_preview.Margins(0, 36, 36, 36)); |
checkElementDisplayed(headerFooterEl, true); |
+ this.waitForTransitionEvents(4); |
}); |
// Test that the color settings, one option, standard monochrome. |
@@ -687,6 +644,7 @@ TEST_F('PrintPreviewWebUITest', 'TestColorSettingsMonochrome', function() { |
this.nativeLayer_.dispatchEvent(capsSetEvent); |
checkSectionVisible($('color-settings'), false); |
+ testDone(); |
}); |
// Test that the color settings, one option, custom monochrome. |
@@ -706,6 +664,7 @@ TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomMonochrome', |
this.nativeLayer_.dispatchEvent(capsSetEvent); |
checkSectionVisible($('color-settings'), false); |
+ testDone(); |
}); |
// Test that the color settings, one option, standard color. |
@@ -723,6 +682,7 @@ TEST_F('PrintPreviewWebUITest', 'TestColorSettingsColor', function() { |
this.nativeLayer_.dispatchEvent(capsSetEvent); |
checkSectionVisible($('color-settings'), false); |
+ testDone(); |
}); |
// Test that the color settings, one option, custom color. |
@@ -740,6 +700,7 @@ TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomColor', function() { |
this.nativeLayer_.dispatchEvent(capsSetEvent); |
checkSectionVisible($('color-settings'), false); |
+ testDone(); |
}); |
// Test that the color settings, two options, both standard, defaults to color. |
@@ -762,6 +723,7 @@ TEST_F('PrintPreviewWebUITest', 'TestColorSettingsBothStandardDefaultColor', |
expectEquals( |
'color', |
$('color-settings').querySelector('.color-settings-select').value); |
+ testDone(); |
}); |
// Test that the color settings, two options, both standard, defaults to |
@@ -784,6 +746,7 @@ TEST_F('PrintPreviewWebUITest', |
checkSectionVisible($('color-settings'), true); |
expectEquals( |
'bw', $('color-settings').querySelector('.color-settings-select').value); |
+ testDone(); |
}); |
// Test that the color settings, two options, both custom, defaults to color. |
@@ -806,20 +769,13 @@ TEST_F('PrintPreviewWebUITest', |
expectEquals( |
'color', |
$('color-settings').querySelector('.color-settings-select').value); |
+ testDone(); |
}); |
// Test to verify that duplex settings are set according to the printer |
// capabilities. |
TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() { |
- var initialSettingsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); |
- initialSettingsSetEvent.initialSettings = this.initialSettings_; |
- this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); |
- |
- var localDestsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); |
- localDestsSetEvent.destinationInfos = this.localDestinationInfos_; |
- this.nativeLayer_.dispatchEvent(localDestsSetEvent); |
+ this.setUpPreview(); |
var otherOptionsDiv = $('other-options-settings'); |
var duplexDiv = otherOptionsDiv.querySelector('.duplex-container'); |
@@ -833,20 +789,13 @@ TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() { |
checkSectionVisible(otherOptionsDiv, true); |
expectFalse(duplexDiv.hidden); |
expectFalse(duplexCheckbox.checked); |
+ testDone(); |
}); |
// Test to verify that duplex settings are set according to the printer |
// capabilities. |
TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() { |
- var initialSettingsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); |
- initialSettingsSetEvent.initialSettings = this.initialSettings_; |
- this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); |
- |
- var localDestsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); |
- localDestsSetEvent.destinationInfos = this.localDestinationInfos_; |
- this.nativeLayer_.dispatchEvent(localDestsSetEvent); |
+ this.setUpPreview(); |
var moreSettingsDiv = $('more-settings'); |
var otherOptionsDiv = $('other-options-settings'); |
@@ -866,20 +815,13 @@ TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() { |
// Now it should be visible. |
checkSectionVisible(otherOptionsDiv, true); |
expectTrue(duplexDiv.hidden); |
+ |
+ this.waitForTransitionEvents(1); |
}); |
// Test that changing the selected printer updates the preview. |
TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() { |
- |
- var initialSettingsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET); |
- initialSettingsSetEvent.initialSettings = this.initialSettings_; |
- this.nativeLayer_.dispatchEvent(initialSettingsSetEvent); |
- |
- var localDestsSetEvent = |
- new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); |
- localDestsSetEvent.destinationInfos = this.localDestinationInfos_; |
- this.nativeLayer_.dispatchEvent(localDestsSetEvent); |
+ this.setUpPreview(); |
var capsSetEvent = |
new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); |
@@ -910,6 +852,7 @@ TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() { |
] |
}; |
this.nativeLayer_.dispatchEvent(capsSetEvent); |
+ testDone(); |
}); |
// Test that error message is displayed when plugin doesn't exist. |
@@ -931,4 +874,5 @@ TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() { |
var customMessageEl = |
previewAreaEl.getElementsByClassName('preview-area-custom-message')[0]; |
expectEquals(false, customMessageEl.hidden); |
+ testDone(); |
}); |