Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Unified Diff: chrome/browser/ui/cocoa/page_info/page_info_bubble_controller_unittest.mm

Issue 2743423004: Permissions: Show the reason for permission decisions made on the user's behalf. (Closed)
Patch Set: Review comments. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/page_info/page_info_bubble_controller_unittest.mm
diff --git a/chrome/browser/ui/cocoa/page_info/page_info_bubble_controller_unittest.mm b/chrome/browser/ui/cocoa/page_info/page_info_bubble_controller_unittest.mm
index d3d804d31aed715dbdb9401ff8e678d7c42a99f0..4c545aac72d0d3560793742af4fc1429de015b6a 100644
--- a/chrome/browser/ui/cocoa/page_info/page_info_bubble_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/page_info/page_info_bubble_controller_unittest.mm
@@ -60,24 +60,29 @@ enum PermissionMenuIndices {
};
const ContentSettingsType kTestPermissionTypes[] = {
- CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTINGS_TYPE_JAVASCRIPT,
- CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTINGS_TYPE_POPUPS,
- CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
+ CONTENT_SETTINGS_TYPE_IMAGES,
+ CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
+ CONTENT_SETTINGS_TYPE_JAVASCRIPT,
+ CONTENT_SETTINGS_TYPE_PLUGINS,
+ CONTENT_SETTINGS_TYPE_POPUPS,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION,
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC};
const ContentSetting kTestSettings[] = {
- CONTENT_SETTING_DEFAULT, CONTENT_SETTING_DEFAULT, CONTENT_SETTING_ALLOW,
- CONTENT_SETTING_BLOCK, CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK,
- CONTENT_SETTING_BLOCK};
+ CONTENT_SETTING_DEFAULT, CONTENT_SETTING_DEFAULT, CONTENT_SETTING_DEFAULT,
+ CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK, CONTENT_SETTING_ALLOW,
+ CONTENT_SETTING_BLOCK, CONTENT_SETTING_BLOCK};
-const ContentSetting kTestDefaultSettings[] = {CONTENT_SETTING_BLOCK,
- CONTENT_SETTING_ASK};
+const ContentSetting kTestDefaultSettings[] = {
+ CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK, CONTENT_SETTING_ASK};
const content_settings::SettingSource kTestSettingSources[] = {
content_settings::SETTING_SOURCE_USER,
content_settings::SETTING_SOURCE_USER,
content_settings::SETTING_SOURCE_USER,
content_settings::SETTING_SOURCE_USER,
+ content_settings::SETTING_SOURCE_USER,
content_settings::SETTING_SOURCE_POLICY,
content_settings::SETTING_SOURCE_POLICY,
content_settings::SETTING_SOURCE_EXTENSION};
@@ -159,7 +164,7 @@ class PageInfoBubbleControllerTest : public CocoaTest {
// Create a list of 5 different permissions, corresponding to all the
// possible settings:
// - [allow, block, ask] by default
- // - [block, allow] * [by user, by policy, by extension]
+ // - [block, allow] * by user
PermissionInfoList permission_info_list;
PageInfoUI::PermissionInfo info;
for (size_t i = 0; i < arraysize(kTestPermissionTypes); ++i) {
@@ -176,6 +181,16 @@ class PageInfoBubbleControllerTest : public CocoaTest {
std::move(chosen_object_info_list));
}
+ int NumSettingsNotSetByUser() const {
+ int num_non_user_settings = 0;
+ for (size_t i = 0; i < arraysize(kTestSettingSources); ++i) {
+ num_non_user_settings +=
+ (kTestSettingSources[i] != content_settings::SETTING_SOURCE_USER) ? 1
+ : 0;
+ }
+ return num_non_user_settings;
+ }
+
content::TestBrowserThreadBundle thread_bundle_;
TestingProfile profile_;
content::TestWebContentsFactory web_contents_factory_;
@@ -233,34 +248,37 @@ TEST_F(PageInfoBubbleControllerTest, SetPermissionInfo) {
// There should be three subviews per permission.
NSArray* subviews = [[controller_ permissionsView] subviews];
- EXPECT_EQ(arraysize(kTestPermissionTypes) * 3, [subviews count]);
+ EXPECT_EQ(arraysize(kTestPermissionTypes) * 3,
+ [subviews count] - NumSettingsNotSetByUser());
- // Ensure that there is a distinct label for each permission.
- NSMutableSet* labels = [NSMutableSet set];
+ // Ensure that there is a label for each permission.
+ NSMutableArray* permission_labels = [NSMutableArray array];
for (NSView* view in subviews) {
if ([view isKindOfClass:[NSTextField class]])
- [labels addObject:[static_cast<NSTextField*>(view) stringValue]];
+ [permission_labels
+ addObject:[static_cast<NSTextField*>(view) stringValue]];
}
- EXPECT_EQ(arraysize(kTestPermissionTypes), [labels count]);
+ EXPECT_EQ(arraysize(kTestPermissionTypes),
+ [permission_labels count] - NumSettingsNotSetByUser());
// Ensure that the button labels are distinct, and look for the correct
// number of disabled buttons.
int disabled_count = 0;
- [labels removeAllObjects];
+ NSMutableSet* button_labels = [NSMutableSet set];
for (NSView* view in subviews) {
if ([view isKindOfClass:[NSPopUpButton class]]) {
NSPopUpButton* button = static_cast<NSPopUpButton*>(view);
- [labels addObject:[[button selectedCell] title]];
+ [button_labels addObject:[[button selectedCell] title]];
if (![button isEnabled])
++disabled_count;
}
}
- EXPECT_EQ(arraysize(kTestPermissionTypes), [labels count]);
+ EXPECT_EQ(5UL, [button_labels count]);
- // 3 of the buttons should be disabled -- the ones that have a setting source
- // of SETTING_SOURCE_POLICY or SETTING_SOURCE_EXTENSION.
- EXPECT_EQ(3, disabled_count);
+ // Permissions with a setting source of SETTING_SOURCE_POLICY or
+ // SETTING_SOURCE_EXTENSION should have their buttons disabled.
+ EXPECT_EQ(NumSettingsNotSetByUser(), disabled_count);
}
TEST_F(PageInfoBubbleControllerTest, WindowWidth) {
« no previous file with comments | « chrome/browser/ui/cocoa/page_info/page_info_bubble_controller.mm ('k') | chrome/browser/ui/page_info/page_info_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698