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

Side by Side Diff: chrome/browser/ui/views/extensions/extension_message_bubble_view_browsertest.cc

Issue 1877143002: Convert ToolbarActionsBarBubbleViews to BubbleDialogDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/views/settings_api_bubble_helper_views.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/extensions/extension_message_bubble_browsertest.h" 6 #include "chrome/browser/ui/extensions/extension_message_bubble_browsertest.h"
7 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" 7 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
8 #include "chrome/browser/ui/views/frame/browser_view.h" 8 #include "chrome/browser/ui/views/frame/browser_view.h"
9 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" 9 #include "chrome/browser/ui/views/toolbar/app_menu_button.h"
10 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" 10 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
11 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" 11 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
12 #include "ui/views/bubble/bubble_delegate.h" 12 #include "ui/views/bubble/bubble_delegate.h"
13 13
14 namespace { 14 namespace {
15 15
16 // Returns the ToolbarView for the given |browser|. 16 // Returns the ToolbarView for the given |browser|.
17 ToolbarView* GetToolbarViewForBrowser(Browser* browser) { 17 ToolbarView* GetToolbarViewForBrowser(Browser* browser) {
18 return BrowserView::GetBrowserViewForBrowser(browser)->toolbar(); 18 return BrowserView::GetBrowserViewForBrowser(browser)->toolbar();
19 } 19 }
20 20
21 // Checks that the |bubble| is using the |expected_reference_view|, and is in 21 // Checks that the |bubble| is using the |expected_reference_view|, and is in
22 // approximately the correct position. 22 // approximately the correct position.
23 void CheckBubbleAndReferenceView(views::BubbleDelegateView* bubble, 23 void CheckBubbleAndReferenceView(views::BubbleDialogDelegateView* bubble,
24 views::View* expected_reference_view) { 24 views::View* expected_reference_view) {
25 ASSERT_TRUE(bubble); 25 ASSERT_TRUE(bubble);
26 ASSERT_TRUE(expected_reference_view); 26 ASSERT_TRUE(expected_reference_view);
27 EXPECT_EQ(expected_reference_view, bubble->GetAnchorView()); 27 EXPECT_EQ(expected_reference_view, bubble->GetAnchorView());
28 28
29 // Do a rough check that the bubble is in the right place. 29 // Do a rough check that the bubble is in the right place.
30 gfx::Rect bubble_bounds = bubble->GetBoundsInScreen(); 30 gfx::Rect bubble_bounds = bubble->GetWidget()->GetWindowBoundsInScreen();
31 gfx::Rect reference_bounds = expected_reference_view->GetBoundsInScreen(); 31 gfx::Rect reference_bounds = expected_reference_view->GetBoundsInScreen();
32 // It should be below the reference view, but not too far below. 32 // It should be below the reference view, but not too far below.
33 EXPECT_GE(bubble_bounds.y(), reference_bounds.bottom()); 33 EXPECT_GE(bubble_bounds.y(), reference_bounds.y());
34 // "Too far below" is kind of ambiguous. The exact logic of where a bubble 34 // The arrow should be poking into the anchor.
35 // is positioned with respect to its anchor view should be tested as part of 35 EXPECT_LE(bubble_bounds.y(), reference_bounds.bottom());
36 // the bubble logic, but we still want to make sure we didn't accidentally
37 // place it somewhere crazy (which can happen if we draw it, and then
38 // animate or reposition the reference view).
39 const int kFudgeFactor = 50;
40 EXPECT_LE(bubble_bounds.y(), reference_bounds.bottom() + kFudgeFactor);
41 // The bubble should intersect the reference view somewhere along the x-axis. 36 // The bubble should intersect the reference view somewhere along the x-axis.
42 EXPECT_FALSE(bubble_bounds.x() > reference_bounds.right()); 37 EXPECT_FALSE(bubble_bounds.x() > reference_bounds.right());
43 EXPECT_FALSE(reference_bounds.x() > bubble_bounds.right()); 38 EXPECT_FALSE(reference_bounds.x() > bubble_bounds.right());
44 39
45 // And, of course, the bubble should be visible... 40 // And, of course, the bubble should be visible...
46 EXPECT_TRUE(bubble->visible()); 41 EXPECT_TRUE(bubble->visible());
47 // ... as should its Widget. 42 // ... as should its Widget.
48 EXPECT_TRUE(bubble->GetWidget()->IsVisible()); 43 EXPECT_TRUE(bubble->GetWidget()->IsVisible());
49 } 44 }
50 45
(...skipping 11 matching lines...) Expand all
62 void CloseBubble(Browser* browser) override; 57 void CloseBubble(Browser* browser) override;
63 void CheckBubbleIsNotPresent(Browser* browser) override; 58 void CheckBubbleIsNotPresent(Browser* browser) override;
64 59
65 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleViewBrowserTest); 60 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleViewBrowserTest);
66 }; 61 };
67 62
68 void ExtensionMessageBubbleViewBrowserTest::CheckBubble(Browser* browser, 63 void ExtensionMessageBubbleViewBrowserTest::CheckBubble(Browser* browser,
69 AnchorPosition anchor) { 64 AnchorPosition anchor) {
70 ToolbarView* toolbar_view = GetToolbarViewForBrowser(browser); 65 ToolbarView* toolbar_view = GetToolbarViewForBrowser(browser);
71 BrowserActionsContainer* container = toolbar_view->browser_actions(); 66 BrowserActionsContainer* container = toolbar_view->browser_actions();
72 views::BubbleDelegateView* bubble = container->active_bubble(); 67 views::BubbleDialogDelegateView* bubble = container->active_bubble();
73 views::View* anchor_view = nullptr; 68 views::View* anchor_view = nullptr;
74 switch (anchor) { 69 switch (anchor) {
75 case ANCHOR_BROWSER_ACTION: 70 case ANCHOR_BROWSER_ACTION:
76 anchor_view = container->GetToolbarActionViewAt(0); 71 anchor_view = container->GetToolbarActionViewAt(0);
77 break; 72 break;
78 case ANCHOR_APP_MENU: 73 case ANCHOR_APP_MENU:
79 anchor_view = toolbar_view->app_menu_button(); 74 anchor_view = toolbar_view->app_menu_button();
80 break; 75 break;
81 } 76 }
82 CheckBubbleAndReferenceView(bubble, anchor_view); 77 CheckBubbleAndReferenceView(bubble, anchor_view);
83 } 78 }
84 79
85 void ExtensionMessageBubbleViewBrowserTest::CloseBubble(Browser* browser) { 80 void ExtensionMessageBubbleViewBrowserTest::CloseBubble(Browser* browser) {
86 BrowserActionsContainer* container = 81 BrowserActionsContainer* container =
87 GetToolbarViewForBrowser(browser)->browser_actions(); 82 GetToolbarViewForBrowser(browser)->browser_actions();
88 views::BubbleDelegateView* bubble = container->active_bubble(); 83 views::BubbleDialogDelegateView* bubble = container->active_bubble();
89 ASSERT_TRUE(bubble); 84 ASSERT_TRUE(bubble);
90 bubble->GetWidget()->Close(); 85 bubble->GetWidget()->Close();
91 EXPECT_EQ(nullptr, container->active_bubble()); 86 EXPECT_EQ(nullptr, container->active_bubble());
92 } 87 }
93 88
94 void ExtensionMessageBubbleViewBrowserTest::CheckBubbleIsNotPresent( 89 void ExtensionMessageBubbleViewBrowserTest::CheckBubbleIsNotPresent(
95 Browser* browser) { 90 Browser* browser) {
96 EXPECT_EQ( 91 EXPECT_EQ(
97 nullptr, 92 nullptr,
98 GetToolbarViewForBrowser(browser)->browser_actions()->active_bubble()); 93 GetToolbarViewForBrowser(browser)->browser_actions()->active_bubble());
(...skipping 21 matching lines...) Expand all
120 115
121 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest, 116 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest,
122 ExtensionBubbleShowsOnStartup) { 117 ExtensionBubbleShowsOnStartup) {
123 TestBubbleShowsOnStartup(); 118 TestBubbleShowsOnStartup();
124 } 119 }
125 120
126 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest, 121 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest,
127 TestUninstallDangerousExtension) { 122 TestUninstallDangerousExtension) {
128 TestUninstallDangerousExtension(); 123 TestUninstallDangerousExtension();
129 } 124 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/settings_api_bubble_helper_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698