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 "chrome/test/media_router/media_router_e2e_browsertest.h" |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/stl_util.h" |
| 9 #include "chrome/browser/media/router/media_router.h" |
| 10 #include "chrome/browser/media/router/media_router_mojo_impl.h" |
| 11 #include "chrome/browser/media/router/media_router_mojo_impl_factory.h" |
| 12 #include "chrome/browser/media/router/media_source.h" |
| 13 #include "chrome/browser/media/router/media_source_helper.h" |
| 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/sessions/session_tab_helper.h" |
| 16 #include "chrome/browser/ui/browser_finder.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/test/base/ui_test_utils.h" |
| 19 #include "content/public/test/test_utils.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 |
| 22 // Use the following command to run e2e browser tests: |
| 23 // ./out/Debug/browser_tests --user-data-dir=<empty user data dir> \ |
| 24 // --extension-unpacked=<mr extension dir> \ |
| 25 // --receiver=<chromecast device name> \ |
| 26 // --enable-pixel-output-in-tests --run-manual \ |
| 27 // --gtest_filter=MediaRouterE2EBrowserTest.<test case name> \ |
| 28 // --enable-logging=stderr \ |
| 29 // --whitelisted-extension-id=enhhojjnijigcajfphajepfemndkmdlo \ |
| 30 // --ui-test-action-timeout=200000 \ |
| 31 // --enable-media-router |
| 32 |
| 33 namespace { |
| 34 // Command line argument to specify receiver, |
| 35 const char kReceiver[] = "receiver"; |
| 36 // URL to launch Castv2Player_Staging app on Chromecast |
| 37 const char kCastAppPresentationUrl[] = |
| 38 "https://google.com/cast#__castAppId__=BE6E4473"; |
| 39 } // namespace |
| 40 |
| 41 namespace media_router { |
| 42 |
| 43 MediaRouterE2EBrowserTest::MediaRouterE2EBrowserTest() |
| 44 : media_router_(nullptr) { |
| 45 } |
| 46 |
| 47 MediaRouterE2EBrowserTest::~MediaRouterE2EBrowserTest() { |
| 48 } |
| 49 |
| 50 void MediaRouterE2EBrowserTest::SetUpOnMainThread() { |
| 51 MediaRouterBaseBrowserTest::SetUpOnMainThread(); |
| 52 media_router_ = |
| 53 MediaRouterMojoImplFactory::GetApiForBrowserContext(browser()->profile()); |
| 54 DCHECK(media_router_); |
| 55 } |
| 56 |
| 57 void MediaRouterE2EBrowserTest::TearDownOnMainThread() { |
| 58 MediaRouterBaseBrowserTest::TearDownOnMainThread(); |
| 59 media_router_ = nullptr; |
| 60 } |
| 61 |
| 62 void MediaRouterE2EBrowserTest::OnRouteResponseReceived( |
| 63 scoped_ptr<MediaRoute> route, |
| 64 const std::string& error) { |
| 65 ASSERT_TRUE(route.get()); |
| 66 route_id_ = route->media_route_id(); |
| 67 } |
| 68 |
| 69 void MediaRouterE2EBrowserTest::CreateMediaRoute(const MediaSource& source) { |
| 70 DCHECK(media_router_); |
| 71 observer_.reset(new TestMediaSinksObserver(media_router_, source)); |
| 72 |
| 73 DVLOG(1) << "Receiver name: " << receiver_; |
| 74 // Wait for MediaSinks compatible with |source| to be discovered. |
| 75 Wait(base::TimeDelta::FromSeconds(30), base::TimeDelta::FromSeconds(1), |
| 76 base::Bind(&MediaRouterE2EBrowserTest::IsDeviceDiscoveried, |
| 77 base::Unretained(this))); |
| 78 |
| 79 const auto& sink_map = observer_->sink_map; |
| 80 const auto it = sink_map.find(receiver_); |
| 81 const MediaSink& sink = it->second; |
| 82 |
| 83 // The callback will set route_id_ when invoked. |
| 84 media_router_->CreateRoute( |
| 85 source.id(), sink.id(), |
| 86 base::Bind(&MediaRouterE2EBrowserTest::OnRouteResponseReceived, |
| 87 base::Unretained(this))); |
| 88 |
| 89 // Wait for the route request to be fulfilled (and route to be started). |
| 90 Wait(base::TimeDelta::FromSeconds(30), base::TimeDelta::FromSeconds(1), |
| 91 base::Bind(&MediaRouterE2EBrowserTest::IsRouteCreated, |
| 92 base::Unretained(this))); |
| 93 } |
| 94 |
| 95 void MediaRouterE2EBrowserTest::StopMediaRoute() { |
| 96 ASSERT_FALSE(route_id_.empty()); |
| 97 |
| 98 media_router_->CloseRoute(route_id_); |
| 99 |
| 100 observer_.reset(); |
| 101 route_id_.clear(); |
| 102 } |
| 103 |
| 104 void MediaRouterE2EBrowserTest::ParseCommandLine() { |
| 105 MediaRouterBaseBrowserTest::ParseCommandLine(); |
| 106 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 107 |
| 108 receiver_ = command_line->GetSwitchValueASCII(kReceiver); |
| 109 ASSERT_FALSE(receiver_.empty()); |
| 110 } |
| 111 |
| 112 bool MediaRouterE2EBrowserTest::IsDeviceDiscoveried() const { |
| 113 return ContainsKey(observer_->sink_map, receiver_); |
| 114 } |
| 115 |
| 116 bool MediaRouterE2EBrowserTest::IsRouteCreated() const { |
| 117 return !route_id_.empty(); |
| 118 } |
| 119 |
| 120 // Test cases |
| 121 |
| 122 IN_PROC_BROWSER_TEST_F(MediaRouterE2EBrowserTest, MANUAL_TabMirroring) { |
| 123 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 124 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 125 |
| 126 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 127 browser(), GURL("chrome://extensions"), 1); |
| 128 int tab_id = SessionTabHelper::IdForTab( |
| 129 browser()->tab_strip_model()->GetActiveWebContents()); |
| 130 |
| 131 // Wait for 30 seconds to make sure the route is stable. |
| 132 CreateMediaRoute(MediaSourceForTab(tab_id)); |
| 133 Wait(base::TimeDelta::FromSeconds(30)); |
| 134 |
| 135 // Wait for 10 seconds to make sure route has been stopped. |
| 136 StopMediaRoute(); |
| 137 Wait(base::TimeDelta::FromSeconds(10)); |
| 138 } |
| 139 |
| 140 IN_PROC_BROWSER_TEST_F(MediaRouterE2EBrowserTest, MANUAL_CastApp) { |
| 141 // Wait for 30 seconds to make sure the route is stable. |
| 142 CreateMediaRoute(MediaSourceForPresentationUrl(kCastAppPresentationUrl)); |
| 143 Wait(base::TimeDelta::FromSeconds(30)); |
| 144 |
| 145 // Wait for 10 seconds to make sure route has been stopped. |
| 146 StopMediaRoute(); |
| 147 Wait(base::TimeDelta::FromSeconds(10)); |
| 148 } |
| 149 |
| 150 } // namespace media_router |
OLD | NEW |