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

Side by Side Diff: chrome/browser/ui/cocoa/extensions/extension_message_bubble_browsertest_mac.mm

Issue 2086193002: [Extensions UI] Fix a crash when clicking on a bubble's learn more (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Views clicking Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/macros.h" 5 #include "base/macros.h"
6 #include "chrome/browser/ui/browser_window.h" 6 #include "chrome/browser/ui/browser_window.h"
7 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 7 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
8 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" 8 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h"
9 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" 9 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h"
10 #import "chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_mac.h" 10 #import "chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_mac.h"
11 #import "chrome/browser/ui/cocoa/run_loop_testing.h"
11 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 12 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
12 #include "chrome/browser/ui/extensions/extension_message_bubble_browsertest.h" 13 #include "chrome/browser/ui/extensions/extension_message_bubble_browsertest.h"
13 #include "ui/base/cocoa/cocoa_base_utils.h" 14 #include "ui/base/cocoa/cocoa_base_utils.h"
15 #include "ui/events/test/cocoa_test_event_utils.h"
14 16
15 namespace { 17 namespace {
16 18
17 // Returns the ToolbarController for the given browser. 19 // Returns the ToolbarController for the given browser.
18 ToolbarController* ToolbarControllerForBrowser(Browser* browser) { 20 ToolbarController* ToolbarControllerForBrowser(Browser* browser) {
19 return [[BrowserWindowController browserWindowControllerForWindow: 21 return [[BrowserWindowController browserWindowControllerForWindow:
20 browser->window()->GetNativeWindow()] toolbarController]; 22 browser->window()->GetNativeWindow()] toolbarController];
21 } 23 }
22 24
25 ToolbarActionsBarBubbleMac* GetBubbleForBrowser(Browser* browser) {
26 ToolbarController* toolbarController = ToolbarControllerForBrowser(browser);
27 BrowserActionsController* actionsController =
28 [toolbarController browserActionsController];
29 return [actionsController activeBubble];
30 }
31
32 void ClickInView(NSView* view) {
33 ASSERT_TRUE(view);
34 std::pair<NSEvent*, NSEvent*> events =
35 cocoa_test_event_utils::MouseClickInView(view, 1);
36 [NSApp postEvent:events.second atStart:YES];
37 [NSApp sendEvent:events.first];
38 chrome::testing::NSRunLoopRunAllPending();
39 }
40
23 // Checks that the |bubble| is using the |expectedReferenceView|, and is in 41 // Checks that the |bubble| is using the |expectedReferenceView|, and is in
24 // approximately the correct position. 42 // approximately the correct position.
25 void CheckBubbleAndReferenceView(ToolbarActionsBarBubbleMac* bubble, 43 void CheckBubbleAndReferenceView(ToolbarActionsBarBubbleMac* bubble,
26 NSView* expectedReferenceView) { 44 NSView* expectedReferenceView) {
27 ASSERT_TRUE(bubble); 45 ASSERT_TRUE(bubble);
28 ASSERT_TRUE(expectedReferenceView); 46 ASSERT_TRUE(expectedReferenceView);
29 47
30 // Do a rough check that the bubble is in the right place. 48 // Do a rough check that the bubble is in the right place.
31 // A window's frame (like the bubble's) is already in screen coordinates. 49 // A window's frame (like the bubble's) is already in screen coordinates.
32 NSRect bubbleFrame = [[bubble window] frame]; 50 NSRect bubbleFrame = [[bubble window] frame];
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 84
67 } // namespace 85 } // namespace
68 86
69 class ExtensionMessageBubbleBrowserTestMac 87 class ExtensionMessageBubbleBrowserTestMac
70 : public ExtensionMessageBubbleBrowserTest { 88 : public ExtensionMessageBubbleBrowserTest {
71 public: 89 public:
72 ExtensionMessageBubbleBrowserTestMac() {} 90 ExtensionMessageBubbleBrowserTestMac() {}
73 ~ExtensionMessageBubbleBrowserTestMac() override {} 91 ~ExtensionMessageBubbleBrowserTestMac() override {}
74 92
75 private: 93 private:
94 // ExtensionMessageBubbleBrowserTest:
76 void SetUpCommandLine(base::CommandLine* command_line) override; 95 void SetUpCommandLine(base::CommandLine* command_line) override;
77 void CheckBubbleNative(Browser* browser, AnchorPosition anchor) override; 96 void CheckBubbleNative(Browser* browser, AnchorPosition anchor) override;
78 void CloseBubbleNative(Browser* browser) override; 97 void CloseBubbleNative(Browser* browser) override;
79 void CheckBubbleIsNotPresentNative(Browser* browser) override; 98 void CheckBubbleIsNotPresentNative(Browser* browser) override;
99 void ClickLearnMoreButton(Browser* browser) override;
100 void ClickActionButton(Browser* browser) override;
101 void ClickDismissButton(Browser* browser) override;
80 102
81 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleBrowserTestMac); 103 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleBrowserTestMac);
82 }; 104 };
83 105
84 void ExtensionMessageBubbleBrowserTestMac::SetUpCommandLine( 106 void ExtensionMessageBubbleBrowserTestMac::SetUpCommandLine(
85 base::CommandLine* command_line) { 107 base::CommandLine* command_line) {
86 ExtensionMessageBubbleBrowserTest::SetUpCommandLine(command_line); 108 ExtensionMessageBubbleBrowserTest::SetUpCommandLine(command_line);
87 [ToolbarActionsBarBubbleMac setAnimationEnabledForTesting:NO]; 109 [ToolbarActionsBarBubbleMac setAnimationEnabledForTesting:NO];
88 } 110 }
89 111
(...skipping 26 matching lines...) Expand all
116 } 138 }
117 139
118 void ExtensionMessageBubbleBrowserTestMac::CheckBubbleIsNotPresentNative( 140 void ExtensionMessageBubbleBrowserTestMac::CheckBubbleIsNotPresentNative(
119 Browser* browser) { 141 Browser* browser) {
120 EXPECT_EQ( 142 EXPECT_EQ(
121 nil, 143 nil,
122 [[ToolbarControllerForBrowser(browser) browserActionsController] 144 [[ToolbarControllerForBrowser(browser) browserActionsController]
123 activeBubble]); 145 activeBubble]);
124 } 146 }
125 147
148 void ExtensionMessageBubbleBrowserTestMac::ClickLearnMoreButton(
149 Browser* browser) {
150 ToolbarActionsBarBubbleMac* bubble = GetBubbleForBrowser(browser);
151 ClickInView([bubble learnMoreButton]);
152 }
153
154 void ExtensionMessageBubbleBrowserTestMac::ClickActionButton(Browser* browser) {
155 ToolbarActionsBarBubbleMac* bubble = GetBubbleForBrowser(browser);
156 ClickInView([bubble actionButton]);
157 }
158
159 void ExtensionMessageBubbleBrowserTestMac::ClickDismissButton(
160 Browser* browser) {
161 ToolbarActionsBarBubbleMac* bubble = GetBubbleForBrowser(browser);
162 ClickInView([bubble dismissButton]);
163 }
164
126 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac, 165 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
127 ExtensionBubbleAnchoredToExtensionAction) { 166 ExtensionBubbleAnchoredToExtensionAction) {
128 TestBubbleAnchoredToExtensionAction(); 167 TestBubbleAnchoredToExtensionAction();
129 } 168 }
130 169
131 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac, 170 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
132 ExtensionBubbleAnchoredToAppMenu) { 171 ExtensionBubbleAnchoredToAppMenu) {
133 TestBubbleAnchoredToAppMenu(); 172 TestBubbleAnchoredToAppMenu();
134 } 173 }
135 174
(...skipping 19 matching lines...) Expand all
155 194
156 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac, 195 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
157 TestDevModeBubbleIsntShownTwice) { 196 TestDevModeBubbleIsntShownTwice) {
158 TestDevModeBubbleIsntShownTwice(); 197 TestDevModeBubbleIsntShownTwice();
159 } 198 }
160 199
161 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac, 200 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
162 TestBubbleWithMultipleWindows) { 201 TestBubbleWithMultipleWindows) {
163 TestBubbleWithMultipleWindows(); 202 TestBubbleWithMultipleWindows();
164 } 203 }
204
205 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
206 TestClickingLearnMoreButton) {
207 TestClickingLearnMoreButton();
208 }
209
210 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
211 TestClickingActionButton) {
212 TestClickingActionButton();
213 }
214
215 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleBrowserTestMac,
216 TestClickingDismissButton) {
217 TestClickingDismissButton();
218 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698