Commit 6dfe3931 authored by James Vecore's avatar James Vecore Committed by Chromium LUCI CQ

[Nearby] Introduce additional errors to High Vis Dialog

This is a clone of this CL: https://crrev.com/c/2594273 with fixes for
browser tests that were failing.

PS1: original CL
PS2: changes to get browser tests running

There were a duplicate string resource id being used and some issues
with not waiting for the page to re-render fully.

Original Message:

This change adds support for Transfer in Progress and No Connection
Medium available.

Screenshots:
https://screenshot.googleplex.com/7HUWhCacjyWanCP.png
https://screenshot.googleplex.com/9vpAjoNMJnkw32n.png

Bug: 1156391
Change-Id: If4d0ff802e398567bd06500688713d31a098bb59
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2596819
Auto-Submit: James Vecore <vecore@google.com>
Commit-Queue: James Vecore <vecore@google.com>
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837945}
parent 3d29c4c0
...@@ -202,6 +202,18 @@ ...@@ -202,6 +202,18 @@
<message name="IDS_NEARBY_HIGH_VISIBILITY_TIMEOUT_TEXT" desc="Describes to the user that their device is visible to nearby devices with a specific device name. This is used on the sub-title of the of high visibility receive dialog for the Nearby Share feature."> <message name="IDS_NEARBY_HIGH_VISIBILITY_TIMEOUT_TEXT" desc="Describes to the user that their device is visible to nearby devices with a specific device name. This is used on the sub-title of the of high visibility receive dialog for the Nearby Share feature.">
No available devices sharing nearby. <ph name="LINK_BEGIN">&lt;a&gt;</ph>Learn more<ph name="LINK_END">&lt;/a&gt;</ph> No available devices sharing nearby. <ph name="LINK_BEGIN">&lt;a&gt;</ph>Learn more<ph name="LINK_END">&lt;/a&gt;</ph>
</message> </message>
<message name="IDS_NEARBY_HIGH_VISIBILITY_TRANSFER_IN_PROGRESS_ERROR" desc="An error title telling the user that there is already a Nearby Share transfer in progress">
Can’t share
</message>
<message name="IDS_NEARBY_HIGH_VISIBILITY_TRANSFER_IN_PROGRESS_DESCRIPTION" desc="An error description telling the user that there is already a Nearby Share transfer in progress">
You can only share one file at a time. Try again when the current transfer is complete.
</message>
<message name="IDS_NEARBY_HIGH_VISIBILITY_CONNECTION_MEDIUM_ERROR" desc="When the Nearby Share receive dialog is open, an error title telling the user that there is no available connection medium such as wifi or Bluetooth">
Bluetooth and Wi-Fi needed
</message>
<message name="IDS_NEARBY_HIGH_VISIBILITY_CONNECTION_MEDIUM_DESCRIPTION" desc="When the Nearby Share receive dialog is open, an error title telling the user that there is no available connection medium such as wifi or Bluetooth">
To use Nearby Share, turn on Bluetooth and Wi-Fi
</message>
<!-- Receive Confirmation Page Strings --> <!-- Receive Confirmation Page Strings -->
<message name="IDS_NEARBY_RECEIVE_CONFIRM_PAGE_TITLE" desc="The title of the recieve confirmation page which askign the user to confirm receving a share from a specific device."> <message name="IDS_NEARBY_RECEIVE_CONFIRM_PAGE_TITLE" desc="The title of the recieve confirmation page which askign the user to confirm receving a share from a specific device.">
......
5cd21ff4dc115159c3f423136fd503c1e2051909
\ No newline at end of file
e787abaca8f9cb92a138f2ab9e0367a04b5917b0
\ No newline at end of file
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<style> <style>
#content { #content {
background: linear-gradient(to top, var(--google-blue-50) 5%, background: linear-gradient(to top, var(--google-blue-50) 5%,
rgba(255, 255, 255, 0) 50%); rgba(255, 255, 255, 0) 50%);
display: flex; display: flex;
flex-direction: column-reverse; flex-direction: column-reverse;
height: 100%; height: 100%;
...@@ -59,6 +59,12 @@ ...@@ -59,6 +59,12 @@
font-weight: bold; font-weight: bold;
margin-bottom: 3px; margin-bottom: 3px;
} }
#errorDescription {
color: var(--google-grey-700);
line-height: 13px;
}
cr-lottie { cr-lottie {
bottom: 0; bottom: 0;
height: 100px; height: 100px;
...@@ -69,15 +75,14 @@ ...@@ -69,15 +75,14 @@
} }
</style> </style>
<nearby-page-template title="$i18n{nearbyShareFeatureName}" <nearby-page-template title="$i18n{nearbyShareFeatureName}"
sub-title="[[getSubTitle_(deviceName, remainingTimeInSeconds_)]]" sub-title="[[getSubTitle_(deviceName, remainingTimeInSeconds_)]]"
cancel-button-label="$i18n{cancel}"> cancel-button-label="$i18n{cancel}">
<div id="content" slot="content"> <div id="content" slot="content">
<cr-lottie animation-url="nearby_share_pulse_animation.json" <cr-lottie animation-url="nearby_share_pulse_animation.json"
autoplay="true"> autoplay="true">
</cr-lottie> </cr-lottie>
<div id="help"> <div id="help">
<template is="dom-if" if="[[!highVisibilityTimedOut_( <template is="dom-if" if="[[!getErrorTitle_(errorState_)]]">
remainingTimeInSeconds_, shutoffTimestamp)]]">
<iron-icon id="infoIcon" icon="nearby20:info"></iron-icon> <iron-icon id="infoIcon" icon="nearby20:info"></iron-icon>
<div id="helpText"> <div id="helpText">
<settings-localized-link <settings-localized-link
...@@ -86,20 +91,20 @@ ...@@ -86,20 +91,20 @@
</settings-localized-link> </settings-localized-link>
</div> </div>
</template> </template>
<template is="dom-if" if="[[highVisibilityTimedOut_( <template is="dom-if" if="[[getErrorTitle_(errorState_)]]">
remainingTimeInSeconds_, shutoffTimestamp)]]"> <iron-icon id="infoIcon" icon="nearby20:info"
<iron-icon id="infoIcon" icon="nearby20:info" class="icon-error-state">
class="icon-error-state">
</iron-icon> </iron-icon>
<div id="error" role="alert" aria-labelledby="errorTitle" <div id="error" role="alert" aria-labelledby="errorTitle"
aria-describedby="errorDescription"> aria-describedby="errorDescription">
<div id="errorTitle" aria-hidden="true"> <div id="errorTitle" aria-hidden="true">
$i18n{nearbyShareErrorTimeOut} [[getErrorTitle_(errorState_)]]
</div> </div>
<settings-localized-link <div id="errorDescription" aria-hidden="true">
localized-string="$i18n{nearbyShareHighVisibilityTimeoutText}" <settings-localized-link
link-url="$i18n{nearbyShareLearnMoreLink}"> localized-string="[[getErrorDescription_(errorState_)]]"
</settings-localized-link> link-url="$i18n{nearbyShareLearnMoreLink}">
</settings-localized-link>
</div> </div>
</div> </div>
</template> </template>
......
...@@ -7,6 +7,17 @@ ...@@ -7,6 +7,17 @@
* user is broadcast in high-visibility mode. The user may cancel to stop high * user is broadcast in high-visibility mode. The user may cancel to stop high
* visibility mode at any time. * visibility mode at any time.
*/ */
/**
* Represents the current error state, if one exists.
* @enum {number}
*/
const NearbyVisibilityErrorState = {
TIMED_OUT: 0,
NO_CONNECTION_MEDIUM: 1,
TRANSFER_IN_PROGRESS: 2,
};
Polymer({ Polymer({
is: 'nearby-share-high-visibility-page', is: 'nearby-share-high-visibility-page',
...@@ -41,6 +52,25 @@ Polymer({ ...@@ -41,6 +52,25 @@ Polymer({
type: Number, type: Number,
value: -1, value: -1,
}, },
/** @private {?nearbyShare.mojom.RegisterReceiveSurfaceResult} */
registerResult: {
type: nearbyShare.mojom.RegisterReceiveSurfaceResult,
value: null,
},
/**
* A null |setupState_| indicates that the operation has not yet started.
* @private {?NearbyVisibilityErrorState}
*/
errorState_: {
type: Number,
value: null,
computed:
'computeErrorState_(shutoffTimestamp, remainingTimeInSeconds_,' +
'registerResult)'
}
}, },
/** @private {number} */ /** @private {number} */
...@@ -85,6 +115,60 @@ Polymer({ ...@@ -85,6 +115,60 @@ Polymer({
(this.shutoffTimestamp !== 0); (this.shutoffTimestamp !== 0);
}, },
/**
* @return {?NearbyVisibilityErrorState}
* @protected
*/
computeErrorState_() {
if (this.registerResult ===
nearbyShare.mojom.RegisterReceiveSurfaceResult.kNoConnectionMedium) {
return NearbyVisibilityErrorState.NO_CONNECTION_MEDIUM;
}
if (this.registerResult ===
nearbyShare.mojom.RegisterReceiveSurfaceResult.kTransferInProgress) {
return NearbyVisibilityErrorState.TRANSFER_IN_PROGRESS;
}
if (this.highVisibilityTimedOut_()) {
return NearbyVisibilityErrorState.TIMED_OUT;
}
return null;
},
/**
* @return {string} localized string
* @protected
*/
getErrorTitle_() {
switch (this.errorState_) {
case NearbyVisibilityErrorState.TIMED_OUT:
return this.i18n('nearbyShareErrorTimeOut');
case NearbyVisibilityErrorState.NO_CONNECTION_MEDIUM:
return this.i18n('nearbyShareErrorNoConnectionMedium');
case NearbyVisibilityErrorState.TRANSFER_IN_PROGRESS:
return this.i18n('nearbyShareErrorTransferInProgressTitle');
default:
return '';
}
},
/**
* @return {string} localized string
* @protected
*/
getErrorDescription_() {
switch (this.errorState_) {
case NearbyVisibilityErrorState.TIMED_OUT:
return this.i18nAdvanced('nearbyShareHighVisibilityTimeoutText');
case NearbyVisibilityErrorState.NO_CONNECTION_MEDIUM:
return this.i18n('nearbyShareErrorNoConnectionMediumDescription');
case NearbyVisibilityErrorState.TRANSFER_IN_PROGRESS:
return this.i18n('nearbyShareErrorTransferInProgressDescription');
default:
return '';
}
},
/** /**
* @return {string} localized string * @return {string} localized string
* @protected * @protected
......
...@@ -25,7 +25,8 @@ ...@@ -25,7 +25,8 @@
<cr-view-manager id="viewManager"> <cr-view-manager id="viewManager">
<nearby-share-high-visibility-page id="[[Page.HIGH_VISIBILITY]]" <nearby-share-high-visibility-page id="[[Page.HIGH_VISIBILITY]]"
slot="view" device-name="[[settings.deviceName]]" slot="view" device-name="[[settings.deviceName]]"
shutoff-timestamp="[[highVisibilityShutoffTimestamp_]]"> shutoff-timestamp="[[highVisibilityShutoffTimestamp_]]"
register-result="[[registerForegroundReceiveSurfaceResult_]]">
</nearby-share-high-visibility-page> </nearby-share-high-visibility-page>
<nearby-share-confirm-page id="[[Page.CONFIRM]]" slot="view" <nearby-share-confirm-page id="[[Page.CONFIRM]]" slot="view"
share-target="[[shareTarget]]" share-target="[[shareTarget]]"
......
...@@ -108,6 +108,9 @@ Polymer({ ...@@ -108,6 +108,9 @@ Polymer({
*/ */
highVisibilityShutoffTimestamp_: 0, highVisibilityShutoffTimestamp_: 0,
/** @private {?nearbyShare.mojom.RegisterReceiveSurfaceResult} */
registerForegroundReceiveSurfaceResult_: null,
/** @override */ /** @override */
attached() { attached() {
this.closing_ = false; this.closing_ = false;
...@@ -260,8 +263,10 @@ Polymer({ ...@@ -260,8 +263,10 @@ Polymer({
performance.now() + (shutoffTimeoutInSeconds * 1000); performance.now() + (shutoffTimeoutInSeconds * 1000);
// Register a receive surface to enter high visibility and show the page. // Register a receive surface to enter high visibility and show the page.
this.receiveManager_.registerForegroundReceiveSurface(); this.receiveManager_.registerForegroundReceiveSurface().then((result) => {
this.getViewManager_().switchView(Page.HIGH_VISIBILITY); this.registerForegroundReceiveSurfaceResult_ = result.result;
this.getViewManager_().switchView(Page.HIGH_VISIBILITY);
});
}, },
/** /**
......
...@@ -111,7 +111,15 @@ void RegisterNearbySharedStrings(content::WebUIDataSource* data_source) { ...@@ -111,7 +111,15 @@ void RegisterNearbySharedStrings(content::WebUIDataSource* data_source) {
{"nearbyShareReceiveConfirmPageTitle", {"nearbyShareReceiveConfirmPageTitle",
IDS_NEARBY_RECEIVE_CONFIRM_PAGE_TITLE}, IDS_NEARBY_RECEIVE_CONFIRM_PAGE_TITLE},
{"nearbyShareReceiveConfirmPageConnectionId", {"nearbyShareReceiveConfirmPageConnectionId",
IDS_NEARBY_RECEIVE_CONFIRM_PAGE_CONNECTION_ID}}; IDS_NEARBY_RECEIVE_CONFIRM_PAGE_CONNECTION_ID},
{"nearbyShareErrorNoConnectionMedium",
IDS_NEARBY_HIGH_VISIBILITY_CONNECTION_MEDIUM_ERROR},
{"nearbyShareErrorNoConnectionMediumDescription",
IDS_NEARBY_HIGH_VISIBILITY_CONNECTION_MEDIUM_DESCRIPTION},
{"nearbyShareErrorTransferInProgressTitle",
IDS_NEARBY_HIGH_VISIBILITY_TRANSFER_IN_PROGRESS_ERROR},
{"nearbyShareErrorTransferInProgressDescription",
IDS_NEARBY_HIGH_VISIBILITY_TRANSFER_IN_PROGRESS_DESCRIPTION}};
webui::AddLocalizedStringsBulk(data_source, kLocalizedStrings); webui::AddLocalizedStringsBulk(data_source, kLocalizedStrings);
data_source->AddString("nearbyShareLearnMoreLink", data_source->AddString("nearbyShareLearnMoreLink",
......
...@@ -83,6 +83,7 @@ suite('NearbyShare', function() { ...@@ -83,6 +83,7 @@ suite('NearbyShare', function() {
}); });
test('show high visibility page, get a target, accept', async function() { test('show high visibility page, get a target, accept', async function() {
await test_util.waitAfterNextRender(dialog);
// When attached we enter high visibility mode by default // When attached we enter high visibility mode by default
assertTrue(isVisible('nearby-share-high-visibility-page')); assertTrue(isVisible('nearby-share-high-visibility-page'));
assertFalse(isVisible('nearby-share-confirm-page')); assertFalse(isVisible('nearby-share-confirm-page'));
...@@ -105,6 +106,7 @@ suite('NearbyShare', function() { ...@@ -105,6 +106,7 @@ suite('NearbyShare', function() {
}); });
test('show high visibility page, get a target, reject', async function() { test('show high visibility page, get a target, reject', async function() {
await test_util.waitAfterNextRender(dialog);
// When attached we enter high visibility mode by default // When attached we enter high visibility mode by default
assertTrue(isVisible('nearby-share-high-visibility-page')); assertTrue(isVisible('nearby-share-high-visibility-page'));
assertFalse(isVisible('nearby-share-confirm-page')); assertFalse(isVisible('nearby-share-confirm-page'));
...@@ -129,6 +131,7 @@ suite('NearbyShare', function() { ...@@ -129,6 +131,7 @@ suite('NearbyShare', function() {
test( test(
'show high visibility page, unregister surface, closes dialog', 'show high visibility page, unregister surface, closes dialog',
async function() { async function() {
await test_util.waitAfterNextRender(dialog);
// When attached we enter high visibility mode by default // When attached we enter high visibility mode by default
assertTrue(isVisible('nearby-share-high-visibility-page')); assertTrue(isVisible('nearby-share-high-visibility-page'));
assertFalse(isVisible('nearby-share-confirm-page')); assertFalse(isVisible('nearby-share-confirm-page'));
...@@ -141,6 +144,7 @@ suite('NearbyShare', function() { ...@@ -141,6 +144,7 @@ suite('NearbyShare', function() {
test( test(
'unregister surface, OnTransferUpdate, does not close dialog', 'unregister surface, OnTransferUpdate, does not close dialog',
async function() { async function() {
await test_util.waitAfterNextRender(dialog);
// When attached we enter high visibility mode by default // When attached we enter high visibility mode by default
assertTrue(isVisible('nearby-share-high-visibility-page')); assertTrue(isVisible('nearby-share-high-visibility-page'));
assertFalse(isVisible('nearby-share-confirm-page')); assertFalse(isVisible('nearby-share-confirm-page'));
......
...@@ -229,7 +229,7 @@ suite('NearbyShare', function() { ...@@ -229,7 +229,7 @@ suite('NearbyShare', function() {
dialog.$$('.action-button').click(); dialog.$$('.action-button').click();
}); });
test('toggle high visibility from UI', function() { test('toggle high visibility from UI', async function() {
subpage.$$('#highVisibilityToggle').click(); subpage.$$('#highVisibilityToggle').click();
Polymer.dom.flush(); Polymer.dom.flush();
assertTrue(fakeReceiveManager.getInHighVisibilityForTest()); assertTrue(fakeReceiveManager.getInHighVisibilityForTest());
...@@ -237,6 +237,7 @@ suite('NearbyShare', function() { ...@@ -237,6 +237,7 @@ suite('NearbyShare', function() {
const dialog = subpage.$$('nearby-share-receive-dialog'); const dialog = subpage.$$('nearby-share-receive-dialog');
assertTrue(!!dialog); assertTrue(!!dialog);
await test_util.waitAfterNextRender(dialog);
const highVisibilityDialog = dialog.$$('nearby-share-high-visibility-page'); const highVisibilityDialog = dialog.$$('nearby-share-high-visibility-page');
assertTrue(test_util.isVisible(highVisibilityDialog)); assertTrue(test_util.isVisible(highVisibilityDialog));
...@@ -273,7 +274,7 @@ suite('NearbyShare', function() { ...@@ -273,7 +274,7 @@ suite('NearbyShare', function() {
assertTrue(!!dialog); assertTrue(!!dialog);
}); });
test('show high visibility dialog', function() { test('show high visibility dialog', async function() {
// Mock performance.now to return a constant 0 for testing. // Mock performance.now to return a constant 0 for testing.
const originalNow = performance.now; const originalNow = performance.now;
performance.now = () => { performance.now = () => {
...@@ -293,6 +294,7 @@ suite('NearbyShare', function() { ...@@ -293,6 +294,7 @@ suite('NearbyShare', function() {
assertFalse(highVisibilityDialog.highVisibilityTimedOut_()); assertFalse(highVisibilityDialog.highVisibilityTimedOut_());
Polymer.dom.flush(); Polymer.dom.flush();
await test_util.waitAfterNextRender(dialog);
assertTrue(test_util.isVisible(highVisibilityDialog)); assertTrue(test_util.isVisible(highVisibilityDialog));
assertEquals(highVisibilityDialog.shutoffTimestamp, 600 * 1000); assertEquals(highVisibilityDialog.shutoffTimestamp, 600 * 1000);
...@@ -301,7 +303,7 @@ suite('NearbyShare', function() { ...@@ -301,7 +303,7 @@ suite('NearbyShare', function() {
performance.now = originalNow; performance.now = originalNow;
}); });
test('high visibility dialog times out', function() { test('high visibility dialog times out', async function() {
// Mock performance.now to return a constant 0 for testing. // Mock performance.now to return a constant 0 for testing.
const originalNow = performance.now; const originalNow = performance.now;
performance.now = () => { performance.now = () => {
...@@ -328,6 +330,7 @@ suite('NearbyShare', function() { ...@@ -328,6 +330,7 @@ suite('NearbyShare', function() {
}; };
highVisibilityDialog.calculateRemainingTime_(); highVisibilityDialog.calculateRemainingTime_();
await test_util.waitAfterNextRender(dialog);
assertTrue(test_util.isVisible(highVisibilityDialog)); assertTrue(test_util.isVisible(highVisibilityDialog));
assertTrue(highVisibilityDialog.highVisibilityTimedOut_()); assertTrue(highVisibilityDialog.highVisibilityTimedOut_());
......
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