Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Unified Diff: chrome/test/data/webui/print_preview/print_preview.js

Issue 2893003003: Print Preview: Merge NativeLayerStubs for tests (Closed)
Patch Set: Address comments, rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/webui/print_preview/print_preview.js
diff --git a/chrome/test/data/webui/print_preview.js b/chrome/test/data/webui/print_preview/print_preview.js
similarity index 90%
rename from chrome/test/data/webui/print_preview.js
rename to chrome/test/data/webui/print_preview/print_preview.js
index 30aea19b5934b318b27607b1996d5a0588039e6b..55a52053dfcf916db2040563aa73c5c5a0d069d6 100644
--- a/chrome/test/data/webui/print_preview.js
+++ b/chrome/test/data/webui/print_preview/print_preview.js
@@ -2,10 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-GEN('#include "base/feature_list.h"');
-GEN('#include "chrome/common/chrome_features.h"');
-
-var ROOT_PATH = '../../../../';
+var ROOT_PATH = '../../../../../';
/**
* Test fixture for print preview WebUI testing.
@@ -50,7 +47,7 @@ PrintPreviewWebUITest.prototype = {
* @type {string}
* @override
*/
- browsePrintPreload: 'print_preview_hello_world_test.html',
+ browsePrintPreload: 'print_preview/print_preview_hello_world_test.html',
/** @override */
runAccessibilityChecks: true,
@@ -70,45 +67,6 @@ PrintPreviewWebUITest.prototype = {
preLoad: function() {
window.isTest = true;
window.addEventListener('DOMContentLoaded', function() {
- /**
- * Test version of the native layer.
- * @constructor
- * @extends {settings.TestBrowserProxy}
- */
- function NativeLayerStub() {
- settings.TestBrowserProxy.call(this, [ 'getInitialSettings' ]);
- this.eventTarget_ = new cr.EventTarget();
- this.printStarted_ = false;
- this.generateDraft_ = false;
- this.initialSettings_ = null;
- }
- NativeLayerStub.prototype = {
- __proto__: settings.TestBrowserProxy.prototype,
- getEventTarget: function() { return this.eventTarget_; },
- isPrintStarted: function() { return this.printStarted_; },
- generateDraft: function() { return this.generateDraft_; },
- getInitialSettings: function() {
- this.methodCalled('getInitialSettings');
- return Promise.resolve(this.initialSettings_);
- },
- previewReadyForTest: function() {},
- startGetLocalDestinations: function() {},
- startGetPrivetDestinations: function() {},
- startGetExtensionDestinations: function() {},
- startGetLocalDestinationCapabilities: function(destinationId) {},
- startGetPreview: function(destination, printTicketStore, documentInfo,
- generateDraft, requestId) {
- this.generateDraft_ = generateDraft;
- },
- startHideDialog: function () {},
- startPrint: function () { this.printStarted_ = true; }
- };
- var oldNativeLayerEventType = print_preview.NativeLayer.EventType;
- var oldDuplexMode = print_preview.NativeLayer.DuplexMode;
- print_preview.NativeLayer = NativeLayerStub;
- print_preview.NativeLayer.EventType = oldNativeLayerEventType;
- print_preview.NativeLayer.DuplexMode = oldDuplexMode;
-
function CloudPrintInterfaceStub() {
cr.EventTarget.call(this);
}
@@ -132,6 +90,7 @@ PrintPreviewWebUITest.prototype = {
ROOT_PATH + 'ui/webui/resources/js/promise_resolver.js',
ROOT_PATH + 'ui/webui/resources/js/util.js',
ROOT_PATH + 'chrome/test/data/webui/settings/test_browser_proxy.js',
+ 'native_layer_stub.js',
],
/**
@@ -139,9 +98,10 @@ PrintPreviewWebUITest.prototype = {
* |nativeLayer_| and |previewArea_|.
*/
createPrintPreview: function() {
+ this.nativeLayer_ = new print_preview.NativeLayerStub();
+ print_preview.NativeLayer.setInstance(this.nativeLayer_);
this.printPreview_ = new print_preview.PrintPreview();
- this.nativeLayer_ = this.printPreview_.nativeLayer_;
- this.previewArea_ = this.printPreview_.previewArea_;
+ this.previewArea_ = this.printPreview_.getPreviewArea();
},
/**
@@ -150,12 +110,9 @@ PrintPreviewWebUITest.prototype = {
* already exist.
*/
setInitialSettings: function() {
- if (!this.printPreview_) {
- this.printPreview_ = new print_preview.PrintPreview();
- this.nativeLayer_ = this.printPreview_.nativeLayer_;
- this.previewArea_ = this.printPreview_.previewArea_;
- }
- this.nativeLayer_.initialSettings_ = this.initialSettings_;
+ if (!this.printPreview_)
+ this.createPrintPreview();
+ this.nativeLayer_.setInitialSettings(this.initialSettings_);
this.printPreview_.initialize();
testing.Test.disableAnimationsAndTransitions();
// Enable when failure is resolved.
@@ -264,13 +221,6 @@ PrintPreviewWebUITest.prototype = {
},
/**
- * Generate a real C++ class; don't typedef.
- * @type {?string}
- * @override
- */
- typedefCppFixture: null,
-
- /**
* @this {PrintPreviewWebUITest}
* @override
*/
@@ -298,12 +248,10 @@ PrintPreviewWebUITest.prototype = {
},
};
-GEN('#include "chrome/test/data/webui/print_preview.h"');
-
// Test some basic assumptions about the print preview WebUI.
TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() {
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
var recentList =
@@ -335,7 +283,7 @@ TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() {
TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() {
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
@@ -467,7 +415,7 @@ TEST_F('PrintPreviewWebUITest', 'TestPrintPreviewRestoreLocalDestination',
'"extensionName":""}]}';
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
testDone();
});
@@ -514,7 +462,7 @@ TEST_F('PrintPreviewWebUITest', 'TestPrintPreviewRestoreMultipleDestinations',
this.initialSettings_.serializedAppStateStr_ = JSON.stringify(appState);
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
// Set capabilities for the three recently used destinations + 1 more
this.setCapabilities(getCddTemplate('ID1'));
@@ -556,7 +504,7 @@ TEST_F('PrintPreviewWebUITest',
this.initialSettings_.serializedDefaultDestinationSelectionRulesStr_ =
'{"namePattern":".*Bar.*"}';
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
@@ -574,7 +522,7 @@ TEST_F('PrintPreviewWebUITest', 'TestSystemDialogLinkIsHiddenInAppKioskMode',
this.initialSettings_.isInAppKioskMode_ = true;
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
if (cr.isChromeOS)
assertEquals(null, $('system-dialog-link'));
@@ -592,7 +540,7 @@ TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() {
checkSectionVisible($('copies-settings'), false);
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
var device = getCddTemplate("FooDevice");
@@ -620,7 +568,7 @@ TEST_F('PrintPreviewWebUITest', 'PrintToPDFSelectedCapabilities', function() {
this.initialSettings_.systemDefaultDestinationId_ = 'Save as PDF';
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
var device = {
printerId: 'Save as PDF',
@@ -674,7 +622,7 @@ TEST_F('PrintPreviewWebUITest', 'PrintToPDFSelectedCapabilities', function() {
// media size option.
TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLCapabilities', function() {
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
this.setCapabilities(getCddTemplate("FooDevice"));
@@ -713,7 +661,7 @@ TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLCapabilities', function() {
TEST_F('PrintPreviewWebUITest', 'SourceIsPDFCapabilities', function() {
this.initialSettings_.isDocumentModifiable_ = false;
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
this.setCapabilities(getCddTemplate("FooDevice"));
@@ -752,7 +700,7 @@ TEST_F('PrintPreviewWebUITest', 'SourceIsPDFCapabilities', function() {
TEST_F('PrintPreviewWebUITest', 'ScalingUnchecksFitToPage', function() {
this.initialSettings_.isDocumentModifiable_ = false;
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
this.setCapabilities(getCddTemplate("FooDevice"));
@@ -793,7 +741,7 @@ TEST_F('PrintPreviewWebUITest', 'ScalingUnchecksFitToPage', function() {
TEST_F('PrintPreviewWebUITest', 'CheckNumCopiesPrintPreset', function() {
this.initialSettings_.isDocumentModifiable_ = false;
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
this.setCapabilities(getCddTemplate("FooDevice"));
@@ -825,7 +773,7 @@ TEST_F('PrintPreviewWebUITest', 'CheckDuplexPrintPreset', function() {
this.initialSettings_.isDocumentModifiable_ = false;
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
this.setCapabilities(getCddTemplate("FooDevice"));
@@ -854,7 +802,7 @@ TEST_F('PrintPreviewWebUITest', 'CheckDuplexPrintPreset', function() {
// Make sure that custom margins controls are properly set up.
TEST_F('PrintPreviewWebUITest', 'CustomMarginsControlsCheck', function() {
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
this.setCapabilities(getCddTemplate("FooDevice"));
@@ -878,7 +826,7 @@ TEST_F('PrintPreviewWebUITest', 'CustomMarginsControlsCheck', function() {
TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter',
function() {
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
this.setCapabilities(getCddTemplate("FooDevice"));
@@ -911,7 +859,7 @@ TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter',
TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter',
function() {
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
this.setCapabilities(getCddTemplate("FooDevice"));
@@ -945,7 +893,7 @@ TEST_F('PrintPreviewWebUITest',
'ZeroTopAndBottomMarginsHideHeaderFooter',
function() {
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
this.setCapabilities(getCddTemplate("FooDevice"));
@@ -980,7 +928,7 @@ TEST_F('PrintPreviewWebUITest',
'ZeroTopAndNonZeroBottomMarginShowHeaderFooter',
function() {
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
this.setCapabilities(getCddTemplate("FooDevice"));
@@ -1012,7 +960,7 @@ TEST_F('PrintPreviewWebUITest',
// Check header footer availability with small (label) page size.
TEST_F('PrintPreviewWebUITest', 'SmallPaperSizeHeaderFooter', function() {
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
var device = getCddTemplate("FooDevice");
@@ -1057,7 +1005,7 @@ TEST_F('PrintPreviewWebUITest', 'SmallPaperSizeHeaderFooter', function() {
// Test that the color settings, one option, standard monochrome.
TEST_F('PrintPreviewWebUITest', 'TestColorSettingsMonochrome', function() {
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
@@ -1080,7 +1028,7 @@ TEST_F('PrintPreviewWebUITest', 'TestColorSettingsMonochrome', function() {
TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomMonochrome',
function() {
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
@@ -1103,7 +1051,7 @@ TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomMonochrome',
// Test that the color settings, one option, standard color.
TEST_F('PrintPreviewWebUITest', 'TestColorSettingsColor', function() {
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
@@ -1124,7 +1072,7 @@ TEST_F('PrintPreviewWebUITest', 'TestColorSettingsColor', function() {
// Test that the color settings, one option, custom color.
TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomColor', function() {
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
@@ -1146,7 +1094,7 @@ TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomColor', function() {
TEST_F('PrintPreviewWebUITest', 'TestColorSettingsBothStandardDefaultColor',
function() {
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
@@ -1173,7 +1121,7 @@ TEST_F('PrintPreviewWebUITest', 'TestColorSettingsBothStandardDefaultColor',
TEST_F('PrintPreviewWebUITest',
'TestColorSettingsBothStandardDefaultMonochrome', function() {
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
@@ -1199,7 +1147,7 @@ TEST_F('PrintPreviewWebUITest',
TEST_F('PrintPreviewWebUITest',
'TestColorSettingsBothCustomDefaultColor', function() {
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
@@ -1225,7 +1173,7 @@ TEST_F('PrintPreviewWebUITest',
// capabilities.
TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() {
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
this.setCapabilities(getCddTemplate("FooDevice"));
@@ -1244,7 +1192,7 @@ TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() {
// capabilities.
TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() {
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
var device = getCddTemplate("FooDevice");
@@ -1268,13 +1216,13 @@ TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() {
// Test that changing the selected printer updates the preview.
TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() {
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
this.setCapabilities(getCddTemplate("FooDevice"));
var previewGenerator = mock(print_preview.PreviewGenerator);
- this.printPreview_.previewArea_.previewGenerator_ =
+ this.previewArea_.previewGenerator_ =
previewGenerator.proxy();
// The number of settings that can change due to a change in the
@@ -1304,7 +1252,7 @@ TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() {
// Test that error message is displayed when plugin doesn't exist.
TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() {
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
var previewAreaEl = $('preview-area');
@@ -1334,7 +1282,7 @@ TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() {
// Test custom localized paper names.
TEST_F('PrintPreviewWebUITest', 'TestCustomPaperNames', function() {
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
@@ -1460,7 +1408,7 @@ TEST_F('PrintPreviewWebUITest', 'TestAdvancedSettings1Option', function() {
var device = getCddTemplateWithAdvancedSettings("FooDevice");
this.accessibilityIssuesAreErrors = false;
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setupAdvancedSettingsTest(device);
@@ -1498,7 +1446,7 @@ TEST_F('PrintPreviewWebUITest', 'TestAdvancedSettings2Options', function() {
});
this.accessibilityIssuesAreErrors = false;
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setupAdvancedSettingsTest(device);
@@ -1539,7 +1487,7 @@ TEST_F('PrintPreviewWebUITest', 'TestInitIssuesOneRequest', function() {
this.setCapabilities(getCddTemplate('ID3'));
// Use a real preview generator.
- this.printPreview_.previewArea_.previewGenerator_ =
+ this.previewArea_.previewGenerator_ =
new print_preview.PreviewGenerator(this.printPreview_.destinationStore_,
this.printPreview_.printTicketStore_, this.nativeLayer_,
this.printPreview_.documentInfo_);
@@ -1550,13 +1498,13 @@ TEST_F('PrintPreviewWebUITest', 'TestInitIssuesOneRequest', function() {
// crbug.com/666595
expectEquals(
-1,
- this.printPreview_.previewArea_.previewGenerator_.inFlightRequestId_);
+ this.previewArea_.previewGenerator_.inFlightRequestId_);
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
expectEquals(
0,
- this.printPreview_.previewArea_.previewGenerator_.
+ this.previewArea_.previewGenerator_.
inFlightRequestId_);
testDone();
}.bind(this));
@@ -1568,7 +1516,7 @@ TEST_F('PrintPreviewWebUITest', 'TestInitIssuesOneRequest', function() {
TEST_F('PrintPreviewWebUITest', 'TestInvalidSettingsError', function() {
// Setup
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
this.setCapabilities(getCddTemplate("FooDevice"));
@@ -1633,13 +1581,13 @@ TEST_F('PrintPreviewWebUITest', 'TestGenerateDraft', function() {
this.createPrintPreview();
// Use a real preview generator.
- this.printPreview_.previewArea_.previewGenerator_ =
+ this.previewArea_.previewGenerator_ =
new print_preview.PreviewGenerator(this.printPreview_.destinationStore_,
this.printPreview_.printTicketStore_, this.nativeLayer_,
this.printPreview_.documentInfo_);
this.setInitialSettings();
- this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
+ this.nativeLayer_.whenCalled('getInitialSettings').then(
function() {
this.setLocalDestinations();
this.setCapabilities(getCddTemplate("FooDevice"));

Powered by Google App Engine
This is Rietveld 408576698