Chromium Code Reviews| Index: chrome/browser/media/router/presentation_service_delegate_impl_browsertest.cc |
| diff --git a/chrome/browser/media/router/presentation_service_delegate_impl_browsertest.cc b/chrome/browser/media/router/presentation_service_delegate_impl_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cec44f4e618526db99e179735a60715d38077f17 |
| --- /dev/null |
| +++ b/chrome/browser/media/router/presentation_service_delegate_impl_browsertest.cc |
| @@ -0,0 +1,121 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/command_line.h" |
| +#include "chrome/browser/media/router/media_router_impl.h" |
| +#include "chrome/browser/media/router/mock_media_router.h" |
| +#include "chrome/browser/media/router/mock_screen_availability_listener.h" |
| +#include "chrome/browser/media/router/presentation_service_delegate_impl.h" |
| +#include "chrome/browser/ui/browser_commands.h" |
| +#include "chrome/browser/ui/browser_finder.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "chrome/browser/ui/webui/media_router/media_router_ui.h" |
| +#include "chrome/common/chrome_switches.h" |
| +#include "chrome/test/base/in_process_browser_test.h" |
| +#include "chrome/test/base/ui_test_utils.h" |
| +#include "content/public/browser/navigation_details.h" |
| +#include "content/public/browser/render_process_host.h" |
| +#include "content/public/common/url_constants.h" |
| +#include "content/public/test/browser_test.h" |
| +#include "content/public/test/browser_test_utils.h" |
| +#include "net/test/embedded_test_server/embedded_test_server.h" |
| + |
| +using ::testing::_; |
| +using ::testing::Return; |
| + |
| +namespace media_router { |
| + |
| +namespace { |
| +const char kTestingPage[] = "/empty.html"; |
| +} |
| + |
| +using content::WebContents; |
|
mark a. foltz
2015/05/14 22:20:47
Declare all usings above
|
| +using content::RenderFrameHost; |
| + |
| +class PresentationServiceDelegateImplBrowserTest : public InProcessBrowserTest { |
|
mark a. foltz
2015/05/14 22:20:47
Why does this need to be a browser test? It seems
|
| + public: |
| + PresentationServiceDelegateImplBrowserTest() { |
| + base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| + switches::kEnableMediaRouter); |
| + } |
| + ~PresentationServiceDelegateImplBrowserTest() override {} |
| + |
| + void SetUpOnMainThread() override { |
| + InProcessBrowserTest::SetUpOnMainThread(); |
| + ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| + |
| + WebContents* web_contents = |
| + browser()->tab_strip_model()->GetActiveWebContents(); |
| + ASSERT_TRUE(web_contents); |
| + |
| + source_manager_ = |
| + PresentationServiceDelegateImpl::FromWebContents(web_contents); |
| + ASSERT_TRUE(source_manager_); |
| + |
| + // TODO(imcheng): Should probably stub out the MediaRouteProviderManagerHost |
| + // instead of MediaRouter in browser tests. |
|
mark a. foltz
2015/05/14 22:20:47
Why?
|
| + source_manager_->SetMediaRouterForTest(&router_); |
| + } |
| + |
| + void TearDown() override { InProcessBrowserTest::TearDown(); } |
| + |
| + PresentationServiceDelegateImpl* source_manager_; |
| + MockMediaRouter router_; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(PresentationServiceDelegateImplBrowserTest); |
| +}; |
| + |
| +// Test disabled for now since currently there is currently no way to |
| +// trigger the creation of PresentationServiceImpl on the RenderFrameHost from |
| +// here. It is lazily initialized via mojo from PresentationDispatcher on |
| +// renderer process. |
| +// TODO(imcheng): Re-enable this test when we find a way to trigger the |
| +// instantiation of PresentationServiceImpl. |
| +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
|
| + DISABLED_RemoveObserversOnNavigation) { |
| + WebContents* web_contents = |
| + browser()->tab_strip_model()->GetActiveWebContents(); |
| + RenderFrameHost* rfh = web_contents->GetMainFrame(); |
| + ASSERT_TRUE(rfh); |
| + |
| + GURL gurl = embedded_test_server()->GetURL(kTestingPage); |
| + |
| + ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), gurl, 1); |
| + |
| + MockScreenAvailabilityListener mock_listener1("http://fooUrl"); |
| + MockScreenAvailabilityListener mock_listener2("http://barUrl"); |
| + |
| + PresentationServiceDelegateImpl::RenderFrameHostId rfh_id( |
| + PresentationServiceDelegateImpl::GetRenderFrameHostId( |
| + web_contents->GetMainFrame())); |
| + EXPECT_CALL(router_, RegisterMediaSinksObserver(_)) |
| + .Times(2) |
| + .WillRepeatedly(Return(true)); |
| + EXPECT_TRUE(source_manager_->AddScreenAvailabilityListener( |
| + rfh_id.first, rfh_id.second, &mock_listener1)); |
| + EXPECT_TRUE(source_manager_->AddScreenAvailabilityListener( |
| + rfh_id.first, rfh_id.second, &mock_listener2)); |
| + |
| + const auto& observers = source_manager_->observers_; |
| + auto it = observers.find(rfh_id); |
| + ASSERT_TRUE(it != observers.end()); |
| + EXPECT_EQ(2u, it->second.size()); |
| + |
| + // In-page navigation; should not unregister observers. |
| + ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| + browser(), GURL(gurl.spec() + "#blah"), 1); |
| + it = observers.find(rfh_id); |
| + ASSERT_TRUE(it != observers.end()); |
| + EXPECT_EQ(2u, it->second.size()); |
| + |
| + EXPECT_CALL(router_, UnregisterMediaSinksObserver(_)).Times(2); |
| + // Navigating away should cause registered observers to be removed. |
| + ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| + browser(), GURL("about:blank"), 1); |
| + it = observers.find(rfh_id); |
| + EXPECT_TRUE(it == observers.end()); |
| +} |
| + |
| +} // namespace media_router |