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
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "chrome/browser/ui/browser_commands.h"
7 #include "chrome/browser/ui/browser_finder.h"
8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller.h"
10 #include "chrome/browser/ui/webui/media_router/media_router_ui.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/public/common/url_constants.h"
15 #include "content/public/test/browser_test_utils.h"
16 #include "content/public/test/test_navigation_observer.h"
18 using content::WebContents
;
19 using content::TestNavigationObserver
;
21 namespace media_router
{
23 class MediaRouterDialogControllerBrowserTest
: public InProcessBrowserTest
{
25 MediaRouterDialogControllerBrowserTest()
26 : dialog_controller_(nullptr),
28 media_router_dialog_(nullptr) {
29 base::CommandLine::ForCurrentProcess()->AppendSwitch(
30 switches::kEnableMediaRouter
);
32 ~MediaRouterDialogControllerBrowserTest() override
{}
35 void SetUpOnMainThread() override
{
36 // Start with one window with one tab.
37 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
38 EXPECT_EQ(1, browser()->tab_strip_model()->count());
40 initiator_
= browser()->tab_strip_model()->GetActiveWebContents();
41 ASSERT_TRUE(initiator_
);
42 MediaRouterDialogController::CreateForWebContents(initiator_
);
44 MediaRouterDialogController::FromWebContents(initiator_
);
45 ASSERT_TRUE(dialog_controller_
);
47 // Get the media router dialog for the initiator.
48 media_router_dialog_
= dialog_controller_
->ShowMediaRouterDialog();
49 ASSERT_TRUE(media_router_dialog_
);
52 MediaRouterDialogController
* dialog_controller_
;
53 WebContents
* initiator_
;
54 WebContents
* media_router_dialog_
;
57 DISALLOW_COPY_AND_ASSIGN(MediaRouterDialogControllerBrowserTest
);
60 IN_PROC_BROWSER_TEST_F(MediaRouterDialogControllerBrowserTest
, ShowDialog
) {
61 // Waits for the dialog to initialize.
62 TestNavigationObserver
nav_observer(media_router_dialog_
);
65 // New media router dialog is a constrained window, so the number of
67 EXPECT_EQ(1, browser()->tab_strip_model()->count());
68 EXPECT_NE(initiator_
, media_router_dialog_
);
69 EXPECT_EQ(media_router_dialog_
, dialog_controller_
->GetMediaRouterDialog());
71 content::WebUI
* web_ui
= media_router_dialog_
->GetWebUI();
73 MediaRouterUI
* media_router_ui
=
74 static_cast<MediaRouterUI
*>(web_ui
->GetController());
75 ASSERT_TRUE(media_router_ui
);
78 IN_PROC_BROWSER_TEST_F(MediaRouterDialogControllerBrowserTest
, Navigate
) {
79 // New media router dialog is a constrained window, so the number of
81 EXPECT_EQ(1, browser()->tab_strip_model()->count());
82 EXPECT_EQ(media_router_dialog_
, dialog_controller_
->GetMediaRouterDialog());
84 // Navigate to another URL.
85 content::WebContentsDestroyedWatcher
dialog_watcher(media_router_dialog_
);
87 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
89 // Blocks until the dialog WebContents has been destroyed.
90 dialog_watcher
.Wait();
92 // Entry has been removed.
93 EXPECT_FALSE(dialog_controller_
->GetMediaRouterDialog());
96 IN_PROC_BROWSER_TEST_F(MediaRouterDialogControllerBrowserTest
,
98 // New media router dialog is a constrained window, so the number of
100 EXPECT_EQ(1, browser()->tab_strip_model()->count());
101 EXPECT_EQ(media_router_dialog_
, dialog_controller_
->GetMediaRouterDialog());
103 // Crash initiator_'s renderer process.
104 content::WebContentsDestroyedWatcher
dialog_watcher(media_router_dialog_
);
105 content::RenderProcessHostWatcher
rph_watcher(initiator_
,
106 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT
);
108 ui_test_utils::NavigateToURL(browser(), GURL(content::kChromeUICrashURL
));
110 // Blocks until the dialog WebContents has been destroyed.
112 dialog_watcher
.Wait();
114 // Entry has been removed.
115 EXPECT_FALSE(dialog_controller_
->GetMediaRouterDialog());
118 } // namespace media_router