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

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

Issue 986333006: Center permission bubble if location bar is hidden in MacOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Apply Feedback Created 5 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_cocoa_browsertest.mm
diff --git a/chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa_browsertest.mm b/chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa_browsertest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..c14b1f416c1db8e928877f686ade77e0434fa532
--- /dev/null
+++ b/chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa_browsertest.mm
@@ -0,0 +1,114 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_window.h"
+#import "chrome/browser/ui/cocoa/browser_window_controller.h"
+#include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
+#import "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h"
+#include "chrome/browser/ui/test/permission_bubble_browser_test_util.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#import "ui/base/cocoa/fullscreen_window_manager.h"
+
+namespace {
+// To be used when getting the anchor with a location bar. The bubble should be
+// in the top-right corner.
+const int kAnchorTop = 61;
groby-ooo-7-16 2015/04/10 20:58:55 Hrm. It works, but is fragile. Can you compute thi
hcarmona 2015/04/10 22:28:05 The size of the bubble doesn't affect the anchor.
groby-ooo-7-16 2015/04/10 23:00:33 OIC - Can we just test against location_bar_bridge
hcarmona 2015/04/13 19:11:58 Done.
+const int kAnchorLeft = 105;
+const int kTolerance = 5;
+
+class MockPermissionBubbleCocoa : public PermissionBubbleCocoa {
+ public:
+ MockPermissionBubbleCocoa(NSWindow* parent_window)
+ : PermissionBubbleCocoa(parent_window) {}
+
+ MOCK_METHOD0(HasLocationBar, bool());
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockPermissionBubbleCocoa);
+};
+}
+
+IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowsertest, HasLocationBarByDefault) {
+ PermissionBubbleCocoa bubble(browser()->window()->GetNativeWindow());
+ bubble.SetDelegate(test_delegate());
+ bubble.Show(requests(), accept_states());
+ EXPECT_TRUE(bubble.HasLocationBar());
+}
+
+IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowsertest, FullscreenHasLocationBar) {
+ PermissionBubbleCocoa bubble(browser()->window()->GetNativeWindow());
+ bubble.SetDelegate(test_delegate());
+ bubble.Show(requests(), accept_states());
+
+ NSWindow* window = browser()->window()->GetNativeWindow();
+ base::scoped_nsobject<FullscreenWindowManager> manager(
+ [[FullscreenWindowManager alloc] initWithWindow:window
+ desiredScreen:[NSScreen mainScreen]]);
+ EXPECT_TRUE(bubble.HasLocationBar());
+ [manager enterFullscreenMode];
+ EXPECT_TRUE(bubble.HasLocationBar());
+ [manager exitFullscreenMode];
+ EXPECT_TRUE(bubble.HasLocationBar());
+}
+
+IN_PROC_BROWSER_TEST_F(PermissionBubbleAppBrowsertest, AppHasNoLocationBar) {
+ PermissionBubbleCocoa bubble(app_browser()->window()->GetNativeWindow());
+ bubble.SetDelegate(test_delegate());
+ bubble.Show(requests(), accept_states());
+ EXPECT_FALSE(bubble.HasLocationBar());
+}
+
+// http://crbug.com/470724
+// Kiosk mode on Mac has a location bar but it shouldn't.
+IN_PROC_BROWSER_TEST_F(PermissionBubbleKioskBrowsertest,
+ DISABLED_KioskHasNoLocationBar) {
+ PermissionBubbleCocoa bubble(browser()->window()->GetNativeWindow());
+ bubble.SetDelegate(test_delegate());
+ bubble.Show(requests(), accept_states());
+ EXPECT_FALSE(bubble.HasLocationBar());
+}
+
+IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowsertest,
+ AnchorPositionWithLocationBar) {
+ testing::NiceMock<MockPermissionBubbleCocoa> bubble(
+ browser()->window()->GetNativeWindow());
+ bubble.SetDelegate(test_delegate());
+ bubble.Show(requests(), accept_states());
+ ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(true));
+
+ NSPoint anchor = bubble.GetAnchorPoint();
+ NSWindow* window = browser()->window()->GetNativeWindow();
+ NSRect frame = [window frame];
+
+ // Expected anchor location will be top left when there's a location bar.
+ NSPoint expected =
+ NSMakePoint(NSMinX(frame) + kAnchorLeft, NSMaxY(frame) - kAnchorTop);
+
+ // Anchor should be close to the left of the screen.
+ ASSERT_NEAR(expected.x, anchor.x, kTolerance);
+
+ // Anchor should be close to the top of the screen.
+ ASSERT_NEAR(expected.y, anchor.y, kTolerance);
+}
+
+IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowsertest,
+ AnchorPositionWithoutLocationBar) {
+ testing::NiceMock<MockPermissionBubbleCocoa> bubble(
+ browser()->window()->GetNativeWindow());
+ bubble.SetDelegate(test_delegate());
+ bubble.Show(requests(), accept_states());
+ ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(false));
+
+ NSPoint anchor = bubble.GetAnchorPoint();
+ NSWindow* window = browser()->window()->GetNativeWindow();
+ NSRect frame = [window frame];
+
+ // Expected anchor location will be top center when there's no location bar.
+ NSPoint expected = NSMakePoint(frame.size.width / 2, frame.size.height);
+ expected = [window convertBaseToScreen:expected];
+
+ // Anchor should be centered.
+ EXPECT_TRUE(NSEqualPoints(expected, anchor));
+}

Powered by Google App Engine
This is Rietveld 408576698