Commit ee73c358 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Print Preview: Closure compile destination_search/select tests

Adding closure targets for:
destination_select_test
destination_search_test
destination_search_test_chromeos

Bug: 1000989
Change-Id: Iac91004ee5b78120f2a894194a28a13f7626ca1c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2303875Reviewed-by: default avatarJohn Lee <johntlee@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790131}
parent 7d81bf92
...@@ -7,7 +7,7 @@ import './ui/app.js'; ...@@ -7,7 +7,7 @@ import './ui/app.js';
export {PluralStringProxyImpl as PrintPreviewPluralStringProxyImpl} from 'chrome://resources/js/plural_string_proxy.js'; export {PluralStringProxyImpl as PrintPreviewPluralStringProxyImpl} from 'chrome://resources/js/plural_string_proxy.js';
export {CloudPrintInterface, CloudPrintInterfaceEventType} from './cloud_print_interface.js'; export {CloudPrintInterface, CloudPrintInterfaceEventType} from './cloud_print_interface.js';
export {CloudPrintInterfaceImpl} from './cloud_print_interface_impl.js'; export {CloudPrintInterfaceImpl} from './cloud_print_interface_impl.js';
export {ColorMode, createDestinationKey, Destination, DestinationCertificateStatus, DestinationConnectionStatus, DestinationOrigin, DestinationType, makeRecentDestination, RecentDestination} from './data/destination.js'; export {Cdd, ColorMode, createDestinationKey, Destination, DestinationCertificateStatus, DestinationConnectionStatus, DestinationOrigin, DestinationType, makeRecentDestination, RecentDestination} from './data/destination.js';
export {PrinterType} from './data/destination_match.js'; export {PrinterType} from './data/destination_match.js';
// <if expr="chromeos"> // <if expr="chromeos">
export {ColorModeRestriction, DuplexModeRestriction, PinModeRestriction} from './data/destination_policies.js'; export {ColorModeRestriction, DuplexModeRestriction, PinModeRestriction} from './data/destination_policies.js';
......
...@@ -26,10 +26,6 @@ js_type_check("closure_compile") { ...@@ -26,10 +26,6 @@ js_type_check("closure_compile") {
":destination_dialog_test", ":destination_dialog_test",
":destination_item_test", ":destination_item_test",
":destination_list_test", ":destination_list_test",
#":destination_search_test_chromeos",
#":destination_search_test",
#":destination_select_test",
":destination_settings_test", ":destination_settings_test",
#":destination_store_test", #":destination_store_test",
...@@ -75,8 +71,14 @@ js_type_check("closure_compile") { ...@@ -75,8 +71,14 @@ js_type_check("closure_compile") {
if (is_chromeos) { if (is_chromeos) {
deps += [ deps += [
":destination_dropdown_cros_test", ":destination_dropdown_cros_test",
":destination_search_test_chromeos",
":destination_select_test_cros", ":destination_select_test_cros",
] ]
} else {
deps += [
":destination_search_test",
":destination_select_test",
]
} }
} }
...@@ -264,4 +266,38 @@ if (is_chromeos) { ...@@ -264,4 +266,38 @@ if (is_chromeos) {
"//ui/webui/resources/js:assert.m", "//ui/webui/resources/js:assert.m",
] ]
} }
js_library("destination_search_test_chromeos") {
deps = [
":native_layer_stub",
":print_preview_test_utils",
"..:chai_assert",
"..:test_util.m",
"//chrome/browser/resources/print_preview:print_preview",
"//ui/webui/resources/js:assert.m",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
}
} else {
js_library("destination_select_test") {
deps = [
":print_preview_test_utils",
"..:chai_assert",
"//chrome/browser/resources/print_preview:print_preview",
"//ui/webui/resources/js:assert.m",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
}
js_library("destination_search_test") {
deps = [
":native_layer_stub",
":print_preview_test_utils",
"..:chai_assert",
"..:test_util.m",
"//chrome/browser/resources/print_preview:print_preview",
"//ui/webui/resources/js:assert.m",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
}
} }
...@@ -4,12 +4,17 @@ ...@@ -4,12 +4,17 @@
import {Destination, DestinationConnectionStatus, DestinationOrigin, DestinationStore, DestinationType, InvitationStore, NativeLayer, NativeLayerImpl} from 'chrome://print/print_preview.js'; import {Destination, DestinationConnectionStatus, DestinationOrigin, DestinationStore, DestinationType, InvitationStore, NativeLayer, NativeLayerImpl} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js'; import {assert} from 'chrome://resources/js/assert.m.js';
import {NativeEventTarget as EventTarget} from 'chrome://resources/js/cr/event_target.m.js';
import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {NativeLayerStub} from 'chrome://test/print_preview/native_layer_stub.js';
import {createDestinationStore, getCddTemplate, setupTestListenerElement} from 'chrome://test/print_preview/print_preview_test_utils.js'; import {assertEquals, assertNotEquals} from '../chai_assert.js';
import {eventToPromise} from 'chrome://test/test_util.m.js'; import {eventToPromise} from '../test_util.m.js';
import {NativeLayerStub} from './native_layer_stub.js';
import {createDestinationStore, getCddTemplate, setupTestListenerElement} from './print_preview_test_utils.js';
window.destination_search_test = {}; window.destination_search_test = {};
const destination_search_test = window.destination_search_test;
destination_search_test.suiteName = 'DestinationSearchTest'; destination_search_test.suiteName = 'DestinationSearchTest';
/** @enum {string} */ /** @enum {string} */
destination_search_test.TestNames = { destination_search_test.TestNames = {
...@@ -18,14 +23,14 @@ destination_search_test.TestNames = { ...@@ -18,14 +23,14 @@ destination_search_test.TestNames = {
}; };
suite(destination_search_test.suiteName, function() { suite(destination_search_test.suiteName, function() {
/** @type {?PrintPreviewDestinationDialogElement} */ /** @type {PrintPreviewDestinationDialogElement} */
let dialog = null; let dialog;
/** @type {?DestinationStore} */ /** @type {DestinationStore} */
let destinationStore = null; let destinationStore;
/** @type {?NativeLayer} */ /** @type {NativeLayerStub} */
let nativeLayer = null; let nativeLayer;
/** @override */ /** @override */
suiteSetup(function() { suiteSetup(function() {
...@@ -46,12 +51,13 @@ suite(destination_search_test.suiteName, function() { ...@@ -46,12 +51,13 @@ suite(destination_search_test.suiteName, function() {
[] /* recentDestinations */); [] /* recentDestinations */);
// Set up dialog // Set up dialog
dialog = document.createElement('print-preview-destination-dialog'); dialog = /** @type {!PrintPreviewDestinationDialogElement} */ (
document.createElement('print-preview-destination-dialog'));
dialog.users = []; dialog.users = [];
dialog.activeUser = ''; dialog.activeUser = '';
dialog.destinationStore = destinationStore; dialog.destinationStore = destinationStore;
dialog.invitationStore = new InvitationStore(); dialog.invitationStore = new InvitationStore();
PolymerTest.clearBody(); document.body.innerHTML = '';
document.body.appendChild(dialog); document.body.appendChild(dialog);
return nativeLayer.whenCalled('getPrinterCapabilities').then(function() { return nativeLayer.whenCalled('getPrinterCapabilities').then(function() {
dialog.show(); dialog.show();
...@@ -85,7 +91,6 @@ suite(destination_search_test.suiteName, function() { ...@@ -85,7 +91,6 @@ suite(destination_search_test.suiteName, function() {
DestinationConnectionStatus.ONLINE); DestinationConnectionStatus.ONLINE);
// Add the destination to the list. // Add the destination to the list.
dialog.updateDestinations_([dest]);
simulateDestinationSelect(dest); simulateDestinationSelect(dest);
} }
...@@ -103,7 +108,8 @@ suite(destination_search_test.suiteName, function() { ...@@ -103,7 +108,8 @@ suite(destination_search_test.suiteName, function() {
nativeLayer.setLocalDestinationCapabilities(getCddTemplate(destId)); nativeLayer.setLocalDestinationCapabilities(getCddTemplate(destId));
const waiter = eventToPromise( const waiter = eventToPromise(
DestinationStore.EventType.DESTINATION_SELECT, destinationStore); DestinationStore.EventType.DESTINATION_SELECT,
/** @type {!EventTarget} */ (destinationStore));
requestSetup(destId); requestSetup(destId);
return Promise return Promise
.all([nativeLayer.whenCalled('getPrinterCapabilities'), waiter]) .all([nativeLayer.whenCalled('getPrinterCapabilities'), waiter])
......
...@@ -4,12 +4,18 @@ ...@@ -4,12 +4,18 @@
import {ColorModeRestriction, Destination, DestinationConnectionStatus, DestinationOrigin, DestinationStore, DestinationType, DuplexModeRestriction, InvitationStore, NativeLayer, NativeLayerImpl} from 'chrome://print/print_preview.js'; import {ColorModeRestriction, Destination, DestinationConnectionStatus, DestinationOrigin, DestinationStore, DestinationType, DuplexModeRestriction, InvitationStore, NativeLayer, NativeLayerImpl} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js'; import {assert} from 'chrome://resources/js/assert.m.js';
import {NativeEventTarget as EventTarget} from 'chrome://resources/js/cr/event_target.m.js';
import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {NativeLayerStub} from 'chrome://test/print_preview/native_layer_stub.js';
import {createDestinationStore, getCddTemplate, setupTestListenerElement} from 'chrome://test/print_preview/print_preview_test_utils.js'; import {assertEquals, assertNotEquals} from '../chai_assert.js';
import {eventToPromise} from 'chrome://test/test_util.m.js'; import {eventToPromise} from '../test_util.m.js';
import {NativeLayerStub} from './native_layer_stub.js';
import {createDestinationStore, getCddTemplate, setupTestListenerElement} from './print_preview_test_utils.js';
window.destination_search_test_chromeos = {}; window.destination_search_test_chromeos = {};
const destination_search_test_chromeos =
window.destination_search_test_chromeos;
destination_search_test_chromeos.suiteName = 'DestinationSearchTest'; destination_search_test_chromeos.suiteName = 'DestinationSearchTest';
/** @enum {string} */ /** @enum {string} */
destination_search_test_chromeos.TestNames = { destination_search_test_chromeos.TestNames = {
...@@ -21,14 +27,14 @@ destination_search_test_chromeos.TestNames = { ...@@ -21,14 +27,14 @@ destination_search_test_chromeos.TestNames = {
}; };
suite(destination_search_test_chromeos.suiteName, function() { suite(destination_search_test_chromeos.suiteName, function() {
/** @type {?PrintPreviewDestinationDialogElement} */ /** @type {PrintPreviewDestinationDialogElement} */
let dialog = null; let dialog;
/** @type {?DestinationStore} */ /** @type {DestinationStore} */
let destinationStore = null; let destinationStore;
/** @type {?NativeLayer} */ /** @type {NativeLayerStub} */
let nativeLayer = null; let nativeLayer;
/** @override */ /** @override */
suiteSetup(function() { suiteSetup(function() {
...@@ -49,7 +55,8 @@ suite(destination_search_test_chromeos.suiteName, function() { ...@@ -49,7 +55,8 @@ suite(destination_search_test_chromeos.suiteName, function() {
[] /* recentDestinations */); [] /* recentDestinations */);
// Set up dialog // Set up dialog
dialog = document.createElement('print-preview-destination-dialog'); dialog = /** @type {!PrintPreviewDestinationDialogElement} */ (
document.createElement('print-preview-destination-dialog'));
dialog.users = []; dialog.users = [];
dialog.activeUser = ''; dialog.activeUser = '';
dialog.destinationStore = destinationStore; dialog.destinationStore = destinationStore;
...@@ -88,7 +95,6 @@ suite(destination_search_test_chromeos.suiteName, function() { ...@@ -88,7 +95,6 @@ suite(destination_search_test_chromeos.suiteName, function() {
DestinationConnectionStatus.ONLINE); DestinationConnectionStatus.ONLINE);
// Add the destination to the list. // Add the destination to the list.
dialog.updateDestinations_([dest]);
simulateDestinationSelect(dest); simulateDestinationSelect(dest);
} }
...@@ -106,7 +112,8 @@ suite(destination_search_test_chromeos.suiteName, function() { ...@@ -106,7 +112,8 @@ suite(destination_search_test_chromeos.suiteName, function() {
nativeLayer.setSetupPrinterResponse(response); nativeLayer.setSetupPrinterResponse(response);
const waiter = eventToPromise( const waiter = eventToPromise(
DestinationStore.EventType.DESTINATION_SELECT, destinationStore); DestinationStore.EventType.DESTINATION_SELECT,
/** @type {!EventTarget} */ (destinationStore));
requestSetup(destId); requestSetup(destId);
return Promise.all([nativeLayer.whenCalled('setupPrinter'), waiter]) return Promise.all([nativeLayer.whenCalled('setupPrinter'), waiter])
.then(function(results) { .then(function(results) {
...@@ -126,7 +133,12 @@ suite(destination_search_test_chromeos.suiteName, function() { ...@@ -126,7 +133,12 @@ suite(destination_search_test_chromeos.suiteName, function() {
const destId = '001122DEADBEEF'; const destId = '001122DEADBEEF';
const originalDestination = destinationStore.selectedDestination; const originalDestination = destinationStore.selectedDestination;
nativeLayer.setSetupPrinterResponse( nativeLayer.setSetupPrinterResponse(
{printerId: destId, success: false}, true); {
printerId: destId,
success: false,
capabilities: {printer: {}, version: '1'}
},
true);
requestSetup(destId); requestSetup(destId);
return nativeLayer.whenCalled('setupPrinter').then(function(actualId) { return nativeLayer.whenCalled('setupPrinter').then(function(actualId) {
assertEquals(destId, actualId); assertEquals(destId, actualId);
...@@ -175,7 +187,6 @@ suite(destination_search_test_chromeos.suiteName, function() { ...@@ -175,7 +187,6 @@ suite(destination_search_test_chromeos.suiteName, function() {
getCddTemplate(printerId, 'displayName').capabilities; getCddTemplate(printerId, 'displayName').capabilities;
// Place destination in the local list as happens for Kiosk printers. // Place destination in the local list as happens for Kiosk printers.
dialog.updateDestinations_([cloudDest]);
simulateDestinationSelect(cloudDest); simulateDestinationSelect(cloudDest);
// Verify that the destination has been selected. // Verify that the destination has been selected.
...@@ -195,6 +206,10 @@ suite(destination_search_test_chromeos.suiteName, function() { ...@@ -195,6 +206,10 @@ suite(destination_search_test_chromeos.suiteName, function() {
policies: { policies: {
allowedColorModes: ColorModeRestriction.MONOCHROME, allowedColorModes: ColorModeRestriction.MONOCHROME,
allowedDuplexModes: DuplexModeRestriction.DUPLEX, allowedDuplexModes: DuplexModeRestriction.DUPLEX,
allowedPinMode: null,
defaultColorMode: null,
defaultDuplexMode: null,
defaultPinMode: null,
}, },
success: true, success: true,
}; };
......
...@@ -4,9 +4,14 @@ ...@@ -4,9 +4,14 @@
import {Destination, DestinationConnectionStatus, DestinationOrigin, DestinationType, getSelectDropdownBackground} from 'chrome://print/print_preview.js'; import {Destination, DestinationConnectionStatus, DestinationOrigin, DestinationType, getSelectDropdownBackground} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js'; import {assert} from 'chrome://resources/js/assert.m.js';
import {getGoogleDriveDestination, selectOption} from 'chrome://test/print_preview/print_preview_test_utils.js'; import {Base} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {assertEquals, assertFalse, assertTrue} from '../chai_assert.js';
import {getGoogleDriveDestination, selectOption} from './print_preview_test_utils.js';
window.destination_select_test = {}; window.destination_select_test = {};
const destination_select_test = window.destination_select_test;
destination_select_test.suiteName = 'DestinationSelectTest'; destination_select_test.suiteName = 'DestinationSelectTest';
/** @enum {string} */ /** @enum {string} */
destination_select_test.TestNames = { destination_select_test.TestNames = {
...@@ -15,19 +20,24 @@ destination_select_test.TestNames = { ...@@ -15,19 +20,24 @@ destination_select_test.TestNames = {
}; };
suite(destination_select_test.suiteName, function() { suite(destination_select_test.suiteName, function() {
/** @type {?PrintPreviewDestinationSelectElement} */ /** @type {!PrintPreviewDestinationSelectElement} */
let destinationSelect = null; let destinationSelect;
/** @type {string} */
const account = 'foo@chromium.org'; const account = 'foo@chromium.org';
/** @type {!Array<!Destination>} */
let recentDestinationList = []; let recentDestinationList = [];
const meta = /** @type {!IronMetaElement} */ (
Base.create('iron-meta', {type: 'iconset'}));
/** @override */ /** @override */
setup(function() { setup(function() {
PolymerTest.clearBody(); document.body.innerHTML = '';
destinationSelect = destinationSelect =
document.createElement('print-preview-destination-select'); /** @type {!PrintPreviewDestinationSelectElement} */ (
document.createElement('print-preview-destination-select'));
destinationSelect.activeUser = account; destinationSelect.activeUser = account;
destinationSelect.appKioskMode = false; destinationSelect.appKioskMode = false;
destinationSelect.disabled = false; destinationSelect.disabled = false;
...@@ -38,10 +48,10 @@ suite(destination_select_test.suiteName, function() { ...@@ -38,10 +48,10 @@ suite(destination_select_test.suiteName, function() {
'ID1', DestinationType.LOCAL, DestinationOrigin.LOCAL, 'One', 'ID1', DestinationType.LOCAL, DestinationOrigin.LOCAL, 'One',
DestinationConnectionStatus.ONLINE), DestinationConnectionStatus.ONLINE),
new Destination( new Destination(
'ID2', DestinationType.CLOUD, DestinationOrigin.COOKIES, 'Two', 'ID2', DestinationType.GOOGLE, DestinationOrigin.COOKIES, 'Two',
DestinationConnectionStatus.OFFLINE, {account: account}), DestinationConnectionStatus.OFFLINE, {account: account}),
new Destination( new Destination(
'ID3', DestinationType.CLOUD, DestinationOrigin.COOKIES, 'Three', 'ID3', DestinationType.GOOGLE, DestinationOrigin.COOKIES, 'Three',
DestinationConnectionStatus.ONLINE, DestinationConnectionStatus.ONLINE,
{account: account, isOwned: true}), {account: account, isOwned: true}),
]; ];
...@@ -53,8 +63,8 @@ suite(destination_select_test.suiteName, function() { ...@@ -53,8 +63,8 @@ suite(destination_select_test.suiteName, function() {
function compareIcon(selectEl, expectedIcon) { function compareIcon(selectEl, expectedIcon) {
const icon = selectEl.style['background-image'].replace(/ /gi, ''); const icon = selectEl.style['background-image'].replace(/ /gi, '');
const expected = getSelectDropdownBackground( const expected = getSelectDropdownBackground(
destinationSelect.meta_.byKey('print-preview'), expectedIcon, /** @type {!IronIconsetSvgElement} */ (meta.byKey('print-preview')),
destinationSelect); expectedIcon, destinationSelect);
assertEquals(expected, icon); assertEquals(expected, icon);
} }
......
...@@ -320,7 +320,7 @@ export class NativeLayerStub extends TestBrowserProxy { ...@@ -320,7 +320,7 @@ export class NativeLayerStub extends TestBrowserProxy {
/** /**
* @param {!PrinterSetupResponse} response The response to send when * @param {!PrinterSetupResponse} response The response to send when
* |setupPrinter| is called. * |setupPrinter| is called.
* @param {?boolean} opt_reject Whether printSetup requests should be * @param {boolean=} opt_reject Whether printSetup requests should be
* rejected. Defaults to false (will resolve callback) if not provided. * rejected. Defaults to false (will resolve callback) if not provided.
*/ */
setSetupPrinterResponse(response, opt_reject) { setSetupPrinterResponse(response, opt_reject) {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import {CapabilitiesResponse, DEFAULT_MAX_COPIES, Destination, DestinationCertificateStatus, DestinationConnectionStatus, DestinationOrigin, DestinationStore, DestinationType, LocalDestinationInfo, MeasurementSystemUnitType, NativeInitialSettings, SelectOption} from 'chrome://print/print_preview.js'; import {CapabilitiesResponse, Cdd, DEFAULT_MAX_COPIES, Destination, DestinationCertificateStatus, DestinationConnectionStatus, DestinationOrigin, DestinationStore, DestinationType, LocalDestinationInfo, MeasurementSystemUnitType, NativeInitialSettings, SelectOption} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js'; import {assert} from 'chrome://resources/js/assert.m.js';
import {isChromeOS} from 'chrome://resources/js/cr.m.js'; import {isChromeOS} from 'chrome://resources/js/cr.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js'; import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
...@@ -37,7 +37,7 @@ export function getDefaultInitialSettings() { ...@@ -37,7 +37,7 @@ export function getDefaultInitialSettings() {
/** /**
* @param {string} printerId * @param {string} printerId
* @param {string=} opt_printerName Defaults to an empty string. * @param {string=} opt_printerName Defaults to an empty string.
* @return {!CapabilitiesResponse} * @return {!{printer: !LocalDestinationInfo, capabilities: !Cdd}}
*/ */
export function getCddTemplate(printerId, opt_printerName) { export function getCddTemplate(printerId, opt_printerName) {
const template = { const template = {
......
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