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