Commit 3dd6dab7 authored by Patricia Lor's avatar Patricia Lor Committed by Commit Bot

MD Settings: Show default settings in the drop-down menu in Site Details.

The Site Details page currently only shows two options in the drop-down menu
for each permission, 'Allow' and 'Block'. This change adds a third option to the
list, which shows the default option, similar to the Page Info bubble.

The "Site Details" page that opens should show matching permissions to those
seen in the Page Info bubble, including the defaults - e.g. Javascript should be
"Allow (default)", Popups should be "Block (default)", and Camera should be
"Ask (default)". Navigating to chrome:settings/content/camera and toggling the
"Ask before accessing (recommended)" option should then make the Site Details
page for for https://permission.site show "Block (default)" next to the Camera
permission.

Bug: 656758
Change-Id: I74cd332c44d8fcb1ab5c700e4fa394ce74fe973b
Test: With the #enable-site-details flag turned on, navigate to
https: //permission.site, open the Page Info bubble, and click "Site settings".
Reviewed-on: https://chromium-review.googlesource.com/558541
Commit-Queue: Patti <patricialor@chromium.org>
Reviewed-by: default avatarDave Schuyler <dschuyler@chromium.org>
Reviewed-by: default avatarcalamity <calamity@chromium.org>
Reviewed-by: default avatarRaymes Khoury <raymes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488086}
parent b1e047ad
...@@ -2176,6 +2176,15 @@ ...@@ -2176,6 +2176,15 @@
<message name="IDS_SETTINGS_SITE_SETTINGS_SITE_URL" desc="Label for site URL text entry in site settings."> <message name="IDS_SETTINGS_SITE_SETTINGS_SITE_URL" desc="Label for site URL text entry in site settings.">
Site URL Site URL
</message> </message>
<message name="IDS_SETTINGS_SITE_SETTINGS_ASK_DEFAULT_MENU" desc="Label for the default menu item to ask for permission for a particular site.">
Ask (default)
</message>
<message name="IDS_SETTINGS_SITE_SETTINGS_ALLOW_DEFAULT_MENU" desc="Label for the default menu item to allow a permission for a particular site.">
Allow (default)
</message>
<message name="IDS_SETTINGS_SITE_SETTINGS_BLOCK_DEFAULT_MENU" desc="Label for the default menu item to block a permission for a particular site.">
Block (default)
</message>
<message name="IDS_SETTINGS_SITE_SETTINGS_ALLOW_MENU" desc="Label for the menu item to allow permission for a particular site."> <message name="IDS_SETTINGS_SITE_SETTINGS_ALLOW_MENU" desc="Label for the menu item to allow permission for a particular site.">
Allow Allow
</message> </message>
......
...@@ -195,6 +195,7 @@ ...@@ -195,6 +195,7 @@
'dependencies': [ 'dependencies': [
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:cr', '<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:cr',
'<(EXTERNS_GYP):chrome_send', '<(EXTERNS_GYP):chrome_send',
'<(EXTERNS_GYP):settings_private',
'constants', 'constants',
'cookie_tree_node', 'cookie_tree_node',
], ],
......
...@@ -83,10 +83,8 @@ Polymer({ ...@@ -83,10 +83,8 @@ Polymer({
exceptionList.forEach(function(exception, i) { exceptionList.forEach(function(exception, i) {
// |exceptionList| should be in the same order as |categoryList|, // |exceptionList| should be in the same order as |categoryList|,
// which is in the same order as |siteDetailsPermissions|. // which is in the same order as |siteDetailsPermissions|.
var element = /** @type{!SiteDetailsPermissionElement} */ ( siteDetailsPermissions[i].site =
siteDetailsPermissions[i]); /** @type {!RawSiteException} */ (exception);
element.site = /** @type{!SiteException} */ (
element.expandSiteException(exception));
}); });
}); });
}, },
......
...@@ -23,6 +23,13 @@ ...@@ -23,6 +23,13 @@
<select id="permission" class="md-select" <select id="permission" class="md-select"
aria-labelledby="permissionHeader" aria-labelledby="permissionHeader"
on-change="onPermissionSelectionChange_"> on-change="onPermissionSelectionChange_">
<option id="default" value$="[[ContentSetting.DEFAULT]]">
[[defaultSettingString_(
defaultSetting_,
'$i18nPolymer{siteSettingsActionAskDefault}',
'$i18nPolymer{siteSettingsActionAllowDefault}',
'$i18nPolymer{siteSettingsActionBlockDefault}')]]
</option>
<option id="allow" value$="[[ContentSetting.ALLOW]]"> <option id="allow" value$="[[ContentSetting.ALLOW]]">
$i18n{siteSettingsActionAllow} $i18n{siteSettingsActionAllow}
</option> </option>
......
...@@ -15,9 +15,16 @@ Polymer({ ...@@ -15,9 +15,16 @@ Polymer({
properties: { properties: {
/** /**
* The site that this widget is showing details for. * The site that this widget is showing details for.
* @type {SiteException} * @type {RawSiteException}
*/ */
site: Object, site: Object,
/**
* The default setting for this permission category.
* @type {settings.ContentSetting}
* @private
*/
defaultSetting_: String,
}, },
observers: ['siteChanged_(site, category)'], observers: ['siteChanged_(site, category)'],
...@@ -44,10 +51,20 @@ Polymer({ ...@@ -44,10 +51,20 @@ Polymer({
/** /**
* Updates the drop-down value after |site| has changed. * Updates the drop-down value after |site| has changed.
* @param {!SiteException} site The site to display. * @param {!RawSiteException} site The site to display.
* @private * @private
*/ */
siteChanged_: function(site) { siteChanged_: function(site) {
if (site.source == 'default') {
this.defaultSetting_ = site.setting;
this.$.permission.value = settings.ContentSetting.DEFAULT;
return;
}
// The default setting is unknown, so consult the C++ backend for it.
this.browserProxy.getDefaultValueForContentType(this.category)
.then((defaultValue) => {
this.defaultSetting_ = defaultValue.setting;
});
this.$.permission.value = site.setting; this.$.permission.value = site.setting;
}, },
...@@ -86,8 +103,34 @@ Polymer({ ...@@ -86,8 +103,34 @@ Polymer({
* @private * @private
*/ */
onPermissionSelectionChange_: function() { onPermissionSelectionChange_: function() {
if (this.$.permission.value == settings.ContentSetting.DEFAULT) {
this.resetPermission();
return;
}
this.browserProxy.setCategoryPermissionForOrigin( this.browserProxy.setCategoryPermissionForOrigin(
this.site.origin, this.site.embeddingOrigin, this.category, this.site.origin, this.site.embeddingOrigin, this.category,
this.$.permission.value, this.site.incognito); this.$.permission.value, this.site.incognito);
}, },
/**
* Updates the string used for this permission category's default setting.
* @param {!settings.ContentSetting} defaultSetting Value of the default
* setting for this permission category.
* @param {string} askString 'Ask' label, e.g. 'Ask (default)'.
* @param {string} allowString 'Allow' label, e.g. 'Allow (default)'.
* @param {string} blockString 'Block' label, e.g. 'Blocked (default)'.
* @private
*/
defaultSettingString_(defaultSetting, askString, allowString, blockString) {
if (defaultSetting == settings.ContentSetting.ASK ||
defaultSetting == settings.ContentSetting.IMPORTANT_CONTENT) {
return askString;
} else if (defaultSetting == settings.ContentSetting.ALLOW) {
return allowString;
} else if (defaultSetting == settings.ContentSetting.BLOCK) {
return blockString;
}
assertNotReached(
`No string for ${this.category}'s default of ${defaultSetting}`);
},
}); });
...@@ -145,13 +145,15 @@ var SiteSettingsBehaviorImpl = { ...@@ -145,13 +145,15 @@ var SiteSettingsBehaviorImpl = {
var origin = exception.origin; var origin = exception.origin;
var embeddingOrigin = exception.embeddingOrigin; var embeddingOrigin = exception.embeddingOrigin;
var enforcement = ''; var enforcement = /** @type {?chrome.settingsPrivate.Enforcement} */ (null);
if (exception.source == 'extension' || exception.source == 'HostedApp' || if (exception.source == 'extension' || exception.source == 'HostedApp' ||
exception.source == 'platform_app' || exception.source == 'policy') { exception.source == 'platform_app' || exception.source == 'policy') {
enforcement = chrome.settingsPrivate.Enforcement.ENFORCED; enforcement = chrome.settingsPrivate.Enforcement.ENFORCED;
} }
var controlledBy = kControlledByLookup[exception.source] || ''; var controlledBy = /** @type {!chrome.settingsPrivate.ControlledBy} */ (
kControlledByLookup[exception.source] ||
chrome.settingsPrivate.ControlledBy.PRIMARY_USER);
return { return {
category: this.category, category: this.category,
......
...@@ -21,11 +21,12 @@ var ContentSettingProvider = { ...@@ -21,11 +21,12 @@ var ContentSettingProvider = {
/** /**
* The site exception information passed from the C++ handler. * The site exception information passed from the C++ handler.
* See also: SiteException. * See also: SiteException.
* TODO(patricialor): Investigate making the |source| field an enum type.
* @typedef {{embeddingOrigin: string, * @typedef {{embeddingOrigin: string,
* incognito: boolean, * incognito: boolean,
* origin: string, * origin: string,
* displayName: string, * displayName: string,
* setting: string, * setting: !settings.ContentSetting,
* source: string}} * source: string}}
*/ */
var RawSiteException; var RawSiteException;
...@@ -38,21 +39,15 @@ var RawSiteException; ...@@ -38,21 +39,15 @@ var RawSiteException;
* incognito: boolean, * incognito: boolean,
* origin: string, * origin: string,
* displayName: string, * displayName: string,
* setting: string, * setting: !settings.ContentSetting,
* enforcement: string, * enforcement: ?chrome.settingsPrivate.Enforcement,
* controlledBy: string}} * controlledBy: !chrome.settingsPrivate.ControlledBy}}
*/ */
var SiteException; var SiteException;
/** /**
* @typedef {{location: string, * @typedef {{setting: !settings.ContentSetting,
* notifications: string}} * source: !ContentSettingProvider}}
*/
var CategoryDefaultsPref;
/**
* @typedef {{setting: string,
* source: ContentSettingProvider}}
*/ */
var DefaultContentSetting; var DefaultContentSetting;
......
...@@ -1893,6 +1893,12 @@ void AddSiteSettingsStrings(content::WebUIDataSource* html_source, ...@@ -1893,6 +1893,12 @@ void AddSiteSettingsStrings(content::WebUIDataSource* html_source,
{"siteSettingsBlockedRecommended", {"siteSettingsBlockedRecommended",
IDS_SETTINGS_SITE_SETTINGS_BLOCKED_RECOMMENDED}, IDS_SETTINGS_SITE_SETTINGS_BLOCKED_RECOMMENDED},
{"siteSettingsSiteUrl", IDS_SETTINGS_SITE_SETTINGS_SITE_URL}, {"siteSettingsSiteUrl", IDS_SETTINGS_SITE_SETTINGS_SITE_URL},
{"siteSettingsActionAskDefault",
IDS_SETTINGS_SITE_SETTINGS_ASK_DEFAULT_MENU},
{"siteSettingsActionAllowDefault",
IDS_SETTINGS_SITE_SETTINGS_ALLOW_DEFAULT_MENU},
{"siteSettingsActionBlockDefault",
IDS_SETTINGS_SITE_SETTINGS_BLOCK_DEFAULT_MENU},
{"siteSettingsActionAllow", IDS_SETTINGS_SITE_SETTINGS_ALLOW_MENU}, {"siteSettingsActionAllow", IDS_SETTINGS_SITE_SETTINGS_ALLOW_MENU},
{"siteSettingsActionBlock", IDS_SETTINGS_SITE_SETTINGS_BLOCK_MENU}, {"siteSettingsActionBlock", IDS_SETTINGS_SITE_SETTINGS_BLOCK_MENU},
{"siteSettingsActionReset", IDS_SETTINGS_SITE_SETTINGS_RESET_MENU}, {"siteSettingsActionReset", IDS_SETTINGS_SITE_SETTINGS_RESET_MENU},
......
...@@ -114,23 +114,23 @@ void AddExceptionsGrantedByHostedApps(content::BrowserContext* context, ...@@ -114,23 +114,23 @@ void AddExceptionsGrantedByHostedApps(content::BrowserContext* context,
// 7. User-set global default for a ContentSettingsType. // 7. User-set global default for a ContentSettingsType.
// 8. Chrome's built-in default. // 8. Chrome's built-in default.
std::string ConvertContentSettingSourceToString( std::string ConvertContentSettingSourceToString(
content_settings::SettingSource content_settings_source, const content_settings::SettingInfo& info,
PermissionStatusSource permission_status_source) { PermissionStatusSource permission_status_source) {
// TODO(patricialor): Do some plumbing for sources #1, #2, #3, and #5 through // TODO(patricialor): Do some plumbing for sources #1, #2, #3, and #5 through
// to the Web UI. Currently there aren't strings to represent these sources. // to the Web UI. Currently there aren't strings to represent these sources.
if (permission_status_source == PermissionStatusSource::KILL_SWITCH) if (permission_status_source == PermissionStatusSource::KILL_SWITCH)
return site_settings::kPreferencesSource; // Source #1. return site_settings::kPreferencesSource; // Source #1.
if (content_settings_source == content_settings::SETTING_SOURCE_POLICY || if (info.source == content_settings::SETTING_SOURCE_POLICY ||
content_settings_source == content_settings::SETTING_SOURCE_SUPERVISED) { info.source == content_settings::SETTING_SOURCE_SUPERVISED) {
return site_settings::kPolicyProviderId; // Source #2. return site_settings::kPolicyProviderId; // Source #2.
} }
if (content_settings_source == content_settings::SETTING_SOURCE_EXTENSION) if (info.source == content_settings::SETTING_SOURCE_EXTENSION)
return site_settings::kExtensionProviderId; // Source #3. return site_settings::kExtensionProviderId; // Source #3.
DCHECK_NE(content_settings::SETTING_SOURCE_NONE, content_settings_source); DCHECK_NE(content_settings::SETTING_SOURCE_NONE, info.source);
if (content_settings_source == content_settings::SETTING_SOURCE_USER) { if (info.source == content_settings::SETTING_SOURCE_USER) {
if (permission_status_source == if (permission_status_source ==
PermissionStatusSource::SAFE_BROWSING_BLACKLIST || PermissionStatusSource::SAFE_BROWSING_BLACKLIST ||
permission_status_source == permission_status_source ==
...@@ -138,7 +138,11 @@ std::string ConvertContentSettingSourceToString( ...@@ -138,7 +138,11 @@ std::string ConvertContentSettingSourceToString(
permission_status_source == PermissionStatusSource::MULTIPLE_IGNORES) { permission_status_source == PermissionStatusSource::MULTIPLE_IGNORES) {
return site_settings::kPreferencesSource; // Source #5. return site_settings::kPreferencesSource; // Source #5.
} }
// Source #4, #6, #7, #8. When #4 is the source, |permission_status_source| if (info.primary_pattern == ContentSettingsPattern::Wildcard() &&
info.secondary_pattern == ContentSettingsPattern::Wildcard()) {
return "default"; // Source #7, #8.
}
// Source #4, #6. When #4 is the source, |permission_status_source|
// won't be set to any of the source #5 enum values, as PermissionManager is // won't be set to any of the source #5 enum values, as PermissionManager is
// aware of the difference between these two sources internally. The // aware of the difference between these two sources internally. The
// subtlety here should go away when PermissionManager can handle all // subtlety here should go away when PermissionManager can handle all
...@@ -177,8 +181,8 @@ ContentSetting GetContentSettingForOrigin(const GURL& origin, ...@@ -177,8 +181,8 @@ ContentSetting GetContentSettingForOrigin(const GURL& origin,
} }
// Retrieve the source of the content setting. // Retrieve the source of the content setting.
*source_string = *source_string = ConvertContentSettingSourceToString(info, result.source);
ConvertContentSettingSourceToString(info.source, result.source);
return result.content_setting; return result.content_setting;
} }
......
...@@ -59,6 +59,7 @@ class SiteSettingsHandler : public SettingsPageUIHandler, ...@@ -59,6 +59,7 @@ class SiteSettingsHandler : public SettingsPageUIHandler,
private: private:
friend class SiteSettingsHandlerTest; friend class SiteSettingsHandlerTest;
FRIEND_TEST_ALL_PREFIXES(SiteSettingsHandlerTest, DefaultSettingSource);
FRIEND_TEST_ALL_PREFIXES(SiteSettingsHandlerTest, GetAndSetDefault); FRIEND_TEST_ALL_PREFIXES(SiteSettingsHandlerTest, GetAndSetDefault);
FRIEND_TEST_ALL_PREFIXES(SiteSettingsHandlerTest, Origins); FRIEND_TEST_ALL_PREFIXES(SiteSettingsHandlerTest, Origins);
FRIEND_TEST_ALL_PREFIXES(SiteSettingsHandlerTest, ExceptionHelpers); FRIEND_TEST_ALL_PREFIXES(SiteSettingsHandlerTest, ExceptionHelpers);
......
...@@ -8,10 +8,14 @@ ...@@ -8,10 +8,14 @@
#include "base/test/histogram_tester.h" #include "base/test/histogram_tester.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/ui/webui/site_settings_helper.h" #include "chrome/browser/ui/webui/site_settings_helper.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h" #include "components/content_settings/core/common/content_settings_types.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/web_ui_data_source.h" #include "content/public/browser/web_ui_data_source.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
...@@ -34,6 +38,40 @@ const char kSource[] = "source"; ...@@ -34,6 +38,40 @@ const char kSource[] = "source";
namespace settings { namespace settings {
// Helper class for setting ContentSettings via different sources.
class ContentSettingSourceSetter {
public:
ContentSettingSourceSetter(TestingProfile* profile,
ContentSettingsType content_type)
: prefs_(profile->GetTestingPrefService()),
host_content_settings_map_(
HostContentSettingsMapFactory::GetForProfile(profile)),
content_type_(content_type) {}
void SetPolicyDefault(ContentSetting setting) {
prefs_->SetManagedPref(GetPrefNameForDefaultPermissionSetting(),
base::MakeUnique<base::Value>(setting));
}
const char* GetPrefNameForDefaultPermissionSetting() {
switch (content_type_) {
case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
return prefs::kManagedDefaultNotificationsSetting;
default:
// Add support as needed.
NOTREACHED();
return "";
}
}
private:
sync_preferences::TestingPrefServiceSyncable* prefs_;
HostContentSettingsMap* host_content_settings_map_;
ContentSettingsType content_type_;
DISALLOW_COPY_AND_ASSIGN(ContentSettingSourceSetter);
};
class SiteSettingsHandlerTest : public testing::Test { class SiteSettingsHandlerTest : public testing::Test {
public: public:
SiteSettingsHandlerTest() : handler_(&profile_) { SiteSettingsHandlerTest() : handler_(&profile_) {
...@@ -50,7 +88,7 @@ class SiteSettingsHandlerTest : public testing::Test { ...@@ -50,7 +88,7 @@ class SiteSettingsHandlerTest : public testing::Test {
web_ui()->ClearTrackedCalls(); web_ui()->ClearTrackedCalls();
} }
Profile* profile() { return &profile_; } TestingProfile* profile() { return &profile_; }
content::TestWebUI* web_ui() { return &web_ui_; } content::TestWebUI* web_ui() { return &web_ui_; }
SiteSettingsHandler* handler() { return &handler_; } SiteSettingsHandler* handler() { return &handler_; }
...@@ -315,7 +353,61 @@ TEST_F(SiteSettingsHandlerTest, Origins) { ...@@ -315,7 +353,61 @@ TEST_F(SiteSettingsHandlerTest, Origins) {
handler()->HandleGetOriginPermissions(&get_origin_permissions_args); handler()->HandleGetOriginPermissions(&get_origin_permissions_args);
// "Ask" is the default value for Notifications. // "Ask" is the default value for Notifications.
ValidateOrigin(google, google, google, "ask", "preference", 6U); ValidateOrigin(google, google, google, "ask", "default", 6U);
}
TEST_F(SiteSettingsHandlerTest, DefaultSettingSource) {
const std::string google("http://www.google.com");
ContentSettingSourceSetter source_setter(profile(),
CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
base::ListValue get_origin_permissions_args;
get_origin_permissions_args.AppendString(kCallbackId);
get_origin_permissions_args.AppendString(google);
auto category_list = base::MakeUnique<base::ListValue>();
category_list->AppendString("notifications");
get_origin_permissions_args.Append(std::move(category_list));
// Test Chrome built-in defaults are marked as default.
handler()->HandleGetOriginPermissions(&get_origin_permissions_args);
ValidateOrigin(google, google, google, "ask", "default", 1U);
base::ListValue default_value_args;
default_value_args.AppendString("notifications");
default_value_args.AppendString("block");
handler()->HandleSetDefaultValueForContentType(&default_value_args);
// A user-set global default should also show up as default.
handler()->HandleGetOriginPermissions(&get_origin_permissions_args);
ValidateOrigin(google, google, google, "block", "default", 3U);
base::ListValue set_notification_pattern_args;
set_notification_pattern_args.AppendString("[*.]google.com");
set_notification_pattern_args.AppendString("*");
set_notification_pattern_args.AppendString("notifications");
set_notification_pattern_args.AppendString("allow");
set_notification_pattern_args.AppendBoolean(false);
handler()->HandleSetCategoryPermissionForOrigin(
&set_notification_pattern_args);
// A user-set pattern should not show up as default.
handler()->HandleGetOriginPermissions(&get_origin_permissions_args);
ValidateOrigin(google, google, google, "allow", "preference", 5U);
base::ListValue set_notification_origin_args;
set_notification_origin_args.AppendString(google);
set_notification_origin_args.AppendString(google);
set_notification_origin_args.AppendString("notifications");
set_notification_origin_args.AppendString("block");
set_notification_origin_args.AppendBoolean(false);
handler()->HandleSetCategoryPermissionForOrigin(
&set_notification_origin_args);
// A user-set per-origin permission should not show up as default.
handler()->HandleGetOriginPermissions(&get_origin_permissions_args);
ValidateOrigin(google, google, google, "block", "preference", 7U);
// Enterprise-policy set defaults should not show up as default.
source_setter.SetPolicyDefault(CONTENT_SETTING_ALLOW);
handler()->HandleGetOriginPermissions(&get_origin_permissions_args);
ValidateOrigin(google, google, google, "allow", "policy", 8U);
} }
TEST_F(SiteSettingsHandlerTest, ExceptionHelpers) { TEST_F(SiteSettingsHandlerTest, ExceptionHelpers) {
......
...@@ -12,22 +12,30 @@ suite('SiteDetailsPermission', function() { ...@@ -12,22 +12,30 @@ suite('SiteDetailsPermission', function() {
/** /**
* An example pref with only camera allowed. * An example pref with only camera allowed.
* @type {SiteSettingsPref}
*/ */
var prefs = { var prefs;
// Initialize a site-details-permission before each test.
setup(function() {
prefs = {
defaults: {
camera: {
setting: settings.ContentSetting.ALLOW,
}
},
exceptions: { exceptions: {
camera: [ camera: [
{ {
embeddingOrigin: '', embeddingOrigin: '',
origin: 'https://www.example.com', origin: 'https://www.example.com',
setting: 'allow', setting: settings.ContentSetting.ALLOW,
source: 'preference', source: 'preference',
}, },
] ]
} }
}; };
// Initialize a site-details-permission before each test.
setup(function() {
browserProxy = new TestSiteSettingsPrefsBrowserProxy(); browserProxy = new TestSiteSettingsPrefsBrowserProxy();
settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy;
PolymerTest.clearBody(); PolymerTest.clearBody();
...@@ -45,23 +53,30 @@ suite('SiteDetailsPermission', function() { ...@@ -45,23 +53,30 @@ suite('SiteDetailsPermission', function() {
function isAllowed(origin, exceptionList) { function isAllowed(origin, exceptionList) {
for (var i = 0; i < exceptionList.length; ++i) { for (var i = 0; i < exceptionList.length; ++i) {
if (exceptionList[i].origin == origin) if (exceptionList[i].origin == origin)
return exceptionList[i].setting == 'allow'; return exceptionList[i].setting == settings.ContentSetting.ALLOW;
} }
return false; return false;
}; };
function validatePermissionFlipWorks(origin, expectedContentSetting) { function validatePermissionFlipWorks(origin, expectedContentSetting) {
browserProxy.resetResolver('setCategoryPermissionForOrigin'); // Flipping a permission typically calls setCategoryPermissionForOrigin, but
// clearing it should call resetCategoryPermissionForOrigin.
var isReset = expectedContentSetting == settings.ContentSetting.DEFAULT;
var expectedMethodCalled = isReset ? 'resetCategoryPermissionForOrigin' :
'setCategoryPermissionForOrigin';
browserProxy.resetResolver(expectedMethodCalled);
// Simulate permission change initiated by the user. // Simulate permission change initiated by the user.
testElement.$.permission.value = expectedContentSetting; testElement.$.permission.value = expectedContentSetting;
testElement.$.permission.dispatchEvent(new CustomEvent('change')); testElement.$.permission.dispatchEvent(new CustomEvent('change'));
return browserProxy.whenCalled('setCategoryPermissionForOrigin') return browserProxy.whenCalled(expectedMethodCalled).then(function(args) {
.then(function(args) {
assertEquals(origin, args[0]); assertEquals(origin, args[0]);
assertEquals('', args[1]); assertEquals('', args[1]);
assertEquals(testElement.category, args[2]); assertEquals(testElement.category, args[2]);
// Since resetting the permission doesn't return its new value, don't
// test it here - checking that the correct method was called is fine.
if (!isReset)
assertEquals(expectedContentSetting, args[3]); assertEquals(expectedContentSetting, args[3]);
}); });
}; };
...@@ -92,6 +107,60 @@ suite('SiteDetailsPermission', function() { ...@@ -92,6 +107,60 @@ suite('SiteDetailsPermission', function() {
.then(function() { .then(function() {
return validatePermissionFlipWorks( return validatePermissionFlipWorks(
origin, settings.ContentSetting.ALLOW); origin, settings.ContentSetting.ALLOW);
})
.then(function() {
return validatePermissionFlipWorks(
origin, settings.ContentSetting.DEFAULT);
});
});
test('default string is correct', function() {
var origin = 'https://www.example.com';
browserProxy.setPrefs(prefs)
testElement.category = settings.ContentSettingsTypes.CAMERA;
testElement.label = 'Camera';
testElement.site = {
origin: origin,
embeddingOrigin: '',
setting: settings.ContentSetting.ALLOW,
};
return browserProxy.whenCalled('getDefaultValueForContentType')
.then(function() {
// The default option will always be the first in the menu.
assertEquals(
'Allow (default)', testElement.$.permission.options[0].text,
'Default setting string should match prefs');
browserProxy.resetResolver('getDefaultValueForContentType');
prefs.defaults.camera.setting = settings.ContentSetting.BLOCK;
browserProxy.setPrefs(prefs);
// Trigger a call to siteChanged_() by touching |testElement.site|.
testElement.site = {
origin: origin,
embeddingOrigin: '',
setting: settings.ContentSetting.BLOCK
};
return browserProxy.whenCalled('getDefaultValueForContentType');
})
.then(function() {
assertEquals(
'Block (default)', testElement.$.permission.options[0].text,
'Default setting string should match prefs');
browserProxy.resetResolver('getDefaultValueForContentType');
prefs.defaults.camera.setting = settings.ContentSetting.ASK;
browserProxy.setPrefs(prefs);
// Trigger a call to siteChanged_() by touching |testElement.site|.
testElement.site = {
origin: origin,
embeddingOrigin: '',
setting: settings.ContentSetting.ASK
};
return browserProxy.whenCalled('getDefaultValueForContentType');
})
.then(function() {
assertEquals(
'Ask (default)', testElement.$.permission.options[0].text,
'Default setting string should match prefs');
}); });
}); });
}); });
...@@ -11,103 +11,141 @@ suite('SiteDetails', function() { ...@@ -11,103 +11,141 @@ suite('SiteDetails', function() {
var testElement; var testElement;
/** /**
* An example pref with 1 allowed in each category. * An example pref with 1 pref in each category.
* @type {SiteSettingsPref}
*/ */
var prefs = { var prefs;
// Initialize a site-details before each test.
setup(function() {
prefs = {
defaults: {
auto_downloads: {
setting: settings.ContentSetting.ASK,
},
background_sync: {
setting: settings.ContentSetting.ALLOW,
},
camera: {
setting: settings.ContentSetting.ASK,
},
geolocation: {
setting: settings.ContentSetting.ASK,
},
images: {
setting: settings.ContentSetting.ALLOW,
},
javascript: {
setting: settings.ContentSetting.ALLOW,
},
mic: {
setting: settings.ContentSetting.ASK,
},
notifications: {
setting: settings.ContentSetting.ASK,
},
plugins: {
setting: settings.ContentSetting.ASK,
},
popups: {
setting: settings.ContentSetting.BLOCK,
},
unsandboxed_plugins: {
setting: settings.ContentSetting.ASK,
},
},
exceptions: { exceptions: {
auto_downloads: [ auto_downloads: [
{ {
embeddingOrigin: 'https://foo-allow.com:443', embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo-allow.com:443', origin: 'https://foo.com:443',
setting: 'allow', setting: settings.ContentSetting.ALLOW,
source: 'preference', source: 'preference',
}, },
], ],
background_sync: [ background_sync: [
{ {
embeddingOrigin: 'https://foo-allow.com:443', embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo-allow.com:443', origin: 'https://foo.com:443',
setting: 'allow', setting: settings.ContentSetting.ALLOW,
source: 'preference', source: 'preference',
}, },
], ],
camera: [ camera: [
{ {
embeddingOrigin: 'https://foo-allow.com:443', embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo-allow.com:443', origin: 'https://foo.com:443',
setting: 'allow', setting: settings.ContentSetting.ALLOW,
source: 'extension', source: 'preference',
}, },
], ],
geolocation: [ geolocation: [
{ {
embeddingOrigin: 'https://foo-allow.com:443', embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo-allow.com:443', origin: 'https://foo.com:443',
setting: 'block', setting: settings.ContentSetting.ALLOW,
source: 'policy', source: 'preference',
}, },
], ],
images: [ images: [
{ {
embeddingOrigin: 'https://foo-allow.com:443', embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo-allow.com:443', origin: 'https://foo.com:443',
setting: 'allow', setting: settings.ContentSetting.ALLOW,
source: 'preference', source: 'default',
}, },
], ],
javascript: [ javascript: [
{ {
embeddingOrigin: 'https://foo-allow.com:443', embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo-allow.com:443', origin: 'https://foo.com:443',
setting: 'allow', setting: settings.ContentSetting.ALLOW,
source: 'preference', source: 'preference',
}, },
], ],
mic: [ mic: [
{ {
embeddingOrigin: 'https://foo-allow.com:443', embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo-allow.com:443', origin: 'https://foo.com:443',
setting: 'allow', setting: settings.ContentSetting.ALLOW,
source: 'preference', source: 'preference',
}, },
], ],
notifications: [ notifications: [
{ {
embeddingOrigin: 'https://foo-allow.com:443', embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo-allow.com:443', origin: 'https://foo.com:443',
setting: 'allow', setting: settings.ContentSetting.BLOCK,
source: 'preference', source: 'policy',
}, },
], ],
plugins: [ plugins: [
{ {
embeddingOrigin: 'https://foo-allow.com:443', embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo-allow.com:443', origin: 'https://foo.com:443',
setting: 'allow', setting: settings.ContentSetting.ALLOW,
source: 'preference', source: 'extension',
}, },
], ],
popups: [ popups: [
{ {
embeddingOrigin: 'https://foo-allow.com:443', embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo-allow.com:443', origin: 'https://foo.com:443',
setting: 'allow', setting: settings.ContentSetting.BLOCK,
source: 'preference', source: 'default',
}, },
], ],
unsandboxed_plugins: [ unsandboxed_plugins: [
{ {
embeddingOrigin: 'https://foo-allow.com:443', embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo-allow.com:443', origin: 'https://foo.com:443',
setting: 'allow', setting: settings.ContentSetting.ALLOW,
source: 'preference', source: 'preference',
}, },
], ],
} }
}; };
// Initialize a site-details before each test.
setup(function() {
browserProxy = new TestSiteSettingsPrefsBrowserProxy(); browserProxy = new TestSiteSettingsPrefsBrowserProxy();
settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy; settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy;
PolymerTest.clearBody(); PolymerTest.clearBody();
...@@ -133,7 +171,7 @@ suite('SiteDetails', function() { ...@@ -133,7 +171,7 @@ suite('SiteDetails', function() {
Polymer.dom(parent).appendChild(api); Polymer.dom(parent).appendChild(api);
browserProxy.setPrefs(prefs); browserProxy.setPrefs(prefs);
testElement.origin = 'https://foo-allow.com:443'; testElement.origin = 'https://foo.com:443';
Polymer.dom.flush(); Polymer.dom.flush();
...@@ -143,17 +181,40 @@ suite('SiteDetails', function() { ...@@ -143,17 +181,40 @@ suite('SiteDetails', function() {
test('correct pref settings are shown', function() { test('correct pref settings are shown', function() {
browserProxy.setPrefs(prefs); browserProxy.setPrefs(prefs);
testElement.origin = 'https://foo-allow.com:443'; testElement.origin = 'https://foo.com:443';
return browserProxy.whenCalled('getOriginPermissions').then(function() { return browserProxy.whenCalled('getOriginPermissions').then(function() {
testElement.root.querySelectorAll('site-details-permission') testElement.root.querySelectorAll('site-details-permission')
.forEach(function(siteDetailsPermission) { .forEach(function(siteDetailsPermission) {
// Verify settings match the values specified in |prefs|. // Verify settings match the values specified in |prefs|.
var setting = 'allow'; var expectedSetting = settings.ContentSetting.ALLOW;
if (siteDetailsPermission.site.category == 'location') var expectedSource = 'preference';
setting = 'block'; var expectedMenuValue = settings.ContentSetting.ALLOW;
assertEquals(setting, siteDetailsPermission.site.setting);
assertEquals(setting, siteDetailsPermission.$.permission.value); // For all the categories with non-user-set 'Allow' preferences,
// update expected values.
if (siteDetailsPermission.category ==
settings.ContentSettingsTypes.NOTIFICATIONS ||
siteDetailsPermission.category ==
settings.ContentSettingsTypes.PLUGINS ||
siteDetailsPermission.category ==
settings.ContentSettingsTypes.JAVASCRIPT ||
siteDetailsPermission.category ==
settings.ContentSettingsTypes.IMAGES ||
siteDetailsPermission.category ==
settings.ContentSettingsTypes.POPUPS) {
expectedSetting =
prefs.exceptions[siteDetailsPermission.category][0].setting;
expectedSource =
prefs.exceptions[siteDetailsPermission.category][0].source;
expectedMenuValue = (expectedSource == 'default') ?
settings.ContentSetting.DEFAULT :
expectedSetting;
}
assertEquals(expectedSetting, siteDetailsPermission.site.setting);
assertEquals(expectedSource, siteDetailsPermission.site.source);
assertEquals(
expectedMenuValue, siteDetailsPermission.$.permission.value);
}); });
}); });
}); });
......
...@@ -546,7 +546,7 @@ suite('SiteList', function() { ...@@ -546,7 +546,7 @@ suite('SiteList', function() {
assertEquals( assertEquals(
kControlledByLookup[prefsMixedProvider.exceptions.geolocation[i] kControlledByLookup[prefsMixedProvider.exceptions.geolocation[i]
.source] || .source] ||
'', chrome.settingsPrivate.ControlledBy.PRIMARY_USER,
testElement.sites[i].controlledBy); testElement.sites[i].controlledBy);
} }
}); });
......
...@@ -3,53 +3,35 @@ ...@@ -3,53 +3,35 @@
// found in the LICENSE file. // found in the LICENSE file.
/** /**
* In the real (non-test) code, this data comes from the C++ handler.
* Only used for tests. * Only used for tests.
* @typedef {{ * @typedef {{defaults: Map<string, !DefaultContentSetting>,
* auto_downloads: !Array<!RawSiteException>}, * exceptions: !Map<string, !Array<!RawSiteException>>}}
* background_sync: !Array<!RawSiteException>},
* camera: !Array<!RawSiteException>},
* cookies: !Array<!RawSiteException>},
* geolocation: !Array<!RawSiteException>},
* javascript: !Array<!RawSiteException>},
* mic: !Array<!RawSiteException>},
* midiDevices: !Array<!RawSiteException>},
* notifications: !Array<!RawSiteException>},
* plugins: !Array<!RawSiteException>},
* images: !Array<!RawSiteException>},
* popups: !Array<!RawSiteException>},
* unsandboxed_plugins: !Array<!RawSiteException>},
* }}
*/
var ExceptionListPref;
/**
* In the real (non-test) code, these data come from the C++ handler.
* Only used for tests.
* @typedef {{defaults: CategoryDefaultsPref,
* exceptions: ExceptionListPref}}
*/ */
var SiteSettingsPref; var SiteSettingsPref;
/** /**
* An example empty pref. * An example empty pref.
* TODO(patricialor): Use the values from settings.ContentSettingsTypes (see
* site_settings/constants.js) as the keys for these instead.
* @type {SiteSettingsPref} * @type {SiteSettingsPref}
*/ */
var prefsEmpty = { var prefsEmpty = {
defaults: { defaults: {
ads: '', ads: {},
auto_downloads: '', auto_downloads: {},
background_sync: '', background_sync: {},
camera: '', camera: {},
cookies: '', cookies: {},
geolocation: '', geolocation: {},
javascript: '', javascript: {},
mic: '', mic: {},
midiDevices: '', midiDevices: {},
notifications: '', notifications: {},
plugins: '', plugins: {},
images: '', images: {},
popups: '', popups: {},
unsandboxed_plugins: '', unsandboxed_plugins: {},
}, },
exceptions: { exceptions: {
ads: [], ads: [],
...@@ -203,10 +185,11 @@ TestSiteSettingsPrefsBrowserProxy.prototype = { ...@@ -203,10 +185,11 @@ TestSiteSettingsPrefsBrowserProxy.prototype = {
var pref = undefined; var pref = undefined;
if (contentType == settings.ContentSettingsTypes.ADS) { if (contentType == settings.ContentSettingsTypes.ADS) {
pref = this.prefs_.defaults.ads; pref = this.prefs_.defaults.ads;
} else if (contentType == settings.ContentSettingsTypes.AUTOMATIC_DOWNLOADS) { } else if (
contentType == settings.ContentSettingsTypes.AUTOMATIC_DOWNLOADS) {
pref = this.prefs_.defaults.auto_downloads; pref = this.prefs_.defaults.auto_downloads;
} else if (contentType == settings.ContentSettingsTypes.BACKGROUND_SYNC) { } else if (contentType == settings.ContentSettingsTypes.BACKGROUND_SYNC) {
pref = this.prefs_.background_sync; pref = this.prefs_.defaults.background_sync;
} else if (contentType == settings.ContentSettingsTypes.CAMERA) { } else if (contentType == settings.ContentSettingsTypes.CAMERA) {
pref = this.prefs_.defaults.camera; pref = this.prefs_.defaults.camera;
} else if (contentType == settings.ContentSettingsTypes.COOKIES) { } else if (contentType == settings.ContentSettingsTypes.COOKIES) {
...@@ -336,10 +319,12 @@ TestSiteSettingsPrefsBrowserProxy.prototype = { ...@@ -336,10 +319,12 @@ TestSiteSettingsPrefsBrowserProxy.prototype = {
contentType = 'unsandboxed_plugins'; contentType = 'unsandboxed_plugins';
} }
var setting = undefined; var setting;
var source;
this.prefs_.exceptions[contentType].some(function(originPrefs) { this.prefs_.exceptions[contentType].some(function(originPrefs) {
if (originPrefs.origin == origin) { if (originPrefs.origin == origin) {
setting = originPrefs.setting; setting = originPrefs.setting;
source = originPrefs.source;
return true; return true;
} }
}); });
...@@ -354,7 +339,7 @@ TestSiteSettingsPrefsBrowserProxy.prototype = { ...@@ -354,7 +339,7 @@ TestSiteSettingsPrefsBrowserProxy.prototype = {
origin: origin, origin: origin,
displayName: '', displayName: '',
setting: setting, setting: setting,
source: undefined source: source,
}) })
}, this); }, this);
return Promise.resolve(exceptionList); return Promise.resolve(exceptionList);
......
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