Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/test/media_router/media_router_integration_browsertest.h" | 5 #include "chrome/test/media_router/media_router_integration_browsertest.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 // browser test resources. | 38 // browser test resources. |
| 39 const base::FilePath::StringPieceType kResourcePath = FILE_PATH_LITERAL( | 39 const base::FilePath::StringPieceType kResourcePath = FILE_PATH_LITERAL( |
| 40 "media_router/browser_test_resources/"); | 40 "media_router/browser_test_resources/"); |
| 41 const char kTestSinkName[] = "test-sink-1"; | 41 const char kTestSinkName[] = "test-sink-1"; |
| 42 // The javascript snippets. | 42 // The javascript snippets. |
| 43 const char kCheckSessionScript[] = "checkSession();"; | 43 const char kCheckSessionScript[] = "checkSession();"; |
| 44 const char kCheckStartFailedScript[] = "checkStartFailed('%s', '%s');"; | 44 const char kCheckStartFailedScript[] = "checkStartFailed('%s', '%s');"; |
| 45 const char kStartSessionScript[] = "startSession();"; | 45 const char kStartSessionScript[] = "startSession();"; |
| 46 const char kTerminateSessionScript[] = | 46 const char kTerminateSessionScript[] = |
| 47 "terminateSessionAndWaitForStateChange();"; | 47 "terminateSessionAndWaitForStateChange();"; |
| 48 const char kCloseSessionScript[] = "closeSessionAndWaitForStateChange();"; | |
| 49 const char kReconnectToSessionScript[] = | |
| 50 "reconnectToClosedSessionAndWaitForStateChange();"; | |
| 51 const char kCheckSendMessageFailedScript[] = "checkSendMessageFailed();"; | |
| 48 const char kWaitDeviceScript[] = "waitUntilDeviceAvailable();"; | 52 const char kWaitDeviceScript[] = "waitUntilDeviceAvailable();"; |
| 49 const char kSendMessageAndExpectResponseScript[] = | 53 const char kSendMessageAndExpectResponseScript[] = |
| 50 "sendMessageAndExpectResponse('%s');"; | 54 "sendMessageAndExpectResponse('%s');"; |
| 51 const char kSendMessageAndExpectConnectionCloseOnErrorScript[] = | 55 const char kSendMessageAndExpectConnectionCloseOnErrorScript[] = |
| 52 "sendMessageAndExpectConnectionCloseOnError()"; | 56 "sendMessageAndExpectConnectionCloseOnError()"; |
| 53 const char kChooseSinkScript[] = | 57 const char kChooseSinkScript[] = |
| 54 "var sinks = document.getElementById('media-router-container')." | 58 "var sinks = document.getElementById('media-router-container')." |
| 55 " shadowRoot.getElementById('sink-list').getElementsByTagName('span');" | 59 " shadowRoot.getElementById('sink-list').getElementsByTagName('span');" |
| 56 "for (var i=0; i<sinks.length; i++) {" | 60 "for (var i=0; i<sinks.length; i++) {" |
| 57 " if(sinks[i].textContent.trim() == '%s') {" | 61 " if(sinks[i].textContent.trim() == '%s') {" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 | 153 |
| 150 // Extract the fields. | 154 // Extract the fields. |
| 151 bool passed = false; | 155 bool passed = false; |
| 152 ASSERT_TRUE(dict_value->GetBoolean("passed", &passed)); | 156 ASSERT_TRUE(dict_value->GetBoolean("passed", &passed)); |
| 153 std::string error_message; | 157 std::string error_message; |
| 154 ASSERT_TRUE(dict_value->GetString("errorMessage", &error_message)); | 158 ASSERT_TRUE(dict_value->GetString("errorMessage", &error_message)); |
| 155 | 159 |
| 156 ASSERT_TRUE(passed) << error_message; | 160 ASSERT_TRUE(passed) << error_message; |
| 157 } | 161 } |
| 158 | 162 |
| 163 void MediaRouterIntegrationBrowserTest::StartSessionWithTestPage( | |
| 164 Browser* browser) { | |
| 165 OpenTestPage(FILE_PATH_LITERAL("basic_test.html"), browser); | |
| 166 content::WebContents* web_contents = | |
| 167 browser->tab_strip_model()->GetActiveWebContents(); | |
| 168 ASSERT_TRUE(web_contents); | |
| 169 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); | |
| 170 StartSession(web_contents); | |
| 171 } | |
| 172 | |
| 173 void MediaRouterIntegrationBrowserTest::StartSessionWithTestPageAndChooseSink( | |
| 174 Browser* browser) { | |
| 175 StartSessionWithTestPage(browser); | |
| 176 content::WebContents* web_contents = | |
| 177 browser->tab_strip_model()->GetActiveWebContents(); | |
| 178 WaitUntilSinkDiscoveredOnUI(web_contents); | |
| 179 ChooseSink(web_contents, kTestSinkName); | |
| 180 } | |
| 181 | |
| 159 void MediaRouterIntegrationBrowserTest::OpenTestPage( | 182 void MediaRouterIntegrationBrowserTest::OpenTestPage( |
| 160 base::FilePath::StringPieceType file_name) { | 183 base::FilePath::StringPieceType file_name, |
| 184 Browser* browser) { | |
| 161 base::FilePath full_path = GetResourceFile(file_name); | 185 base::FilePath full_path = GetResourceFile(file_name); |
| 162 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(full_path)); | 186 ui_test_utils::NavigateToURL(browser, net::FilePathToFileURL(full_path)); |
| 163 } | 187 } |
| 164 | 188 |
| 165 void MediaRouterIntegrationBrowserTest::OpenTestPageInNewTab( | 189 void MediaRouterIntegrationBrowserTest::OpenTestPageInNewTab( |
| 166 base::FilePath::StringPieceType file_name) { | 190 base::FilePath::StringPieceType file_name, |
| 191 Browser* browser) { | |
| 167 base::FilePath full_path = GetResourceFile(file_name); | 192 base::FilePath full_path = GetResourceFile(file_name); |
| 168 ui_test_utils::NavigateToURLWithDisposition( | 193 ui_test_utils::NavigateToURLWithDisposition( |
| 169 browser(), net::FilePathToFileURL(full_path), | 194 browser, net::FilePathToFileURL(full_path), |
| 170 WindowOpenDisposition::NEW_FOREGROUND_TAB, | 195 WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 171 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 196 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 172 } | 197 } |
| 173 | 198 |
| 174 void MediaRouterIntegrationBrowserTest::StartSession( | 199 void MediaRouterIntegrationBrowserTest::StartSession( |
| 175 content::WebContents* web_contents) { | 200 content::WebContents* web_contents) { |
| 176 test_navigation_observer_.reset( | 201 test_navigation_observer_.reset( |
| 177 new content::TestNavigationObserver(web_contents, 1)); | 202 new content::TestNavigationObserver(web_contents, 1)); |
| 178 test_navigation_observer_->StartWatchingNewWebContents(); | 203 test_navigation_observer_->StartWatchingNewWebContents(); |
| 179 ExecuteJavaScriptAPI(web_contents, kStartSessionScript); | 204 ExecuteJavaScriptAPI(web_contents, kStartSessionScript); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 content::WebContents* web_contents = | 412 content::WebContents* web_contents = |
| 388 browser()->tab_strip_model()->GetActiveWebContents(); | 413 browser()->tab_strip_model()->GetActiveWebContents(); |
| 389 content::WebContents* dialog_contents = GetMRDialog(web_contents); | 414 content::WebContents* dialog_contents = GetMRDialog(web_contents); |
| 390 ASSERT_TRUE(content::ExecuteScript(dialog_contents, kCloseRouteScript)); | 415 ASSERT_TRUE(content::ExecuteScript(dialog_contents, kCloseRouteScript)); |
| 391 ASSERT_TRUE(ConditionalWait( | 416 ASSERT_TRUE(ConditionalWait( |
| 392 base::TimeDelta::FromSeconds(10), base::TimeDelta::FromSeconds(1), | 417 base::TimeDelta::FromSeconds(10), base::TimeDelta::FromSeconds(1), |
| 393 base::Bind(&MediaRouterIntegrationBrowserTest::IsRouteClosedOnUI, | 418 base::Bind(&MediaRouterIntegrationBrowserTest::IsRouteClosedOnUI, |
| 394 base::Unretained(this)))); | 419 base::Unretained(this)))); |
| 395 } | 420 } |
| 396 | 421 |
| 397 bool MediaRouterIntegrationBrowserTest::IsSinkDiscoveredOnUI() { | 422 bool MediaRouterIntegrationBrowserTest::IsSinkDiscoveredOnUI( |
| 398 content::WebContents* web_contents = | 423 content::WebContents* web_contents) { |
| 399 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 400 content::WebContents* dialog_contents = GetMRDialog(web_contents); | 424 content::WebContents* dialog_contents = GetMRDialog(web_contents); |
| 401 std::string script = base::StringPrintf(kFindSinkScript, receiver().c_str()); | 425 std::string script = base::StringPrintf(kFindSinkScript, receiver().c_str()); |
| 402 return ExecuteScriptAndExtractBool(dialog_contents, script); | 426 return ExecuteScriptAndExtractBool(dialog_contents, script); |
| 403 } | 427 } |
| 404 | 428 |
| 405 void MediaRouterIntegrationBrowserTest::WaitUntilSinkDiscoveredOnUI() { | 429 void MediaRouterIntegrationBrowserTest::WaitUntilSinkDiscoveredOnUI( |
| 430 content::WebContents* web_contents) { | |
| 406 DVLOG(0) << "Receiver name: " << receiver_; | 431 DVLOG(0) << "Receiver name: " << receiver_; |
| 407 // Wait for sink to show up in UI. | 432 // Wait for sink to show up in UI. |
| 408 ASSERT_TRUE(ConditionalWait( | 433 ASSERT_TRUE(ConditionalWait( |
| 409 base::TimeDelta::FromSeconds(30), base::TimeDelta::FromSeconds(1), | 434 base::TimeDelta::FromSeconds(30), base::TimeDelta::FromSeconds(1), |
| 410 base::Bind(&MediaRouterIntegrationBrowserTest::IsSinkDiscoveredOnUI, | 435 base::Bind(&MediaRouterIntegrationBrowserTest::IsSinkDiscoveredOnUI, |
| 411 base::Unretained(this)))); | 436 base::Unretained(this), web_contents))); |
| 412 } | 437 } |
| 413 | 438 |
| 414 bool MediaRouterIntegrationBrowserTest::IsDialogLoaded( | 439 bool MediaRouterIntegrationBrowserTest::IsDialogLoaded( |
| 415 content::WebContents* dialog_contents) { | 440 content::WebContents* dialog_contents) { |
| 416 return ExecuteScriptAndExtractBool(dialog_contents, kCheckDialogLoadedScript); | 441 return ExecuteScriptAndExtractBool(dialog_contents, kCheckDialogLoadedScript); |
| 417 } | 442 } |
| 418 | 443 |
| 419 void MediaRouterIntegrationBrowserTest::WaitUntilDialogFullyLoaded( | 444 void MediaRouterIntegrationBrowserTest::WaitUntilDialogFullyLoaded( |
| 420 content::WebContents* dialog_contents) { | 445 content::WebContents* dialog_contents) { |
| 421 ASSERT_TRUE(ConditionalWait( | 446 ASSERT_TRUE(ConditionalWait( |
| 422 base::TimeDelta::FromSeconds(30), base::TimeDelta::FromSeconds(1), | 447 base::TimeDelta::FromSeconds(30), base::TimeDelta::FromSeconds(1), |
| 423 base::Bind(&MediaRouterIntegrationBrowserTest::IsDialogLoaded, | 448 base::Bind(&MediaRouterIntegrationBrowserTest::IsDialogLoaded, |
| 424 base::Unretained(this), dialog_contents))); | 449 base::Unretained(this), dialog_contents))); |
| 425 } | 450 } |
| 426 | 451 |
| 427 void MediaRouterIntegrationBrowserTest::ParseCommandLine() { | 452 void MediaRouterIntegrationBrowserTest::ParseCommandLine() { |
| 428 MediaRouterBaseBrowserTest::ParseCommandLine(); | 453 MediaRouterBaseBrowserTest::ParseCommandLine(); |
| 429 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 454 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 430 | 455 |
| 431 receiver_ = command_line->GetSwitchValueASCII(kReceiver); | 456 receiver_ = command_line->GetSwitchValueASCII(kReceiver); |
| 432 if (receiver_.empty()) | 457 if (receiver_.empty()) |
| 433 receiver_ = kTestSinkName; | 458 receiver_ = kTestSinkName; |
| 434 } | 459 } |
| 435 | 460 |
| 436 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_Basic) { | 461 void MediaRouterIntegrationBrowserTest::CheckSessionValidity( |
| 437 OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); | 462 content::WebContents* web_contents) { |
| 438 content::WebContents* web_contents = | |
| 439 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 440 ASSERT_TRUE(web_contents); | |
| 441 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); | |
| 442 StartSession(web_contents); | |
| 443 WaitUntilSinkDiscoveredOnUI(); | |
| 444 ChooseSink(web_contents, kTestSinkName); | |
| 445 ExecuteJavaScriptAPI(web_contents, kCheckSessionScript); | 463 ExecuteJavaScriptAPI(web_contents, kCheckSessionScript); |
| 446 std::string session_id(GetStartedConnectionId(web_contents)); | 464 std::string session_id(GetStartedConnectionId(web_contents)); |
| 447 EXPECT_FALSE(session_id.empty()); | 465 EXPECT_FALSE(session_id.empty()); |
| 448 | |
| 449 std::string default_request_session_id( | 466 std::string default_request_session_id( |
| 450 GetDefaultRequestSessionId(web_contents)); | 467 GetDefaultRequestSessionId(web_contents)); |
| 451 EXPECT_EQ(session_id, default_request_session_id); | 468 EXPECT_EQ(session_id, default_request_session_id); |
| 469 } | |
| 452 | 470 |
| 471 void MediaRouterIntegrationBrowserTest::RunBasicTest(Browser* browser) { | |
| 472 StartSessionWithTestPageAndChooseSink(browser); | |
| 473 content::WebContents* web_contents = | |
| 474 browser->tab_strip_model()->GetActiveWebContents(); | |
| 475 CheckSessionValidity(web_contents); | |
| 453 ExecuteJavaScriptAPI(web_contents, kTerminateSessionScript); | 476 ExecuteJavaScriptAPI(web_contents, kTerminateSessionScript); |
| 454 } | 477 } |
| 455 | 478 |
| 479 void MediaRouterIntegrationBrowserTest::RunReconnectSessionTest( | |
| 480 Browser* browser) { | |
| 481 StartSessionWithTestPageAndChooseSink(browser); | |
| 482 content::WebContents* web_contents = | |
| 483 browser->tab_strip_model()->GetActiveWebContents(); | |
| 484 ExecuteJavaScriptAPI(web_contents, kCheckSessionScript); | |
| 485 std::string session_id(GetStartedConnectionId(web_contents)); | |
| 486 | |
| 487 // Wait a few seconds for MediaRouter to receive updates containing the | |
| 488 // created route. | |
| 489 Wait(base::TimeDelta::FromSeconds(3)); | |
| 490 | |
| 491 OpenTestPageInNewTab(FILE_PATH_LITERAL("basic_test.html"), browser); | |
| 492 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.
| |
| 493 browser->tab_strip_model()->GetActiveWebContents(); | |
| 494 ASSERT_TRUE(new_web_contents); | |
| 495 ASSERT_NE(web_contents, new_web_contents); | |
| 496 ExecuteJavaScriptAPI( | |
| 497 new_web_contents, | |
| 498 base::StringPrintf("reconnectSession('%s');", session_id.c_str())); | |
| 499 std::string reconnected_session_id; | |
| 500 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 501 new_web_contents, | |
| 502 "window.domAutomationController.send(reconnectedSession.id)", | |
| 503 &reconnected_session_id)); | |
| 504 ASSERT_EQ(session_id, reconnected_session_id); | |
| 505 } | |
| 506 | |
| 507 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_Basic) { | |
| 508 RunBasicTest(browser()); | |
| 509 } | |
| 510 | |
| 511 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, | |
| 512 MANUAL_IncognitoBasic) { | |
| 513 RunBasicTest(GetIncognitoBrowserWithMRExtension()); | |
| 514 } | |
| 515 | |
| 456 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, | 516 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| 457 MANUAL_SendAndOnMessage) { | 517 MANUAL_SendAndOnMessage) { |
| 458 OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); | 518 StartSessionWithTestPageAndChooseSink(browser()); |
| 459 content::WebContents* web_contents = | 519 content::WebContents* web_contents = |
| 460 browser()->tab_strip_model()->GetActiveWebContents(); | 520 browser()->tab_strip_model()->GetActiveWebContents(); |
| 461 ASSERT_TRUE(web_contents); | 521 CheckSessionValidity(web_contents); |
| 462 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); | |
| 463 StartSession(web_contents); | |
| 464 WaitUntilSinkDiscoveredOnUI(); | |
| 465 ChooseSink(web_contents, kTestSinkName); | |
| 466 ExecuteJavaScriptAPI(web_contents, kCheckSessionScript); | |
| 467 std::string session_id(GetStartedConnectionId(web_contents)); | |
| 468 EXPECT_FALSE(session_id.empty()); | |
| 469 | 522 |
| 470 ExecuteJavaScriptAPI( | 523 ExecuteJavaScriptAPI( |
| 471 web_contents, | 524 web_contents, |
| 472 base::StringPrintf(kSendMessageAndExpectResponseScript, "foo")); | 525 base::StringPrintf(kSendMessageAndExpectResponseScript, "foo")); |
| 473 } | 526 } |
| 474 | 527 |
| 475 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_OnClose) { | 528 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| 476 SetTestData(FILE_PATH_LITERAL("close_route_with_error_on_send.json")); | 529 MANUAL_CloseAndReconnect) { |
| 477 OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); | 530 StartSessionWithTestPageAndChooseSink(browser()); |
| 478 content::WebContents* web_contents = | 531 content::WebContents* web_contents = |
| 479 browser()->tab_strip_model()->GetActiveWebContents(); | 532 browser()->tab_strip_model()->GetActiveWebContents(); |
| 480 ASSERT_TRUE(web_contents); | 533 CheckSessionValidity(web_contents); |
| 481 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); | 534 ExecuteJavaScriptAPI(web_contents, kCloseSessionScript); |
| 482 StartSession(web_contents); | 535 ExecuteJavaScriptAPI(web_contents, kReconnectToSessionScript); |
| 483 WaitUntilSinkDiscoveredOnUI(); | 536 } |
| 484 ChooseSink(web_contents, kTestSinkName); | 537 |
| 485 ExecuteJavaScriptAPI(web_contents, kCheckSessionScript); | 538 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_CloseOnError) { |
| 486 std::string session_id(GetStartedConnectionId(web_contents)); | 539 SetTestData(FILE_PATH_LITERAL("close_route_with_error_on_send.json")); |
| 487 EXPECT_FALSE(session_id.empty()); | 540 StartSessionWithTestPageAndChooseSink(browser()); |
| 541 content::WebContents* web_contents = | |
| 542 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 543 CheckSessionValidity(web_contents); | |
|
mark a. foltz
2017/01/20 19:00:09
Why not have StartSessionWithTestPageAndChooseSink
takumif
2017/02/07 22:17:35
Done.
| |
| 488 | 544 |
| 489 ExecuteJavaScriptAPI( | 545 ExecuteJavaScriptAPI( |
| 490 web_contents, | 546 web_contents, |
| 491 base::StringPrintf("%s", | 547 base::StringPrintf("%s", |
| 492 kSendMessageAndExpectConnectionCloseOnErrorScript)); | 548 kSendMessageAndExpectConnectionCloseOnErrorScript)); |
| 493 } | 549 } |
| 494 | 550 |
| 495 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, | 551 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| 552 MANUAL_Fail_SendMessage) { | |
| 553 StartSessionWithTestPageAndChooseSink(browser()); | |
| 554 content::WebContents* web_contents = | |
| 555 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 556 CheckSessionValidity(web_contents); | |
| 557 ExecuteJavaScriptAPI(web_contents, kCloseSessionScript); | |
| 558 ExecuteJavaScriptAPI(web_contents, kCheckSendMessageFailedScript); | |
| 559 } | |
| 560 | |
| 561 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, | |
| 496 MANUAL_Fail_NoProvider) { | 562 MANUAL_Fail_NoProvider) { |
| 497 SetTestData(FILE_PATH_LITERAL("no_provider.json")); | 563 SetTestData(FILE_PATH_LITERAL("no_provider.json")); |
| 498 OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); | 564 StartSessionWithTestPageAndChooseSink(browser()); |
| 499 content::WebContents* web_contents = | 565 CheckStartFailed(browser()->tab_strip_model()->GetActiveWebContents(), |
| 500 browser()->tab_strip_model()->GetActiveWebContents(); | 566 "UnknownError", |
| 501 ASSERT_TRUE(web_contents); | 567 "No provider supports createRoute with source"); |
| 502 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); | |
| 503 StartSession(web_contents); | |
| 504 WaitUntilSinkDiscoveredOnUI(); | |
| 505 ChooseSink(web_contents, kTestSinkName); | |
| 506 CheckStartFailed(web_contents, "UnknownError", | |
| 507 "No provider supports createRoute with source"); | |
| 508 } | 568 } |
| 509 | 569 |
| 510 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, | 570 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| 511 MANUAL_Fail_CreateRoute) { | 571 MANUAL_Fail_CreateRoute) { |
| 512 SetTestData(FILE_PATH_LITERAL("fail_create_route.json")); | 572 SetTestData(FILE_PATH_LITERAL("fail_create_route.json")); |
| 513 OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); | 573 StartSessionWithTestPageAndChooseSink(browser()); |
| 514 content::WebContents* web_contents = | 574 CheckStartFailed(browser()->tab_strip_model()->GetActiveWebContents(), |
| 515 browser()->tab_strip_model()->GetActiveWebContents(); | 575 "UnknownError", "Unknown sink"); |
| 516 ASSERT_TRUE(web_contents); | |
| 517 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); | |
| 518 StartSession(web_contents); | |
| 519 WaitUntilSinkDiscoveredOnUI(); | |
| 520 ChooseSink(web_contents, kTestSinkName); | |
| 521 CheckStartFailed(web_contents, "UnknownError", "Unknown sink"); | |
| 522 } | 576 } |
| 523 | 577 |
| 524 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, | 578 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| 525 MANUAL_ReconnectSession) { | 579 MANUAL_ReconnectSession) { |
| 526 OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); | 580 RunReconnectSessionTest(browser()); |
| 527 content::WebContents* web_contents = | 581 } |
| 528 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 529 ASSERT_TRUE(web_contents); | |
| 530 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); | |
| 531 StartSession(web_contents); | |
| 532 WaitUntilSinkDiscoveredOnUI(); | |
| 533 ChooseSink(web_contents, kTestSinkName); | |
| 534 ExecuteJavaScriptAPI(web_contents, kCheckSessionScript); | |
| 535 std::string session_id(GetStartedConnectionId(web_contents)); | |
| 536 | 582 |
| 537 // Wait a few seconds for MediaRouter to receive updates containing the | 583 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| 538 // created route. | 584 MANUAL_IncognitoReconnectSession) { |
| 539 Wait(base::TimeDelta::FromSeconds(3)); | 585 RunReconnectSessionTest(GetIncognitoBrowserWithMRExtension()); |
| 540 | |
| 541 OpenTestPageInNewTab(FILE_PATH_LITERAL("basic_test.html")); | |
| 542 content::WebContents* new_web_contents = | |
| 543 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 544 ASSERT_TRUE(new_web_contents); | |
| 545 ASSERT_NE(web_contents, new_web_contents); | |
| 546 ExecuteJavaScriptAPI( | |
| 547 new_web_contents, | |
| 548 base::StringPrintf("reconnectSession('%s');", session_id.c_str())); | |
| 549 std::string reconnected_session_id; | |
| 550 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 551 new_web_contents, | |
| 552 "window.domAutomationController.send(reconnectedSession.id)", | |
| 553 &reconnected_session_id)); | |
| 554 ASSERT_EQ(session_id, reconnected_session_id); | |
| 555 } | 586 } |
| 556 | 587 |
| 557 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, | 588 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| 558 MANUAL_Fail_ReconnectSession) { | 589 MANUAL_Fail_ReconnectSession) { |
| 559 OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); | 590 StartSessionWithTestPageAndChooseSink(browser()); |
| 560 content::WebContents* web_contents = | 591 content::WebContents* web_contents = |
| 561 browser()->tab_strip_model()->GetActiveWebContents(); | 592 browser()->tab_strip_model()->GetActiveWebContents(); |
| 562 ASSERT_TRUE(web_contents); | |
| 563 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); | |
| 564 content::TestNavigationObserver test_navigation_observer(web_contents, 1); | |
| 565 StartSession(web_contents); | |
| 566 WaitUntilSinkDiscoveredOnUI(); | |
| 567 ChooseSink(web_contents, kTestSinkName); | |
| 568 ExecuteJavaScriptAPI(web_contents, kCheckSessionScript); | 593 ExecuteJavaScriptAPI(web_contents, kCheckSessionScript); |
| 569 std::string session_id(GetStartedConnectionId(web_contents)); | 594 std::string session_id(GetStartedConnectionId(web_contents)); |
| 570 | 595 |
| 571 // Wait a few seconds for MediaRouter to receive updates containing the | 596 // Wait a few seconds for MediaRouter to receive updates containing the |
| 572 // created route. | 597 // created route. |
| 573 Wait(base::TimeDelta::FromSeconds(3)); | 598 Wait(base::TimeDelta::FromSeconds(3)); |
| 574 | 599 |
| 575 SetTestData(FILE_PATH_LITERAL("fail_reconnect_session.json")); | 600 SetTestData(FILE_PATH_LITERAL("fail_reconnect_session.json")); |
| 576 OpenTestPage(FILE_PATH_LITERAL("fail_reconnect_session.html")); | 601 OpenTestPage(FILE_PATH_LITERAL("fail_reconnect_session.html"), browser()); |
| 577 content::WebContents* new_web_contents = | 602 content::WebContents* new_web_contents = |
| 578 browser()->tab_strip_model()->GetActiveWebContents(); | 603 browser()->tab_strip_model()->GetActiveWebContents(); |
| 579 ASSERT_TRUE(new_web_contents); | 604 ASSERT_TRUE(new_web_contents); |
| 580 ExecuteJavaScriptAPI( | 605 ExecuteJavaScriptAPI( |
| 581 new_web_contents, | 606 new_web_contents, |
| 582 base::StringPrintf("checkReconnectSessionFails('%s');", | 607 base::StringPrintf("checkReconnectSessionFails('%s');", |
| 583 session_id.c_str())); | 608 session_id.c_str())); |
| 584 } | 609 } |
| 585 | 610 |
| 586 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, | 611 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| 587 MANUAL_Fail_StartCancelled) { | 612 MANUAL_Fail_StartCancelled) { |
| 588 OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); | 613 StartSessionWithTestPage(browser()); |
| 589 content::WebContents* web_contents = | 614 content::WebContents* web_contents = |
| 590 browser()->tab_strip_model()->GetActiveWebContents(); | 615 browser()->tab_strip_model()->GetActiveWebContents(); |
| 591 ASSERT_TRUE(web_contents); | |
| 592 ExecuteJavaScriptAPI(web_contents, kWaitDeviceScript); | |
| 593 content::TestNavigationObserver test_navigation_observer(web_contents, 1); | |
| 594 StartSession(web_contents); | |
| 595 | 616 |
| 596 MediaRouterDialogControllerImpl* controller = | 617 MediaRouterDialogControllerImpl* controller = |
| 597 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents); | 618 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents); |
| 598 EXPECT_TRUE(controller->IsShowingMediaRouterDialog()); | 619 EXPECT_TRUE(controller->IsShowingMediaRouterDialog()); |
| 599 controller->HideMediaRouterDialog(); | 620 controller->HideMediaRouterDialog(); |
| 600 CheckStartFailed(web_contents, "NotAllowedError", "Dialog closed."); | 621 CheckStartFailed(web_contents, "NotAllowedError", "Dialog closed."); |
| 601 } | 622 } |
| 602 | 623 |
| 603 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, | 624 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| 604 MANUAL_Fail_StartCancelledNoSinks) { | 625 MANUAL_Fail_StartCancelledNoSinks) { |
| 605 SetTestData(FILE_PATH_LITERAL("no_sinks.json")); | 626 SetTestData(FILE_PATH_LITERAL("no_sinks.json")); |
| 606 OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); | 627 OpenTestPage(FILE_PATH_LITERAL("basic_test.html"), browser()); |
| 607 content::WebContents* web_contents = | 628 content::WebContents* web_contents = |
| 608 browser()->tab_strip_model()->GetActiveWebContents(); | 629 browser()->tab_strip_model()->GetActiveWebContents(); |
| 609 ASSERT_TRUE(web_contents); | 630 ASSERT_TRUE(web_contents); |
| 610 content::TestNavigationObserver test_navigation_observer(web_contents, 1); | 631 content::TestNavigationObserver test_navigation_observer(web_contents, 1); |
| 611 StartSession(web_contents); | 632 StartSession(web_contents); |
| 612 | 633 |
| 613 MediaRouterDialogControllerImpl* controller = | 634 MediaRouterDialogControllerImpl* controller = |
| 614 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents); | 635 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents); |
| 615 EXPECT_TRUE(controller->IsShowingMediaRouterDialog()); | 636 EXPECT_TRUE(controller->IsShowingMediaRouterDialog()); |
| 616 controller->HideMediaRouterDialog(); | 637 controller->HideMediaRouterDialog(); |
| 617 CheckStartFailed(web_contents, "NotFoundError", "No screens found."); | 638 CheckStartFailed(web_contents, "NotFoundError", "No screens found."); |
| 618 } | 639 } |
| 619 | 640 |
| 620 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, | 641 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, |
| 621 MANUAL_Fail_StartCancelledNoSupportedSinks) { | 642 MANUAL_Fail_StartCancelledNoSupportedSinks) { |
| 622 SetTestData(FILE_PATH_LITERAL("no_supported_sinks.json")); | 643 SetTestData(FILE_PATH_LITERAL("no_supported_sinks.json")); |
| 623 OpenTestPage(FILE_PATH_LITERAL("basic_test.html")); | 644 OpenTestPage(FILE_PATH_LITERAL("basic_test.html"), browser()); |
| 624 content::WebContents* web_contents = | 645 content::WebContents* web_contents = |
| 625 browser()->tab_strip_model()->GetActiveWebContents(); | 646 browser()->tab_strip_model()->GetActiveWebContents(); |
| 626 ASSERT_TRUE(web_contents); | 647 ASSERT_TRUE(web_contents); |
| 627 content::TestNavigationObserver test_navigation_observer(web_contents, 1); | 648 content::TestNavigationObserver test_navigation_observer(web_contents, 1); |
| 628 StartSession(web_contents); | 649 StartSession(web_contents); |
| 629 | 650 |
| 630 MediaRouterDialogControllerImpl* controller = | 651 MediaRouterDialogControllerImpl* controller = |
| 631 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents); | 652 MediaRouterDialogControllerImpl::GetOrCreateForWebContents(web_contents); |
| 632 EXPECT_TRUE(controller->IsShowingMediaRouterDialog()); | 653 EXPECT_TRUE(controller->IsShowingMediaRouterDialog()); |
| 633 WaitUntilSinkDiscoveredOnUI(); | 654 WaitUntilSinkDiscoveredOnUI(web_contents); |
| 634 controller->HideMediaRouterDialog(); | 655 controller->HideMediaRouterDialog(); |
| 635 CheckStartFailed(web_contents, "NotFoundError", "No screens found."); | 656 CheckStartFailed(web_contents, "NotFoundError", "No screens found."); |
| 636 } | 657 } |
| 637 | 658 |
| 638 } // namespace media_router | 659 } // namespace media_router |
| OLD | NEW |