Skip to content

Commit

Permalink
[unified-consent] Navigate away from sync controls page when unavailable
Browse files Browse the repository at this point in the history
- Navigate to main sync page when sync controls page should *not* be
  available. I.e. when sync is paused, the user is signed out, sync
  is disabled or there is a sync error other than passphrase error.

- Don't show sync controls page when unified consent is disabled.

Bug: 915744
Change-Id: I762a91b170ad379c2ffb8fe9eab4f42a6414fcd0
Reviewed-on: https://chromium-review.googlesource.com/c/1380676
Reviewed-by: Scott Chen <[email protected]>
Commit-Queue: Thomas Tangl <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#617407}(cherry picked from commit 7db78b0)
Reviewed-on: https://chromium-review.googlesource.com/c/1386826
Reviewed-by: Thomas Tangl <[email protected]>
Cr-Commit-Position: refs/branch-heads/3626@{#481}
Cr-Branched-From: d897fb1-refs/heads/master@{#612437}
  • Loading branch information
Thomas Tangl committed Dec 20, 2018
1 parent 17f3e8d commit 177169d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 10 deletions.
16 changes: 9 additions & 7 deletions chrome/browser/resources/settings/people_page/people_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,15 @@
</settings-subpage>
</template>

<template is="dom-if" route-path="/syncSetup/advanced">
<settings-subpage page-title="$i18n{syncAdvancedPageTitle}"
learn-more-url="$i18n{syncAndGoogleServicesLearnMoreURL}">
<settings-sync-controls sync-status="[[syncStatus]]"
on-sync-setup-cancel="cancelSyncSetup_">
</settings-sync-controls>
</settings-subpage>
<template is="dom-if" if="[[unifiedConsentEnabled_]]">
<template is="dom-if" route-path="/syncSetup/advanced">
<settings-subpage page-title="$i18n{syncAdvancedPageTitle}"
learn-more-url="$i18n{syncAndGoogleServicesLearnMoreURL}">
<settings-sync-controls sync-status="[[syncStatus]]"
on-sync-setup-cancel="cancelSyncSetup_">
</settings-sync-controls>
</settings-subpage>
</template>
</template>

<if expr="chromeos">
Expand Down
22 changes: 21 additions & 1 deletion chrome/browser/resources/settings/people_page/sync_controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ Polymer({
* The current sync status, supplied by the parent.
* @type {settings.SyncStatus}
*/
syncStatus: Object,
syncStatus: {
type: Object,
observer: 'syncStatusChanged_',
},
},

/** @private {?settings.SyncBrowserProxy} */
Expand Down Expand Up @@ -168,5 +171,22 @@ Polymer({
onCancelSyncClick_: function() {
this.fire('sync-setup-cancel');
},

/** @private */
syncStatusChanged_: function(syncStatus) {
// When the sync controls are embedded, the parent has to take care of
// showing/hiding them.
if (settings.getCurrentRoute() != settings.routes.SYNC_ADVANCED ||
!syncStatus)
return;

// Navigate to main sync page when the sync controls page should *not* be
// available.
if (!syncStatus.signedIn || !!syncStatus.disabled ||
(!!syncStatus.hasError &&
syncStatus.statusAction !== settings.StatusAction.ENTER_PASSPHRASE)) {
settings.navigateTo(settings.routes.SYNC);
}
},
});
})();
34 changes: 32 additions & 2 deletions chrome/test/data/webui/settings/people_page_sync_controls_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ cr.define('settings_people_page_sync_controls', function() {
settings.navigateTo(settings.routes.SYNC_ADVANCED);
document.body.appendChild(syncControls);

syncControls
.syncStatus = {disabled: false, hasError: false, signedIn: true};
Polymer.dom.flush();

assertEquals(settings.routes.SYNC_ADVANCED, settings.getCurrentRoute());
});

teardown(function() {
Expand All @@ -140,14 +144,40 @@ cr.define('settings_people_page_sync_controls', function() {

if (!cr.isChromeOS) {
test('ToastShownForSyncSetup', function() {
syncControls.syncStatus = {setupInProgress: false};
syncControls.syncStatus = {setupInProgress: false, signedIn: true};
assertFalse(syncControls.$.toast.open);

syncControls.syncStatus = {setupInProgress: true};
syncControls.syncStatus = {setupInProgress: true, signedIn: true};
assertTrue(syncControls.$.toast.open);

syncControls.$.toast.querySelector('paper-button').click();
});
}

test('SignedOut', function() {
syncControls
.syncStatus = {disabled: false, hasError: false, signedIn: false};
assertEquals(settings.routes.SYNC, settings.getCurrentRoute());
});

test('PassphraseError', function() {
syncControls.syncStatus = {
disabled: false,
hasError: true,
signedIn: true,
statusAction: settings.StatusAction.ENTER_PASSPHRASE
};
assertEquals(settings.routes.SYNC_ADVANCED, settings.getCurrentRoute());
});

test('SyncPaused', function() {
syncControls.syncStatus = {
disabled: false,
hasError: true,
signedIn: true,
statusAction: settings.StatusAction.REAUTHENTICATE
};
assertEquals(settings.routes.SYNC, settings.getCurrentRoute());
});
});
});

0 comments on commit 177169d

Please sign in to comment.