| 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/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/browser_commands.h" | 9 #include "chrome/browser/ui/browser_commands.h" |
| 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 10 #include "chrome/browser/ui/toolbar/media_router_action.h" | 11 #include "chrome/browser/ui/toolbar/media_router_action.h" |
| 11 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" | 12 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" |
| 12 #include "chrome/browser/ui/views/frame/browser_view.h" | 13 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 13 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" | 14 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" |
| 14 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 15 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
| 15 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" | 16 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" |
| 16 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 17 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 30 | 31 |
| 31 void SetUpOnMainThread() override { | 32 void SetUpOnMainThread() override { |
| 32 InProcessBrowserTest::SetUpOnMainThread(); | 33 InProcessBrowserTest::SetUpOnMainThread(); |
| 33 | 34 |
| 34 BrowserActionsContainer* browser_actions_container = | 35 BrowserActionsContainer* browser_actions_container = |
| 35 BrowserView::GetBrowserViewForBrowser(browser()) | 36 BrowserView::GetBrowserViewForBrowser(browser()) |
| 36 ->toolbar() | 37 ->toolbar() |
| 37 ->browser_actions(); | 38 ->browser_actions(); |
| 38 ASSERT_TRUE(browser_actions_container); | 39 ASSERT_TRUE(browser_actions_container); |
| 39 | 40 |
| 40 media_router_action_.reset(new MediaRouterAction(browser())); | 41 browser_action_test_util_.reset(new BrowserActionTestUtil(browser(), |
| 42 false)); |
| 43 media_router_action_.reset(new MediaRouterAction(browser(), |
| 44 browser_action_test_util_->GetToolbarActionsBar())); |
| 41 | 45 |
| 42 // Sets delegate on |media_router_action_|. | 46 // Sets delegate on |media_router_action_|. |
| 43 toolbar_action_view_.reset( | 47 toolbar_action_view_.reset( |
| 44 new ToolbarActionView(media_router_action_.get(), browser()->profile(), | 48 new ToolbarActionView(media_router_action_.get(), browser()->profile(), |
| 45 browser_actions_container)); | 49 browser_actions_container)); |
| 46 } | 50 } |
| 47 | 51 |
| 48 void TearDownOnMainThread() override { | 52 void TearDownOnMainThread() override { |
| 49 toolbar_action_view_.reset(); | 53 toolbar_action_view_.reset(); |
| 50 media_router_action_.reset(); | 54 media_router_action_.reset(); |
| 55 browser_action_test_util_.reset(); |
| 51 InProcessBrowserTest::TearDownOnMainThread(); | 56 InProcessBrowserTest::TearDownOnMainThread(); |
| 52 } | 57 } |
| 53 | 58 |
| 54 void OpenMediaRouterDialogAndWaitForNewWebContents() { | 59 void OpenMediaRouterDialogAndWaitForNewWebContents() { |
| 55 content::TestNavigationObserver nav_observer(NULL); | 60 content::TestNavigationObserver nav_observer(NULL); |
| 56 nav_observer.StartWatchingNewWebContents(); | 61 nav_observer.StartWatchingNewWebContents(); |
| 57 | 62 |
| 58 AppMenuButton* app_menu_button = | 63 AppMenuButton* app_menu_button = |
| 59 BrowserView::GetBrowserViewForBrowser(browser()) | 64 BrowserView::GetBrowserViewForBrowser(browser()) |
| 60 ->toolbar() | 65 ->toolbar() |
| (...skipping 14 matching lines...) Expand all Loading... |
| 75 nav_observer.StopWatchingNewWebContents(); | 80 nav_observer.StopWatchingNewWebContents(); |
| 76 } | 81 } |
| 77 | 82 |
| 78 void ExecuteMediaRouterAction(AppMenuButton* app_menu_button) { | 83 void ExecuteMediaRouterAction(AppMenuButton* app_menu_button) { |
| 79 EXPECT_TRUE(app_menu_button->IsMenuShowing()); | 84 EXPECT_TRUE(app_menu_button->IsMenuShowing()); |
| 80 media_router_action_->ExecuteAction(true); | 85 media_router_action_->ExecuteAction(true); |
| 81 } | 86 } |
| 82 | 87 |
| 83 protected: | 88 protected: |
| 84 // Must be initialized after |InProcessBrowserTest::SetUpOnMainThread|. | 89 // Must be initialized after |InProcessBrowserTest::SetUpOnMainThread|. |
| 90 scoped_ptr<BrowserActionTestUtil> browser_action_test_util_; |
| 85 scoped_ptr<MediaRouterAction> media_router_action_; | 91 scoped_ptr<MediaRouterAction> media_router_action_; |
| 86 | 92 |
| 87 // ToolbarActionView constructed to set the delegate on |mr_action|. | 93 // ToolbarActionView constructed to set the delegate on |mr_action|. |
| 88 scoped_ptr<ToolbarActionView> toolbar_action_view_; | 94 scoped_ptr<ToolbarActionView> toolbar_action_view_; |
| 89 }; | 95 }; |
| 90 | 96 |
| 91 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, | 97 IN_PROC_BROWSER_TEST_F(MediaRouterUIBrowserTest, |
| 92 OpenDialogWithMediaRouterAction) { | 98 OpenDialogWithMediaRouterAction) { |
| 93 // We start off at about:blank page. | 99 // We start off at about:blank page. |
| 94 // Make sure there is 1 tab and media router is enabled. | 100 // Make sure there is 1 tab and media router is enabled. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 108 | 114 |
| 109 // Navigate away. | 115 // Navigate away. |
| 110 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 116 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 111 | 117 |
| 112 // The navigation should have removed the previously created dialog. | 118 // The navigation should have removed the previously created dialog. |
| 113 // We expect a new dialog WebContents to be created by calling this. | 119 // We expect a new dialog WebContents to be created by calling this. |
| 114 OpenMediaRouterDialogAndWaitForNewWebContents(); | 120 OpenMediaRouterDialogAndWaitForNewWebContents(); |
| 115 } | 121 } |
| 116 | 122 |
| 117 } // namespace media_router | 123 } // namespace media_router |
| OLD | NEW |