Commit 2114f7f5 authored by sauski's avatar sauski Committed by Commit Bot

Move route observer behavior into Recent Site Permissions element

Previously the Recent Site Permissions display list update needed to be
manually triggered (probably by it's parent). This CL extends the element
to be a route observer so that it can re-trigger updates when appropriate.

Updates are triggered when the route matching that set on the route-path
attribute of the element is navigated to.

Bug: 1032584
Change-Id: Id29191b6586c138e1e1191aaab218c5f7ff92a2f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2088643Reviewed-by: default avatardpapad <dpapad@chromium.org>
Commit-Queue: Theodore Olsauskas-Warren <sauski@google.com>
Cr-Commit-Position: refs/heads/master@{#747512}
parent e59a0494
...@@ -14,6 +14,8 @@ js_type_check("closure_compile") { ...@@ -14,6 +14,8 @@ js_type_check("closure_compile") {
js_library("recent_site_permissions") { js_library("recent_site_permissions") {
deps = [ deps = [
"..:route",
"..:router",
"../people_page:sync_browser_proxy", "../people_page:sync_browser_proxy",
"../prefs:prefs_behavior", "../prefs:prefs_behavior",
"../site_settings:site_settings_behavior", "../site_settings:site_settings_behavior",
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
<link rel="import" href="chrome://resources/html/load_time_data.html"> <link rel="import" href="chrome://resources/html/load_time_data.html">
<link rel="import" href="chrome://resources/html/web_ui_listener_behavior.html"> <link rel="import" href="chrome://resources/html/web_ui_listener_behavior.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-tooltip/paper-tooltip.html"> <link rel="import" href="chrome://resources/polymer/v1_0/paper-tooltip/paper-tooltip.html">
<link rel="import" href="../route.html">
<link rel="import" href="../router.html">
<link rel="import" href="../site_settings/site_settings_behavior.html"> <link rel="import" href="../site_settings/site_settings_behavior.html">
<link rel="import" href="../settings_shared_css.html"> <link rel="import" href="../settings_shared_css.html">
......
...@@ -6,6 +6,7 @@ Polymer({ ...@@ -6,6 +6,7 @@ Polymer({
is: 'settings-recent-site-permissions', is: 'settings-recent-site-permissions',
behaviors: [ behaviors: [
settings.RouteObserverBehavior,
SiteSettingsBehavior, SiteSettingsBehavior,
WebUIListenerBehavior, WebUIListenerBehavior,
I18nBehavior, I18nBehavior,
...@@ -30,6 +31,18 @@ Polymer({ ...@@ -30,6 +31,18 @@ Polymer({
}, },
}, },
/**
* Reload the site recent site permission list whenever the user navigates
* to the site settings page.
* @param {!settings.Route} currentRoute
* @protected
*/
currentRouteChanged(currentRoute) {
if (currentRoute.path == settings.routes.SITE_SETTINGS.path) {
this.populateList_();
}
},
/** @override */ /** @override */
ready() { ready() {
this.addWebUIListener( this.addWebUIListener(
...@@ -214,7 +227,7 @@ Polymer({ ...@@ -214,7 +227,7 @@ Polymer({
// and we are currently displaying an incognito entry. // and we are currently displaying an incognito entry.
if (hasIncognito === false && if (hasIncognito === false &&
this.recentSitePermissionsList_.some(p => p.incognito)) { this.recentSitePermissionsList_.some(p => p.incognito)) {
this.populateList(); this.populateList_();
} }
}, },
...@@ -262,7 +275,7 @@ Polymer({ ...@@ -262,7 +275,7 @@ Polymer({
* the update of the display list. * the update of the display list.
* @private * @private
*/ */
async populateList() { async populateList_() {
this.recentSitePermissionsList_ = this.recentSitePermissionsList_ =
await this.browserProxy.getRecentSitePermissions( await this.browserProxy.getRecentSitePermissions(
this.getCategoryList(), 3); this.getCategoryList(), 3);
......
...@@ -327,8 +327,6 @@ cr.define('settings', function() { ...@@ -327,8 +327,6 @@ cr.define('settings', function() {
Polymer({ Polymer({
is: 'settings-site-settings-page', is: 'settings-site-settings-page',
behaviors: [settings.RouteObserverBehavior],
properties: { properties: {
/** /**
* @private {{ * @private {{
...@@ -479,24 +477,6 @@ cr.define('settings', function() { ...@@ -479,24 +477,6 @@ cr.define('settings', function() {
this.navigateToRoute_(event.detail); this.navigateToRoute_(event.detail);
}, },
/**
* Reload the site recent site permission list when the page is navigated
* to.
* settings.RouteObserverBehavior
* @param {!settings.Route} currentRoute
* @protected
*/
currentRouteChanged(currentRoute) {
if (currentRoute == settings.routes.SITE_SETTINGS &&
this.privacySettingsRedesignEnabled_) {
// Needs to be async to await the surrounding dom-if, should be removed
// when the dom-if is removed.
this.async(() => {
this.$$('#recentSitePermissions').populateList();
});
}
},
/** /**
* @return {string} Class for the all site settings link * @return {string} Class for the all site settings link
* @private * @private
......
...@@ -22,14 +22,20 @@ suite('CrSettingsRecentSitePermissionsTest', function() { ...@@ -22,14 +22,20 @@ suite('CrSettingsRecentSitePermissionsTest', function() {
Polymer.dom.flush(); Polymer.dom.flush();
}); });
teardown(function() {
testElement.remove();
});
test('No recent permissions', async function() { test('No recent permissions', async function() {
browserProxy.setResultFor('getRecentSitePermissions', Promise.resolve([])); browserProxy.setResultFor('getRecentSitePermissions', Promise.resolve([]));
await testElement.populateList(); testElement.currentRouteChanged(settings.routes.SITE_SETTINGS);
await browserProxy.whenCalled('getRecentSitePermissions');
Polymer.dom.flush();
assertTrue(test_util.isVisible(testElement, '#noPermissionsText')); assertTrue(test_util.isVisible(testElement, '#noPermissionsText'));
}); });
test('Various recent permissions', async function() { test('Various recent permissions', async function() {
const mock_data = Promise.resolve([ const mockData = Promise.resolve([
{ {
origin: 'https://bar.com', origin: 'https://bar.com',
incognito: true, incognito: true,
...@@ -53,9 +59,11 @@ suite('CrSettingsRecentSitePermissionsTest', function() { ...@@ -53,9 +59,11 @@ suite('CrSettingsRecentSitePermissionsTest', function() {
] ]
}, },
]); ]);
browserProxy.setResultFor('getRecentSitePermissions', mock_data); browserProxy.setResultFor('getRecentSitePermissions', mockData);
testElement.currentRouteChanged(settings.routes.SITE_SETTINGS);
await browserProxy.whenCalled('getRecentSitePermissions');
Polymer.dom.flush();
await testElement.populateList();
assertFalse(testElement.noRecentPermissions); assertFalse(testElement.noRecentPermissions);
assertFalse(test_util.isChildVisible(testElement, '#noPermissionsText')); assertFalse(test_util.isChildVisible(testElement, '#noPermissionsText'));
......
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