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

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

Issue 2606043004: Perform printer setup on Chrome OS before selecting printer. (Closed)
Patch Set: Created 4 years 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_destination_search_test.js
diff --git a/chrome/test/data/webui/print_preview_destination_search_test.js b/chrome/test/data/webui/print_preview_destination_search_test.js
new file mode 100644
index 0000000000000000000000000000000000000000..4d19bbdb339063f5c9e3042461963e999cb78c4c
--- /dev/null
+++ b/chrome/test/data/webui/print_preview_destination_search_test.js
@@ -0,0 +1,184 @@
+// 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.
+
+var ROOT_PATH = '../../../../';
+
+GEN_INCLUDE(
+ [ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js']);
+
+/**
+ * Test fixture for DestinationSearch of Print Preview.
+ * @constructor
+ * @extends {PolymerTest}
+ */
+function PrintPreviewDestinationSearchTest() {}
+
+PrintPreviewDestinationSearchTest.prototype = {
+ __proto__: PolymerTest.prototype,
+
+ /** @override */
+ browsePreload: 'chrome://print',
+
+ /** @override */
+ runAccessibilityChecks: false,
+
+ /** @override */
+ extraLibraries: PolymerTest.getLibraries(ROOT_PATH),
+};
+
+TEST_F('PrintPreviewDestinationSearchTest', 'Select', function() {
+ var self = this;
+
+ suite('DestinationSearchTest', function() {
+ var root_;
+
+ var destinationSearch_;
+ var nativeLayer_;
+ var invitationStore_;
+ var destinationStore_;
+ var userInfo_;
+
+ function getCaps() {
+ return {
+ 'printer': {
+ 'color': {
+ 'option': [{
+ 'is_default': true,
+ 'type': 'STANDARD_MONOCHROME',
+ 'vendor_id': '13'
+ }]
+ },
+ 'copies': {},
+ 'duplex': {
+ 'option': [
+ {'type': 'NO_DUPLEX'}, {'is_default': true, 'type': 'LONG_EDGE'},
+ {'type': 'SHORT_EDGE'}
+ ]
+ },
+ 'media_size': {
+ 'option': [
+ {
+ 'custom_display_name': 'na letter',
+ 'height_microns': 279400,
+ 'is_default': true,
+ 'name': 'NA_LETTER',
+ 'vendor_id': 'na_letter_8.5x11in',
+ 'width_microns': 215900
+ },
+ {
+ 'custom_display_name': 'na legal',
+ 'height_microns': 355600,
+ 'name': 'NA_LEGAL',
+ 'vendor_id': 'na_legal_8.5x14in',
+ 'width_microns': 215900
+ }
+ ]
+ },
+ 'page_orientation': {
+ 'option': [
+ {'is_default': true, 'type': 'PORTRAIT'}, {'type': 'LANDSCAPE'},
+ {'type': 'AUTO'}
+ ]
+ },
+ 'supported_content_type': [{'content_type': 'application/pdf'}]
+ },
+ 'version': '1.0'
+ };
+ };
+
+ function waitForEvent(element, eventName) {
+ return new Promise(function(resolve) {
+ var listener = function(e) {
+ resolve();
+ element.removeEventListener(eventName, listener);
+ };
+
+ element.addEventListener(eventName, listener);
+ });
+ };
+
+ function requestSetup(destId, nativeLayerMock, destinationSearch) {
+ var dest = new print_preview.Destination(destId,
+ print_preview.Destination.Type.LOCAL,
+ print_preview.Destination.Origin.CROS,
+ "displayName",
+ print_preview.Destination.ConnectionStatus.ONLINE);
+
+ nativeLayerMock.expects(once()).setupPrinter(destId);
+ destinationSearch.handleOnDestinationSelect_(dest);
+ };
+
+ setup(function() {
+ Mock4JS.clearMocksToVerify();
+
+ nativeLayer_ = mock(print_preview.NativeLayer);
+ nativeLayer_.expects(atLeastOnce())
+ .addEventListener(ANYTHING, ANYTHING, ANYTHING);
+
+ invitationStore_ = new print_preview.InvitationStore();
+ destinationStore_ = new print_preview.DestinationStore(
+ nativeLayer_.proxy(), new print_preview.UserInfo(),
+ new print_preview.AppState());
+ userInfo_ = new print_preview.UserInfo();
+
+ destinationSearch_ = new print_preview.DestinationSearch(
+ destinationStore_, invitationStore_, userInfo_);
+ destinationSearch_.decorate($('destination-search'));
+ });
+
+ teardown(function() {
+ Mock4JS.verifyAllMocks();
+ });
+
+ test('DestinationSelected', function() {
+ var destId = "001122DEADBEEF";
+ requestSetup(destId, nativeLayer_, destinationSearch_);
+ });
+
+ test('ReceiveSuccessfulSetup', function() {
+ var destId = "00112233DEADBEEF";
+ requestSetup(destId, nativeLayer_, destinationSearch_);
+
+ evt = new Event(print_preview.NativeLayer.EventType.PRINTER_SETUP);
+ evt.printerId = destId;
+ evt.capabilities = getCaps();
+ evt.success = true;
+
+ waiter = waitForEvent(
+ destinationStore_,
+ print_preview.DestinationStore.EventType.DESTINATION_SELECT);
+
+ destinationStore_.handleCrosDestinationResolved_(evt);
+
+ // wait for event propogation to complete.
+ return waiter.then(function() {
+ // after setup succeeds, the destination should be selected.
+ assertNotEquals(null, destinationStore_.selectedDestination);
+ assertEquals(destId, destinationStore_.selectedDestination.id);
+ });
+ });
+
+ test('ReceiveFailedSetup', function() {
+ var destId = '00112233DEADBEEF';
+ requestSetup(destId, nativeLayer_, destinationSearch_);
+
+ evt = new Event(print_preview.NativeLayer.EventType.PRINTER_SETUP);
+ evt.printerId = destId;
+ evt.capabilities = null;
+ evt.success = false;
+
+ waiter = waitForEvent(
+ destinationStore_,
+ print_preview.DestinationStore.EventType.PRINTER_CONFIGURED);
+
+ destinationStore_.handleCrosDestinationResolved_(evt);
+
+ return waiter.then(function() {
+ assertEquals(null, destinationStore_.selectedDestination);
+ });
+ });
+ });
+
+ mocha.run();
+});
« chrome/browser/resources/print_preview/search/destination_search.js ('K') | « chrome/test/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698