| 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/thread_task_runner_handle.h" | 6 #include "base/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/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_commands.h" | 9 #include "chrome/browser/ui/browser_commands.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 #include "chrome/browser/ui/toolbar/media_router_action.h" | 11 #include "chrome/browser/ui/toolbar/media_router_action.h" |
| 12 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" | 12 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" |
| 13 #include "chrome/browser/ui/views/frame/browser_view.h" | 13 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 14 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" | 14 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" |
| 15 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 15 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
| 16 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" | 16 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" |
| 17 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 17 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 19 #include "chrome/test/base/in_process_browser_test.h" | 19 #include "chrome/test/base/in_process_browser_test.h" |
| 20 #include "chrome/test/base/ui_test_utils.h" | 20 #include "chrome/test/base/ui_test_utils.h" |
| 21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/test/test_navigation_observer.h" | 22 #include "content/public/test/test_navigation_observer.h" |
| 23 #include "content/public/test/test_utils.h" | 23 #include "content/public/test/test_utils.h" |
| 24 #include "ui/views/widget/widget.h" |
| 24 | 25 |
| 25 namespace media_router { | 26 namespace media_router { |
| 26 | 27 |
| 27 class MediaRouterUIBrowserTest : public InProcessBrowserTest { | 28 class MediaRouterUIBrowserTest : public InProcessBrowserTest { |
| 28 public: | 29 public: |
| 29 MediaRouterUIBrowserTest() {} | 30 MediaRouterUIBrowserTest() {} |
| 30 ~MediaRouterUIBrowserTest() override {} | 31 ~MediaRouterUIBrowserTest() override {} |
| 31 | 32 |
| 32 void SetUpOnMainThread() override { | 33 void SetUpOnMainThread() override { |
| 33 InProcessBrowserTest::SetUpOnMainThread(); | 34 InProcessBrowserTest::SetUpOnMainThread(); |
| 34 | 35 |
| 35 BrowserActionsContainer* browser_actions_container = | 36 BrowserActionsContainer* browser_actions_container = |
| 36 BrowserView::GetBrowserViewForBrowser(browser()) | 37 BrowserView::GetBrowserViewForBrowser(browser()) |
| 37 ->toolbar() | 38 ->toolbar() |
| 38 ->browser_actions(); | 39 ->browser_actions(); |
| 39 ASSERT_TRUE(browser_actions_container); | 40 ASSERT_TRUE(browser_actions_container); |
| 40 | 41 |
| 41 browser_action_test_util_.reset(new BrowserActionTestUtil(browser(), | 42 browser_action_test_util_.reset(new BrowserActionTestUtil(browser(), |
| 42 false)); | 43 false)); |
| 43 media_router_action_.reset(new MediaRouterAction(browser(), | 44 media_router_action_.reset(new MediaRouterAction(browser(), |
| 44 browser_action_test_util_->GetToolbarActionsBar())); | 45 browser_action_test_util_->GetToolbarActionsBar())); |
| 45 | 46 |
| 47 toolbar_action_view_widget_ = new views::Widget(); |
| 48 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| 49 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 50 toolbar_action_view_widget_->Init(params); |
| 51 toolbar_action_view_widget_->Show(); |
| 52 |
| 46 // Sets delegate on |media_router_action_|. | 53 // Sets delegate on |media_router_action_|. |
| 47 toolbar_action_view_.reset( | 54 toolbar_action_view_ = new ToolbarActionView(media_router_action_.get(), |
| 48 new ToolbarActionView(media_router_action_.get(), | 55 browser_actions_container); |
| 49 browser_actions_container)); | 56 toolbar_action_view_widget_->SetContentsView(toolbar_action_view_); |
| 50 } | 57 } |
| 51 | 58 |
| 52 void TearDownOnMainThread() override { | 59 void TearDownOnMainThread() override { |
| 53 toolbar_action_view_.reset(); | 60 toolbar_action_view_widget_->Close(); |
| 54 media_router_action_.reset(); | 61 media_router_action_.reset(); |
| 55 browser_action_test_util_.reset(); | 62 browser_action_test_util_.reset(); |
| 56 InProcessBrowserTest::TearDownOnMainThread(); | 63 InProcessBrowserTest::TearDownOnMainThread(); |
| 57 } | 64 } |
| 58 | 65 |
| 59 void OpenMediaRouterDialogAndWaitForNewWebContents() { | 66 void OpenMediaRouterDialogAndWaitForNewWebContents() { |
| 60 content::TestNavigationObserver nav_observer(NULL); | 67 content::TestNavigationObserver nav_observer(NULL); |
| 61 nav_observer.StartWatchingNewWebContents(); | 68 nav_observer.StartWatchingNewWebContents(); |
| 62 | 69 |
| 63 AppMenuButton* app_menu_button = | 70 AppMenuButton* app_menu_button = |
| (...skipping 19 matching lines...) Expand all Loading... |
| 83 void ExecuteMediaRouterAction(AppMenuButton* app_menu_button) { | 90 void ExecuteMediaRouterAction(AppMenuButton* app_menu_button) { |
| 84 EXPECT_TRUE(app_menu_button->IsMenuShowing()); | 91 EXPECT_TRUE(app_menu_button->IsMenuShowing()); |
| 85 media_router_action_->ExecuteAction(true); | 92 media_router_action_->ExecuteAction(true); |
| 86 } | 93 } |
| 87 | 94 |
| 88 protected: | 95 protected: |
| 89 // Must be initialized after |InProcessBrowserTest::SetUpOnMainThread|. | 96 // Must be initialized after |InProcessBrowserTest::SetUpOnMainThread|. |
| 90 scoped_ptr<BrowserActionTestUtil> browser_action_test_util_; | 97 scoped_ptr<BrowserActionTestUtil> browser_action_test_util_; |
| 91 scoped_ptr<MediaRouterAction> media_router_action_; | 98 scoped_ptr<MediaRouterAction> media_router_action_; |
| 92 | 99 |
| 93 // ToolbarActionView constructed to set the delegate on |mr_action|. | 100 // ToolbarActionView constructed to set the delegate on |
| 94 scoped_ptr<ToolbarActionView> toolbar_action_view_; | 101 // |media_router_action_|. |
| 102 ToolbarActionView* toolbar_action_view_; |
| 103 |
| 104 // Hosts the |toolbar_action_view_|. |
| 105 views::Widget* toolbar_action_view_widget_; |
| 95 }; | 106 }; |
| 96 | 107 |
| 97 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, | 108 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, |
| 98 OpenDialogWithMediaRouterAction) { | 109 OpenDialogWithMediaRouterAction) { |
| 99 // We start off at about:blank page. | 110 // We start off at about:blank page. |
| 100 // Make sure there is 1 tab and media router is enabled. | 111 // Make sure there is 1 tab and media router is enabled. |
| 101 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | 112 ASSERT_EQ(1, browser()->tab_strip_model()->count()); |
| 102 | 113 |
| 103 OpenMediaRouterDialogAndWaitForNewWebContents(); | 114 OpenMediaRouterDialogAndWaitForNewWebContents(); |
| 104 | 115 |
| 105 // Reload the browser and wait. | 116 // Reload the browser and wait. |
| 106 content::TestNavigationObserver reload_observer( | 117 content::TestNavigationObserver reload_observer( |
| 107 browser()->tab_strip_model()->GetActiveWebContents()); | 118 browser()->tab_strip_model()->GetActiveWebContents()); |
| 108 chrome::Reload(browser(), CURRENT_TAB); | 119 chrome::Reload(browser(), CURRENT_TAB); |
| 109 reload_observer.Wait(); | 120 reload_observer.Wait(); |
| 110 | 121 |
| 111 // The reload should have removed the previously created dialog. | 122 // The reload should have removed the previously created dialog. |
| 112 // We expect a new dialog WebContents to be created by calling this. | 123 // We expect a new dialog WebContents to be created by calling this. |
| 113 OpenMediaRouterDialogAndWaitForNewWebContents(); | 124 OpenMediaRouterDialogAndWaitForNewWebContents(); |
| 114 | 125 |
| 115 // Navigate away. | 126 // Navigate away. |
| 116 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 127 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 117 | 128 |
| 118 // The navigation should have removed the previously created dialog. | 129 // The navigation should have removed the previously created dialog. |
| 119 // We expect a new dialog WebContents to be created by calling this. | 130 // We expect a new dialog WebContents to be created by calling this. |
| 120 OpenMediaRouterDialogAndWaitForNewWebContents(); | 131 OpenMediaRouterDialogAndWaitForNewWebContents(); |
| 121 } | 132 } |
| 122 | 133 |
| 123 } // namespace media_router | 134 } // namespace media_router |
| OLD | NEW |