Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/browser.h" | |
| 6 #include "chrome/browser/ui/browser_window.h" | |
| 7 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | |
| 8 #import "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h" | |
| 9 #include "chrome/browser/ui/test/permission_bubble_browsertest.h" | |
| 10 #include "testing/gmock/include/gmock/gmock.h" | |
| 11 #import "ui/base/cocoa/fullscreen_window_manager.h" | |
| 12 | |
|
groby-ooo-7-16
2015/04/08 18:39:15
Put all this (constants, test helper classes, stat
hcarmona
2015/04/10 18:54:07
Done.
| |
| 13 // To be used when getting the anchor with a location bar. The bubble should be | |
| 14 // in the top-right corner. | |
| 15 const int kTolerance = 50; | |
|
groby-ooo-7-16
2015/04/08 18:39:15
Still a huge tolerance. Why so big?
hcarmona
2015/04/10 18:54:07
I've changed my expected value to be exactly the a
| |
| 16 | |
| 17 class TestPermissionBubbleCocoa : public PermissionBubbleCocoa { | |
| 18 public: | |
| 19 TestPermissionBubbleCocoa(NSWindow* parent_window) | |
| 20 : PermissionBubbleCocoa(parent_window) {} | |
| 21 | |
| 22 // Returns the base class value for testing |HasLocationBar|. | |
| 23 bool HasLocationBar() override { | |
|
groby-ooo-7-16
2015/04/08 18:39:15
You could just friend the test, saving you a lot o
hcarmona
2015/04/10 18:54:07
Friended.
| |
| 24 return PermissionBubbleCocoa::HasLocationBar(); | |
| 25 } | |
| 26 | |
| 27 private: | |
| 28 DISALLOW_COPY_AND_ASSIGN(TestPermissionBubbleCocoa); | |
| 29 }; | |
| 30 | |
| 31 class MockPermissionBubbleCocoa : public PermissionBubbleCocoa { | |
| 32 public: | |
| 33 MockPermissionBubbleCocoa(NSWindow* parent_window) | |
| 34 : PermissionBubbleCocoa(parent_window) {} | |
| 35 | |
| 36 MOCK_METHOD0(HasLocationBar, bool()); | |
| 37 | |
| 38 private: | |
| 39 DISALLOW_COPY_AND_ASSIGN(MockPermissionBubbleCocoa); | |
| 40 }; | |
| 41 | |
| 42 static void CloseController(Browser* browser) { | |
|
groby-ooo-7-16
2015/04/08 18:39:15
No need to be static in anon namespace.
hcarmona
2015/04/10 18:54:07
Done.
| |
| 43 browser->tab_strip_model()->CloseSelectedTabs(); | |
| 44 | |
| 45 NSWindow* native_window = browser->window()->GetNativeWindow(); | |
| 46 BrowserWindowController* controller = | |
| 47 [BrowserWindowController browserWindowControllerForWindow:native_window]; | |
| 48 | |
| 49 [controller close]; | |
| 50 } | |
| 51 | |
| 52 // Default Window Test ///////////////////////////////////////////////////////// | |
|
groby-ooo-7-16
2015/04/08 18:39:15
I'd get rid of these separators - the test names s
hcarmona
2015/04/10 18:54:07
Done.
| |
| 53 | |
| 54 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowsertest, HasLocationBarByDefault) { | |
| 55 TestPermissionBubbleCocoa bubble(browser()->window()->GetNativeWindow()); | |
| 56 bubble.SetDelegate(test_delegate()); | |
| 57 bubble.Show(requests(), accept_states()); | |
| 58 EXPECT_TRUE(bubble.HasLocationBar()); | |
| 59 CloseController(browser()); | |
|
groby-ooo-7-16
2015/04/08 18:39:15
Why do we need this at all? Shouldn't browser test
hcarmona
2015/04/10 18:54:07
I remember having issues without it, but everythin
| |
| 60 } | |
| 61 | |
| 62 // Fullscreen Test ///////////////////////////////////////////////////////////// | |
| 63 | |
| 64 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowsertest, FullscreenHasLocationBar) { | |
| 65 TestPermissionBubbleCocoa bubble(browser()->window()->GetNativeWindow()); | |
| 66 bubble.SetDelegate(test_delegate()); | |
| 67 bubble.Show(requests(), accept_states()); | |
| 68 | |
| 69 NSWindow* window = browser()->window()->GetNativeWindow(); | |
| 70 base::scoped_nsobject<FullscreenWindowManager> manager( | |
| 71 [[FullscreenWindowManager alloc] initWithWindow:window | |
| 72 desiredScreen:[NSScreen mainScreen]]); | |
| 73 EXPECT_TRUE(bubble.HasLocationBar()); | |
| 74 [manager enterFullscreenMode]; | |
| 75 EXPECT_TRUE(bubble.HasLocationBar()); | |
| 76 [manager exitFullscreenMode]; | |
| 77 EXPECT_TRUE(bubble.HasLocationBar()); | |
| 78 CloseController(browser()); | |
| 79 } | |
| 80 | |
| 81 // App Test //////////////////////////////////////////////////////////////////// | |
| 82 | |
| 83 IN_PROC_BROWSER_TEST_F(PermissionBubbleAppBrowsertest, AppHasNoLocationBar) { | |
| 84 TestPermissionBubbleCocoa bubble(app_browser()->window()->GetNativeWindow()); | |
| 85 bubble.SetDelegate(test_delegate()); | |
| 86 bubble.Show(requests(), accept_states()); | |
| 87 EXPECT_FALSE(bubble.HasLocationBar()); | |
| 88 CloseController(app_browser()); | |
| 89 } | |
| 90 | |
| 91 // Kiosk Test ////////////////////////////////////////////////////////////////// | |
| 92 | |
| 93 // http://crbug.com/470724 | |
| 94 // Kiosk mode on Mac has a location bar but it shouldn't. | |
| 95 IN_PROC_BROWSER_TEST_F(PermissionBubbleKioskBrowsertest, | |
| 96 DISABLED_KioskHasNoLocationBar) { | |
| 97 TestPermissionBubbleCocoa bubble(browser()->window()->GetNativeWindow()); | |
| 98 bubble.SetDelegate(test_delegate()); | |
| 99 bubble.Show(requests(), accept_states()); | |
| 100 EXPECT_FALSE(bubble.HasLocationBar()); | |
| 101 CloseController(browser()); | |
| 102 } | |
| 103 | |
| 104 // Anchor Position Tests /////////////////////////////////////////////////////// | |
| 105 | |
| 106 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowsertest, | |
| 107 AnchorPositionWithLocationBar) { | |
| 108 testing::NiceMock<MockPermissionBubbleCocoa> bubble( | |
| 109 browser()->window()->GetNativeWindow()); | |
| 110 bubble.SetDelegate(test_delegate()); | |
| 111 bubble.Show(requests(), accept_states()); | |
| 112 ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(true)); | |
| 113 | |
| 114 NSPoint anchor = bubble.GetAnchorPoint(); | |
| 115 NSWindow* window = browser()->window()->GetNativeWindow(); | |
| 116 NSRect frame = [window frame]; | |
| 117 | |
| 118 // Expected anchor location will be top left when there's a location bar. | |
| 119 NSPoint expected = NSMakePoint(NSMinX(frame) + 100, NSMaxY(frame) - 25); | |
| 120 | |
| 121 // Anchor should be close to the left of the screen. | |
| 122 ASSERT_NEAR(expected.x, anchor.x, kTolerance); | |
| 123 | |
| 124 // Anchor should be close to the top of the screen. | |
| 125 ASSERT_NEAR(expected.y, anchor.y, kTolerance); | |
| 126 CloseController(browser()); | |
| 127 } | |
| 128 | |
| 129 IN_PROC_BROWSER_TEST_F(PermissionBubbleBrowsertest, | |
| 130 AnchorPositionWithoutLocationBar) { | |
| 131 testing::NiceMock<MockPermissionBubbleCocoa> bubble( | |
| 132 browser()->window()->GetNativeWindow()); | |
| 133 bubble.SetDelegate(test_delegate()); | |
| 134 bubble.Show(requests(), accept_states()); | |
| 135 ON_CALL(bubble, HasLocationBar()).WillByDefault(testing::Return(false)); | |
| 136 | |
| 137 NSPoint anchor = bubble.GetAnchorPoint(); | |
| 138 NSWindow* window = browser()->window()->GetNativeWindow(); | |
| 139 NSRect frame = [window frame]; | |
| 140 | |
| 141 // Expected anchor location will be top center when there's no location bar. | |
| 142 NSPoint expected = NSMakePoint(frame.size.width / 2, frame.size.height); | |
| 143 expected = [window convertBaseToScreen:expected]; | |
| 144 | |
| 145 // Anchor should be centered. | |
| 146 EXPECT_TRUE(NSEqualPoints(expected, anchor)); | |
| 147 CloseController(browser()); | |
| 148 } | |
| OLD | NEW |