Commit 955ef0c8 authored by Daniel Hosseinian's avatar Daniel Hosseinian Committed by Commit Bot

Refactor Print Preview destination select tests

In preparation for adding cloud print deprecation warnings with icons
that can be suppressed with a pref, move some test code to a helper
function to avoid duplication.

Additionally, manually call the creation of recent destinations, as
they will need to be created after a certain pref is set.

Bug: 1112581
Change-Id: I5886f5357c95e95ed50cfe57fa8e2cb6892090a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2352516
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797817}
parent e6bdb79d
......@@ -43,6 +43,15 @@ suite(destination_select_test.suiteName, function() {
destinationSelect.disabled = false;
destinationSelect.loaded = false;
destinationSelect.noDestinations = false;
populateRecentDestinationList();
destinationSelect.recentDestinationList = recentDestinationList;
document.body.appendChild(destinationSelect);
});
// Create three different destinations and use them to populate
// |recentDestinationList|.
function populateRecentDestinationList() {
recentDestinationList = [
new Destination(
'ID1', DestinationType.LOCAL, DestinationOrigin.LOCAL, 'One',
......@@ -55,10 +64,7 @@ suite(destination_select_test.suiteName, function() {
DestinationConnectionStatus.ONLINE,
{account: account, isOwned: true}),
];
destinationSelect.recentDestinationList = recentDestinationList;
document.body.appendChild(destinationSelect);
});
}
function compareIcon(selectEl, expectedIcon) {
const icon = selectEl.style['background-image'].replace(/ /gi, '');
......@@ -68,24 +74,12 @@ suite(destination_select_test.suiteName, function() {
assertEquals(expected, icon);
}
test(assert(destination_select_test.TestNames.UpdateStatus), function() {
assertFalse(destinationSelect.$$('.throbber-container').hidden);
assertTrue(destinationSelect.$$('.md-select').hidden);
destinationSelect.loaded = true;
assertTrue(destinationSelect.$$('.throbber-container').hidden);
assertFalse(destinationSelect.$$('.md-select').hidden);
destinationSelect.destination = recentDestinationList[0];
destinationSelect.updateDestination();
assertTrue(destinationSelect.$$('.destination-additional-info').hidden);
destinationSelect.destination = recentDestinationList[1];
destinationSelect.updateDestination();
assertFalse(destinationSelect.$$('.destination-additional-info').hidden);
});
test(assert(destination_select_test.TestNames.ChangeIcon), function() {
/**
* Test that changing different destinations results in the correct icon being
* shown.
* @return {!Promise} Promise that resolves when the test finishes.
*/
function testChangeIcon() {
const destination = recentDestinationList[0];
destinationSelect.destination = destination;
destinationSelect.updateDestination();
......@@ -127,5 +121,26 @@ suite(destination_select_test.suiteName, function() {
.then(() => {
compareIcon(selectEl, 'print');
});
}
test(assert(destination_select_test.TestNames.UpdateStatus), function() {
assertFalse(destinationSelect.$$('.throbber-container').hidden);
assertTrue(destinationSelect.$$('.md-select').hidden);
destinationSelect.loaded = true;
assertTrue(destinationSelect.$$('.throbber-container').hidden);
assertFalse(destinationSelect.$$('.md-select').hidden);
destinationSelect.destination = recentDestinationList[0];
destinationSelect.updateDestination();
assertTrue(destinationSelect.$$('.destination-additional-info').hidden);
destinationSelect.destination = recentDestinationList[1];
destinationSelect.updateDestination();
assertFalse(destinationSelect.$$('.destination-additional-info').hidden);
});
test(assert(destination_select_test.TestNames.ChangeIcon), function() {
return testChangeIcon();
});
});
......@@ -353,6 +353,15 @@ suite(destination_select_test_cros.suiteName, function() {
destinationSelect.disabled = false;
destinationSelect.loaded = false;
destinationSelect.noDestinations = false;
populateRecentDestinationList();
destinationSelect.recentDestinationList = recentDestinationList;
document.body.appendChild(destinationSelect);
});
// Create three different destinations and use them to populate
// |recentDestinationList|.
function populateRecentDestinationList() {
recentDestinationList = [
new Destination(
'ID1', DestinationType.LOCAL, DestinationOrigin.LOCAL, 'One',
......@@ -365,10 +374,7 @@ suite(destination_select_test_cros.suiteName, function() {
DestinationConnectionStatus.ONLINE,
{account: account, isOwned: true}),
];
destinationSelect.recentDestinationList = recentDestinationList;
document.body.appendChild(destinationSelect);
});
}
function compareIcon(selectEl, expectedIcon) {
const icon = selectEl.style['background-image'].replace(/ /gi, '');
......@@ -378,26 +384,12 @@ suite(destination_select_test_cros.suiteName, function() {
assertEquals(expected, icon);
}
test(assert(destination_select_test_cros.TestNames.UpdateStatus), function() {
return waitBeforeNextRender(destinationSelect).then(() => {
assertFalse(destinationSelect.$$('.throbber-container').hidden);
assertTrue(destinationSelect.$$('.md-select').hidden);
destinationSelect.loaded = true;
assertTrue(destinationSelect.$$('.throbber-container').hidden);
assertFalse(destinationSelect.$$('.md-select').hidden);
destinationSelect.destination = recentDestinationList[0];
destinationSelect.updateDestination();
assertTrue(destinationSelect.$$('.destination-additional-info').hidden);
destinationSelect.destination = recentDestinationList[1];
destinationSelect.updateDestination();
assertFalse(destinationSelect.$$('.destination-additional-info').hidden);
});
});
test(assert(destination_select_test_cros.TestNames.ChangeIcon), function() {
/**
* Test that changing different destinations results in the correct icon being
* shown.
* @return {!Promise} Promise that resolves when the test finishes.
*/
function testChangeIcon() {
const cookieOrigin = DestinationOrigin.COOKIES;
let selectEl;
......@@ -444,6 +436,29 @@ suite(destination_select_test_cros.suiteName, function() {
.then(() => {
compareIcon(selectEl, 'print');
});
}
test(assert(destination_select_test_cros.TestNames.UpdateStatus), function() {
return waitBeforeNextRender(destinationSelect).then(() => {
assertFalse(destinationSelect.$$('.throbber-container').hidden);
assertTrue(destinationSelect.$$('.md-select').hidden);
destinationSelect.loaded = true;
assertTrue(destinationSelect.$$('.throbber-container').hidden);
assertFalse(destinationSelect.$$('.md-select').hidden);
destinationSelect.destination = recentDestinationList[0];
destinationSelect.updateDestination();
assertTrue(destinationSelect.$$('.destination-additional-info').hidden);
destinationSelect.destination = recentDestinationList[1];
destinationSelect.updateDestination();
assertFalse(destinationSelect.$$('.destination-additional-info').hidden);
});
});
test(assert(destination_select_test_cros.TestNames.ChangeIcon), function() {
return testChangeIcon();
});
/**
......
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