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