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.
5 #include "chrome/browser/ui/extensions/extension_message_bubble_browsertest.h"
6 #include "chrome/browser/ui/views/extensions/extension_message_bubble_view.h"
7 #include "chrome/browser/ui/views/frame/browser_view.h"
8 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
9 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
10 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h"
14 // Returns the ToolbarView for the given |browser|.
15 ToolbarView
* GetToolbarViewForBrowser(Browser
* browser
) {
16 return BrowserView::GetBrowserViewForBrowser(browser
)->toolbar();
19 // Checks that the |bubble| is using the |expected_reference_view|, and is in
20 // approximately the correct position.
21 void CheckBubbleAndReferenceView(views::BubbleDelegateView
* bubble
,
22 views::View
* expected_reference_view
) {
24 ASSERT_TRUE(expected_reference_view
);
25 EXPECT_EQ(expected_reference_view
, bubble
->GetAnchorView());
27 // Do a rough check that the bubble is in the right place.
28 gfx::Rect bubble_bounds
= bubble
->GetBoundsInScreen();
29 gfx::Rect reference_bounds
= expected_reference_view
->GetBoundsInScreen();
30 // It should be below the reference view, but not too far below.
31 EXPECT_GE(bubble_bounds
.y(), reference_bounds
.bottom());
32 // "Too far below" is kind of ambiguous. The exact logic of where a bubble
33 // is positioned with respect to its anchor view should be tested as part of
34 // the bubble logic, but we still want to make sure we didn't accidentally
35 // place it somewhere crazy (which can happen if we draw it, and then
36 // animate or reposition the reference view).
37 const int kFudgeFactor
= 50;
38 EXPECT_LE(bubble_bounds
.y(), reference_bounds
.bottom() + kFudgeFactor
);
39 // The bubble should intersect the reference view somewhere along the x-axis.
40 EXPECT_FALSE(bubble_bounds
.x() > reference_bounds
.right());
41 EXPECT_FALSE(reference_bounds
.x() > bubble_bounds
.right());
43 // And, of course, the bubble should be visible.
44 EXPECT_TRUE(bubble
->visible());
49 class ExtensionMessageBubbleViewBrowserTest
50 : public ExtensionMessageBubbleBrowserTest
{
52 ExtensionMessageBubbleViewBrowserTest() {}
53 ~ExtensionMessageBubbleViewBrowserTest() override
{}
56 // ExtensionMessageBubbleBrowserTest:
57 void CheckBubble(Browser
* browser
, AnchorPosition anchor
) override
;
58 void CloseBubble(Browser
* browser
) override
;
60 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleViewBrowserTest
);
63 void ExtensionMessageBubbleViewBrowserTest::CheckBubble(Browser
* browser
,
64 AnchorPosition anchor
) {
65 ToolbarView
* toolbar_view
= GetToolbarViewForBrowser(browser
);
66 BrowserActionsContainer
* container
= toolbar_view
->browser_actions();
67 views::BubbleDelegateView
* bubble
= container
->active_bubble();
68 views::View
* anchor_view
= nullptr;
70 case ANCHOR_BROWSER_ACTION
:
71 anchor_view
= container
->GetToolbarActionViewAt(0);
73 case ANCHOR_WRENCH_MENU
:
74 anchor_view
= toolbar_view
->app_menu();
77 CheckBubbleAndReferenceView(bubble
, anchor_view
);
80 void ExtensionMessageBubbleViewBrowserTest::CloseBubble(Browser
* browser
) {
81 BrowserActionsContainer
* container
=
82 GetToolbarViewForBrowser(browser
)->browser_actions();
83 views::BubbleDelegateView
* bubble
= container
->active_bubble();
85 bubble
->GetWidget()->Close();
86 EXPECT_EQ(nullptr, container
->active_bubble());
89 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest
,
90 ExtensionBubbleAnchoredToExtensionAction
) {
91 TestBubbleAnchoredToExtensionAction();
94 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest
,
95 ExtensionBubbleAnchoredToWrenchMenu
) {
96 TestBubbleAnchoredToWrenchMenu();
99 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest
,
100 ExtensionBubbleAnchoredToWrenchMenuWithOtherAction
) {
101 TestBubbleAnchoredToWrenchMenuWithOtherAction();
104 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest
,
105 PRE_ExtensionBubbleShowsOnStartup
) {
106 PreBubbleShowsOnStartup();
109 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest
,
110 ExtensionBubbleShowsOnStartup
) {
111 TestBubbleShowsOnStartup();