OLD | NEW |
---|---|
(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 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest, | |
79 ExtensionBubbleAnchoredToWrenchMenu) { | |
80 scoped_refptr<const extensions::Extension> action_extension = | |
81 extensions::extension_action_test_util::CreateActionExtension( | |
82 "action_extension", | |
83 extensions::extension_action_test_util::BROWSER_ACTION, | |
84 extensions::Manifest::UNPACKED); | |
85 extension_service()->AddExtension(action_extension.get()); | |
86 | |
87 Browser* second_browser = new Browser( | |
88 Browser::CreateParams(profile(), browser()->host_desktop_type())); | |
89 base::RunLoop().RunUntilIdle(); | |
90 | |
91 BrowserActionsContainer* second_container = | |
92 BrowserView::GetBrowserViewForBrowser(second_browser)->toolbar()-> | |
93 browser_actions(); | |
94 views::BubbleDelegateView* bubble = second_container->active_bubble(); | |
95 CheckBubbleAndReferenceView(bubble, | |
96 second_container->GetToolbarActionViewAt(0)); | |
97 | |
98 bubble->GetWidget()->Close(); | |
99 EXPECT_EQ(nullptr, second_container->active_bubble()); | |
100 } | |
101 | |
102 // Tests that an extension bubble will be anchored to an extension action when | |
103 // there are extensions with actions. | |
104 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest, | |
105 ExtensionBubbleAnchoredToExtensionAction) { | |
106 scoped_refptr<const extensions::Extension> no_action_extension = | |
107 extensions::extension_action_test_util::CreateActionExtension( | |
108 "action_extension", | |
109 extensions::extension_action_test_util::NO_ACTION, | |
110 extensions::Manifest::UNPACKED); | |
111 extension_service()->AddExtension(no_action_extension.get()); | |
112 | |
113 Browser* second_browser = new Browser( | |
114 Browser::CreateParams(profile(), browser()->host_desktop_type())); | |
115 ASSERT_TRUE(second_browser); | |
116 base::RunLoop().RunUntilIdle(); | |
117 | |
118 ToolbarView* toolbar = | |
119 BrowserView::GetBrowserViewForBrowser(second_browser)->toolbar(); | |
120 BrowserActionsContainer* second_container = toolbar->browser_actions(); | |
121 views::BubbleDelegateView* bubble = second_container->active_bubble(); | |
122 CheckBubbleAndReferenceView(bubble, toolbar->app_menu()); | |
123 | |
124 bubble->GetWidget()->Close(); | |
125 EXPECT_EQ(nullptr, second_container->active_bubble()); | |
126 } | |
127 | |
128 // Tests that the extension bubble will show on startup. | |
Finnur
2015/04/15 14:51:37
nit: Would be good for the test that exercises the
Devlin
2015/04/15 16:56:49
Done.
| |
129 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest, | |
130 PRE_ExtensionBubbleShowsOnStartup) { | |
131 LoadExtension(test_data_dir_.AppendASCII("good_unpacked")); | |
132 } | |
133 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest, | |
Finnur
2015/04/15 14:51:37
nit: missing line break above this.
Devlin
2015/04/15 16:56:49
It was a conscious decision, since the one above i
| |
134 ExtensionBubbleShowsOnStartup) { | |
135 base::RunLoop().RunUntilIdle(); | |
136 BrowserActionsContainer* container = | |
137 BrowserView::GetBrowserViewForBrowser(browser())->toolbar()-> | |
138 browser_actions(); | |
139 views::BubbleDelegateView* bubble = container->active_bubble(); | |
140 CheckBubbleAndReferenceView(bubble, container->GetToolbarActionViewAt(0)); | |
141 | |
142 bubble->GetWidget()->Close(); | |
143 EXPECT_EQ(nullptr, container->active_bubble()); | |
144 } | |
OLD | NEW |