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 32a5e7de342edaa59860ce9dde37854c184687d2..1d84948bd513177281496e4b577a9ff463fa2a4b 100644 |
| --- a/chrome/test/media_router/media_router_integration_browsertest.cc |
| +++ b/chrome/test/media_router/media_router_integration_browsertest.cc |
| @@ -45,6 +45,10 @@ const char kCheckStartFailedScript[] = "checkStartFailed('%s', '%s');"; |
| const char kStartSessionScript[] = "startSession();"; |
| const char kTerminateSessionScript[] = |
| "terminateSessionAndWaitForStateChange();"; |
| +const char kCloseSessionScript[] = "closeSessionAndWaitForStateChange();"; |
| +const char kReconnectToSessionScript[] = |
| + "reconnectToClosedSessionAndWaitForStateChange();"; |
| +const char kCheckSendMessageFailedScript[] = "checkSendMessageFailed();"; |
| const char kWaitDeviceScript[] = "waitUntilDeviceAvailable();"; |
| const char kSendMessageAndExpectResponseScript[] = |
| "sendMessageAndExpectResponse('%s');"; |
| @@ -156,17 +160,38 @@ void MediaRouterIntegrationBrowserTest::ExecuteJavaScriptAPI( |
| ASSERT_TRUE(passed) << error_message; |
| } |
| +void MediaRouterIntegrationBrowserTest::StartSessionWithTestPage( |
| + Browser* browser) { |
| + OpenTestPage(FILE_PATH_LITERAL("basic_test.html"), browser); |
| + content::WebContents* web_contents = |
| + browser->tab_strip_model()->GetActiveWebContents(); |
| + ASSERT_TRUE(web_contents); |
| + ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); |
| + StartSession(web_contents); |
| +} |
| + |
| +void MediaRouterIntegrationBrowserTest::StartSessionWithTestPageAndChooseSink( |
| + Browser* browser) { |
| + StartSessionWithTestPage(browser); |
| + content::WebContents* web_contents = |
| + browser->tab_strip_model()->GetActiveWebContents(); |
| + WaitUntilSinkDiscoveredOnUI(web_contents); |
| + ChooseSink(web_contents, kTestSinkName); |
| +} |
| + |
| void MediaRouterIntegrationBrowserTest::OpenTestPage( |
| - base::FilePath::StringPieceType file_name) { |
| + base::FilePath::StringPieceType file_name, |
| + Browser* browser) { |
| base::FilePath full_path = GetResourceFile(file_name); |
| - ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(full_path)); |
| + ui_test_utils::NavigateToURL(browser, net::FilePathToFileURL(full_path)); |
| } |
| void MediaRouterIntegrationBrowserTest::OpenTestPageInNewTab( |
| - base::FilePath::StringPieceType file_name) { |
| + base::FilePath::StringPieceType file_name, |
| + Browser* browser) { |
| base::FilePath full_path = GetResourceFile(file_name); |
| ui_test_utils::NavigateToURLWithDisposition( |
| - browser(), net::FilePathToFileURL(full_path), |
| + browser, net::FilePathToFileURL(full_path), |
| WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| } |
| @@ -394,21 +419,21 @@ void MediaRouterIntegrationBrowserTest::CloseRouteOnUI() { |
| base::Unretained(this)))); |
| } |
| -bool MediaRouterIntegrationBrowserTest::IsSinkDiscoveredOnUI() { |
| - content::WebContents* web_contents = |
| - browser()->tab_strip_model()->GetActiveWebContents(); |
| +bool MediaRouterIntegrationBrowserTest::IsSinkDiscoveredOnUI( |
| + content::WebContents* web_contents) { |
| content::WebContents* dialog_contents = GetMRDialog(web_contents); |
| std::string script = base::StringPrintf(kFindSinkScript, receiver().c_str()); |
| return ExecuteScriptAndExtractBool(dialog_contents, script); |
| } |
| -void MediaRouterIntegrationBrowserTest::WaitUntilSinkDiscoveredOnUI() { |
| +void MediaRouterIntegrationBrowserTest::WaitUntilSinkDiscoveredOnUI( |
| + content::WebContents* web_contents) { |
| DVLOG(0) << "Receiver name: " << receiver_; |
| // Wait for sink to show up in UI. |
| ASSERT_TRUE(ConditionalWait( |
| base::TimeDelta::FromSeconds(30), base::TimeDelta::FromSeconds(1), |
| base::Bind(&MediaRouterIntegrationBrowserTest::IsSinkDiscoveredOnUI, |
| - base::Unretained(this)))); |
| + base::Unretained(this), web_contents))); |
| } |
| bool MediaRouterIntegrationBrowserTest::IsDialogLoaded( |
| @@ -433,58 +458,89 @@ void MediaRouterIntegrationBrowserTest::ParseCommandLine() { |
| receiver_ = kTestSinkName; |
| } |
| -IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_Basic) { |
| - OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); |
| - content::WebContents* web_contents = |
| - browser()->tab_strip_model()->GetActiveWebContents(); |
| - ASSERT_TRUE(web_contents); |
| - ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); |
| - StartSession(web_contents); |
| - WaitUntilSinkDiscoveredOnUI(); |
| - ChooseSink(web_contents, kTestSinkName); |
| +void MediaRouterIntegrationBrowserTest::CheckSessionValidity( |
| + content::WebContents* web_contents) { |
| ExecuteJavaScriptAPI(web_contents, kCheckSessionScript); |
| std::string session_id(GetStartedConnectionId(web_contents)); |
| EXPECT_FALSE(session_id.empty()); |
| - |
| std::string default_request_session_id( |
| GetDefaultRequestSessionId(web_contents)); |
| EXPECT_EQ(session_id, default_request_session_id); |
| +} |
| +void MediaRouterIntegrationBrowserTest::RunBasicTest(Browser* browser) { |
| + StartSessionWithTestPageAndChooseSink(browser); |
| + content::WebContents* web_contents = |
| + browser->tab_strip_model()->GetActiveWebContents(); |
| + CheckSessionValidity(web_contents); |
| ExecuteJavaScriptAPI(web_contents, kTerminateSessionScript); |
| } |
| +void MediaRouterIntegrationBrowserTest::RunReconnectSessionTest( |
| + Browser* browser) { |
| + StartSessionWithTestPageAndChooseSink(browser); |
| + content::WebContents* web_contents = |
| + browser->tab_strip_model()->GetActiveWebContents(); |
| + ExecuteJavaScriptAPI(web_contents, kCheckSessionScript); |
| + std::string session_id(GetStartedConnectionId(web_contents)); |
| + |
| + // Wait a few seconds for MediaRouter to receive updates containing the |
| + // created route. |
| + Wait(base::TimeDelta::FromSeconds(3)); |
| + |
| + OpenTestPageInNewTab(FILE_PATH_LITERAL("basic_test.html"), browser); |
| + content::WebContents* new_web_contents = |
|
mark a. foltz
2017/01/20 19:00:09
This is repeated throughout the code. Add a GetAc
takumif
2017/02/07 22:17:35
Done.
|
| + browser->tab_strip_model()->GetActiveWebContents(); |
| + ASSERT_TRUE(new_web_contents); |
| + ASSERT_NE(web_contents, new_web_contents); |
| + ExecuteJavaScriptAPI( |
| + new_web_contents, |
| + base::StringPrintf("reconnectSession('%s');", session_id.c_str())); |
| + std::string reconnected_session_id; |
| + ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| + new_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(browser()); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| + MANUAL_IncognitoBasic) { |
| + RunBasicTest(GetIncognitoBrowserWithMRExtension()); |
| +} |
| + |
| IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| MANUAL_SendAndOnMessage) { |
| - OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); |
| + StartSessionWithTestPageAndChooseSink(browser()); |
| content::WebContents* web_contents = |
| browser()->tab_strip_model()->GetActiveWebContents(); |
| - ASSERT_TRUE(web_contents); |
| - ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); |
| - StartSession(web_contents); |
| - WaitUntilSinkDiscoveredOnUI(); |
| - ChooseSink(web_contents, kTestSinkName); |
| - ExecuteJavaScriptAPI(web_contents, kCheckSessionScript); |
| - std::string session_id(GetStartedConnectionId(web_contents)); |
| - EXPECT_FALSE(session_id.empty()); |
| + CheckSessionValidity(web_contents); |
| ExecuteJavaScriptAPI( |
| web_contents, |
| base::StringPrintf(kSendMessageAndExpectResponseScript, "foo")); |
| } |
| -IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_OnClose) { |
| +IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| + MANUAL_CloseAndReconnect) { |
| + StartSessionWithTestPageAndChooseSink(browser()); |
| + content::WebContents* web_contents = |
| + browser()->tab_strip_model()->GetActiveWebContents(); |
| + CheckSessionValidity(web_contents); |
| + ExecuteJavaScriptAPI(web_contents, kCloseSessionScript); |
| + ExecuteJavaScriptAPI(web_contents, kReconnectToSessionScript); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_CloseOnError) { |
| SetTestData(FILE_PATH_LITERAL("close_route_with_error_on_send.json")); |
| - OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); |
| + StartSessionWithTestPageAndChooseSink(browser()); |
| content::WebContents* web_contents = |
| browser()->tab_strip_model()->GetActiveWebContents(); |
| - ASSERT_TRUE(web_contents); |
| - ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); |
| - StartSession(web_contents); |
| - WaitUntilSinkDiscoveredOnUI(); |
| - ChooseSink(web_contents, kTestSinkName); |
| - ExecuteJavaScriptAPI(web_contents, kCheckSessionScript); |
| - std::string session_id(GetStartedConnectionId(web_contents)); |
| - EXPECT_FALSE(session_id.empty()); |
| + CheckSessionValidity(web_contents); |
|
mark a. foltz
2017/01/20 19:00:09
Why not have StartSessionWithTestPageAndChooseSink
takumif
2017/02/07 22:17:35
Done.
|
| ExecuteJavaScriptAPI( |
| web_contents, |
| @@ -493,78 +549,47 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_OnClose) { |
| } |
| IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| - MANUAL_Fail_NoProvider) { |
| - SetTestData(FILE_PATH_LITERAL("no_provider.json")); |
| - OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); |
| + MANUAL_Fail_SendMessage) { |
| + StartSessionWithTestPageAndChooseSink(browser()); |
| content::WebContents* web_contents = |
| browser()->tab_strip_model()->GetActiveWebContents(); |
| - ASSERT_TRUE(web_contents); |
| - ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); |
| - StartSession(web_contents); |
| - WaitUntilSinkDiscoveredOnUI(); |
| - ChooseSink(web_contents, kTestSinkName); |
| - CheckStartFailed(web_contents, "UnknownError", |
| - "No provider supports createRoute with source"); |
| + CheckSessionValidity(web_contents); |
| + ExecuteJavaScriptAPI(web_contents, kCloseSessionScript); |
| + ExecuteJavaScriptAPI(web_contents, kCheckSendMessageFailedScript); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| + MANUAL_Fail_NoProvider) { |
| + SetTestData(FILE_PATH_LITERAL("no_provider.json")); |
| + StartSessionWithTestPageAndChooseSink(browser()); |
| + CheckStartFailed(browser()->tab_strip_model()->GetActiveWebContents(), |
| + "UnknownError", |
| + "No provider supports createRoute with source"); |
| } |
| IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| MANUAL_Fail_CreateRoute) { |
| SetTestData(FILE_PATH_LITERAL("fail_create_route.json")); |
| - OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); |
| - content::WebContents* web_contents = |
| - browser()->tab_strip_model()->GetActiveWebContents(); |
| - ASSERT_TRUE(web_contents); |
| - ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); |
| - StartSession(web_contents); |
| - WaitUntilSinkDiscoveredOnUI(); |
| - ChooseSink(web_contents, kTestSinkName); |
| - CheckStartFailed(web_contents, "UnknownError", "Unknown sink"); |
| + StartSessionWithTestPageAndChooseSink(browser()); |
| + CheckStartFailed(browser()->tab_strip_model()->GetActiveWebContents(), |
| + "UnknownError", "Unknown sink"); |
| } |
| IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| MANUAL_ReconnectSession) { |
| - OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); |
| - content::WebContents* web_contents = |
| - browser()->tab_strip_model()->GetActiveWebContents(); |
| - ASSERT_TRUE(web_contents); |
| - ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); |
| - StartSession(web_contents); |
| - WaitUntilSinkDiscoveredOnUI(); |
| - ChooseSink(web_contents, kTestSinkName); |
| - ExecuteJavaScriptAPI(web_contents, kCheckSessionScript); |
| - std::string session_id(GetStartedConnectionId(web_contents)); |
| - |
| - // Wait a few seconds for MediaRouter to receive updates containing the |
| - // created route. |
| - Wait(base::TimeDelta::FromSeconds(3)); |
| + RunReconnectSessionTest(browser()); |
| +} |
| - OpenTestPageInNewTab(FILE_PATH_LITERAL("basic_test.html")); |
| - content::WebContents* new_web_contents = |
| - browser()->tab_strip_model()->GetActiveWebContents(); |
| - ASSERT_TRUE(new_web_contents); |
| - ASSERT_NE(web_contents, new_web_contents); |
| - ExecuteJavaScriptAPI( |
| - new_web_contents, |
| - base::StringPrintf("reconnectSession('%s');", session_id.c_str())); |
| - std::string reconnected_session_id; |
| - ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| - new_web_contents, |
| - "window.domAutomationController.send(reconnectedSession.id)", |
| - &reconnected_session_id)); |
| - ASSERT_EQ(session_id, reconnected_session_id); |
| +IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| + MANUAL_IncognitoReconnectSession) { |
| + RunReconnectSessionTest(GetIncognitoBrowserWithMRExtension()); |
| } |
| IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| MANUAL_Fail_ReconnectSession) { |
| - OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); |
| + StartSessionWithTestPageAndChooseSink(browser()); |
| content::WebContents* web_contents = |
| browser()->tab_strip_model()->GetActiveWebContents(); |
| - ASSERT_TRUE(web_contents); |
| - ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); |
| - content::TestNavigationObserver test_navigation_observer(web_contents, 1); |
| - StartSession(web_contents); |
| - WaitUntilSinkDiscoveredOnUI(); |
| - ChooseSink(web_contents, kTestSinkName); |
| ExecuteJavaScriptAPI(web_contents, kCheckSessionScript); |
| std::string session_id(GetStartedConnectionId(web_contents)); |
| @@ -573,7 +598,7 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| Wait(base::TimeDelta::FromSeconds(3)); |
| SetTestData(FILE_PATH_LITERAL("fail_reconnect_session.json")); |
| - OpenTestPage(FILE_PATH_LITERAL("fail_reconnect_session.html")); |
| + OpenTestPage(FILE_PATH_LITERAL("fail_reconnect_session.html"), browser()); |
| content::WebContents* new_web_contents = |
| browser()->tab_strip_model()->GetActiveWebContents(); |
| ASSERT_TRUE(new_web_contents); |
| @@ -585,13 +610,9 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| MANUAL_Fail_StartCancelled) { |
| - OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); |
| + StartSessionWithTestPage(browser()); |
| content::WebContents* web_contents = |
| browser()->tab_strip_model()->GetActiveWebContents(); |
| - ASSERT_TRUE(web_contents); |
| - ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); |
| - content::TestNavigationObserver test_navigation_observer(web_contents, 1); |
| - StartSession(web_contents); |
| MediaRouterDialogControllerImpl* controller = |
| MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents); |
| @@ -603,7 +624,7 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| MANUAL_Fail_StartCancelledNoSinks) { |
| SetTestData(FILE_PATH_LITERAL("no_sinks.json")); |
| - OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); |
| + OpenTestPage(FILE_PATH_LITERAL("basic_test.html"), browser()); |
| content::WebContents* web_contents = |
| browser()->tab_strip_model()->GetActiveWebContents(); |
| ASSERT_TRUE(web_contents); |
| @@ -620,7 +641,7 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| MANUAL_Fail_StartCancelledNoSupportedSinks) { |
| SetTestData(FILE_PATH_LITERAL("no_supported_sinks.json")); |
| - OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); |
| + OpenTestPage(FILE_PATH_LITERAL("basic_test.html"), browser()); |
| content::WebContents* web_contents = |
| browser()->tab_strip_model()->GetActiveWebContents(); |
| ASSERT_TRUE(web_contents); |
| @@ -630,7 +651,7 @@ IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| MediaRouterDialogControllerImpl* controller = |
| MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents); |
| EXPECT_TRUE(controller->IsShowingMediaRouterDialog()); |
| - WaitUntilSinkDiscoveredOnUI(); |
| + WaitUntilSinkDiscoveredOnUI(web_contents); |
| controller->HideMediaRouterDialog(); |
| CheckStartFailed(web_contents, "NotFoundError", "No screens found."); |
| } |