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

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

Issue 1087713002: [Reland] [Extensions] Make extension message bubble factory platform-abstract (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Finnur's Created 5 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
OLDNEW
(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 "base/run_loop.h"
6 #include "chrome/browser/extensions/extension_action_test_util.h"
7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/ui/extensions/extension_message_bubble_factory.h"
9 #include "chrome/browser/ui/toolbar/browser_actions_bar_browsertest.h"
10 #include "chrome/browser/ui/views/extensions/extension_message_bubble_view.h"
11 #include "chrome/browser/ui/views/frame/browser_view.h"
12 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
13 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
14 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h"
15 #include "extensions/common/feature_switch.h"
16
17 namespace {
18
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) {
23 ASSERT_TRUE(bubble);
24 ASSERT_TRUE(expected_reference_view);
25 EXPECT_EQ(expected_reference_view, bubble->GetAnchorView());
26
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());
42
43 // And, of course, the bubble should be visible.
44 EXPECT_TRUE(bubble->visible());
45 }
46
47 } // namespace
48
49 class ExtensionMessageBubbleViewBrowserTest
50 : public BrowserActionsBarBrowserTest {
51 protected:
52 ExtensionMessageBubbleViewBrowserTest() {}
53 ~ExtensionMessageBubbleViewBrowserTest() override {}
54
55 void SetUpCommandLine(base::CommandLine* command_line) override;
56
57 private:
58 scoped_ptr<extensions::FeatureSwitch::ScopedOverride>
59 dev_mode_bubble_override_;
60
61 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleViewBrowserTest);
62 };
63
64 void ExtensionMessageBubbleViewBrowserTest::SetUpCommandLine(
65 base::CommandLine* command_line) {
66 BrowserActionsBarBrowserTest::SetUpCommandLine(command_line);
67 // The dev mode warning bubble is an easy one to trigger, so we use that for
68 // our testing purposes.
69 dev_mode_bubble_override_.reset(
70 new extensions::FeatureSwitch::ScopedOverride(
71 extensions::FeatureSwitch::force_dev_mode_highlighting(),
72 true));
73 ExtensionMessageBubbleFactory::set_enabled_for_tests(true);
74 }
75
76 // Tests that an extension bubble will be anchored to the wrench menu when there
77 // aren't any extensions with actions.
78 // This also tests that the crashes in crbug.com/476426 are fixed.
79 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest,
80 ExtensionBubbleAnchoredToWrenchMenu) {
81 scoped_refptr<const extensions::Extension> action_extension =
82 extensions::extension_action_test_util::CreateActionExtension(
83 "action_extension",
84 extensions::extension_action_test_util::BROWSER_ACTION,
85 extensions::Manifest::UNPACKED);
86 extension_service()->AddExtension(action_extension.get());
87
88 Browser* second_browser = new Browser(
89 Browser::CreateParams(profile(), browser()->host_desktop_type()));
90 base::RunLoop().RunUntilIdle();
91
92 BrowserActionsContainer* second_container =
93 BrowserView::GetBrowserViewForBrowser(second_browser)->toolbar()->
94 browser_actions();
95 views::BubbleDelegateView* bubble = second_container->active_bubble();
96 CheckBubbleAndReferenceView(bubble,
97 second_container->GetToolbarActionViewAt(0));
98
99 bubble->GetWidget()->Close();
100 EXPECT_EQ(nullptr, second_container->active_bubble());
101 }
102
103 // Tests that an extension bubble will be anchored to an extension action when
104 // there are extensions with actions.
105 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest,
106 ExtensionBubbleAnchoredToExtensionAction) {
107 scoped_refptr<const extensions::Extension> no_action_extension =
108 extensions::extension_action_test_util::CreateActionExtension(
109 "action_extension",
110 extensions::extension_action_test_util::NO_ACTION,
111 extensions::Manifest::UNPACKED);
112 extension_service()->AddExtension(no_action_extension.get());
113
114 Browser* second_browser = new Browser(
115 Browser::CreateParams(profile(), browser()->host_desktop_type()));
116 ASSERT_TRUE(second_browser);
117 base::RunLoop().RunUntilIdle();
118
119 ToolbarView* toolbar =
120 BrowserView::GetBrowserViewForBrowser(second_browser)->toolbar();
121 BrowserActionsContainer* second_container = toolbar->browser_actions();
122 views::BubbleDelegateView* bubble = second_container->active_bubble();
123 CheckBubbleAndReferenceView(bubble, toolbar->app_menu());
124
125 bubble->GetWidget()->Close();
126 EXPECT_EQ(nullptr, second_container->active_bubble());
127 }
128
129 // Tests that the extension bubble will show on startup.
130 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest,
131 PRE_ExtensionBubbleShowsOnStartup) {
132 LoadExtension(test_data_dir_.AppendASCII("good_unpacked"));
133 }
134
135 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest,
136 ExtensionBubbleShowsOnStartup) {
137 base::RunLoop().RunUntilIdle();
138 BrowserActionsContainer* container =
139 BrowserView::GetBrowserViewForBrowser(browser())->toolbar()->
140 browser_actions();
141 views::BubbleDelegateView* bubble = container->active_bubble();
142 CheckBubbleAndReferenceView(bubble, container->GetToolbarActionViewAt(0));
143
144 bubble->GetWidget()->Close();
145 EXPECT_EQ(nullptr, container->active_bubble());
146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698