Commit f7e3bced authored by Daniel Hosseinian's avatar Daniel Hosseinian Committed by Commit Bot

Refactor Print Preview destination select update status tests

Prepare destination select update status tests for cloud print
deprecation messages, allowing for testing of when warnings are
suppressed and not, while avoiding duplicating code.

Bug: 1112581
Change-Id: I7cf97c9ed5a5629c7112c396b7219fcf1b2c23d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2360115
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799223}
parent d75285f9
...@@ -17,6 +17,7 @@ destination_select_test.suiteName = 'DestinationSelectTest'; ...@@ -17,6 +17,7 @@ destination_select_test.suiteName = 'DestinationSelectTest';
/** @enum {string} */ /** @enum {string} */
destination_select_test.TestNames = { destination_select_test.TestNames = {
UpdateStatus: 'update status', UpdateStatus: 'update status',
UpdateStatusDeprecationWarnings: 'update status deprecation warnings',
ChangeIcon: 'change icon', ChangeIcon: 'change icon',
ChangeIconDeprecationWarnings: 'change icon deprecation warnings', ChangeIconDeprecationWarnings: 'change icon deprecation warnings',
}; };
...@@ -28,6 +29,13 @@ suite(destination_select_test.suiteName, function() { ...@@ -28,6 +29,13 @@ suite(destination_select_test.suiteName, function() {
/** @type {string} */ /** @type {string} */
const account = 'foo@chromium.org'; const account = 'foo@chromium.org';
/** @type {!DestinationOrigin} */
const cookieOrigin = DestinationOrigin.COOKIES;
/** @type {string} */
const driveKey =
`${Destination.GooglePromotedId.DOCS}/${cookieOrigin}/${account}`;
/** @type {!Array<!Destination>} */ /** @type {!Array<!Destination>} */
let recentDestinationList = []; let recentDestinationList = [];
...@@ -59,10 +67,10 @@ suite(destination_select_test.suiteName, function() { ...@@ -59,10 +67,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.GOOGLE, DestinationOrigin.COOKIES, 'Two', 'ID2', DestinationType.GOOGLE, cookieOrigin, 'Two',
DestinationConnectionStatus.OFFLINE, {account: account}), DestinationConnectionStatus.OFFLINE, {account: account}),
new Destination( new Destination(
'ID3', DestinationType.GOOGLE, DestinationOrigin.COOKIES, 'Three', 'ID3', DestinationType.GOOGLE, cookieOrigin, 'Three',
DestinationConnectionStatus.ONLINE, DestinationConnectionStatus.ONLINE,
{account: account, isOwned: true}), {account: account, isOwned: true}),
]; ];
...@@ -90,9 +98,6 @@ suite(destination_select_test.suiteName, function() { ...@@ -90,9 +98,6 @@ suite(destination_select_test.suiteName, function() {
destinationSelect.loaded = true; destinationSelect.loaded = true;
const selectEl = destinationSelect.$$('.md-select'); const selectEl = destinationSelect.$$('.md-select');
compareIcon(selectEl, 'print'); compareIcon(selectEl, 'print');
const cookieOrigin = DestinationOrigin.COOKIES;
const driveKey =
`${Destination.GooglePromotedId.DOCS}/${cookieOrigin}/${account}`;
destinationSelect.driveDestinationKey = driveKey; destinationSelect.driveDestinationKey = driveKey;
return selectOption(destinationSelect, driveKey) return selectOption(destinationSelect, driveKey)
...@@ -141,7 +146,17 @@ suite(destination_select_test.suiteName, function() { ...@@ -141,7 +146,17 @@ suite(destination_select_test.suiteName, function() {
}); });
} }
test(assert(destination_select_test.TestNames.UpdateStatus), function() { /**
* Test that changing different destinations results in the correct status
* being shown.
* @param {boolean} cloudPrintDeprecationWarningsSuppressed Whether cloud
* print deprecation warnings should be suppressed.
*/
function testUpdateStatus(cloudPrintDeprecationWarningsSuppressed) {
loadTimeData.overrideValues({
offline: 'offline',
});
assertFalse(destinationSelect.$$('.throbber-container').hidden); assertFalse(destinationSelect.$$('.throbber-container').hidden);
assertTrue(destinationSelect.$$('.md-select').hidden); assertTrue(destinationSelect.$$('.md-select').hidden);
...@@ -149,15 +164,49 @@ suite(destination_select_test.suiteName, function() { ...@@ -149,15 +164,49 @@ suite(destination_select_test.suiteName, function() {
assertTrue(destinationSelect.$$('.throbber-container').hidden); assertTrue(destinationSelect.$$('.throbber-container').hidden);
assertFalse(destinationSelect.$$('.md-select').hidden); assertFalse(destinationSelect.$$('.md-select').hidden);
const additionalInfoEl =
destinationSelect.$$('.destination-additional-info');
const statusEl = destinationSelect.$$('.destination-status');
destinationSelect.driveDestinationKey = driveKey;
destinationSelect.destination = getGoogleDriveDestination(account);
destinationSelect.updateDestination();
assertTrue(additionalInfoEl.hidden);
assertEquals('', statusEl.innerHTML);
destinationSelect.destination = recentDestinationList[0]; destinationSelect.destination = recentDestinationList[0];
destinationSelect.updateDestination(); destinationSelect.updateDestination();
assertTrue(destinationSelect.$$('.destination-additional-info').hidden); assertTrue(additionalInfoEl.hidden);
assertEquals('', statusEl.innerHTML);
destinationSelect.destination = recentDestinationList[1]; destinationSelect.destination = recentDestinationList[1];
destinationSelect.updateDestination(); destinationSelect.updateDestination();
assertFalse(destinationSelect.$$('.destination-additional-info').hidden); assertFalse(additionalInfoEl.hidden);
assertEquals('offline', statusEl.innerHTML);
destinationSelect.destination = recentDestinationList[2];
destinationSelect.updateDestination();
assertTrue(additionalInfoEl.hidden);
assertEquals('', statusEl.innerHTML);
}
test(assert(destination_select_test.TestNames.UpdateStatus), function() {
loadTimeData.overrideValues(
{cloudPrintDeprecationWarningsSuppressed: true});
// Repopulate |recentDestinationList| to have
// |cloudPrintDeprecationWarningsSuppressed| take effect during creation of
// new Destinations.
populateRecentDestinationList();
return testUpdateStatus(true);
}); });
test(
assert(destination_select_test.TestNames.UpdateStatusDeprecationWarnings),
function() {
return testUpdateStatus(false);
});
test(assert(destination_select_test.TestNames.ChangeIcon), function() { test(assert(destination_select_test.TestNames.ChangeIcon), function() {
loadTimeData.overrideValues( loadTimeData.overrideValues(
{cloudPrintDeprecationWarningsSuppressed: true}); {cloudPrintDeprecationWarningsSuppressed: true});
......
...@@ -325,6 +325,7 @@ destination_select_test_cros.suiteName = 'DestinationSelectTestCros'; ...@@ -325,6 +325,7 @@ destination_select_test_cros.suiteName = 'DestinationSelectTestCros';
/** @enum {string} */ /** @enum {string} */
destination_select_test_cros.TestNames = { destination_select_test_cros.TestNames = {
UpdateStatus: 'update status', UpdateStatus: 'update status',
UpdateStatusDeprecationWarnings: 'update status deprecation warnings',
ChangeIcon: 'change icon', ChangeIcon: 'change icon',
ChangeIconDeprecationWarnings: 'change icon deprecation warnings', ChangeIconDeprecationWarnings: 'change icon deprecation warnings',
EulaIsDisplayed: 'eula is displayed', EulaIsDisplayed: 'eula is displayed',
...@@ -335,8 +336,17 @@ suite(destination_select_test_cros.suiteName, function() { ...@@ -335,8 +336,17 @@ suite(destination_select_test_cros.suiteName, function() {
/** @type {!PrintPreviewDestinationSelectCrosElement} */ /** @type {!PrintPreviewDestinationSelectCrosElement} */
let destinationSelect; let destinationSelect;
/** @type {string} */
const account = 'foo@chromium.org'; const account = 'foo@chromium.org';
/** @type {!DestinationOrigin} */
const cookieOrigin = DestinationOrigin.COOKIES;
/** @type {string} */
const driveKey =
`${Destination.GooglePromotedId.DOCS}/${cookieOrigin}/${account}`;
/** @type {!Array<!Destination>} */
let recentDestinationList = []; let recentDestinationList = [];
const meta = /** @type {!IronMetaElement} */ ( const meta = /** @type {!IronMetaElement} */ (
...@@ -368,10 +378,10 @@ suite(destination_select_test_cros.suiteName, function() { ...@@ -368,10 +378,10 @@ suite(destination_select_test_cros.suiteName, function() {
'ID1', DestinationType.LOCAL, DestinationOrigin.LOCAL, 'One', 'ID1', DestinationType.LOCAL, DestinationOrigin.LOCAL, 'One',
DestinationConnectionStatus.ONLINE), DestinationConnectionStatus.ONLINE),
new Destination( new Destination(
'ID2', DestinationType.GOOGLE, DestinationOrigin.COOKIES, 'Two', 'ID2', DestinationType.GOOGLE, cookieOrigin, 'Two',
DestinationConnectionStatus.OFFLINE, {account: account}), DestinationConnectionStatus.OFFLINE, {account: account}),
new Destination( new Destination(
'ID3', DestinationType.GOOGLE, DestinationOrigin.COOKIES, 'Three', 'ID3', DestinationType.GOOGLE, cookieOrigin, 'Three',
DestinationConnectionStatus.ONLINE, DestinationConnectionStatus.ONLINE,
{account: account, isOwned: true}), {account: account, isOwned: true}),
]; ];
...@@ -393,7 +403,6 @@ suite(destination_select_test_cros.suiteName, function() { ...@@ -393,7 +403,6 @@ suite(destination_select_test_cros.suiteName, function() {
* @return {!Promise} Promise that resolves when the test finishes. * @return {!Promise} Promise that resolves when the test finishes.
*/ */
function testChangeIcon(cloudPrintDeprecationWarningsSuppressed) { function testChangeIcon(cloudPrintDeprecationWarningsSuppressed) {
const cookieOrigin = DestinationOrigin.COOKIES;
let selectEl; let selectEl;
return waitBeforeNextRender(destinationSelect) return waitBeforeNextRender(destinationSelect)
...@@ -404,8 +413,6 @@ suite(destination_select_test_cros.suiteName, function() { ...@@ -404,8 +413,6 @@ suite(destination_select_test_cros.suiteName, function() {
destinationSelect.loaded = true; destinationSelect.loaded = true;
selectEl = destinationSelect.$$('.md-select'); selectEl = destinationSelect.$$('.md-select');
compareIcon(selectEl, 'print'); compareIcon(selectEl, 'print');
const driveKey =
`${Destination.GooglePromotedId.DOCS}/${cookieOrigin}/${account}`;
destinationSelect.driveDestinationKey = driveKey; destinationSelect.driveDestinationKey = driveKey;
return selectOption(destinationSelect, driveKey); return selectOption(destinationSelect, driveKey);
...@@ -449,25 +456,74 @@ suite(destination_select_test_cros.suiteName, function() { ...@@ -449,25 +456,74 @@ suite(destination_select_test_cros.suiteName, function() {
}); });
} }
test(assert(destination_select_test_cros.TestNames.UpdateStatus), function() { /**
return waitBeforeNextRender(destinationSelect).then(() => { * Test that changing different destinations results in the correct status
assertFalse(destinationSelect.$$('.throbber-container').hidden); * being shown.
assertTrue(destinationSelect.$$('.md-select').hidden); * @param {boolean} cloudPrintDeprecationWarningsSuppressed Whether cloud
* print deprecation warnings should be suppressed.
*/
function testUpdateStatus(cloudPrintDeprecationWarningsSuppressed) {
loadTimeData.overrideValues({
offline: 'offline',
});
destinationSelect.loaded = true; assertFalse(destinationSelect.$$('.throbber-container').hidden);
assertTrue(destinationSelect.$$('.throbber-container').hidden); assertTrue(destinationSelect.$$('.md-select').hidden);
assertFalse(destinationSelect.$$('.md-select').hidden);
destinationSelect.loaded = true;
assertTrue(destinationSelect.$$('.throbber-container').hidden);
assertFalse(destinationSelect.$$('.md-select').hidden);
const additionalInfoEl =
destinationSelect.$$('.destination-additional-info');
const statusEl = destinationSelect.$$('#statusText');
destinationSelect.driveDestinationKey = driveKey;
destinationSelect.destination = getGoogleDriveDestination(account);
destinationSelect.updateDestination();
assertTrue(additionalInfoEl.hidden);
assertEquals('', statusEl.innerHTML.trim());
destinationSelect.destination = recentDestinationList[0];
destinationSelect.updateDestination();
assertTrue(additionalInfoEl.hidden);
assertEquals('', statusEl.innerHTML.trim());
destinationSelect.destination = recentDestinationList[1];
destinationSelect.updateDestination();
assertFalse(additionalInfoEl.hidden);
assertEquals('offline', statusEl.innerHTML.trim());
destinationSelect.destination = recentDestinationList[2];
destinationSelect.updateDestination();
assertTrue(additionalInfoEl.hidden);
assertEquals('', statusEl.innerHTML.trim());
}
destinationSelect.destination = recentDestinationList[0]; test(assert(destination_select_test_cros.TestNames.UpdateStatus), function() {
destinationSelect.updateDestination(); loadTimeData.overrideValues(
assertTrue(destinationSelect.$$('.destination-additional-info').hidden); {cloudPrintDeprecationWarningsSuppressed: true});
destinationSelect.destination = recentDestinationList[1]; // Repopulate |recentDestinationList| to have
destinationSelect.updateDestination(); // |cloudPrintDeprecationWarningsSuppressed| take effect during creation of
assertFalse(destinationSelect.$$('.destination-additional-info').hidden); // new Destinations.
populateRecentDestinationList();
destinationSelect.recentDestinationList = recentDestinationList;
return waitBeforeNextRender(destinationSelect).then(() => {
testUpdateStatus(true);
}); });
}); });
test(
assert(destination_select_test_cros.TestNames
.UpdateStatusDeprecationWarnings),
function() {
return waitBeforeNextRender(destinationSelect).then(() => {
testUpdateStatus(false);
});
});
test(assert(destination_select_test_cros.TestNames.ChangeIcon), function() { test(assert(destination_select_test_cros.TestNames.ChangeIcon), function() {
loadTimeData.overrideValues( loadTimeData.overrideValues(
{cloudPrintDeprecationWarningsSuppressed: true}); {cloudPrintDeprecationWarningsSuppressed: true});
......
...@@ -1115,6 +1115,13 @@ TEST_F('PrintPreviewDestinationSelectTestCrOS', 'UpdateStatus', function() { ...@@ -1115,6 +1115,13 @@ TEST_F('PrintPreviewDestinationSelectTestCrOS', 'UpdateStatus', function() {
this.runMochaTest(destination_select_test_cros.TestNames.UpdateStatus); this.runMochaTest(destination_select_test_cros.TestNames.UpdateStatus);
}); });
TEST_F(
'PrintPreviewDestinationSelectTestCrOS', 'UpdateStatusDeprecationWarnings',
function() {
this.runMochaTest(destination_select_test_cros.TestNames
.UpdateStatusDeprecationWarnings);
});
TEST_F('PrintPreviewDestinationSelectTestCrOS', 'ChangeIcon', function() { TEST_F('PrintPreviewDestinationSelectTestCrOS', 'ChangeIcon', function() {
this.runMochaTest(destination_select_test_cros.TestNames.ChangeIcon); this.runMochaTest(destination_select_test_cros.TestNames.ChangeIcon);
}); });
...@@ -1305,6 +1312,13 @@ TEST_F('PrintPreviewDestinationSelectTest', 'UpdateStatus', function() { ...@@ -1305,6 +1312,13 @@ TEST_F('PrintPreviewDestinationSelectTest', 'UpdateStatus', function() {
this.runMochaTest(destination_select_test.TestNames.UpdateStatus); this.runMochaTest(destination_select_test.TestNames.UpdateStatus);
}); });
TEST_F(
'PrintPreviewDestinationSelectTest', 'UpdateStatusDeprecationWarnings',
function() {
this.runMochaTest(
destination_select_test.TestNames.UpdateStatusDeprecationWarnings);
});
TEST_F('PrintPreviewDestinationSelectTest', 'ChangeIcon', function() { TEST_F('PrintPreviewDestinationSelectTest', 'ChangeIcon', function() {
this.runMochaTest(destination_select_test.TestNames.ChangeIcon); this.runMochaTest(destination_select_test.TestNames.ChangeIcon);
}); });
......
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