Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/extensions/ntp_overridden_bubble_delegate.h" | |
| 6 #include "chrome/browser/ui/extensions/extension_message_bubble_browsertest.h" | 7 #include "chrome/browser/ui/extensions/extension_message_bubble_browsertest.h" |
| 7 #include "chrome/browser/ui/views/extensions/extension_message_bubble_view.h" | 8 #include "chrome/browser/ui/views/extensions/extension_message_bubble_view.h" |
| 8 #include "chrome/browser/ui/views/frame/browser_view.h" | 9 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 9 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" | 10 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" |
| 10 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 11 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
| 11 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 12 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 13 #include "chrome/test/base/ui_test_utils.h" | |
| 14 #include "extensions/browser/extension_registry.h" | |
| 15 #include "ui/events/event_utils.h" | |
| 16 | |
| 17 namespace extensions { | |
| 12 | 18 |
| 13 namespace { | 19 namespace { |
| 14 | 20 |
| 15 // Returns the ToolbarView for the given |browser|. | 21 // Returns the ToolbarView for the given |browser|. |
| 16 ToolbarView* GetToolbarViewForBrowser(Browser* browser) { | 22 ToolbarView* GetToolbarViewForBrowser(Browser* browser) { |
| 17 return BrowserView::GetBrowserViewForBrowser(browser)->toolbar(); | 23 return BrowserView::GetBrowserViewForBrowser(browser)->toolbar(); |
| 18 } | 24 } |
| 19 | 25 |
| 20 // Checks that the |bubble| is using the |expected_reference_view|, and is in | 26 // Checks that the |bubble| is using the |expected_reference_view|, and is in |
| 21 // approximately the correct position. | 27 // approximately the correct position. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 46 // ... as should its Widget. | 52 // ... as should its Widget. |
| 47 EXPECT_TRUE(bubble->GetWidget()->IsVisible()); | 53 EXPECT_TRUE(bubble->GetWidget()->IsVisible()); |
| 48 } | 54 } |
| 49 | 55 |
| 50 } // namespace | 56 } // namespace |
| 51 | 57 |
| 52 class ExtensionMessageBubbleViewBrowserTest | 58 class ExtensionMessageBubbleViewBrowserTest |
| 53 : public ExtensionMessageBubbleBrowserTest { | 59 : public ExtensionMessageBubbleBrowserTest { |
| 54 protected: | 60 protected: |
| 55 ExtensionMessageBubbleViewBrowserTest() { | 61 ExtensionMessageBubbleViewBrowserTest() { |
| 56 extensions::ExtensionMessageBubbleView:: | 62 ExtensionMessageBubbleView::set_bubble_appearance_wait_time_for_testing(0); |
| 57 set_bubble_appearance_wait_time_for_testing(0); | |
| 58 } | 63 } |
| 59 ~ExtensionMessageBubbleViewBrowserTest() override {} | 64 ~ExtensionMessageBubbleViewBrowserTest() override {} |
| 60 | 65 |
| 66 // Loads and returns an extension that overrides the new tab page. | |
| 67 const Extension* LoadNewTabExtension(); | |
| 68 | |
| 69 // Clicks on the |bubble|'s dismiss button. | |
| 70 void ClickMessageBubbleDismissButton(ExtensionMessageBubbleView* bubble) { | |
|
asargent_no_longer_on_chrome
2016/03/04 22:16:03
consider shortening name to just "ClickDismiss()"
Devlin
2016/03/05 00:36:27
Done (% ClickDismissButton rather than ClickDismis
| |
| 71 ClickMessageBubbleButton(bubble, bubble->dismiss_button_); | |
| 72 } | |
| 73 | |
| 74 // Clicks on the |bubble|'s action button. | |
| 75 void ClickMessageBubbleActionButton(ExtensionMessageBubbleView* bubble) { | |
|
asargent_no_longer_on_chrome
2016/03/04 22:16:03
same thing here
Devlin
2016/03/05 00:36:27
Done.
| |
| 76 ClickMessageBubbleButton(bubble, bubble->action_button_); | |
| 77 } | |
| 78 | |
| 79 ExtensionMessageBubbleView* active_message_bubble() { | |
| 80 return ExtensionMessageBubbleView::active_bubble_for_testing_; | |
| 81 } | |
| 82 | |
| 61 private: | 83 private: |
| 84 void ClickMessageBubbleButton(ExtensionMessageBubbleView* bubble, | |
| 85 views::Button* button); | |
| 86 | |
| 62 // ExtensionMessageBubbleBrowserTest: | 87 // ExtensionMessageBubbleBrowserTest: |
| 63 void CheckBubble(Browser* browser, AnchorPosition anchor) override; | 88 void CheckBubble(Browser* browser, AnchorPosition anchor) override; |
| 64 void CloseBubble(Browser* browser) override; | 89 void CloseBubble(Browser* browser) override; |
| 65 void CheckBubbleIsNotPresent(Browser* browser) override; | 90 void CheckBubbleIsNotPresent(Browser* browser) override; |
| 66 | 91 |
| 67 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleViewBrowserTest); | 92 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleViewBrowserTest); |
| 68 }; | 93 }; |
| 69 | 94 |
| 95 const Extension* ExtensionMessageBubbleViewBrowserTest::LoadNewTabExtension() { | |
| 96 base::FilePath crx_path = PackExtension(test_data_dir_.AppendASCII("api_test") | |
| 97 .AppendASCII("override") | |
| 98 .AppendASCII("newtab")); | |
| 99 EXPECT_FALSE(crx_path.empty()); | |
| 100 const Extension* extension = InstallExtensionFromWebstore(crx_path, 1); | |
| 101 return extension; | |
| 102 } | |
| 103 | |
| 104 void ExtensionMessageBubbleViewBrowserTest::ClickMessageBubbleButton( | |
| 105 ExtensionMessageBubbleView* bubble, | |
| 106 views::Button* button) { | |
| 107 gfx::Point p(button->x(), button->y()); | |
| 108 ui::MouseEvent event(ui::ET_MOUSE_RELEASED, p, p, ui::EventTimeForNow(), | |
| 109 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | |
| 110 bubble->ButtonPressed(button, event); | |
| 111 } | |
| 112 | |
| 70 void ExtensionMessageBubbleViewBrowserTest::CheckBubble(Browser* browser, | 113 void ExtensionMessageBubbleViewBrowserTest::CheckBubble(Browser* browser, |
| 71 AnchorPosition anchor) { | 114 AnchorPosition anchor) { |
| 72 ToolbarView* toolbar_view = GetToolbarViewForBrowser(browser); | 115 ToolbarView* toolbar_view = GetToolbarViewForBrowser(browser); |
| 73 BrowserActionsContainer* container = toolbar_view->browser_actions(); | 116 BrowserActionsContainer* container = toolbar_view->browser_actions(); |
| 74 views::BubbleDelegateView* bubble = container->active_bubble(); | 117 views::BubbleDelegateView* bubble = container->active_bubble(); |
| 75 views::View* anchor_view = nullptr; | 118 views::View* anchor_view = nullptr; |
| 76 switch (anchor) { | 119 switch (anchor) { |
| 77 case ANCHOR_BROWSER_ACTION: | 120 case ANCHOR_BROWSER_ACTION: |
| 78 anchor_view = container->GetToolbarActionViewAt(0); | 121 anchor_view = container->GetToolbarActionViewAt(0); |
| 79 break; | 122 break; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 | 165 |
| 123 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest, | 166 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest, |
| 124 ExtensionBubbleShowsOnStartup) { | 167 ExtensionBubbleShowsOnStartup) { |
| 125 TestBubbleShowsOnStartup(); | 168 TestBubbleShowsOnStartup(); |
| 126 } | 169 } |
| 127 | 170 |
| 128 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest, | 171 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest, |
| 129 TestUninstallDangerousExtension) { | 172 TestUninstallDangerousExtension) { |
| 130 TestUninstallDangerousExtension(); | 173 TestUninstallDangerousExtension(); |
| 131 } | 174 } |
| 175 | |
| 176 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest, | |
| 177 TestClickingDismissButton) { | |
| 178 const Extension* extension = LoadNewTabExtension(); | |
| 179 ASSERT_TRUE(extension); | |
| 180 const std::string extension_id = extension->id(); | |
| 181 | |
| 182 ui_test_utils::NavigateToURLWithDisposition( | |
| 183 browser(), GURL("chrome://newtab/"), NEW_FOREGROUND_TAB, | |
| 184 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 185 | |
| 186 NtpOverriddenBubbleDelegate bubble_delegate(profile()); | |
| 187 EXPECT_FALSE(bubble_delegate.HasBubbleInfoBeenAcknowledged(extension->id())); | |
| 188 | |
| 189 // Check the bubble is showing. | |
| 190 base::RunLoop().RunUntilIdle(); | |
| 191 ExtensionMessageBubbleView* bubble = active_message_bubble(); | |
| 192 views::View* anchor_view = | |
| 193 GetToolbarViewForBrowser(browser())->app_menu_button(); | |
| 194 CheckBubbleAndReferenceView(bubble, anchor_view); | |
| 195 | |
| 196 // Click the dismiss button. The bubble should close, and the extension should | |
| 197 // be acknowledged (and still installed). | |
| 198 ClickMessageBubbleDismissButton(bubble); | |
| 199 base::RunLoop().RunUntilIdle(); | |
| 200 EXPECT_FALSE(active_message_bubble()); | |
| 201 EXPECT_TRUE(bubble_delegate.HasBubbleInfoBeenAcknowledged(extension->id())); | |
| 202 EXPECT_TRUE(ExtensionRegistry::Get(profile())->enabled_extensions().GetByID( | |
| 203 extension_id)); | |
| 204 } | |
| 205 | |
| 206 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest, | |
| 207 TestClickingActionButton) { | |
| 208 const Extension* extension = LoadNewTabExtension(); | |
| 209 ASSERT_TRUE(extension); | |
| 210 const std::string extension_id = extension->id(); | |
| 211 | |
| 212 ui_test_utils::NavigateToURLWithDisposition( | |
| 213 browser(), GURL("chrome://newtab/"), NEW_FOREGROUND_TAB, | |
| 214 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 215 | |
| 216 NtpOverriddenBubbleDelegate bubble_delegate(profile()); | |
| 217 EXPECT_FALSE(bubble_delegate.HasBubbleInfoBeenAcknowledged(extension->id())); | |
| 218 | |
| 219 // Check the bubble is showing. | |
| 220 base::RunLoop().RunUntilIdle(); | |
| 221 ExtensionMessageBubbleView* bubble = active_message_bubble(); | |
| 222 views::View* anchor_view = | |
| 223 GetToolbarViewForBrowser(browser())->app_menu_button(); | |
| 224 CheckBubbleAndReferenceView(bubble, anchor_view); | |
| 225 | |
| 226 // Click the action button. The bubble should close, and the extension should | |
| 227 // not be acknowledged, because it was removed. | |
| 228 ClickMessageBubbleActionButton(bubble); | |
| 229 base::RunLoop().RunUntilIdle(); | |
| 230 EXPECT_FALSE(active_message_bubble()); | |
| 231 EXPECT_FALSE(bubble_delegate.HasBubbleInfoBeenAcknowledged(extension->id())); | |
| 232 EXPECT_FALSE(ExtensionRegistry::Get(profile())->GetExtensionById( | |
| 233 extension_id, ExtensionRegistry::EVERYTHING)); | |
| 234 } | |
| 235 | |
| 236 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest, | |
| 237 TestBubbleFocusLoss) { | |
| 238 const Extension* extension = LoadNewTabExtension(); | |
| 239 ASSERT_TRUE(extension); | |
| 240 const std::string extension_id = extension->id(); | |
| 241 | |
| 242 ui_test_utils::NavigateToURLWithDisposition( | |
| 243 browser(), GURL("chrome://newtab/"), NEW_FOREGROUND_TAB, | |
| 244 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 245 | |
| 246 NtpOverriddenBubbleDelegate bubble_delegate(profile()); | |
| 247 EXPECT_FALSE(bubble_delegate.HasBubbleInfoBeenAcknowledged(extension->id())); | |
| 248 | |
| 249 // Check the bubble is showing. | |
| 250 base::RunLoop().RunUntilIdle(); | |
| 251 ExtensionMessageBubbleView* bubble = active_message_bubble(); | |
| 252 views::View* anchor_view = | |
| 253 GetToolbarViewForBrowser(browser())->app_menu_button(); | |
| 254 CheckBubbleAndReferenceView(bubble, anchor_view); | |
| 255 | |
| 256 // Deactivate the bubble's widget (e.g. due to focus loss). This causes the | |
| 257 // bubble to close, but the extension should not be acknowledged or removed. | |
| 258 bubble->GetWidget()->Deactivate(); | |
| 259 base::RunLoop().RunUntilIdle(); | |
| 260 EXPECT_FALSE(active_message_bubble()); | |
| 261 EXPECT_FALSE(bubble_delegate.HasBubbleInfoBeenAcknowledged(extension->id())); | |
| 262 EXPECT_TRUE(ExtensionRegistry::Get(profile())->enabled_extensions().GetByID( | |
| 263 extension_id)); | |
| 264 } | |
| 265 | |
| 266 } // namespace extensions | |
| OLD | NEW |