Chromium Code Reviews| 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/media/router/media_router_impl.h" | |
| 7 #include "chrome/browser/media/router/mock_media_router.h" | |
| 8 #include "chrome/browser/media/router/mock_screen_availability_listener.h" | |
| 9 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" | |
| 10 #include "chrome/browser/ui/browser_commands.h" | |
| 11 #include "chrome/browser/ui/browser_finder.h" | |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 13 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" | |
| 14 #include "chrome/common/chrome_switches.h" | |
| 15 #include "chrome/test/base/in_process_browser_test.h" | |
| 16 #include "chrome/test/base/ui_test_utils.h" | |
| 17 #include "content/public/browser/navigation_details.h" | |
| 18 #include "content/public/browser/render_process_host.h" | |
| 19 #include "content/public/common/url_constants.h" | |
| 20 #include "content/public/test/browser_test.h" | |
| 21 #include "content/public/test/browser_test_utils.h" | |
| 22 #include "net/test/embedded_test_server/embedded_test_server.h" | |
| 23 | |
| 24 using ::testing::_; | |
| 25 using ::testing::Return; | |
| 26 | |
| 27 namespace media_router { | |
| 28 | |
| 29 namespace { | |
| 30 const char kTestingPage[] = "/empty.html"; | |
| 31 } | |
| 32 | |
| 33 using content::WebContents; | |
|
mark a. foltz
2015/05/14 22:20:47
Declare all usings above
| |
| 34 using content::RenderFrameHost; | |
| 35 | |
| 36 class PresentationServiceDelegateImplBrowserTest : public InProcessBrowserTest { | |
|
mark a. foltz
2015/05/14 22:20:47
Why does this need to be a browser test? It seems
| |
| 37 public: | |
| 38 PresentationServiceDelegateImplBrowserTest() { | |
| 39 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 40 switches::kEnableMediaRouter); | |
| 41 } | |
| 42 ~PresentationServiceDelegateImplBrowserTest() override {} | |
| 43 | |
| 44 void SetUpOnMainThread() override { | |
| 45 InProcessBrowserTest::SetUpOnMainThread(); | |
| 46 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
| 47 | |
| 48 WebContents* web_contents = | |
| 49 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 50 ASSERT_TRUE(web_contents); | |
| 51 | |
| 52 source_manager_ = | |
| 53 PresentationServiceDelegateImpl::FromWebContents(web_contents); | |
| 54 ASSERT_TRUE(source_manager_); | |
| 55 | |
| 56 // TODO(imcheng): Should probably stub out the MediaRouteProviderManagerHost | |
| 57 // instead of MediaRouter in browser tests. | |
|
mark a. foltz
2015/05/14 22:20:47
Why?
| |
| 58 source_manager_->SetMediaRouterForTest(&router_); | |
| 59 } | |
| 60 | |
| 61 void TearDown() override { InProcessBrowserTest::TearDown(); } | |
| 62 | |
| 63 PresentationServiceDelegateImpl* source_manager_; | |
| 64 MockMediaRouter router_; | |
| 65 | |
| 66 private: | |
| 67 DISALLOW_COPY_AND_ASSIGN(PresentationServiceDelegateImplBrowserTest); | |
| 68 }; | |
| 69 | |
| 70 // Test disabled for now since currently there is currently no way to | |
| 71 // trigger the creation of PresentationServiceImpl on the RenderFrameHost from | |
| 72 // here. It is lazily initialized via mojo from PresentationDispatcher on | |
| 73 // renderer process. | |
| 74 // TODO(imcheng): Re-enable this test when we find a way to trigger the | |
| 75 // instantiation of PresentationServiceImpl. | |
| 76 IN_PROC_BROWSER_TEST_F(PresentationServiceDelegateImplBrowserTest, | |
|
mark a. foltz
2015/05/14 22:20:46
Given this isn't even enabled can we remove this f
| |
| 77 DISABLED_RemoveObserversOnNavigation) { | |
| 78 WebContents* web_contents = | |
| 79 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 80 RenderFrameHost* rfh = web_contents->GetMainFrame(); | |
| 81 ASSERT_TRUE(rfh); | |
| 82 | |
| 83 GURL gurl = embedded_test_server()->GetURL(kTestingPage); | |
| 84 | |
| 85 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), gurl, 1); | |
| 86 | |
| 87 MockScreenAvailabilityListener mock_listener1("http://fooUrl"); | |
| 88 MockScreenAvailabilityListener mock_listener2("http://barUrl"); | |
| 89 | |
| 90 PresentationServiceDelegateImpl::RenderFrameHostId rfh_id( | |
| 91 PresentationServiceDelegateImpl::GetRenderFrameHostId( | |
| 92 web_contents->GetMainFrame())); | |
| 93 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)) | |
| 94 .Times(2) | |
| 95 .WillRepeatedly(Return(true)); | |
| 96 EXPECT_TRUE(source_manager_->AddScreenAvailabilityListener( | |
| 97 rfh_id.first, rfh_id.second, &mock_listener1)); | |
| 98 EXPECT_TRUE(source_manager_->AddScreenAvailabilityListener( | |
| 99 rfh_id.first, rfh_id.second, &mock_listener2)); | |
| 100 | |
| 101 const auto& observers = source_manager_->observers_; | |
| 102 auto it = observers.find(rfh_id); | |
| 103 ASSERT_TRUE(it != observers.end()); | |
| 104 EXPECT_EQ(2u, it->second.size()); | |
| 105 | |
| 106 // In-page navigation; should not unregister observers. | |
| 107 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | |
| 108 browser(), GURL(gurl.spec() + "#blah"), 1); | |
| 109 it = observers.find(rfh_id); | |
| 110 ASSERT_TRUE(it != observers.end()); | |
| 111 EXPECT_EQ(2u, it->second.size()); | |
| 112 | |
| 113 EXPECT_CALL(router_, UnregisterMediaSinksObserver(_)).Times(2); | |
| 114 // Navigating away should cause registered observers to be removed. | |
| 115 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | |
| 116 browser(), GURL("about:blank"), 1); | |
| 117 it = observers.find(rfh_id); | |
| 118 EXPECT_TRUE(it == observers.end()); | |
| 119 } | |
| 120 | |
| 121 } // namespace media_router | |
| OLD | NEW |