Chromium Code Reviews| Index: chrome/test/media_router/media_router_integration_browsertest.cc |
| diff --git a/chrome/test/media_router/media_router_integration_browsertest.cc b/chrome/test/media_router/media_router_integration_browsertest.cc |
| index 301e66882a25ae5e84b83439b523499d865748cc..a75a60eafca4422a6031026f8afdce47d3171c12 100644 |
| --- a/chrome/test/media_router/media_router_integration_browsertest.cc |
| +++ b/chrome/test/media_router/media_router_integration_browsertest.cc |
| @@ -184,25 +184,30 @@ WebContents* |
| MediaRouterIntegrationBrowserTest::StartSessionWithTestPageAndChooseSink() { |
| WebContents* web_contents = StartSessionWithTestPageAndSink(); |
| WaitUntilSinkDiscoveredOnUI(); |
| - ChooseSink(web_contents, kTestSinkName); |
| + ChooseSink(web_contents, receiver_); |
| return web_contents; |
| } |
| void MediaRouterIntegrationBrowserTest::OpenTestPage( |
| base::FilePath::StringPieceType file_name) { |
| base::FilePath full_path = GetResourceFile(file_name); |
| - ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(full_path)); |
| + ui_test_utils::NavigateToURL(browser(), GetTestPageUrl(full_path)); |
| } |
| void MediaRouterIntegrationBrowserTest::OpenTestPageInNewTab( |
| base::FilePath::StringPieceType file_name) { |
| base::FilePath full_path = GetResourceFile(file_name); |
| ui_test_utils::NavigateToURLWithDisposition( |
| - browser(), net::FilePathToFileURL(full_path), |
| + browser(), GetTestPageUrl(full_path), |
| WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| } |
| +GURL MediaRouterIntegrationBrowserTest::GetTestPageUrl( |
| + const base::FilePath& full_path) { |
| + return net::FilePathToFileURL(full_path); |
| +} |
| + |
| void MediaRouterIntegrationBrowserTest::StartSession( |
| WebContents* web_contents) { |
| test_navigation_observer_.reset( |
| @@ -487,6 +492,27 @@ void MediaRouterIntegrationBrowserTest::RunBasicTest() { |
| ExecuteJavaScriptAPI(web_contents, kTerminateSessionScript); |
| } |
| +void MediaRouterIntegrationBrowserTest::RunSendMessageTest( |
| + const std::string& message) { |
| + WebContents* web_contents = StartSessionWithTestPageAndChooseSink(); |
| + CheckSessionValidity(web_contents); |
| + ExecuteJavaScriptAPI( |
| + web_contents, |
| + base::StringPrintf(kSendMessageAndExpectResponseScript, message.c_str())); |
| +} |
| + |
| +void MediaRouterIntegrationBrowserTest::RunFailToSendMessageTest() { |
| + WebContents* web_contents = StartSessionWithTestPageAndChooseSink(); |
| + CheckSessionValidity(web_contents); |
| + ExecuteJavaScriptAPI(web_contents, kCloseSessionScript); |
| + |
| + // Wait a few seconds for MediaRouter to receive status updates. |
| + Wait(base::TimeDelta::FromSeconds(3)); |
|
imcheng
2017/04/17 19:06:44
Looking at the JS code again, I am not sure what w
zhaobin
2017/04/17 21:24:07
Done.
|
| + ExecuteJavaScriptAPI( |
| + web_contents, |
| + base::StringPrintf(kCheckSendMessageFailedScript, "closed")); |
| +} |
| + |
| void MediaRouterIntegrationBrowserTest::RunReconnectSessionTest() { |
| WebContents* web_contents = StartSessionWithTestPageAndChooseSink(); |
| CheckSessionValidity(web_contents); |
| @@ -511,17 +537,29 @@ void MediaRouterIntegrationBrowserTest::RunReconnectSessionTest() { |
| ASSERT_EQ(session_id, reconnected_session_id); |
| } |
| +void MediaRouterIntegrationBrowserTest::RunReconnectSessionSameTabTest() { |
| + WebContents* web_contents = StartSessionWithTestPageAndChooseSink(); |
| + CheckSessionValidity(web_contents); |
| + std::string session_id(GetStartedConnectionId(web_contents)); |
| + ExecuteJavaScriptAPI(web_contents, kCloseSessionScript); |
| + |
| + ExecuteJavaScriptAPI(web_contents, base::StringPrintf(kReconnectSessionScript, |
| + session_id.c_str())); |
| + std::string reconnected_session_id; |
| + ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| + web_contents, |
| + "window.domAutomationController.send(reconnectedSession.id)", |
| + &reconnected_session_id)); |
| + ASSERT_EQ(session_id, reconnected_session_id); |
| +} |
| + |
| IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_Basic) { |
| RunBasicTest(); |
| } |
| IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| MANUAL_SendAndOnMessage) { |
| - WebContents* web_contents = StartSessionWithTestPageAndChooseSink(); |
| - CheckSessionValidity(web_contents); |
| - ExecuteJavaScriptAPI( |
| - web_contents, |
| - base::StringPrintf(kSendMessageAndExpectResponseScript, "foo")); |
| + RunSendMessageTest("foo"); |
| } |
| IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_CloseOnError) { |
| @@ -534,15 +572,7 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_CloseOnError) { |
| IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| MANUAL_Fail_SendMessage) { |
| - WebContents* web_contents = StartSessionWithTestPageAndChooseSink(); |
| - CheckSessionValidity(web_contents); |
| - ExecuteJavaScriptAPI(web_contents, kCloseSessionScript); |
| - |
| - // Wait a few seconds for MediaRouter to receive status updates. |
| - Wait(base::TimeDelta::FromSeconds(3)); |
| - ExecuteJavaScriptAPI( |
| - web_contents, |
| - base::StringPrintf(kCheckSendMessageFailedScript, "closed")); |
| + RunFailToSendMessageTest(); |
| } |
| IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |