| 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" |
| 6 #include "base/thread_task_runner_handle.h" |
| 5 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
| 6 #include "chrome/browser/ui/browser_commands.h" | 8 #include "chrome/browser/ui/browser_commands.h" |
| 7 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 8 #include "chrome/browser/ui/toolbar/media_router_action.h" | 10 #include "chrome/browser/ui/toolbar/media_router_action.h" |
| 9 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" | 11 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" |
| 10 #include "chrome/browser/ui/views/frame/browser_view.h" | 12 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 11 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 13 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
| 12 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" | 14 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" |
| 13 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 15 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 16 #include "chrome/common/url_constants.h" |
| 14 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/test/test_navigation_observer.h" | 20 #include "content/public/test/test_navigation_observer.h" |
| 18 #include "content/public/test/test_utils.h" | 21 #include "content/public/test/test_utils.h" |
| 19 | 22 |
| 20 namespace media_router { | 23 namespace media_router { |
| 21 | 24 |
| 22 class MediaRouterUIBrowserTest : public InProcessBrowserTest { | 25 class MediaRouterUIBrowserTest : public InProcessBrowserTest { |
| 23 public: | 26 public: |
| 24 MediaRouterUIBrowserTest() {} | 27 MediaRouterUIBrowserTest() {} |
| 25 ~MediaRouterUIBrowserTest() override {} | 28 ~MediaRouterUIBrowserTest() override {} |
| 26 | 29 |
| 27 void SetUpOnMainThread() override { | 30 void SetUpOnMainThread() override { |
| 28 InProcessBrowserTest::SetUpOnMainThread(); | 31 InProcessBrowserTest::SetUpOnMainThread(); |
| 29 | 32 |
| 30 BrowserActionsContainer* browser_actions_container = | 33 BrowserActionsContainer* browser_actions_container = |
| 31 BrowserView::GetBrowserViewForBrowser(browser()) | 34 BrowserView::GetBrowserViewForBrowser(browser()) |
| 32 ->toolbar() | 35 ->toolbar() |
| 33 ->browser_actions(); | 36 ->browser_actions(); |
| 34 ASSERT_TRUE(browser_actions_container); | 37 ASSERT_TRUE(browser_actions_container); |
| 35 | 38 |
| 36 media_router_action_.reset(new MediaRouterAction); | 39 media_router_action_.reset(new MediaRouterAction(browser())); |
| 37 | 40 |
| 38 // Sets delegate on |media_router_action_|. | 41 // Sets delegate on |media_router_action_|. |
| 39 toolbar_action_view_.reset( | 42 toolbar_action_view_.reset( |
| 40 new ToolbarActionView(media_router_action_.get(), browser()->profile(), | 43 new ToolbarActionView(media_router_action_.get(), browser()->profile(), |
| 41 browser_actions_container)); | 44 browser_actions_container)); |
| 42 } | 45 } |
| 43 | 46 |
| 44 void OpenMediaRouterDialogAndWaitForNewWebContents() { | 47 void OpenMediaRouterDialogAndWaitForNewWebContents() { |
| 45 content::TestNavigationObserver nav_observer(NULL); | 48 content::TestNavigationObserver nav_observer(NULL); |
| 46 nav_observer.StartWatchingNewWebContents(); | 49 nav_observer.StartWatchingNewWebContents(); |
| 50 |
| 51 ToolbarView* toolbar = |
| 52 BrowserView::GetBrowserViewForBrowser(browser())->toolbar(); |
| 53 |
| 54 // When the Media Router Action executes, it opens a dialog with web |
| 55 // contents to chrome://media-router. |
| 56 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 57 base::Bind(&MediaRouterUIBrowserTest::ExecuteMediaRouterAction, |
| 58 this, |
| 59 toolbar)); |
| 60 toolbar->ShowAppMenu(false); |
| 61 |
| 62 EXPECT_FALSE(toolbar->IsWrenchMenuShowing()); |
| 63 nav_observer.Wait(); |
| 64 ASSERT_EQ(chrome::kChromeUIMediaRouterURL, |
| 65 nav_observer.last_navigation_url().spec()); |
| 66 nav_observer.StopWatchingNewWebContents(); |
| 67 } |
| 68 |
| 69 void ExecuteMediaRouterAction(ToolbarView* toolbar) { |
| 70 EXPECT_TRUE(toolbar->IsWrenchMenuShowing()); |
| 47 media_router_action_->ExecuteAction(true); | 71 media_router_action_->ExecuteAction(true); |
| 48 nav_observer.Wait(); | |
| 49 nav_observer.StopWatchingNewWebContents(); | |
| 50 } | 72 } |
| 51 | 73 |
| 52 protected: | 74 protected: |
| 53 // Must be initialized after |InProcessBrowserTest::SetUpOnMainThread|. | 75 // Must be initialized after |InProcessBrowserTest::SetUpOnMainThread|. |
| 54 scoped_ptr<MediaRouterAction> media_router_action_; | 76 scoped_ptr<MediaRouterAction> media_router_action_; |
| 55 | 77 |
| 56 // ToolbarActionView constructed to set the delegate on |mr_action|. | 78 // ToolbarActionView constructed to set the delegate on |mr_action|. |
| 57 scoped_ptr<ToolbarActionView> toolbar_action_view_; | 79 scoped_ptr<ToolbarActionView> toolbar_action_view_; |
| 58 }; | 80 }; |
| 59 | 81 |
| 60 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, | 82 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, |
| 61 OpenDialogWithMediaRouterAction) { | 83 OpenDialogWithMediaRouterAction) { |
| 62 // We start off at about:blank page. | 84 // We start off at about:blank page. |
| 63 // Make sure there is 1 tab and media router is enabled. | 85 // Make sure there is 1 tab and media router is enabled. |
| 64 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | 86 ASSERT_EQ(1, browser()->tab_strip_model()->count()); |
| 65 | 87 |
| 66 OpenMediaRouterDialogAndWaitForNewWebContents(); | 88 OpenMediaRouterDialogAndWaitForNewWebContents(); |
| 67 | 89 |
| 68 // Reload the browser and wait. | 90 // Reload the browser and wait. |
| 69 content::TestNavigationObserver reload_observer( | 91 content::TestNavigationObserver reload_observer( |
| 70 browser()->tab_strip_model()->GetActiveWebContents()); | 92 browser()->tab_strip_model()->GetActiveWebContents()); |
| 71 chrome::Reload(browser(), CURRENT_TAB); | 93 chrome::Reload(browser(), CURRENT_TAB); |
| 72 reload_observer.Wait(); | 94 reload_observer.Wait(); |
| 73 | 95 |
| 74 // The reload should have removed the previously created dialog. | 96 // The reload should have removed the previously created dialog. |
| 75 // We expect a new dialog WebContents to be created by calling this. | 97 // We expect a new dialog WebContents to be created by calling this. |
| 76 OpenMediaRouterDialogAndWaitForNewWebContents(); | 98 OpenMediaRouterDialogAndWaitForNewWebContents(); |
| 77 | 99 |
| 78 // Navigate away and wait. | 100 // Navigate away. |
| 79 content::TestNavigationObserver nav_observer( | |
| 80 browser()->tab_strip_model()->GetActiveWebContents(), 1); | |
| 81 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 101 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 82 nav_observer.Wait(); | |
| 83 | 102 |
| 84 // The navigation should have removed the previously created dialog. | 103 // The navigation should have removed the previously created dialog. |
| 85 // We expect a new dialog WebContents to be created by calling this. | 104 // We expect a new dialog WebContents to be created by calling this. |
| 86 OpenMediaRouterDialogAndWaitForNewWebContents(); | 105 OpenMediaRouterDialogAndWaitForNewWebContents(); |
| 87 } | 106 } |
| 88 | 107 |
| 89 } // namespace media_router | 108 } // namespace media_router |
| OLD | NEW |