| 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/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
| 10 #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" |
| 11 #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" |
| 12 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" | 15 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" |
| 13 #include "chrome/browser/ui/views/frame/browser_view.h" | 16 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 14 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" | 17 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" |
| 15 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 18 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
| 16 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" | 19 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" |
| 17 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 20 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 18 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 19 #include "chrome/test/base/in_process_browser_test.h" | 22 #include "chrome/test/base/in_process_browser_test.h" |
| 20 #include "chrome/test/base/ui_test_utils.h" | 23 #include "chrome/test/base/ui_test_utils.h" |
| 21 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 47 toolbar_action_view_widget_ = new views::Widget(); | 50 toolbar_action_view_widget_ = new views::Widget(); |
| 48 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 51 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| 49 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 52 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 50 toolbar_action_view_widget_->Init(params); | 53 toolbar_action_view_widget_->Init(params); |
| 51 toolbar_action_view_widget_->Show(); | 54 toolbar_action_view_widget_->Show(); |
| 52 | 55 |
| 53 // Sets delegate on |media_router_action_|. | 56 // Sets delegate on |media_router_action_|. |
| 54 toolbar_action_view_ = new ToolbarActionView(media_router_action_.get(), | 57 toolbar_action_view_ = new ToolbarActionView(media_router_action_.get(), |
| 55 browser_actions_container); | 58 browser_actions_container); |
| 56 toolbar_action_view_widget_->SetContentsView(toolbar_action_view_); | 59 toolbar_action_view_widget_->SetContentsView(toolbar_action_view_); |
| 60 |
| 61 action_controller_ = |
| 62 &MediaRouterUIService::Get(browser()->profile())->action_controller_; |
| 63 |
| 64 issue_.reset(new Issue( |
| 65 "title notification", "message notification", |
| 66 media_router::IssueAction(media_router::IssueAction::TYPE_DISMISS), |
| 67 std::vector<media_router::IssueAction>(), "route_id", |
| 68 media_router::Issue::NOTIFICATION, false, -1)); |
| 69 |
| 70 routes_ = {MediaRoute("routeId1", MediaSource("sourceId"), "sinkId1", |
| 71 "description", true, std::string(), true)}; |
| 57 } | 72 } |
| 58 | 73 |
| 59 void TearDownOnMainThread() override { | 74 void TearDownOnMainThread() override { |
| 60 toolbar_action_view_widget_->Close(); | 75 toolbar_action_view_widget_->Close(); |
| 61 media_router_action_.reset(); | 76 media_router_action_.reset(); |
| 62 browser_action_test_util_.reset(); | 77 browser_action_test_util_.reset(); |
| 63 InProcessBrowserTest::TearDownOnMainThread(); | 78 InProcessBrowserTest::TearDownOnMainThread(); |
| 64 } | 79 } |
| 65 | 80 |
| 66 void OpenMediaRouterDialogAndWaitForNewWebContents() { | 81 void OpenMediaRouterDialogAndWaitForNewWebContents() { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 85 ASSERT_EQ(chrome::kChromeUIMediaRouterURL, | 100 ASSERT_EQ(chrome::kChromeUIMediaRouterURL, |
| 86 nav_observer.last_navigation_url().spec()); | 101 nav_observer.last_navigation_url().spec()); |
| 87 nav_observer.StopWatchingNewWebContents(); | 102 nav_observer.StopWatchingNewWebContents(); |
| 88 } | 103 } |
| 89 | 104 |
| 90 void ExecuteMediaRouterAction(AppMenuButton* app_menu_button) { | 105 void ExecuteMediaRouterAction(AppMenuButton* app_menu_button) { |
| 91 EXPECT_TRUE(app_menu_button->IsMenuShowing()); | 106 EXPECT_TRUE(app_menu_button->IsMenuShowing()); |
| 92 media_router_action_->ExecuteAction(true); | 107 media_router_action_->ExecuteAction(true); |
| 93 } | 108 } |
| 94 | 109 |
| 110 bool ActionExists() { |
| 111 return ToolbarActionsModel::Get(browser()->profile()) |
| 112 ->HasComponentAction( |
| 113 ComponentToolbarActionsFactory::kMediaRouterActionId); |
| 114 } |
| 115 |
| 116 void SetAlwaysShowActionPref(bool always_show) { |
| 117 return ToolbarActionsModel::Get(browser()->profile()) |
| 118 ->component_migration_helper() |
| 119 ->SetComponentActionPref( |
| 120 ComponentToolbarActionsFactory::kMediaRouterActionId, always_show); |
| 121 } |
| 122 |
| 95 protected: | 123 protected: |
| 96 // Must be initialized after |InProcessBrowserTest::SetUpOnMainThread|. | 124 // Must be initialized after |InProcessBrowserTest::SetUpOnMainThread|. |
| 97 std::unique_ptr<BrowserActionTestUtil> browser_action_test_util_; | 125 std::unique_ptr<BrowserActionTestUtil> browser_action_test_util_; |
| 98 std::unique_ptr<MediaRouterAction> media_router_action_; | 126 std::unique_ptr<MediaRouterAction> media_router_action_; |
| 99 | 127 |
| 100 // ToolbarActionView constructed to set the delegate on | 128 // ToolbarActionView constructed to set the delegate on |
| 101 // |media_router_action_|. | 129 // |media_router_action_|. |
| 102 ToolbarActionView* toolbar_action_view_; | 130 ToolbarActionView* toolbar_action_view_ = nullptr; |
| 103 | 131 |
| 104 // Hosts the |toolbar_action_view_|. | 132 // Hosts the |toolbar_action_view_|. |
| 105 views::Widget* toolbar_action_view_widget_; | 133 views::Widget* toolbar_action_view_widget_ = nullptr; |
| 134 |
| 135 std::unique_ptr<Issue> issue_; |
| 136 |
| 137 // A vector of MediaRoutes that includes a local route. |
| 138 std::vector<MediaRoute> routes_; |
| 139 |
| 140 MediaRouterActionController* action_controller_ = nullptr; |
| 106 }; | 141 }; |
| 107 | 142 |
| 108 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, | 143 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, |
| 109 OpenDialogWithMediaRouterAction) { | 144 OpenDialogWithMediaRouterAction) { |
| 110 // We start off at about:blank page. | 145 // We start off at about:blank page. |
| 111 // Make sure there is 1 tab and media router is enabled. | 146 // Make sure there is 1 tab and media router is enabled. |
| 112 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | 147 ASSERT_EQ(1, browser()->tab_strip_model()->count()); |
| 113 | 148 |
| 114 OpenMediaRouterDialogAndWaitForNewWebContents(); | 149 OpenMediaRouterDialogAndWaitForNewWebContents(); |
| 115 | 150 |
| 116 // Reload the browser and wait. | 151 // Reload the browser and wait. |
| 117 content::TestNavigationObserver reload_observer( | 152 content::TestNavigationObserver reload_observer( |
| 118 browser()->tab_strip_model()->GetActiveWebContents()); | 153 browser()->tab_strip_model()->GetActiveWebContents()); |
| 119 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); | 154 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 120 reload_observer.Wait(); | 155 reload_observer.Wait(); |
| 121 | 156 |
| 122 // The reload should have removed the previously created dialog. | 157 // The reload should have removed the previously created dialog. |
| 123 // We expect a new dialog WebContents to be created by calling this. | 158 // We expect a new dialog WebContents to be created by calling this. |
| 124 OpenMediaRouterDialogAndWaitForNewWebContents(); | 159 OpenMediaRouterDialogAndWaitForNewWebContents(); |
| 125 | 160 |
| 126 // Navigate away. | 161 // Navigate away. |
| 127 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 162 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 128 | 163 |
| 129 // The navigation should have removed the previously created dialog. | 164 // The navigation should have removed the previously created dialog. |
| 130 // We expect a new dialog WebContents to be created by calling this. | 165 // We expect a new dialog WebContents to be created by calling this. |
| 131 OpenMediaRouterDialogAndWaitForNewWebContents(); | 166 OpenMediaRouterDialogAndWaitForNewWebContents(); |
| 132 } | 167 } |
| 133 | 168 |
| 169 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, EphemeralToolbarIcon) { |
| 170 action_controller_->OnIssueUpdated(issue_.get()); |
| 171 EXPECT_TRUE(ActionExists()); |
| 172 action_controller_->OnIssueUpdated(nullptr); |
| 173 EXPECT_FALSE(ActionExists()); |
| 174 |
| 175 action_controller_->OnRoutesUpdated(routes_, std::vector<MediaRoute::Id>()); |
| 176 EXPECT_TRUE(ActionExists()); |
| 177 action_controller_->OnRoutesUpdated(std::vector<MediaRoute>(), |
| 178 std::vector<MediaRoute::Id>()); |
| 179 EXPECT_FALSE(ActionExists()); |
| 180 |
| 181 SetAlwaysShowActionPref(true); |
| 182 EXPECT_TRUE(ActionExists()); |
| 183 SetAlwaysShowActionPref(false); |
| 184 EXPECT_FALSE(ActionExists()); |
| 185 } |
| 186 |
| 187 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, |
| 188 EphemeralToolbarIconWithMultipleWindows) { |
| 189 action_controller_->OnRoutesUpdated(routes_, std::vector<MediaRoute::Id>()); |
| 190 EXPECT_TRUE(ActionExists()); |
| 191 |
| 192 // Opening and closing a window shouldn't affect the state of the ephemeral |
| 193 // icon. Creating and removing the icon with multiple windows open should also |
| 194 // work. |
| 195 Browser* browser2 = CreateBrowser(browser()->profile()); |
| 196 EXPECT_TRUE(ActionExists()); |
| 197 action_controller_->OnRoutesUpdated(std::vector<MediaRoute>(), |
| 198 std::vector<MediaRoute::Id>()); |
| 199 EXPECT_FALSE(ActionExists()); |
| 200 action_controller_->OnRoutesUpdated(routes_, std::vector<MediaRoute::Id>()); |
| 201 EXPECT_TRUE(ActionExists()); |
| 202 browser2->window()->Close(); |
| 203 EXPECT_TRUE(ActionExists()); |
| 204 } |
| 205 |
| 134 } // namespace media_router | 206 } // namespace media_router |
| OLD | NEW |