1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
|
// 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 "base/macros.h"
#include "chrome/browser/ui/browser_window.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/extensions/browser_action_button.h"
#import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h"
#import "chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_mac.h"
#import "chrome/browser/ui/cocoa/test/run_loop_testing.h"
#import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
#include "chrome/browser/ui/extensions/extension_message_bubble_browsertest.h"
#include "ui/base/cocoa/cocoa_base_utils.h"
#include "ui/events/test/cocoa_test_event_utils.h"
namespace {
// Returns the ToolbarController for the given browser.
ToolbarController* ToolbarControllerForBrowser(Browser* browser) {
return [[BrowserWindowController browserWindowControllerForWindow:
browser->window()->GetNativeWindow()] toolbarController];
}
ToolbarActionsBarBubbleMac* GetBubbleForBrowser(Browser* browser) {
ToolbarController* toolbarController = ToolbarControllerForBrowser(browser);
BrowserActionsController* actionsController =
[toolbarController browserActionsController];
return [actionsController activeBubble];
}
void ClickInView(NSView* view) {
ASSERT_TRUE(view);
std::pair<NSEvent*, NSEvent*> events =
cocoa_test_event_utils::MouseClickInView(view, 1);
[NSApp postEvent:events.second atStart:YES];
[NSApp sendEvent:events.first];
chrome::testing::NSRunLoopRunAllPending();
}
// Checks that the |bubble| is using the |expectedReferenceView|, and is in
// approximately the correct position.
void CheckBubbleAndReferenceView(ToolbarActionsBarBubbleMac* bubble,
NSView* expectedReferenceView) {
ASSERT_TRUE(bubble);
ASSERT_TRUE(expectedReferenceView);
// Do a rough check that the bubble is in the right place.
// A window's frame (like the bubble's) is already in screen coordinates.
NSRect bubbleFrame = [[bubble window] frame];
// Unfortunately, it's more tedious to get the reference view's screen
// coordinates (since -[NSWindow convertRectToScreen is in OSX 10.7).
NSRect referenceFrame = [expectedReferenceView bounds];
referenceFrame =
[expectedReferenceView convertRect:referenceFrame toView:nil];
NSWindow* window = [expectedReferenceView window];
CGFloat refLowY = [expectedReferenceView isFlipped] ?
NSMaxY(referenceFrame) : NSMinY(referenceFrame);
NSPoint refLowerLeft = NSMakePoint(NSMinX(referenceFrame), refLowY);
NSPoint refLowerLeftInScreen =
ui::ConvertPointFromWindowToScreen(window, refLowerLeft);
NSPoint refLowerRight = NSMakePoint(NSMaxX(referenceFrame), refLowY);
NSPoint refLowerRightInScreen =
ui::ConvertPointFromWindowToScreen(window, refLowerRight);
// The bubble should be below the reference view, but not too far below.
EXPECT_LE(NSMaxY(bubbleFrame), refLowerLeftInScreen.y);
// "Too far below" is kind of ambiguous. The exact logic of where a bubble
// is positioned with respect to its anchor view should be tested as part of
// the bubble logic, but we still want to make sure we didn't accidentally
// place it somewhere crazy (which can happen if we draw it, and then
// animate or reposition the reference view).
const int kFudgeFactor = 50;
EXPECT_LE(NSMaxY(bubbleFrame), refLowerLeftInScreen.y + kFudgeFactor);
// The bubble should intersect the reference view somewhere along the x-axis.
EXPECT_LE(refLowerLeftInScreen.x, NSMaxX(bubbleFrame));
EXPECT_LE(NSMinX(bubbleFrame), refLowerRightInScreen.x);
// And, of course, the bubble should be visible.
EXPECT_TRUE([[bubble window] isVisible]);
}
} // namespace
class ExtensionMessageBubbleBrowserTestMac
: public ExtensionMessageBubbleBrowserTest {
public:
ExtensionMessageBubbleBrowserTestMac() {}
~ExtensionMessageBubbleBrowserTestMac() override {}
// ExtensionMessageBubbleBrowserTest:
void SetUpCommandLine(base::CommandLine* command_line) override;
private:
// ExtensionMessageBubbleBrowserTest:
void CheckBubbleNative(Browser* browser, AnchorPosition anchor) override;
void CloseBubbleNative(Browser* browser) override;
void CheckBubbleIsNotPresentNative(Browser* browser) override;
void ClickLearnMoreButton(Browser* browser) override;
void ClickActionButton(Browser* browser) override;
void ClickDismissButton(Browser* browser) override;
DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleBrowserTestMac);
};
class ExtensionMessageBubbleBrowserTestLegacyMac
: public ExtensionMessageBubbleBrowserTestMac {
protected:
void SetUpCommandLine(base::CommandLine* command_line) override {
ExtensionMessageBubbleBrowserTestMac::SetUpCommandLine(command_line);
override_redesign_.reset();
override_redesign_.reset(new extensions::FeatureSwitch::ScopedOverride(
extensions::FeatureSwitch::extension_action_redesign(), false));
}
};
void ExtensionMessageBubbleBrowserTestMac::SetUpCommandLine(
base::CommandLine* command_line) {
ExtensionMessageBubbleBrowserTest::SetUpCommandLine(command_line);
[ToolbarActionsBarBubbleMac setAnimationEnabledForTesting:NO];
}
void ExtensionMessageBubbleBrowserTestMac::CheckBubbleNative(
Browser* browser,
AnchorPosition anchor) {
ToolbarController* toolbarController = ToolbarControllerForBrowser(browser);
BrowserActionsController* actionsController =
[toolbarController browserActionsController];
NSView* anchorView = nil;
ToolbarActionsBarBubbleMac* bubble = [actionsController activeBubble];
switch (anchor) {
case ANCHOR_BROWSER_ACTION:
anchorView = [actionsController buttonWithIndex:0];
break;
case ANCHOR_APP_MENU:
anchorView = [toolbarController appMenuButton];
break;
}
CheckBubbleAndReferenceView(bubble, anchorView);
}
void ExtensionMessageBubbleBrowserTestMac::CloseBubbleNative(Browser* browser) {
BrowserActionsController* controller =
[ToolbarControllerForBrowser(browser) browserActionsController];
ToolbarActionsBarBubbleMac* bubble = [controller activeBubble];
ASSERT_TRUE(bubble);
[bubble close];
EXPECT_EQ(nil, [controller activeBubble]);
}
void ExtensionMessageBubbleBrowserTestMac::CheckBubbleIsNotPresentNative(
Browser* browser) {
EXPECT_EQ(
nil,
[[ToolbarControllerForBrowser(browser) browserActionsController]
activeBubble]);
}
void ExtensionMessageBubbleBrowserTestMac::ClickLearnMoreButton(
Browser* browser) {
ToolbarActionsBarBubbleMac* bubble = GetBubbleForBrowser(browser);
ClickInView([bubble link]);
}
void ExtensionMessageBubbleBrowserTestMac::ClickActionButton(Browser* browser) {
ToolbarActionsBarBubbleMac* bubble = GetBubbleForBrowser(browser);
ClickInView([bubble actionButton]);
}
void ExtensionMessageBubbleBrowserTestMac::ClickDismissButton(
Browser* browser) {
ToolbarActionsBarBubbleMac* bubble = GetBubbleForBrowser(browser);
ClickInView([bubble dismissButton]);
}
IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
ExtensionBubbleAnchoredToExtensionAction) {
TestBubbleAnchoredToExtensionAction();
}
IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestLegacyMac,
ExtensionBubbleAnchoredToAppMenu) {
TestBubbleAnchoredToAppMenu();
}
IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestLegacyMac,
ExtensionBubbleAnchoredToAppMenuWithOtherAction) {
TestBubbleAnchoredToAppMenuWithOtherAction();
}
IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
PRE_ExtensionBubbleShowsOnStartup) {
PreBubbleShowsOnStartup();
}
IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
ExtensionBubbleShowsOnStartup) {
TestBubbleShowsOnStartup();
}
IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
TestUninstallDangerousExtension) {
TestUninstallDangerousExtension();
}
IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
TestDevModeBubbleIsntShownTwice) {
TestDevModeBubbleIsntShownTwice();
}
IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
TestBubbleWithMultipleWindows) {
TestBubbleWithMultipleWindows();
}
IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
TestClickingLearnMoreButton) {
TestClickingLearnMoreButton();
}
IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
TestClickingActionButton) {
TestClickingActionButton();
}
IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
TestClickingDismissButton) {
TestClickingDismissButton();
}
IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
TestControlledHomeMessageBubble) {
TestControlledHomeBubbleShown();
}
IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
TestControlledSearchMessageBubble) {
TestControlledSearchBubbleShown();
}
IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
PRE_TestControlledStartupMessageBubble) {
PreTestControlledStartupBubbleShown();
}
IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
TestControlledStartupMessageBubble) {
TestControlledStartupBubbleShown();
}
IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
PRE_TestControlledStartupNotShownOnRestart) {
PreTestControlledStartupNotShownOnRestart();
}
IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
TestControlledStartupNotShownOnRestart) {
TestControlledStartupNotShownOnRestart();
}
|