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/app/chrome_command_ids.h" | |
| 7 #include "chrome/browser/extensions/browser_action_test_util.h" | 8 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 8 #include "chrome/browser/media/router/media_router_ui_service.h" | 9 #include "chrome/browser/media/router/media_router_ui_service.h" |
| 10 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" | |
| 9 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_commands.h" | 12 #include "chrome/browser/ui/browser_commands.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" | 14 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" |
| 13 #include "chrome/browser/ui/toolbar/media_router_action.h" | 15 #include "chrome/browser/ui/toolbar/media_router_action.h" |
| 14 #include "chrome/browser/ui/toolbar/media_router_action_controller.h" | 16 #include "chrome/browser/ui/toolbar/media_router_action_controller.h" |
| 15 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" | 17 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" |
| 16 #include "chrome/browser/ui/views/frame/browser_view.h" | 18 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 19 #include "chrome/browser/ui/views/toolbar/app_menu.h" | |
| 17 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" | 20 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" |
| 18 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 21 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
| 19 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" | 22 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" |
| 20 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 23 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 21 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_im pl.h" | 24 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller_im pl.h" |
| 22 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 23 #include "chrome/test/base/in_process_browser_test.h" | 26 #include "chrome/test/base/in_process_browser_test.h" |
| 24 #include "chrome/test/base/ui_test_utils.h" | 27 #include "chrome/test/base/ui_test_utils.h" |
| 28 #include "content/public/browser/navigation_entry.h" | |
| 25 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 30 #include "content/public/common/context_menu_params.h" | |
| 26 #include "content/public/test/test_navigation_observer.h" | 31 #include "content/public/test/test_navigation_observer.h" |
| 27 #include "content/public/test/test_utils.h" | 32 #include "content/public/test/test_utils.h" |
| 28 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
| 29 | 34 |
| 30 namespace media_router { | 35 namespace media_router { |
| 31 | 36 |
| 32 class MediaRouterUIBrowserTest : public InProcessBrowserTest { | 37 class MediaRouterUIBrowserTest : public InProcessBrowserTest { |
| 33 public: | 38 public: |
| 34 MediaRouterUIBrowserTest() | 39 MediaRouterUIBrowserTest() |
| 35 : issue_(IssueInfo("title notification", | 40 : issue_(IssueInfo("title notification", |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 51 MediaRouterUIService::Get(browser()->profile())->action_controller(); | 56 MediaRouterUIService::Get(browser()->profile())->action_controller(); |
| 52 | 57 |
| 53 routes_ = {MediaRoute("routeId1", MediaSource("sourceId"), "sinkId1", | 58 routes_ = {MediaRoute("routeId1", MediaSource("sourceId"), "sinkId1", |
| 54 "description", true, std::string(), true)}; | 59 "description", true, std::string(), true)}; |
| 55 } | 60 } |
| 56 | 61 |
| 57 void OpenMediaRouterDialogAndWaitForNewWebContents() { | 62 void OpenMediaRouterDialogAndWaitForNewWebContents() { |
| 58 content::TestNavigationObserver nav_observer(NULL); | 63 content::TestNavigationObserver nav_observer(NULL); |
| 59 nav_observer.StartWatchingNewWebContents(); | 64 nav_observer.StartWatchingNewWebContents(); |
| 60 | 65 |
| 61 AppMenuButton* app_menu_button = | 66 AppMenuButton* app_menu_button = GetAppMenuButton(); |
| 62 BrowserView::GetBrowserViewForBrowser(browser()) | |
| 63 ->toolbar() | |
| 64 ->app_menu_button(); | |
| 65 | 67 |
| 66 // When the Media Router Action executes, it opens a dialog with web | 68 // When the Media Router Action executes, it opens a dialog with web |
| 67 // contents to chrome://media-router. | 69 // contents to chrome://media-router. |
| 68 base::ThreadTaskRunnerHandle::Get()->PostTask( | 70 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 69 FROM_HERE, | 71 FROM_HERE, |
| 70 base::Bind(&MediaRouterUIBrowserTest::ExecuteMediaRouterAction, | 72 base::Bind(&MediaRouterUIBrowserTest::ExecuteMediaRouterAction, |
| 71 base::Unretained(this), app_menu_button)); | 73 base::Unretained(this), app_menu_button)); |
| 72 | 74 |
| 73 base::RunLoop run_loop; | 75 base::RunLoop run_loop; |
| 74 app_menu_button->ShowMenu(false); | 76 app_menu_button->ShowMenu(false); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 98 ComponentToolbarActionsFactory::kMediaRouterActionId); | 100 ComponentToolbarActionsFactory::kMediaRouterActionId); |
| 99 } | 101 } |
| 100 | 102 |
| 101 void SetAlwaysShowActionPref(bool always_show) { | 103 void SetAlwaysShowActionPref(bool always_show) { |
| 102 return ToolbarActionsModel::Get(browser()->profile()) | 104 return ToolbarActionsModel::Get(browser()->profile()) |
| 103 ->component_migration_helper() | 105 ->component_migration_helper() |
| 104 ->SetComponentActionPref( | 106 ->SetComponentActionPref( |
| 105 ComponentToolbarActionsFactory::kMediaRouterActionId, always_show); | 107 ComponentToolbarActionsFactory::kMediaRouterActionId, always_show); |
| 106 } | 108 } |
| 107 | 109 |
| 110 AppMenuButton* GetAppMenuButton() { | |
| 111 return BrowserView::GetBrowserViewForBrowser(browser()) | |
| 112 ->toolbar() | |
| 113 ->app_menu_button(); | |
| 114 } | |
| 115 | |
| 108 protected: | 116 protected: |
| 109 ToolbarActionsBar* toolbar_actions_bar_ = nullptr; | 117 ToolbarActionsBar* toolbar_actions_bar_ = nullptr; |
| 110 | 118 |
| 111 Issue issue_; | 119 Issue issue_; |
| 112 | 120 |
| 113 // A vector of MediaRoutes that includes a local route. | 121 // A vector of MediaRoutes that includes a local route. |
| 114 std::vector<MediaRoute> routes_; | 122 std::vector<MediaRoute> routes_; |
| 115 | 123 |
| 116 MediaRouterActionController* action_controller_ = nullptr; | 124 MediaRouterActionController* action_controller_ = nullptr; |
| 117 }; | 125 }; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 140 // Navigate away. | 148 // Navigate away. |
| 141 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 149 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 142 | 150 |
| 143 // The navigation should have removed the previously created dialog. | 151 // The navigation should have removed the previously created dialog. |
| 144 // We expect a new dialog WebContents to be created by calling this. | 152 // We expect a new dialog WebContents to be created by calling this. |
| 145 OpenMediaRouterDialogAndWaitForNewWebContents(); | 153 OpenMediaRouterDialogAndWaitForNewWebContents(); |
| 146 | 154 |
| 147 SetAlwaysShowActionPref(false); | 155 SetAlwaysShowActionPref(false); |
| 148 } | 156 } |
| 149 | 157 |
| 158 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, OpenDialogFromContextMenu) { | |
| 159 // Start with one tab showing about:blank. | |
| 160 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | |
| 161 | |
| 162 content::WebContents* web_contents = | |
| 163 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 164 MediaRouterDialogController* dialog_controller = | |
| 165 MediaRouterDialogController::GetOrCreateForWebContents( | |
| 166 browser()->tab_strip_model()->GetActiveWebContents()); | |
| 167 content::ContextMenuParams params; | |
| 168 params.page_url = web_contents->GetController().GetActiveEntry()->GetURL(); | |
| 169 TestRenderViewContextMenu menu(web_contents->GetMainFrame(), params); | |
| 170 menu.Init(); | |
| 171 | |
| 172 ASSERT_TRUE(menu.IsItemPresent(IDC_ROUTE_MEDIA)); | |
| 173 ASSERT_FALSE(dialog_controller->IsShowingMediaRouterDialog()); | |
| 174 menu.ExecuteCommand(IDC_ROUTE_MEDIA, 0); | |
| 175 EXPECT_TRUE(dialog_controller->IsShowingMediaRouterDialog()); | |
| 176 | |
| 177 // Executing the command again should be a no-op, and there should only be one | |
| 178 // dialog to close. | |
|
apacible
2017/01/12 19:06:50
Suggestion: "...should only be one dialog opened p
takumif
2017/01/12 21:44:50
Done.
| |
| 179 menu.ExecuteCommand(IDC_ROUTE_MEDIA, 0); | |
| 180 EXPECT_TRUE(dialog_controller->IsShowingMediaRouterDialog()); | |
| 181 dialog_controller->HideMediaRouterDialog(); | |
| 182 EXPECT_FALSE(dialog_controller->IsShowingMediaRouterDialog()); | |
| 183 } | |
| 184 | |
| 185 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, OpenDialogFromAppMenu) { | |
| 186 // Start with one tab showing about:blank. | |
| 187 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | |
| 188 | |
| 189 AppMenuButton* menu_button = GetAppMenuButton(); | |
| 190 base::RunLoop run_loop; | |
| 191 menu_button->ShowMenu(false); | |
| 192 run_loop.RunUntilIdle(); | |
| 193 | |
| 194 MediaRouterDialogController* dialog_controller = | |
| 195 MediaRouterDialogController::GetOrCreateForWebContents( | |
| 196 browser()->tab_strip_model()->GetActiveWebContents()); | |
| 197 AppMenu* menu = menu_button->app_menu_for_testing(); | |
| 198 ASSERT_FALSE(dialog_controller->IsShowingMediaRouterDialog()); | |
| 199 menu->ExecuteCommand(IDC_ROUTE_MEDIA, 0); | |
| 200 EXPECT_TRUE(dialog_controller->IsShowingMediaRouterDialog()); | |
| 201 | |
| 202 // Executing the command again should be a no-op, and there should only be one | |
| 203 // dialog to close. | |
| 204 menu->ExecuteCommand(IDC_ROUTE_MEDIA, 0); | |
| 205 EXPECT_TRUE(dialog_controller->IsShowingMediaRouterDialog()); | |
| 206 dialog_controller->HideMediaRouterDialog(); | |
| 207 EXPECT_FALSE(dialog_controller->IsShowingMediaRouterDialog()); | |
| 208 } | |
| 209 | |
| 210 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, OpenDialogsInMultipleTabs) { | |
| 211 // Start with two tabs. | |
| 212 chrome::NewTab(browser()); | |
| 213 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | |
| 214 MediaRouterDialogController* dialog_controller1 = | |
| 215 MediaRouterDialogController::GetOrCreateForWebContents( | |
| 216 browser()->tab_strip_model()->GetWebContentsAt(0)); | |
| 217 MediaRouterDialogController* dialog_controller2 = | |
| 218 MediaRouterDialogController::GetOrCreateForWebContents( | |
| 219 browser()->tab_strip_model()->GetWebContentsAt(1)); | |
| 220 | |
| 221 SetAlwaysShowActionPref(true); | |
|
apacible
2017/01/12 19:06:50
Is this needed? Why is this different from the oth
takumif
2017/01/12 21:44:50
This is to show the toolbar action which I use in
| |
| 222 | |
| 223 // Open a dialog in the first tab using the toolbar action. | |
| 224 browser()->tab_strip_model()->ActivateTabAt(0, true); | |
| 225 EXPECT_FALSE(dialog_controller1->IsShowingMediaRouterDialog()); | |
| 226 GetMediaRouterAction()->ExecuteAction(true); | |
| 227 EXPECT_TRUE(dialog_controller1->IsShowingMediaRouterDialog()); | |
| 228 | |
| 229 // Move to the second tab, which shouldn't have a dialog at first. Open and | |
| 230 // close a dialog in that tab. | |
| 231 browser()->tab_strip_model()->ActivateTabAt(1, true); | |
| 232 EXPECT_FALSE(dialog_controller2->IsShowingMediaRouterDialog()); | |
| 233 GetMediaRouterAction()->ExecuteAction(true); | |
| 234 EXPECT_TRUE(dialog_controller2->IsShowingMediaRouterDialog()); | |
| 235 GetMediaRouterAction()->ExecuteAction(true); | |
| 236 EXPECT_FALSE(dialog_controller2->IsShowingMediaRouterDialog()); | |
| 237 | |
| 238 // Move back to the first tab, whose dialog should still be open. Hide the | |
| 239 // dialog. | |
| 240 browser()->tab_strip_model()->ActivateTabAt(0, true); | |
| 241 EXPECT_TRUE(dialog_controller1->IsShowingMediaRouterDialog()); | |
| 242 GetMediaRouterAction()->ExecuteAction(true); | |
| 243 EXPECT_FALSE(dialog_controller1->IsShowingMediaRouterDialog()); | |
| 244 | |
| 245 SetAlwaysShowActionPref(false); | |
| 246 } | |
| 247 | |
| 150 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, | 248 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, |
| 151 EphemeralToolbarIconForRoutesAndIssues) { | 249 EphemeralToolbarIconForRoutesAndIssues) { |
| 152 action_controller_->OnIssue(issue_); | 250 action_controller_->OnIssue(issue_); |
| 153 EXPECT_TRUE(ActionExists()); | 251 EXPECT_TRUE(ActionExists()); |
| 154 action_controller_->OnIssuesCleared(); | 252 action_controller_->OnIssuesCleared(); |
| 155 EXPECT_FALSE(ActionExists()); | 253 EXPECT_FALSE(ActionExists()); |
| 156 | 254 |
| 157 action_controller_->OnRoutesUpdated(routes_, std::vector<MediaRoute::Id>()); | 255 action_controller_->OnRoutesUpdated(routes_, std::vector<MediaRoute::Id>()); |
| 158 EXPECT_TRUE(ActionExists()); | 256 EXPECT_TRUE(ActionExists()); |
| 159 action_controller_->OnRoutesUpdated(std::vector<MediaRoute>(), | 257 action_controller_->OnRoutesUpdated(std::vector<MediaRoute>(), |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 action_controller_->OnRoutesUpdated(std::vector<MediaRoute>(), | 310 action_controller_->OnRoutesUpdated(std::vector<MediaRoute>(), |
| 213 std::vector<MediaRoute::Id>()); | 311 std::vector<MediaRoute::Id>()); |
| 214 EXPECT_FALSE(ActionExists()); | 312 EXPECT_FALSE(ActionExists()); |
| 215 action_controller_->OnRoutesUpdated(routes_, std::vector<MediaRoute::Id>()); | 313 action_controller_->OnRoutesUpdated(routes_, std::vector<MediaRoute::Id>()); |
| 216 EXPECT_TRUE(ActionExists()); | 314 EXPECT_TRUE(ActionExists()); |
| 217 browser2->window()->Close(); | 315 browser2->window()->Close(); |
| 218 EXPECT_TRUE(ActionExists()); | 316 EXPECT_TRUE(ActionExists()); |
| 219 } | 317 } |
| 220 | 318 |
| 221 } // namespace media_router | 319 } // namespace media_router |
| OLD | NEW |