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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/threading/thread_task_runner_handle.h" | 6 #include "base/threading/thread_task_runner_handle.h" |
| 7 #include "chrome/browser/extensions/browser_action_test_util.h" | 7 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 8 #include "chrome/browser/media/router/media_router_ui_service.h" | 8 #include "chrome/browser/media/router/media_router_ui_service.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" | 12 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" |
| 13 #include "chrome/browser/ui/toolbar/media_router_action.h" | 13 #include "chrome/browser/ui/toolbar/media_router_action.h" |
| 14 #include "chrome/browser/ui/toolbar/media_router_action_controller.h" | 14 #include "chrome/browser/ui/toolbar/media_router_action_controller.h" |
| 15 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" | 15 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" |
| 16 #include "chrome/browser/ui/views/frame/browser_view.h" | 16 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 17 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" | 17 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" |
| 18 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 18 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
| 19 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" | 19 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" |
| 20 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 20 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 21 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_im pl.h" | |
| 21 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
| 22 #include "chrome/test/base/in_process_browser_test.h" | 23 #include "chrome/test/base/in_process_browser_test.h" |
| 23 #include "chrome/test/base/ui_test_utils.h" | 24 #include "chrome/test/base/ui_test_utils.h" |
| 24 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/test/test_navigation_observer.h" | 26 #include "content/public/test/test_navigation_observer.h" |
| 26 #include "content/public/test/test_utils.h" | 27 #include "content/public/test/test_utils.h" |
| 27 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
| 28 | 29 |
| 29 namespace media_router { | 30 namespace media_router { |
| 30 | 31 |
| 31 class MediaRouterUIBrowserTest : public InProcessBrowserTest { | 32 class MediaRouterUIBrowserTest : public InProcessBrowserTest { |
| 32 public: | 33 public: |
| 33 MediaRouterUIBrowserTest() {} | 34 MediaRouterUIBrowserTest() {} |
| 34 ~MediaRouterUIBrowserTest() override {} | 35 ~MediaRouterUIBrowserTest() override {} |
| 35 | 36 |
| 36 void SetUpOnMainThread() override { | 37 void SetUpOnMainThread() override { |
| 37 InProcessBrowserTest::SetUpOnMainThread(); | 38 InProcessBrowserTest::SetUpOnMainThread(); |
| 38 | 39 |
| 39 BrowserActionsContainer* browser_actions_container = | 40 BrowserActionsContainer* browser_actions_container = |
| 40 BrowserView::GetBrowserViewForBrowser(browser()) | 41 BrowserView::GetBrowserViewForBrowser(browser()) |
| 41 ->toolbar() | 42 ->toolbar() |
| 42 ->browser_actions(); | 43 ->browser_actions(); |
| 43 ASSERT_TRUE(browser_actions_container); | 44 ASSERT_TRUE(browser_actions_container); |
| 44 | 45 toolbar_actions_bar_ = browser_actions_container->toolbar_actions_bar(); |
| 45 browser_action_test_util_.reset(new BrowserActionTestUtil(browser(), | |
| 46 false)); | |
| 47 media_router_action_.reset(new MediaRouterAction(browser(), | |
| 48 browser_action_test_util_->GetToolbarActionsBar())); | |
| 49 | |
| 50 toolbar_action_view_widget_ = new views::Widget(); | |
| 51 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | |
| 52 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 53 toolbar_action_view_widget_->Init(params); | |
| 54 toolbar_action_view_widget_->Show(); | |
| 55 | |
| 56 // Sets delegate on |media_router_action_|. | |
| 57 toolbar_action_view_ = new ToolbarActionView(media_router_action_.get(), | |
| 58 browser_actions_container); | |
| 59 toolbar_action_view_widget_->SetContentsView(toolbar_action_view_); | |
| 60 | 46 |
| 61 action_controller_ = | 47 action_controller_ = |
| 62 &MediaRouterUIService::Get(browser()->profile())->action_controller_; | 48 MediaRouterUIService::Get(browser()->profile())->action_controller(); |
| 63 | 49 |
| 64 issue_.reset(new Issue( | 50 issue_.reset(new Issue( |
| 65 "title notification", "message notification", | 51 "title notification", "message notification", |
| 66 media_router::IssueAction(media_router::IssueAction::TYPE_DISMISS), | 52 media_router::IssueAction(media_router::IssueAction::TYPE_DISMISS), |
| 67 std::vector<media_router::IssueAction>(), "route_id", | 53 std::vector<media_router::IssueAction>(), "route_id", |
| 68 media_router::Issue::NOTIFICATION, false, -1)); | 54 media_router::Issue::NOTIFICATION, false, -1)); |
| 69 | 55 |
| 70 routes_ = {MediaRoute("routeId1", MediaSource("sourceId"), "sinkId1", | 56 routes_ = {MediaRoute("routeId1", MediaSource("sourceId"), "sinkId1", |
| 71 "description", true, std::string(), true)}; | 57 "description", true, std::string(), true)}; |
| 72 } | 58 } |
| 73 | 59 |
| 74 void TearDownOnMainThread() override { | |
| 75 toolbar_action_view_widget_->Close(); | |
| 76 media_router_action_.reset(); | |
| 77 browser_action_test_util_.reset(); | |
| 78 InProcessBrowserTest::TearDownOnMainThread(); | |
| 79 } | |
| 80 | |
| 81 void OpenMediaRouterDialogAndWaitForNewWebContents() { | 60 void OpenMediaRouterDialogAndWaitForNewWebContents() { |
| 82 content::TestNavigationObserver nav_observer(NULL); | 61 content::TestNavigationObserver nav_observer(NULL); |
| 83 nav_observer.StartWatchingNewWebContents(); | 62 nav_observer.StartWatchingNewWebContents(); |
| 84 | 63 |
| 85 AppMenuButton* app_menu_button = | 64 AppMenuButton* app_menu_button = |
| 86 BrowserView::GetBrowserViewForBrowser(browser()) | 65 BrowserView::GetBrowserViewForBrowser(browser()) |
| 87 ->toolbar() | 66 ->toolbar() |
| 88 ->app_menu_button(); | 67 ->app_menu_button(); |
| 89 | 68 |
| 90 // When the Media Router Action executes, it opens a dialog with web | 69 // When the Media Router Action executes, it opens a dialog with web |
| 91 // contents to chrome://media-router. | 70 // contents to chrome://media-router. |
| 92 base::ThreadTaskRunnerHandle::Get()->PostTask( | 71 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 93 FROM_HERE, | 72 FROM_HERE, |
| 94 base::Bind(&MediaRouterUIBrowserTest::ExecuteMediaRouterAction, | 73 base::Bind(&MediaRouterUIBrowserTest::ExecuteMediaRouterAction, |
| 95 base::Unretained(this), app_menu_button)); | 74 base::Unretained(this), app_menu_button)); |
| 96 app_menu_button->ShowMenu(false); | 75 app_menu_button->ShowMenu(false); |
| 97 | 76 |
| 98 nav_observer.Wait(); | 77 nav_observer.Wait(); |
| 99 EXPECT_FALSE(app_menu_button->IsMenuShowing()); | 78 EXPECT_FALSE(app_menu_button->IsMenuShowing()); |
| 100 ASSERT_EQ(chrome::kChromeUIMediaRouterURL, | 79 ASSERT_EQ(chrome::kChromeUIMediaRouterURL, |
| 101 nav_observer.last_navigation_url().spec()); | 80 nav_observer.last_navigation_url().spec()); |
| 102 nav_observer.StopWatchingNewWebContents(); | 81 nav_observer.StopWatchingNewWebContents(); |
| 103 } | 82 } |
| 104 | 83 |
| 84 MediaRouterAction* GetMediaRouterAction() { | |
|
msw
2016/11/04 00:07:16
nit: expose MediaRouterDialogControllerImpl::actio
takumif
2016/11/09 04:37:27
Done.
| |
| 85 for (auto* action : toolbar_actions_bar_->GetActions()) { | |
| 86 if (action->GetId() == | |
| 87 ComponentToolbarActionsFactory::kMediaRouterActionId) { | |
| 88 return static_cast<MediaRouterAction*>(action); | |
| 89 } | |
| 90 } | |
| 91 NOTREACHED(); | |
| 92 return nullptr; | |
| 93 } | |
| 94 | |
| 105 void ExecuteMediaRouterAction(AppMenuButton* app_menu_button) { | 95 void ExecuteMediaRouterAction(AppMenuButton* app_menu_button) { |
| 106 EXPECT_TRUE(app_menu_button->IsMenuShowing()); | 96 EXPECT_TRUE(app_menu_button->IsMenuShowing()); |
| 107 media_router_action_->ExecuteAction(true); | 97 GetMediaRouterAction()->ExecuteAction(true); |
| 108 } | 98 } |
| 109 | 99 |
| 110 bool ActionExists() { | 100 bool ActionExists() { |
| 111 return ToolbarActionsModel::Get(browser()->profile()) | 101 return ToolbarActionsModel::Get(browser()->profile()) |
| 112 ->HasComponentAction( | 102 ->HasComponentAction( |
| 113 ComponentToolbarActionsFactory::kMediaRouterActionId); | 103 ComponentToolbarActionsFactory::kMediaRouterActionId); |
| 114 } | 104 } |
| 115 | 105 |
| 116 void SetAlwaysShowActionPref(bool always_show) { | 106 void SetAlwaysShowActionPref(bool always_show) { |
| 117 return ToolbarActionsModel::Get(browser()->profile()) | 107 return ToolbarActionsModel::Get(browser()->profile()) |
| 118 ->component_migration_helper() | 108 ->component_migration_helper() |
| 119 ->SetComponentActionPref( | 109 ->SetComponentActionPref( |
| 120 ComponentToolbarActionsFactory::kMediaRouterActionId, always_show); | 110 ComponentToolbarActionsFactory::kMediaRouterActionId, always_show); |
| 121 } | 111 } |
| 122 | 112 |
| 123 protected: | 113 protected: |
| 124 // Must be initialized after |InProcessBrowserTest::SetUpOnMainThread|. | 114 ToolbarActionsBar* toolbar_actions_bar_ = nullptr; |
| 125 std::unique_ptr<BrowserActionTestUtil> browser_action_test_util_; | |
| 126 std::unique_ptr<MediaRouterAction> media_router_action_; | |
| 127 | |
| 128 // ToolbarActionView constructed to set the delegate on | |
| 129 // |media_router_action_|. | |
| 130 ToolbarActionView* toolbar_action_view_ = nullptr; | |
| 131 | |
| 132 // Hosts the |toolbar_action_view_|. | |
| 133 views::Widget* toolbar_action_view_widget_ = nullptr; | |
| 134 | 115 |
| 135 std::unique_ptr<Issue> issue_; | 116 std::unique_ptr<Issue> issue_; |
| 136 | 117 |
| 137 // A vector of MediaRoutes that includes a local route. | 118 // A vector of MediaRoutes that includes a local route. |
| 138 std::vector<MediaRoute> routes_; | 119 std::vector<MediaRoute> routes_; |
| 139 | 120 |
| 140 MediaRouterActionController* action_controller_ = nullptr; | 121 MediaRouterActionController* action_controller_ = nullptr; |
| 141 }; | 122 }; |
| 142 | 123 |
| 143 // TODO(crbug.com/658005): Fails on multiple platforms. | 124 // TODO(crbug.com/658005): Fails on multiple platforms. |
| 144 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, | 125 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, |
| 145 DISABLED_OpenDialogWithMediaRouterAction) { | 126 DISABLED_OpenDialogWithMediaRouterAction) { |
| 146 // We start off at about:blank page. | 127 // We start off at about:blank page. |
| 147 // Make sure there is 1 tab and media router is enabled. | 128 // Make sure there is 1 tab and media router is enabled. |
| 148 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | 129 ASSERT_EQ(1, browser()->tab_strip_model()->count()); |
| 149 | 130 |
| 131 SetAlwaysShowActionPref(true); | |
|
msw
2016/11/04 00:07:16
Why is this important (for a disabled test)?
takumif
2016/11/09 04:37:27
This test was disabled recently.
Without this lin
| |
| 132 EXPECT_TRUE(ActionExists()); | |
| 133 | |
| 150 OpenMediaRouterDialogAndWaitForNewWebContents(); | 134 OpenMediaRouterDialogAndWaitForNewWebContents(); |
| 151 | 135 |
| 152 // Reload the browser and wait. | 136 // Reload the browser and wait. |
| 153 content::TestNavigationObserver reload_observer( | 137 content::TestNavigationObserver reload_observer( |
| 154 browser()->tab_strip_model()->GetActiveWebContents()); | 138 browser()->tab_strip_model()->GetActiveWebContents()); |
| 155 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); | 139 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 156 reload_observer.Wait(); | 140 reload_observer.Wait(); |
| 157 | 141 |
| 158 // The reload should have removed the previously created dialog. | 142 // The reload should have removed the previously created dialog. |
| 159 // We expect a new dialog WebContents to be created by calling this. | 143 // We expect a new dialog WebContents to be created by calling this. |
| 160 OpenMediaRouterDialogAndWaitForNewWebContents(); | 144 OpenMediaRouterDialogAndWaitForNewWebContents(); |
| 161 | 145 |
| 162 // Navigate away. | 146 // Navigate away. |
| 163 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 147 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 164 | 148 |
| 165 // The navigation should have removed the previously created dialog. | 149 // The navigation should have removed the previously created dialog. |
| 166 // We expect a new dialog WebContents to be created by calling this. | 150 // We expect a new dialog WebContents to be created by calling this. |
| 167 OpenMediaRouterDialogAndWaitForNewWebContents(); | 151 OpenMediaRouterDialogAndWaitForNewWebContents(); |
| 152 | |
| 153 SetAlwaysShowActionPref(false); | |
| 168 } | 154 } |
| 169 | 155 |
| 170 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, EphemeralToolbarIcon) { | 156 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, |
| 157 EphemeralToolbarIconForRoutesAndIssues) { | |
| 171 action_controller_->OnIssueUpdated(issue_.get()); | 158 action_controller_->OnIssueUpdated(issue_.get()); |
| 172 EXPECT_TRUE(ActionExists()); | 159 EXPECT_TRUE(ActionExists()); |
| 173 action_controller_->OnIssueUpdated(nullptr); | 160 action_controller_->OnIssueUpdated(nullptr); |
| 174 EXPECT_FALSE(ActionExists()); | 161 EXPECT_FALSE(ActionExists()); |
| 175 | 162 |
| 176 action_controller_->OnRoutesUpdated(routes_, std::vector<MediaRoute::Id>()); | 163 action_controller_->OnRoutesUpdated(routes_, std::vector<MediaRoute::Id>()); |
| 177 EXPECT_TRUE(ActionExists()); | 164 EXPECT_TRUE(ActionExists()); |
| 178 action_controller_->OnRoutesUpdated(std::vector<MediaRoute>(), | 165 action_controller_->OnRoutesUpdated(std::vector<MediaRoute>(), |
| 179 std::vector<MediaRoute::Id>()); | 166 std::vector<MediaRoute::Id>()); |
| 180 EXPECT_FALSE(ActionExists()); | 167 EXPECT_FALSE(ActionExists()); |
| 181 | 168 |
| 182 SetAlwaysShowActionPref(true); | 169 SetAlwaysShowActionPref(true); |
| 183 EXPECT_TRUE(ActionExists()); | 170 EXPECT_TRUE(ActionExists()); |
| 184 SetAlwaysShowActionPref(false); | 171 SetAlwaysShowActionPref(false); |
| 185 EXPECT_FALSE(ActionExists()); | 172 EXPECT_FALSE(ActionExists()); |
| 186 } | 173 } |
| 187 | 174 |
| 188 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, | 175 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, |
| 176 EphemeralToolbarIconForDialog) { | |
| 177 MediaRouterDialogControllerImpl* dialog_controller = | |
|
msw
2016/11/04 00:07:16
Why is the impl subclass used here? It seems like
takumif
2016/11/09 04:37:27
It'd be okay to use either, but only the Impl clas
msw
2016/11/09 20:32:33
I think it's generally beneficial to use the most
takumif
2016/11/10 01:53:59
Got it. Using MediaRouterDialogController. Thanks
| |
| 178 MediaRouterDialogControllerImpl::GetOrCreateForWebContents( | |
| 179 browser()->tab_strip_model()->GetActiveWebContents()); | |
| 180 | |
| 181 dialog_controller->ShowMediaRouterDialog(); | |
|
msw
2016/11/04 00:07:16
nit: EXPECT_FALSE(ActionExists()); above this
takumif
2016/11/09 04:37:27
Done.
| |
| 182 EXPECT_TRUE(ActionExists()); | |
| 183 dialog_controller->HideMediaRouterDialog(); | |
| 184 EXPECT_FALSE(ActionExists()); | |
| 185 | |
| 186 dialog_controller->ShowMediaRouterDialog(); | |
| 187 EXPECT_TRUE(ActionExists()); | |
| 188 // Clicking on the toolbar icon should hide both the dialog and the icon. | |
| 189 GetMediaRouterAction()->ExecuteAction(true); | |
| 190 EXPECT_FALSE(dialog_controller->IsShowingMediaRouterDialog()); | |
|
msw
2016/11/04 00:07:16
To be clear, calling ExecuteAction above calls thr
takumif
2016/11/09 04:37:27
Right.
| |
| 191 EXPECT_FALSE(ActionExists()); | |
| 192 | |
| 193 dialog_controller->ShowMediaRouterDialog(); | |
| 194 SetAlwaysShowActionPref(true); | |
| 195 // When the pref is set to true, hiding the dialog shouldn't hide the icon. | |
| 196 dialog_controller->HideMediaRouterDialog(); | |
| 197 EXPECT_TRUE(ActionExists()); | |
| 198 dialog_controller->ShowMediaRouterDialog(); | |
| 199 // While the dialog is showing, setting the pref to false shouldn't hide the | |
| 200 // icon. | |
| 201 SetAlwaysShowActionPref(false); | |
| 202 EXPECT_TRUE(ActionExists()); | |
| 203 dialog_controller->HideMediaRouterDialog(); | |
| 204 EXPECT_FALSE(ActionExists()); | |
| 205 } | |
| 206 | |
| 207 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, | |
| 189 EphemeralToolbarIconWithMultipleWindows) { | 208 EphemeralToolbarIconWithMultipleWindows) { |
| 190 action_controller_->OnRoutesUpdated(routes_, std::vector<MediaRoute::Id>()); | 209 action_controller_->OnRoutesUpdated(routes_, std::vector<MediaRoute::Id>()); |
| 191 EXPECT_TRUE(ActionExists()); | 210 EXPECT_TRUE(ActionExists()); |
| 192 | 211 |
| 193 // Opening and closing a window shouldn't affect the state of the ephemeral | 212 // Opening and closing a window shouldn't affect the state of the ephemeral |
| 194 // icon. Creating and removing the icon with multiple windows open should also | 213 // icon. Creating and removing the icon with multiple windows open should also |
| 195 // work. | 214 // work. |
| 196 Browser* browser2 = CreateBrowser(browser()->profile()); | 215 Browser* browser2 = CreateBrowser(browser()->profile()); |
| 197 EXPECT_TRUE(ActionExists()); | 216 EXPECT_TRUE(ActionExists()); |
| 198 action_controller_->OnRoutesUpdated(std::vector<MediaRoute>(), | 217 action_controller_->OnRoutesUpdated(std::vector<MediaRoute>(), |
| 199 std::vector<MediaRoute::Id>()); | 218 std::vector<MediaRoute::Id>()); |
| 200 EXPECT_FALSE(ActionExists()); | 219 EXPECT_FALSE(ActionExists()); |
| 201 action_controller_->OnRoutesUpdated(routes_, std::vector<MediaRoute::Id>()); | 220 action_controller_->OnRoutesUpdated(routes_, std::vector<MediaRoute::Id>()); |
| 202 EXPECT_TRUE(ActionExists()); | 221 EXPECT_TRUE(ActionExists()); |
| 203 browser2->window()->Close(); | 222 browser2->window()->Close(); |
| 204 EXPECT_TRUE(ActionExists()); | 223 EXPECT_TRUE(ActionExists()); |
| 205 } | 224 } |
| 206 | 225 |
| 207 } // namespace media_router | 226 } // namespace media_router |
| OLD | NEW |