| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 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" | |
| 17 | |
| 18 using content::WebContents; | |
| 19 using content::TestNavigationObserver; | |
| 20 | |
| 21 namespace media_router { | |
| 22 | |
| 23 class MediaRouterDialogControllerBrowserTest : public InProcessBrowserTest { | |
| 24 public: | |
| 25 MediaRouterDialogControllerBrowserTest() | |
| 26 : dialog_controller_(nullptr), | |
| 27 initiator_(nullptr), | |
| 28 media_router_dialog_(nullptr) { | |
| 29 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 30 switches::kEnableMediaRouter); | |
| 31 } | |
| 32 ~MediaRouterDialogControllerBrowserTest() override {} | |
| 33 | |
| 34 protected: | |
| 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()); | |
| 39 | |
| 40 initiator_ = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 41 ASSERT_TRUE(initiator_); | |
| 42 MediaRouterDialogController::CreateForWebContents(initiator_); | |
| 43 dialog_controller_ = | |
| 44 MediaRouterDialogController::FromWebContents(initiator_); | |
| 45 ASSERT_TRUE(dialog_controller_); | |
| 46 | |
| 47 // Get the media router dialog for the initiator. | |
| 48 media_router_dialog_ = dialog_controller_->ShowMediaRouterDialog(); | |
| 49 ASSERT_TRUE(media_router_dialog_); | |
| 50 } | |
| 51 | |
| 52 MediaRouterDialogController* dialog_controller_; | |
| 53 WebContents* initiator_; | |
| 54 WebContents* media_router_dialog_; | |
| 55 | |
| 56 private: | |
| 57 DISALLOW_COPY_AND_ASSIGN(MediaRouterDialogControllerBrowserTest); | |
| 58 }; | |
| 59 | |
| 60 IN_PROC_BROWSER_TEST_F(MediaRouterDialogControllerBrowserTest, ShowDialog) { | |
| 61 // Waits for the dialog to initialize. | |
| 62 TestNavigationObserver nav_observer(media_router_dialog_); | |
| 63 nav_observer.Wait(); | |
| 64 | |
| 65 // New media router dialog is a constrained window, so the number of | |
| 66 // tabs is still 1. | |
| 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()); | |
| 70 | |
| 71 content::WebUI* web_ui = media_router_dialog_->GetWebUI(); | |
| 72 ASSERT_TRUE(web_ui); | |
| 73 MediaRouterUI* media_router_ui = | |
| 74 static_cast<MediaRouterUI*>(web_ui->GetController()); | |
| 75 ASSERT_TRUE(media_router_ui); | |
| 76 } | |
| 77 | |
| 78 IN_PROC_BROWSER_TEST_F(MediaRouterDialogControllerBrowserTest, Navigate) { | |
| 79 // New media router dialog is a constrained window, so the number of | |
| 80 // tabs is still 1. | |
| 81 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
| 82 EXPECT_EQ(media_router_dialog_, dialog_controller_->GetMediaRouterDialog()); | |
| 83 | |
| 84 // Navigate to another URL. | |
| 85 content::WebContentsDestroyedWatcher dialog_watcher(media_router_dialog_); | |
| 86 | |
| 87 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | |
| 88 | |
| 89 // Blocks until the dialog WebContents has been destroyed. | |
| 90 dialog_watcher.Wait(); | |
| 91 | |
| 92 // Entry has been removed. | |
| 93 EXPECT_FALSE(dialog_controller_->GetMediaRouterDialog()); | |
| 94 } | |
| 95 | |
| 96 IN_PROC_BROWSER_TEST_F(MediaRouterDialogControllerBrowserTest, | |
| 97 RenderProcessHost) { | |
| 98 // New media router dialog is a constrained window, so the number of | |
| 99 // tabs is still 1. | |
| 100 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
| 101 EXPECT_EQ(media_router_dialog_, dialog_controller_->GetMediaRouterDialog()); | |
| 102 | |
| 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); | |
| 107 | |
| 108 ui_test_utils::NavigateToURL(browser(), GURL(content::kChromeUICrashURL)); | |
| 109 | |
| 110 // Blocks until the dialog WebContents has been destroyed. | |
| 111 rph_watcher.Wait(); | |
| 112 dialog_watcher.Wait(); | |
| 113 | |
| 114 // Entry has been removed. | |
| 115 EXPECT_FALSE(dialog_controller_->GetMediaRouterDialog()); | |
| 116 } | |
| 117 | |
| 118 } // namespace media_router | |
| OLD | NEW |