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

Unified Diff: chrome/browser/ui/cocoa/website_settings/permission_bubble_controller_unittest.mm

Issue 242443005: Changes cocoa implementation of permission bubble to better match mocks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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/website_settings/permission_bubble_controller_unittest.mm
diff --git a/chrome/browser/ui/cocoa/website_settings/permission_bubble_controller_unittest.mm b/chrome/browser/ui/cocoa/website_settings/permission_bubble_controller_unittest.mm
index 1a7a93c4f2e30c4ceae606b3145d7a6d736478d1..90639b4e294a7796d2f6cf316d9a0d7223dec61b 100644
--- a/chrome/browser/ui/cocoa/website_settings/permission_bubble_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/website_settings/permission_bubble_controller_unittest.mm
@@ -73,19 +73,29 @@ class PermissionBubbleControllerTest : public CocoaTest,
}
NSButton* FindButtonWithTitle(const std::string& title) {
- return FindButtonWithTitle(base::SysUTF8ToNSString(title));
+ return FindButtonWithTitle(base::SysUTF8ToNSString(title), false);
}
NSButton* FindButtonWithTitle(int title_id) {
- return FindButtonWithTitle(l10n_util::GetNSString(title_id));
+ return FindButtonWithTitle(l10n_util::GetNSString(title_id), false);
}
- NSButton* FindButtonWithTitle(NSString* title) {
+ NSButton* FindMenuButtonWithTitle(int title_id) {
+ return FindButtonWithTitle(l10n_util::GetNSString(title_id), true);
+ }
+
+ // IDS_PERMISSION_ALLOW and IDS_PERMISSION_DENY are used for two distinct
+ // UI elements, both of which derive from NSButton. In order to test for
+ // each kind of element, check the derived class of one - NSPopUpButton -
+ // to distinguish between the two.
+ NSButton* FindButtonWithTitle(NSString* title, bool want_nspopup) {
NSView* parent = base::mac::ObjCCastStrict<NSView>([controller_ bubble]);
groby-ooo-7-16 2014/04/18 18:18:18 No need to cast - the bubble is always an NSView
leng 2014/04/18 22:48:46 Made NSButton to avoid a cast.
for (NSView* child in [parent subviews]) {
NSButton* button = base::mac::ObjCCast<NSButton>(child);
groby-ooo-7-16 2014/04/18 18:18:18 Shorter & less casts: Class button_class = want_n
leng 2014/04/18 22:48:46 I like it. I need to use ConstrainedWindowButton
if ([title isEqualToString:[button title]]) {
- return button;
+ NSPopUpButton* popup = base::mac::ObjCCast<NSPopUpButton>(button);
+ if ((!want_nspopup && !popup) || (want_nspopup && popup))
+ return button;
}
}
return nil;
@@ -109,6 +119,15 @@ class PermissionBubbleControllerTest : public CocoaTest,
return textField;
}
+ void ChangePermissionMenuSelection(NSButton* menu_button, int next_title_id) {
+ NSMenu* menu = [base::mac::ObjCCast<NSPopUpButton>(menu_button) menu];
groby-ooo-7-16 2014/04/18 18:18:18 I think you want strict here, or even pass in an N
leng 2014/04/18 22:48:46 Done.
+ NSString* next_title = l10n_util::GetNSString(next_title_id);
+ EXPECT_EQ([[menu itemWithTitle:[menu_button title]] state], NSOnState);
+ NSMenuItem* next_item = [menu itemWithTitle:next_title];
+ EXPECT_EQ([next_item state], NSOffState);
+ [menu performActionForItemAtIndex:[menu indexOfItem:next_item]];
+ }
+
NSMenuItem* FindCustomizeMenuItem() {
NSButton* button = FindButtonWithTitle(IDS_PERMISSION_DENY);
if (!button || ![button isKindOfClass:[SplitBlockButton class]])
@@ -170,25 +189,35 @@ TEST_F(PermissionBubbleControllerTest, ShowMultiplePermissions) {
EXPECT_FALSE(FindButtonWithTitle(IDS_OK));
}
-TEST_F(PermissionBubbleControllerTest, ShowCustomizationMode) {
- AddRequest(kPermissionB);
-
+TEST_F(PermissionBubbleControllerTest, ShowCustomizationModeAllow) {
accept_states_.push_back(true);
- accept_states_.push_back(false);
+ [controller_ showAtAnchor:NSZeroPoint
+ withDelegate:this
+ forRequests:requests_
+ acceptStates:accept_states_
+ customizationMode:YES];
+
+ // Test that there is one menu, with 'Allow' visible.
+ EXPECT_TRUE(FindMenuButtonWithTitle(IDS_PERMISSION_ALLOW));
+ EXPECT_FALSE(FindMenuButtonWithTitle(IDS_PERMISSION_DENY));
+
+ EXPECT_TRUE(FindButtonWithTitle(IDS_OK));
+ EXPECT_FALSE(FindButtonWithTitle(IDS_PERMISSION_ALLOW));
+ EXPECT_FALSE(FindButtonWithTitle(IDS_PERMISSION_DENY));
+ EXPECT_FALSE(FindCustomizeMenuItem());
+}
+TEST_F(PermissionBubbleControllerTest, ShowCustomizationModeBlock) {
+ accept_states_.push_back(false);
[controller_ showAtAnchor:NSZeroPoint
withDelegate:this
forRequests:requests_
acceptStates:accept_states_
customizationMode:YES];
- // Test that each checkbox is visible and only the first is checked.
- NSButton* checkbox_a = FindButtonWithTitle(kPermissionA);
- NSButton* checkbox_b = FindButtonWithTitle(kPermissionB);
- EXPECT_TRUE(checkbox_a);
- EXPECT_TRUE(checkbox_b);
- EXPECT_EQ(NSOnState, [checkbox_a state]);
- EXPECT_EQ(NSOffState, [checkbox_b state]);
+ // Test that there is one menu, with 'Block' visible.
+ EXPECT_TRUE(FindMenuButtonWithTitle(IDS_PERMISSION_DENY));
+ EXPECT_FALSE(FindMenuButtonWithTitle(IDS_PERMISSION_ALLOW));
EXPECT_TRUE(FindButtonWithTitle(IDS_OK));
EXPECT_FALSE(FindButtonWithTitle(IDS_PERMISSION_ALLOW));
@@ -230,7 +259,7 @@ TEST_F(PermissionBubbleControllerTest, Deny) {
[FindButtonWithTitle(IDS_PERMISSION_DENY) performClick:nil];
}
-TEST_F(PermissionBubbleControllerTest, ToggleCheckbox) {
+TEST_F(PermissionBubbleControllerTest, ChangePermissionSelection) {
AddRequest(kPermissionB);
accept_states_.push_back(true);
@@ -244,8 +273,10 @@ TEST_F(PermissionBubbleControllerTest, ToggleCheckbox) {
EXPECT_CALL(*this, ToggleAccept(0, false)).Times(1);
EXPECT_CALL(*this, ToggleAccept(1, true)).Times(1);
- [FindButtonWithTitle(kPermissionA) performClick:nil];
- [FindButtonWithTitle(kPermissionB) performClick:nil];
+ NSButton* menu_a = FindMenuButtonWithTitle(IDS_PERMISSION_ALLOW);
+ NSButton* menu_b = FindMenuButtonWithTitle(IDS_PERMISSION_DENY);
+ ChangePermissionMenuSelection(menu_a, IDS_PERMISSION_DENY);
+ ChangePermissionMenuSelection(menu_b, IDS_PERMISSION_ALLOW);
}
TEST_F(PermissionBubbleControllerTest, ClickCustomize) {

Powered by Google App Engine
This is Rietveld 408576698