Skip to content

Commit

Permalink
personalization: Redirect from Google Photos collection if disabled.
Browse files Browse the repository at this point in the history
If the user manages to navigate to the Google Photos collection but
Google Photos access is disabled, redirect back to the collections
page.

Bug: b:225243368
Change-Id: Ia820ed5af7a89b3db514aa3e5b6d62f59f6b5687
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3564778
Reviewed-by: Jeffrey Young <cowmoo@chromium.org>
Commit-Queue: David Black <dmblack@google.com>
Cr-Commit-Position: refs/heads/main@{#988151}
  • Loading branch information
David Black authored and Chromium LUCI CQ committed Apr 1, 2022
1 parent 76c9965 commit 176ee36
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import '../../common/styles.js';
import {assertNotReached} from 'chrome://resources/js/assert_ts.js';

import {isNonEmptyArray} from '../../common/utils.js';
import {GooglePhotosAlbum, GooglePhotosPhoto, WallpaperProviderInterface} from '../personalization_app.mojom-webui.js';
import {GooglePhotosAlbum, GooglePhotosEnablementState, GooglePhotosPhoto, WallpaperProviderInterface} from '../personalization_app.mojom-webui.js';
import {Paths, PersonalizationRouter} from '../personalization_router_element.js';
import {WithPersonalizationStore} from '../personalization_store.js';

import {getTemplate} from './google_photos_collection_element.html.js';
Expand Down Expand Up @@ -55,7 +56,10 @@ export class GooglePhotosCollection extends WithPersonalizationStore {
observer: 'onHiddenChanged_',
},

path: String,

albums_: Array,
enabled_: Number,
photos_: Array,

tab_: {
Expand All @@ -65,15 +69,25 @@ export class GooglePhotosCollection extends WithPersonalizationStore {
};
}

static get observers() {
return ['onPathOrEnabledChanged_(path, enabled_)'];
}

/** The currently selected album id. */
albumId: string|undefined;

/** Whether or not this element is currently hidden. */
override hidden: boolean;

/** The currently selected path. */
path: string|undefined;

/** The list of albums. */
private albums_: GooglePhotosAlbum[]|null|undefined;

/** Whether the user is allowed to access Google Photos. */
private enabled_: GooglePhotosEnablementState|undefined;

/** The list of photos. */
private photos_: GooglePhotosPhoto[]|null|undefined;

Expand All @@ -89,6 +103,8 @@ export class GooglePhotosCollection extends WithPersonalizationStore {

this.watch<GooglePhotosCollection['albums_']>(
'albums_', state => state.wallpaper.googlePhotos.albums);
this.watch<GooglePhotosCollection['enabled_']>(
'enabled_', state => state.wallpaper.googlePhotos.enabled);
this.watch<GooglePhotosCollection['photos_']>(
'photos_', state => state.wallpaper.googlePhotos.photos);

Expand All @@ -112,6 +128,18 @@ export class GooglePhotosCollection extends WithPersonalizationStore {
this.$.main.focus();
}

/** Invoked on changes to either |path| or |enabled_|. */
private onPathOrEnabledChanged_(
path: GooglePhotosCollection['path'],
enabled: GooglePhotosCollection['enabled_']) {
// If the Google Photos collection is selected but the user is not allowed
// to access Google Photos, redirect back to the collections page.
if (path === Paths.GooglePhotosCollection &&
enabled === GooglePhotosEnablementState.kDisabled) {
PersonalizationRouter.reloadAtWallpaper();
}
}

/** Invoked on tab selected. */
private onTabSelected_(e: Event) {
const currentTarget: HTMLElement = e.currentTarget as HTMLElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
<wallpaper-images collection-id="[[queryParams.id]]"
hidden="[[!shouldShowCollectionImages_(path)]]"></wallpaper-images>
<template is="dom-if" if="[[isGooglePhotosIntegrationEnabled_()]]">
<google-photos-collection album-id="[[queryParams.googlePhotosAlbumId]]"
<google-photos-collection path="[[path]]"
album-id="[[queryParams.googlePhotosAlbumId]]"
hidden="[[!shouldShowGooglePhotosCollection_(path)]]">
</google-photos-collection>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'chrome://personalization/strings.m.js';
import 'chrome://webui-test/mojo_webui_test_support.js';

import {GooglePhotosAlbum, GooglePhotosCollection} from 'chrome://personalization/trusted/personalization_app.js';
import {GooglePhotosAlbum, GooglePhotosCollection, GooglePhotosEnablementState, Paths, PersonalizationRouter} from 'chrome://personalization/trusted/personalization_app.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {assertEquals, assertFalse, assertTrue} from 'chrome://webui-test/chai_assert.js';
import {waitAfterNextRender} from 'chrome://webui-test/test_util.js';
Expand Down Expand Up @@ -234,4 +234,34 @@ suite('GooglePhotosCollectionTest', function() {
googlePhotosCollectionElement.$.main.getAttribute('aria-label'),
'google photos main aria label is set');
});

[GooglePhotosEnablementState.kDisabled, GooglePhotosEnablementState.kEnabled,
GooglePhotosEnablementState.kError]
.forEach(
enabled => test(
'Redirects when Google Photos access is disabled.', async () => {
// Set values returned by |wallpaperProvider|.
wallpaperProvider.setGooglePhotosEnabled(enabled);

// Initialize |googlePhotosCollectionElement|.
googlePhotosCollectionElement =
initElement(GooglePhotosCollection, {hidden: false});
await waitAfterNextRender(googlePhotosCollectionElement);

// Mock |PersonalizationRouter.reloadAtWallpaper()|.
let didCallReloadAtWallpaper = false;
PersonalizationRouter.reloadAtWallpaper = () => {
didCallReloadAtWallpaper = true;
};

// Select Google Photos collection.
googlePhotosCollectionElement.setAttribute(
'path', Paths.GooglePhotosCollection);
await waitAfterNextRender(googlePhotosCollectionElement);

// Verify redirect expecations.
assertEquals(
didCallReloadAtWallpaper,
enabled === GooglePhotosEnablementState.kDisabled);
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'chrome://personalization/strings.m.js';
import 'chrome://webui-test/mojo_webui_test_support.js';

import {emptyState, GooglePhotosEnablementState, GooglePhotosPhoto, IFrameApi, kMaximumGooglePhotosPreviews, kMaximumLocalImagePreviews, PersonalizationRouter, WallpaperActionName, WallpaperCollections} from 'chrome://personalization/trusted/personalization_app.js';
import {emptyState, GooglePhotosEnablementState, GooglePhotosPhoto, IFrameApi, kMaximumGooglePhotosPreviews, kMaximumLocalImagePreviews, Paths, PersonalizationRouter, WallpaperActionName, WallpaperCollections} from 'chrome://personalization/trusted/personalization_app.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {assertDeepEquals, assertEquals, assertFalse, assertNotEquals, assertTrue} from 'chrome://webui-test/chai_assert.js';
import {TestBrowserProxy} from 'chrome://webui-test/test_browser_proxy.js';
Expand Down Expand Up @@ -167,6 +167,10 @@ suite('WallpaperCollectionsTest', function() {
assertEquals(
proxy.getCallCount('goToRoute'),
enabled === GooglePhotosEnablementState.kDisabled ? 0 : 1);
assertEquals(
proxy.getArgs('goToRoute')[0] ??
Paths.GooglePhotosCollection,
Paths.GooglePhotosCollection);
}));

test('sends image counts when a collection loads', async () => {
Expand Down

0 comments on commit 176ee36

Please sign in to comment.