| 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/auto_reset.h" |
| 5 #include "base/macros.h" | 6 #include "base/macros.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/toolbar/toolbar_actions_bar.h" | 8 #include "chrome/browser/ui/test/test_browser_dialog.h" |
| 8 #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/browser_actions_container.h" | |
| 11 #include "chrome/browser/ui/views/toolbar/toolbar_actions_bar_bubble_views.h" | 9 #include "chrome/browser/ui/views/toolbar/toolbar_actions_bar_bubble_views.h" |
| 12 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 10 #include "ui/base/ui_base_switches.h" |
| 13 #include "ui/views/bubble/bubble_dialog_delegate.h" | 11 #include "ui/views/bubble/bubble_dialog_delegate.h" |
| 14 #include "ui/views/controls/link.h" | 12 #include "ui/views/controls/link.h" |
| 15 #include "ui/views/controls/link_listener.h" | 13 #include "ui/views/controls/link_listener.h" |
| 16 #include "ui/views/window/dialog_client_view.h" | 14 #include "ui/views/window/dialog_client_view.h" |
| 17 | 15 |
| 18 namespace { | 16 namespace { |
| 19 | 17 |
| 20 // Returns the ToolbarView for the given |browser|. | 18 // Checks that the |bubble| is showing. Uses |reference_bounds| to ensure it is |
| 21 ToolbarView* GetToolbarViewForBrowser(Browser* browser) { | 19 // in approximately the correct position. |
| 22 return BrowserView::GetBrowserViewForBrowser(browser)->toolbar(); | 20 void CheckBubbleAgainstReferenceBounds(views::BubbleDialogDelegateView* bubble, |
| 23 } | 21 const gfx::Rect& reference_bounds) { |
| 24 | |
| 25 ToolbarActionsBarBubbleViews* GetBubbleForBrowser(Browser* browser) { | |
| 26 return static_cast<ToolbarActionsBarBubbleViews*>( | |
| 27 GetToolbarViewForBrowser(browser)->browser_actions()->active_bubble()); | |
| 28 } | |
| 29 | |
| 30 // Checks that the |bubble| is using the |expected_reference_view|, and is in | |
| 31 // approximately the correct position. | |
| 32 void CheckBubbleAndReferenceView(views::BubbleDialogDelegateView* bubble, | |
| 33 views::View* expected_reference_view) { | |
| 34 ASSERT_TRUE(bubble); | 22 ASSERT_TRUE(bubble); |
| 35 ASSERT_TRUE(expected_reference_view); | |
| 36 EXPECT_EQ(expected_reference_view, bubble->GetAnchorView()); | |
| 37 | 23 |
| 38 // Do a rough check that the bubble is in the right place. | 24 // Do a rough check that the bubble is in the right place. |
| 39 gfx::Rect bubble_bounds = bubble->GetWidget()->GetWindowBoundsInScreen(); | 25 gfx::Rect bubble_bounds = bubble->GetWidget()->GetWindowBoundsInScreen(); |
| 40 gfx::Rect reference_bounds = expected_reference_view->GetBoundsInScreen(); | |
| 41 // It should be below the reference view, but not too far below. | 26 // It should be below the reference view, but not too far below. |
| 42 EXPECT_GE(bubble_bounds.y(), reference_bounds.y()); | 27 EXPECT_GE(bubble_bounds.y(), reference_bounds.y()); |
| 43 // The arrow should be poking into the anchor. | 28 // The arrow should be poking into the anchor. |
| 44 const int kShadowWidth = 1; | 29 const int kShadowWidth = 1; |
| 45 EXPECT_LE(bubble_bounds.y(), reference_bounds.bottom() + kShadowWidth); | 30 EXPECT_LE(bubble_bounds.y(), reference_bounds.bottom() + kShadowWidth); |
| 46 // The bubble should intersect the reference view somewhere along the x-axis. | 31 // The bubble should intersect the reference view somewhere along the x-axis. |
| 47 EXPECT_FALSE(bubble_bounds.x() > reference_bounds.right()); | 32 EXPECT_FALSE(bubble_bounds.x() > reference_bounds.right()); |
| 48 EXPECT_FALSE(reference_bounds.x() > bubble_bounds.right()); | 33 EXPECT_FALSE(reference_bounds.x() > bubble_bounds.right()); |
| 49 | 34 |
| 50 // And, of course, the bubble should be visible... | 35 // And, of course, the bubble should be visible... |
| 51 EXPECT_TRUE(bubble->visible()); | 36 EXPECT_TRUE(bubble->visible()); |
| 52 // ... as should its Widget. | 37 // ... as should its Widget. |
| 53 EXPECT_TRUE(bubble->GetWidget()->IsVisible()); | 38 EXPECT_TRUE(bubble->GetWidget()->IsVisible()); |
| 54 } | 39 } |
| 55 | 40 |
| 56 } // namespace | 41 } // namespace |
| 57 | 42 |
| 58 class ExtensionMessageBubbleViewBrowserTest | 43 class ExtensionMessageBubbleViewBrowserTest |
| 59 : public ExtensionMessageBubbleBrowserTest { | 44 : public SupportsTestDialog<ExtensionMessageBubbleBrowserTest> { |
| 60 protected: | 45 protected: |
| 61 ExtensionMessageBubbleViewBrowserTest() {} | 46 ExtensionMessageBubbleViewBrowserTest() {} |
| 62 ~ExtensionMessageBubbleViewBrowserTest() override {} | 47 ~ExtensionMessageBubbleViewBrowserTest() override {} |
| 63 | 48 |
| 49 // ExtensionMessageBubbleBrowserTest: |
| 50 void SetUpCommandLine(base::CommandLine* command_line) override; |
| 51 |
| 52 // TestBrowserDialog: |
| 53 void ShowDialog(const std::string& name) override; |
| 54 |
| 64 private: | 55 private: |
| 65 // ExtensionMessageBubbleBrowserTest: | 56 // ExtensionMessageBubbleBrowserTest: |
| 66 void CheckBubbleNative(Browser* browser, AnchorPosition anchor) override; | 57 void CheckBubbleNative(Browser* browser, AnchorPosition anchor) override; |
| 58 void CloseBubble(Browser* browser) override; |
| 67 void CloseBubbleNative(Browser* browser) override; | 59 void CloseBubbleNative(Browser* browser) override; |
| 68 void CheckBubbleIsNotPresentNative(Browser* browser) override; | 60 void CheckBubbleIsNotPresentNative(Browser* browser) override; |
| 69 void ClickLearnMoreButton(Browser* browser) override; | 61 void ClickLearnMoreButton(Browser* browser) override; |
| 70 void ClickActionButton(Browser* browser) override; | 62 void ClickActionButton(Browser* browser) override; |
| 71 void ClickDismissButton(Browser* browser) override; | 63 void ClickDismissButton(Browser* browser) override; |
| 72 | 64 |
| 65 // Whether to ignore requests from ExtensionMessageBubbleBrowserTest to |
| 66 // CloseBubble(). |
| 67 bool block_close_ = false; |
| 68 |
| 73 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleViewBrowserTest); | 69 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleViewBrowserTest); |
| 74 }; | 70 }; |
| 75 | 71 |
| 76 class ExtensionMessageBubbleViewBrowserTestLegacy | 72 class ExtensionMessageBubbleViewBrowserTestLegacy |
| 77 : public ExtensionMessageBubbleViewBrowserTest { | 73 : public ExtensionMessageBubbleViewBrowserTest { |
| 78 protected: | 74 protected: |
| 79 void SetUpCommandLine(base::CommandLine* command_line) override { | 75 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 80 ExtensionMessageBubbleViewBrowserTest::SetUpCommandLine(command_line); | 76 ExtensionMessageBubbleViewBrowserTest::SetUpCommandLine(command_line); |
| 81 override_redesign_.reset(); | 77 override_redesign_.reset(); |
| 82 override_redesign_.reset(new extensions::FeatureSwitch::ScopedOverride( | 78 override_redesign_.reset(new extensions::FeatureSwitch::ScopedOverride( |
| 83 extensions::FeatureSwitch::extension_action_redesign(), false)); | 79 extensions::FeatureSwitch::extension_action_redesign(), false)); |
| 84 } | 80 } |
| 85 }; | 81 }; |
| 86 | 82 |
| 83 void ExtensionMessageBubbleViewBrowserTest::SetUpCommandLine( |
| 84 base::CommandLine* command_line) { |
| 85 ExtensionMessageBubbleBrowserTest::SetUpCommandLine(command_line); |
| 86 // MD is required on Mac to get a Views bubble. On other platforms, it should |
| 87 // not affect the behavior of the bubble (just the appearance), so enable for |
| 88 // all platforms. |
| 89 command_line->AppendSwitch(switches::kExtendMdToSecondaryUi); |
| 90 } |
| 91 |
| 92 void ExtensionMessageBubbleViewBrowserTest::ShowDialog( |
| 93 const std::string& name) { |
| 94 // TODO(tapted): Add cases for all bubble types. |
| 95 EXPECT_EQ("devmode_warning", name); |
| 96 |
| 97 // When invoked this way, the dialog test harness must close the bubble. |
| 98 base::AutoReset<bool> guard(&block_close_, true); |
| 99 TestBubbleAnchoredToExtensionAction(); |
| 100 } |
| 101 |
| 87 void ExtensionMessageBubbleViewBrowserTest::CheckBubbleNative( | 102 void ExtensionMessageBubbleViewBrowserTest::CheckBubbleNative( |
| 88 Browser* browser, | 103 Browser* browser, |
| 89 AnchorPosition anchor) { | 104 AnchorPosition anchor) { |
| 90 ToolbarView* toolbar_view = GetToolbarViewForBrowser(browser); | 105 gfx::Rect reference_bounds = |
| 91 BrowserActionsContainer* container = toolbar_view->browser_actions(); | 106 GetAnchorReferenceBoundsForBrowser(browser, anchor); |
| 92 views::BubbleDialogDelegateView* bubble = container->active_bubble(); | 107 CheckBubbleAgainstReferenceBounds(GetViewsBubbleForBrowser(browser), |
| 93 views::View* anchor_view = nullptr; | 108 reference_bounds); |
| 94 switch (anchor) { | 109 } |
| 95 case ANCHOR_BROWSER_ACTION: | 110 |
| 96 DCHECK_GT(container->num_toolbar_actions(), 0u); | 111 void ExtensionMessageBubbleViewBrowserTest::CloseBubble(Browser* browser) { |
| 97 anchor_view = container->GetToolbarActionViewAt(0); | 112 if (!block_close_) |
| 98 break; | 113 ExtensionMessageBubbleBrowserTest::CloseBubble(browser); |
| 99 case ANCHOR_APP_MENU: | |
| 100 anchor_view = toolbar_view->app_menu_button(); | |
| 101 break; | |
| 102 } | |
| 103 CheckBubbleAndReferenceView(bubble, anchor_view); | |
| 104 } | 114 } |
| 105 | 115 |
| 106 void ExtensionMessageBubbleViewBrowserTest::CloseBubbleNative( | 116 void ExtensionMessageBubbleViewBrowserTest::CloseBubbleNative( |
| 107 Browser* browser) { | 117 Browser* browser) { |
| 108 BrowserActionsContainer* container = | 118 views::BubbleDialogDelegateView* bubble = GetViewsBubbleForBrowser(browser); |
| 109 GetToolbarViewForBrowser(browser)->browser_actions(); | |
| 110 views::BubbleDialogDelegateView* bubble = container->active_bubble(); | |
| 111 ASSERT_TRUE(bubble); | 119 ASSERT_TRUE(bubble); |
| 112 bubble->GetWidget()->Close(); | 120 bubble->GetWidget()->Close(); |
| 113 EXPECT_EQ(nullptr, container->active_bubble()); | 121 EXPECT_EQ(nullptr, GetViewsBubbleForBrowser(browser)); |
| 114 } | 122 } |
| 115 | 123 |
| 116 void ExtensionMessageBubbleViewBrowserTest::CheckBubbleIsNotPresentNative( | 124 void ExtensionMessageBubbleViewBrowserTest::CheckBubbleIsNotPresentNative( |
| 117 Browser* browser) { | 125 Browser* browser) { |
| 118 EXPECT_EQ( | 126 EXPECT_EQ(nullptr, GetViewsBubbleForBrowser(browser)); |
| 119 nullptr, | |
| 120 GetToolbarViewForBrowser(browser)->browser_actions()->active_bubble()); | |
| 121 } | 127 } |
| 122 | 128 |
| 123 void ExtensionMessageBubbleViewBrowserTest::ClickLearnMoreButton( | 129 void ExtensionMessageBubbleViewBrowserTest::ClickLearnMoreButton( |
| 124 Browser* browser) { | 130 Browser* browser) { |
| 125 ToolbarActionsBarBubbleViews* bubble = GetBubbleForBrowser(browser); | 131 ToolbarActionsBarBubbleViews* bubble = GetViewsBubbleForBrowser(browser); |
| 126 static_cast<views::LinkListener*>(bubble)->LinkClicked( | 132 static_cast<views::LinkListener*>(bubble)->LinkClicked( |
| 127 const_cast<views::Link*>(bubble->learn_more_button()), 0); | 133 const_cast<views::Link*>(bubble->learn_more_button()), 0); |
| 128 } | 134 } |
| 129 | 135 |
| 130 void ExtensionMessageBubbleViewBrowserTest::ClickActionButton( | 136 void ExtensionMessageBubbleViewBrowserTest::ClickActionButton( |
| 131 Browser* browser) { | 137 Browser* browser) { |
| 132 ToolbarActionsBarBubbleViews* bubble = GetBubbleForBrowser(browser); | 138 ToolbarActionsBarBubbleViews* bubble = GetViewsBubbleForBrowser(browser); |
| 133 bubble->GetDialogClientView()->AcceptWindow(); | 139 bubble->GetDialogClientView()->AcceptWindow(); |
| 134 } | 140 } |
| 135 | 141 |
| 136 void ExtensionMessageBubbleViewBrowserTest::ClickDismissButton( | 142 void ExtensionMessageBubbleViewBrowserTest::ClickDismissButton( |
| 137 Browser* browser) { | 143 Browser* browser) { |
| 138 ToolbarActionsBarBubbleViews* bubble = GetBubbleForBrowser(browser); | 144 ToolbarActionsBarBubbleViews* bubble = GetViewsBubbleForBrowser(browser); |
| 139 bubble->GetDialogClientView()->CancelWindow(); | 145 bubble->GetDialogClientView()->CancelWindow(); |
| 140 } | 146 } |
| 141 | 147 |
| 142 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest, | 148 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest, |
| 143 ExtensionBubbleAnchoredToExtensionAction) { | 149 ExtensionBubbleAnchoredToExtensionAction) { |
| 144 TestBubbleAnchoredToExtensionAction(); | 150 TestBubbleAnchoredToExtensionAction(); |
| 145 } | 151 } |
| 146 | 152 |
| 147 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTestLegacy, | 153 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTestLegacy, |
| 148 ExtensionBubbleAnchoredToAppMenu) { | 154 ExtensionBubbleAnchoredToAppMenu) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 232 |
| 227 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest, | 233 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest, |
| 228 TestClickingActionButton) { | 234 TestClickingActionButton) { |
| 229 TestClickingActionButton(); | 235 TestClickingActionButton(); |
| 230 } | 236 } |
| 231 | 237 |
| 232 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest, | 238 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest, |
| 233 TestClickingDismissButton) { | 239 TestClickingDismissButton) { |
| 234 TestClickingDismissButton(); | 240 TestClickingDismissButton(); |
| 235 } | 241 } |
| 242 |
| 243 // BrowserDialogTest for the warning bubble that appears at startup when there |
| 244 // are extensions installed in developer mode. Can be invoked interactively with |
| 245 // --gtest_filter=BrowserDialogTest.Invoke. |
| 246 IN_PROC_BROWSER_TEST_F(ExtensionMessageBubbleViewBrowserTest, |
| 247 InvokeDialog_devmode_warning) { |
| 248 RunDialog(); |
| 249 } |
| OLD | NEW |