Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: chrome/test/media_router/media_router_integration_browsertest.cc

Issue 2820433003: [Presentation API] Add browser tests for 1-UA mode (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 CHECK(web_contents); 177 CHECK(web_contents);
178 ExecuteJavaScriptAPI(web_contents, kWaitSinkScript); 178 ExecuteJavaScriptAPI(web_contents, kWaitSinkScript);
179 StartSession(web_contents); 179 StartSession(web_contents);
180 return web_contents; 180 return web_contents;
181 } 181 }
182 182
183 WebContents* 183 WebContents*
184 MediaRouterIntegrationBrowserTest::StartSessionWithTestPageAndChooseSink() { 184 MediaRouterIntegrationBrowserTest::StartSessionWithTestPageAndChooseSink() {
185 WebContents* web_contents = StartSessionWithTestPageAndSink(); 185 WebContents* web_contents = StartSessionWithTestPageAndSink();
186 WaitUntilSinkDiscoveredOnUI(); 186 WaitUntilSinkDiscoveredOnUI();
187 ChooseSink(web_contents, kTestSinkName); 187 ChooseSink(web_contents, receiver_);
188 return web_contents; 188 return web_contents;
189 } 189 }
190 190
191 void MediaRouterIntegrationBrowserTest::OpenTestPage( 191 void MediaRouterIntegrationBrowserTest::OpenTestPage(
192 base::FilePath::StringPieceType file_name) { 192 base::FilePath::StringPieceType file_name) {
193 base::FilePath full_path = GetResourceFile(file_name); 193 base::FilePath full_path = GetResourceFile(file_name);
194 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(full_path)); 194 ui_test_utils::NavigateToURL(browser(), GetTestPageUrl(full_path));
195 } 195 }
196 196
197 void MediaRouterIntegrationBrowserTest::OpenTestPageInNewTab( 197 void MediaRouterIntegrationBrowserTest::OpenTestPageInNewTab(
198 base::FilePath::StringPieceType file_name) { 198 base::FilePath::StringPieceType file_name) {
199 base::FilePath full_path = GetResourceFile(file_name); 199 base::FilePath full_path = GetResourceFile(file_name);
200 ui_test_utils::NavigateToURLWithDisposition( 200 ui_test_utils::NavigateToURLWithDisposition(
201 browser(), net::FilePathToFileURL(full_path), 201 browser(), GetTestPageUrl(full_path),
202 WindowOpenDisposition::NEW_FOREGROUND_TAB, 202 WindowOpenDisposition::NEW_FOREGROUND_TAB,
203 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 203 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
204 } 204 }
205 205
206 GURL MediaRouterIntegrationBrowserTest::GetTestPageUrl(
207 const base::FilePath& full_path) {
208 return net::FilePathToFileURL(full_path);
209 }
210
206 void MediaRouterIntegrationBrowserTest::StartSession( 211 void MediaRouterIntegrationBrowserTest::StartSession(
207 WebContents* web_contents) { 212 WebContents* web_contents) {
208 test_navigation_observer_.reset( 213 test_navigation_observer_.reset(
209 new content::TestNavigationObserver(web_contents, 1)); 214 new content::TestNavigationObserver(web_contents, 1));
210 test_navigation_observer_->StartWatchingNewWebContents(); 215 test_navigation_observer_->StartWatchingNewWebContents();
211 ExecuteJavaScriptAPI(web_contents, kStartSessionScript); 216 ExecuteJavaScriptAPI(web_contents, kStartSessionScript);
212 test_navigation_observer_->Wait(); 217 test_navigation_observer_->Wait();
213 test_navigation_observer_->StopWatchingNewWebContents(); 218 test_navigation_observer_->StopWatchingNewWebContents();
214 } 219 }
215 220
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 WebContents* MediaRouterIntegrationBrowserTest::GetActiveWebContents() { 485 WebContents* MediaRouterIntegrationBrowserTest::GetActiveWebContents() {
481 return browser()->tab_strip_model()->GetActiveWebContents(); 486 return browser()->tab_strip_model()->GetActiveWebContents();
482 } 487 }
483 488
484 void MediaRouterIntegrationBrowserTest::RunBasicTest() { 489 void MediaRouterIntegrationBrowserTest::RunBasicTest() {
485 WebContents* web_contents = StartSessionWithTestPageAndChooseSink(); 490 WebContents* web_contents = StartSessionWithTestPageAndChooseSink();
486 CheckSessionValidity(web_contents); 491 CheckSessionValidity(web_contents);
487 ExecuteJavaScriptAPI(web_contents, kTerminateSessionScript); 492 ExecuteJavaScriptAPI(web_contents, kTerminateSessionScript);
488 } 493 }
489 494
495 void MediaRouterIntegrationBrowserTest::RunSendMessageTest(
496 const std::string& message) {
497 WebContents* web_contents = StartSessionWithTestPageAndChooseSink();
498 CheckSessionValidity(web_contents);
499 ExecuteJavaScriptAPI(
500 web_contents,
501 base::StringPrintf(kSendMessageAndExpectResponseScript, message.c_str()));
502 }
503
504 void MediaRouterIntegrationBrowserTest::RunFailToSendMessageTest() {
505 WebContents* web_contents = StartSessionWithTestPageAndChooseSink();
506 CheckSessionValidity(web_contents);
507 ExecuteJavaScriptAPI(web_contents, kCloseSessionScript);
508
509 // Wait a few seconds for MediaRouter to receive status updates.
510 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.
511 ExecuteJavaScriptAPI(
512 web_contents,
513 base::StringPrintf(kCheckSendMessageFailedScript, "closed"));
514 }
515
490 void MediaRouterIntegrationBrowserTest::RunReconnectSessionTest() { 516 void MediaRouterIntegrationBrowserTest::RunReconnectSessionTest() {
491 WebContents* web_contents = StartSessionWithTestPageAndChooseSink(); 517 WebContents* web_contents = StartSessionWithTestPageAndChooseSink();
492 CheckSessionValidity(web_contents); 518 CheckSessionValidity(web_contents);
493 std::string session_id(GetStartedConnectionId(web_contents)); 519 std::string session_id(GetStartedConnectionId(web_contents));
494 520
495 // Wait a few seconds for MediaRouter to receive updates containing the 521 // Wait a few seconds for MediaRouter to receive updates containing the
496 // created route. 522 // created route.
497 Wait(base::TimeDelta::FromSeconds(3)); 523 Wait(base::TimeDelta::FromSeconds(3));
498 524
499 OpenTestPageInNewTab(FILE_PATH_LITERAL("basic_test.html")); 525 OpenTestPageInNewTab(FILE_PATH_LITERAL("basic_test.html"));
500 WebContents* new_web_contents = GetActiveWebContents(); 526 WebContents* new_web_contents = GetActiveWebContents();
501 ASSERT_TRUE(new_web_contents); 527 ASSERT_TRUE(new_web_contents);
502 ASSERT_NE(web_contents, new_web_contents); 528 ASSERT_NE(web_contents, new_web_contents);
503 ExecuteJavaScriptAPI( 529 ExecuteJavaScriptAPI(
504 new_web_contents, 530 new_web_contents,
505 base::StringPrintf(kReconnectSessionScript, session_id.c_str())); 531 base::StringPrintf(kReconnectSessionScript, session_id.c_str()));
506 std::string reconnected_session_id; 532 std::string reconnected_session_id;
507 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 533 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
508 new_web_contents, 534 new_web_contents,
509 "window.domAutomationController.send(reconnectedSession.id)", 535 "window.domAutomationController.send(reconnectedSession.id)",
510 &reconnected_session_id)); 536 &reconnected_session_id));
511 ASSERT_EQ(session_id, reconnected_session_id); 537 ASSERT_EQ(session_id, reconnected_session_id);
512 } 538 }
513 539
540 void MediaRouterIntegrationBrowserTest::RunReconnectSessionSameTabTest() {
541 WebContents* web_contents = StartSessionWithTestPageAndChooseSink();
542 CheckSessionValidity(web_contents);
543 std::string session_id(GetStartedConnectionId(web_contents));
544 ExecuteJavaScriptAPI(web_contents, kCloseSessionScript);
545
546 ExecuteJavaScriptAPI(web_contents, base::StringPrintf(kReconnectSessionScript,
547 session_id.c_str()));
548 std::string reconnected_session_id;
549 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
550 web_contents,
551 "window.domAutomationController.send(reconnectedSession.id)",
552 &reconnected_session_id));
553 ASSERT_EQ(session_id, reconnected_session_id);
554 }
555
514 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_Basic) { 556 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_Basic) {
515 RunBasicTest(); 557 RunBasicTest();
516 } 558 }
517 559
518 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, 560 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
519 MANUAL_SendAndOnMessage) { 561 MANUAL_SendAndOnMessage) {
520 WebContents* web_contents = StartSessionWithTestPageAndChooseSink(); 562 RunSendMessageTest("foo");
521 CheckSessionValidity(web_contents);
522 ExecuteJavaScriptAPI(
523 web_contents,
524 base::StringPrintf(kSendMessageAndExpectResponseScript, "foo"));
525 } 563 }
526 564
527 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_CloseOnError) { 565 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_CloseOnError) {
528 SetTestData(FILE_PATH_LITERAL("close_route_with_error_on_send.json")); 566 SetTestData(FILE_PATH_LITERAL("close_route_with_error_on_send.json"));
529 WebContents* web_contents = StartSessionWithTestPageAndChooseSink(); 567 WebContents* web_contents = StartSessionWithTestPageAndChooseSink();
530 CheckSessionValidity(web_contents); 568 CheckSessionValidity(web_contents);
531 ExecuteJavaScriptAPI(web_contents, 569 ExecuteJavaScriptAPI(web_contents,
532 kSendMessageAndExpectConnectionCloseOnErrorScript); 570 kSendMessageAndExpectConnectionCloseOnErrorScript);
533 } 571 }
534 572
535 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, 573 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
536 MANUAL_Fail_SendMessage) { 574 MANUAL_Fail_SendMessage) {
537 WebContents* web_contents = StartSessionWithTestPageAndChooseSink(); 575 RunFailToSendMessageTest();
538 CheckSessionValidity(web_contents);
539 ExecuteJavaScriptAPI(web_contents, kCloseSessionScript);
540
541 // Wait a few seconds for MediaRouter to receive status updates.
542 Wait(base::TimeDelta::FromSeconds(3));
543 ExecuteJavaScriptAPI(
544 web_contents,
545 base::StringPrintf(kCheckSendMessageFailedScript, "closed"));
546 } 576 }
547 577
548 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, 578 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
549 MANUAL_Fail_NoProvider) { 579 MANUAL_Fail_NoProvider) {
550 SetTestData(FILE_PATH_LITERAL("no_provider.json")); 580 SetTestData(FILE_PATH_LITERAL("no_provider.json"));
551 WebContents* web_contents = StartSessionWithTestPageAndChooseSink(); 581 WebContents* web_contents = StartSessionWithTestPageAndChooseSink();
552 CheckStartFailed(web_contents, "UnknownError", 582 CheckStartFailed(web_contents, "UnknownError",
553 "No provider supports createRoute with source"); 583 "No provider supports createRoute with source");
554 } 584 }
555 585
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 MANUAL_Basic) { 661 MANUAL_Basic) {
632 RunBasicTest(); 662 RunBasicTest();
633 } 663 }
634 664
635 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationIncognitoBrowserTest, 665 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationIncognitoBrowserTest,
636 MANUAL_ReconnectSession) { 666 MANUAL_ReconnectSession) {
637 RunReconnectSessionTest(); 667 RunReconnectSessionTest();
638 } 668 }
639 669
640 } // namespace media_router 670 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698