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';
export {PluralStringProxyImpl as PrintPreviewPluralStringProxyImpl} from 'chrome://resources/js/plural_string_proxy.js';
export {CloudPrintInterface, CloudPrintInterfaceEventType} from './cloud_print_interface.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';
// <if expr="chromeos">
export {ColorModeRestriction, DuplexModeRestriction, PinModeRestriction} from './data/destination_policies.js';
......
......@@ -26,10 +26,6 @@ js_type_check("closure_compile") {
":destination_dialog_test",
":destination_item_test",
":destination_list_test",
#":destination_search_test_chromeos",
#":destination_search_test",
#":destination_select_test",
":destination_settings_test",
#":destination_store_test",
......@@ -75,8 +71,14 @@ js_type_check("closure_compile") {
if (is_chromeos) {
deps += [
":destination_dropdown_cros_test",
":destination_search_test_chromeos",
":destination_select_test_cros",
]
} else {
deps += [
":destination_search_test",
":destination_select_test",
]
}
}
......@@ -264,4 +266,38 @@ if (is_chromeos) {
"//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 @@
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 {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 {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 {eventToPromise} from 'chrome://test/test_util.m.js';
import {assertEquals, assertNotEquals} from '../chai_assert.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 = {};
const destination_search_test = window.destination_search_test;
destination_search_test.suiteName = 'DestinationSearchTest';
/** @enum {string} */
destination_search_test.TestNames = {
......@@ -18,14 +23,14 @@ destination_search_test.TestNames = {
};
suite(destination_search_test.suiteName, function() {
/** @type {?PrintPreviewDestinationDialogElement} */
let dialog = null;
/** @type {PrintPreviewDestinationDialogElement} */
let dialog;
/** @type {?DestinationStore} */
let destinationStore = null;
/** @type {DestinationStore} */
let destinationStore;
/** @type {?NativeLayer} */
let nativeLayer = null;
/** @type {NativeLayerStub} */
let nativeLayer;
/** @override */
suiteSetup(function() {
......@@ -46,12 +51,13 @@ suite(destination_search_test.suiteName, function() {
[] /* recentDestinations */);
// Set up dialog
dialog = document.createElement('print-preview-destination-dialog');
dialog = /** @type {!PrintPreviewDestinationDialogElement} */ (
document.createElement('print-preview-destination-dialog'));
dialog.users = [];
dialog.activeUser = '';
dialog.destinationStore = destinationStore;
dialog.invitationStore = new InvitationStore();
PolymerTest.clearBody();
document.body.innerHTML = '';
document.body.appendChild(dialog);
return nativeLayer.whenCalled('getPrinterCapabilities').then(function() {
dialog.show();
......@@ -85,7 +91,6 @@ suite(destination_search_test.suiteName, function() {
DestinationConnectionStatus.ONLINE);
// Add the destination to the list.
dialog.updateDestinations_([dest]);
simulateDestinationSelect(dest);
}
......@@ -103,7 +108,8 @@ suite(destination_search_test.suiteName, function() {
nativeLayer.setLocalDestinationCapabilities(getCddTemplate(destId));
const waiter = eventToPromise(
DestinationStore.EventType.DESTINATION_SELECT, destinationStore);
DestinationStore.EventType.DESTINATION_SELECT,
/** @type {!EventTarget} */ (destinationStore));
requestSetup(destId);
return Promise
.all([nativeLayer.whenCalled('getPrinterCapabilities'), waiter])
......
......@@ -4,12 +4,18 @@
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 {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 {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 {eventToPromise} from 'chrome://test/test_util.m.js';
import {assertEquals, assertNotEquals} from '../chai_assert.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 = {};
const destination_search_test_chromeos =
window.destination_search_test_chromeos;
destination_search_test_chromeos.suiteName = 'DestinationSearchTest';
/** @enum {string} */
destination_search_test_chromeos.TestNames = {
......@@ -21,14 +27,14 @@ destination_search_test_chromeos.TestNames = {
};
suite(destination_search_test_chromeos.suiteName, function() {
/** @type {?PrintPreviewDestinationDialogElement} */
let dialog = null;
/** @type {PrintPreviewDestinationDialogElement} */
let dialog;
/** @type {?DestinationStore} */
let destinationStore = null;
/** @type {DestinationStore} */
let destinationStore;
/** @type {?NativeLayer} */
let nativeLayer = null;
/** @type {NativeLayerStub} */
let nativeLayer;
/** @override */
suiteSetup(function() {
......@@ -49,7 +55,8 @@ suite(destination_search_test_chromeos.suiteName, function() {
[] /* recentDestinations */);
// Set up dialog
dialog = document.createElement('print-preview-destination-dialog');
dialog = /** @type {!PrintPreviewDestinationDialogElement} */ (
document.createElement('print-preview-destination-dialog'));
dialog.users = [];
dialog.activeUser = '';
dialog.destinationStore = destinationStore;
......@@ -88,7 +95,6 @@ suite(destination_search_test_chromeos.suiteName, function() {
DestinationConnectionStatus.ONLINE);
// Add the destination to the list.
dialog.updateDestinations_([dest]);
simulateDestinationSelect(dest);
}
......@@ -106,7 +112,8 @@ suite(destination_search_test_chromeos.suiteName, function() {
nativeLayer.setSetupPrinterResponse(response);
const waiter = eventToPromise(
DestinationStore.EventType.DESTINATION_SELECT, destinationStore);
DestinationStore.EventType.DESTINATION_SELECT,
/** @type {!EventTarget} */ (destinationStore));
requestSetup(destId);
return Promise.all([nativeLayer.whenCalled('setupPrinter'), waiter])
.then(function(results) {
......@@ -126,7 +133,12 @@ suite(destination_search_test_chromeos.suiteName, function() {
const destId = '001122DEADBEEF';
const originalDestination = destinationStore.selectedDestination;
nativeLayer.setSetupPrinterResponse(
{printerId: destId, success: false}, true);
{
printerId: destId,
success: false,
capabilities: {printer: {}, version: '1'}
},
true);
requestSetup(destId);
return nativeLayer.whenCalled('setupPrinter').then(function(actualId) {
assertEquals(destId, actualId);
......@@ -175,7 +187,6 @@ suite(destination_search_test_chromeos.suiteName, function() {
getCddTemplate(printerId, 'displayName').capabilities;
// Place destination in the local list as happens for Kiosk printers.
dialog.updateDestinations_([cloudDest]);
simulateDestinationSelect(cloudDest);
// Verify that the destination has been selected.
......@@ -195,6 +206,10 @@ suite(destination_search_test_chromeos.suiteName, function() {
policies: {
allowedColorModes: ColorModeRestriction.MONOCHROME,
allowedDuplexModes: DuplexModeRestriction.DUPLEX,
allowedPinMode: null,
defaultColorMode: null,
defaultDuplexMode: null,
defaultPinMode: null,
},
success: true,
};
......
......@@ -4,9 +4,14 @@
import {Destination, DestinationConnectionStatus, DestinationOrigin, DestinationType, getSelectDropdownBackground} from 'chrome://print/print_preview.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 = {};
const destination_select_test = window.destination_select_test;
destination_select_test.suiteName = 'DestinationSelectTest';
/** @enum {string} */
destination_select_test.TestNames = {
......@@ -15,19 +20,24 @@ destination_select_test.TestNames = {
};
suite(destination_select_test.suiteName, function() {
/** @type {?PrintPreviewDestinationSelectElement} */
let destinationSelect = null;
/** @type {!PrintPreviewDestinationSelectElement} */
let destinationSelect;
/** @type {string} */
const account = 'foo@chromium.org';
/** @type {!Array<!Destination>} */
let recentDestinationList = [];
const meta = /** @type {!IronMetaElement} */ (
Base.create('iron-meta', {type: 'iconset'}));
/** @override */
setup(function() {
PolymerTest.clearBody();
document.body.innerHTML = '';
destinationSelect =
document.createElement('print-preview-destination-select');
/** @type {!PrintPreviewDestinationSelectElement} */ (
document.createElement('print-preview-destination-select'));
destinationSelect.activeUser = account;
destinationSelect.appKioskMode = false;
destinationSelect.disabled = false;
......@@ -38,10 +48,10 @@ suite(destination_select_test.suiteName, function() {
'ID1', DestinationType.LOCAL, DestinationOrigin.LOCAL, 'One',
DestinationConnectionStatus.ONLINE),
new Destination(
'ID2', DestinationType.CLOUD, DestinationOrigin.COOKIES, 'Two',
'ID2', DestinationType.GOOGLE, DestinationOrigin.COOKIES, 'Two',
DestinationConnectionStatus.OFFLINE, {account: account}),
new Destination(
'ID3', DestinationType.CLOUD, DestinationOrigin.COOKIES, 'Three',
'ID3', DestinationType.GOOGLE, DestinationOrigin.COOKIES, 'Three',
DestinationConnectionStatus.ONLINE,
{account: account, isOwned: true}),
];
......@@ -53,8 +63,8 @@ suite(destination_select_test.suiteName, function() {
function compareIcon(selectEl, expectedIcon) {
const icon = selectEl.style['background-image'].replace(/ /gi, '');
const expected = getSelectDropdownBackground(
destinationSelect.meta_.byKey('print-preview'), expectedIcon,
destinationSelect);
/** @type {!IronIconsetSvgElement} */ (meta.byKey('print-preview')),
expectedIcon, destinationSelect);
assertEquals(expected, icon);
}
......
......@@ -320,7 +320,7 @@ export class NativeLayerStub extends TestBrowserProxy {
/**
* @param {!PrinterSetupResponse} response The response to send when
* |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.
*/
setSetupPrinterResponse(response, opt_reject) {
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// 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 {isChromeOS} from 'chrome://resources/js/cr.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
......@@ -37,7 +37,7 @@ export function getDefaultInitialSettings() {
/**
* @param {string} printerId
* @param {string=} opt_printerName Defaults to an empty string.
* @return {!CapabilitiesResponse}
* @return {!{printer: !LocalDestinationInfo, capabilities: !Cdd}}
*/
export function getCddTemplate(printerId, opt_printerName) {
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