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

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: fix android test failures 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 ExecuteJavaScriptAPI(
510 web_contents,
511 base::StringPrintf(kCheckSendMessageFailedScript, "closed"));
512 }
513
490 void MediaRouterIntegrationBrowserTest::RunReconnectSessionTest() { 514 void MediaRouterIntegrationBrowserTest::RunReconnectSessionTest() {
491 WebContents* web_contents = StartSessionWithTestPageAndChooseSink(); 515 WebContents* web_contents = StartSessionWithTestPageAndChooseSink();
492 CheckSessionValidity(web_contents); 516 CheckSessionValidity(web_contents);
493 std::string session_id(GetStartedConnectionId(web_contents)); 517 std::string session_id(GetStartedConnectionId(web_contents));
494 518
495 // Wait a few seconds for MediaRouter to receive updates containing the 519 // Wait a few seconds for MediaRouter to receive updates containing the
496 // created route. 520 // created route.
497 Wait(base::TimeDelta::FromSeconds(3)); 521 Wait(base::TimeDelta::FromSeconds(3));
498 522
499 OpenTestPageInNewTab(FILE_PATH_LITERAL("basic_test.html")); 523 OpenTestPageInNewTab(FILE_PATH_LITERAL("basic_test.html"));
500 WebContents* new_web_contents = GetActiveWebContents(); 524 WebContents* new_web_contents = GetActiveWebContents();
501 ASSERT_TRUE(new_web_contents); 525 ASSERT_TRUE(new_web_contents);
502 ASSERT_NE(web_contents, new_web_contents); 526 ASSERT_NE(web_contents, new_web_contents);
503 ExecuteJavaScriptAPI( 527 ExecuteJavaScriptAPI(
504 new_web_contents, 528 new_web_contents,
505 base::StringPrintf(kReconnectSessionScript, session_id.c_str())); 529 base::StringPrintf(kReconnectSessionScript, session_id.c_str()));
506 std::string reconnected_session_id; 530 std::string reconnected_session_id;
507 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 531 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
508 new_web_contents, 532 new_web_contents,
509 "window.domAutomationController.send(reconnectedSession.id)", 533 "window.domAutomationController.send(reconnectedSession.id)",
510 &reconnected_session_id)); 534 &reconnected_session_id));
511 ASSERT_EQ(session_id, reconnected_session_id); 535 ASSERT_EQ(session_id, reconnected_session_id);
512 } 536 }
513 537
538 void MediaRouterIntegrationBrowserTest::RunReconnectSessionSameTabTest() {
539 WebContents* web_contents = StartSessionWithTestPageAndChooseSink();
540 CheckSessionValidity(web_contents);
541 std::string session_id(GetStartedConnectionId(web_contents));
542 ExecuteJavaScriptAPI(web_contents, kCloseSessionScript);
543
544 ExecuteJavaScriptAPI(web_contents, base::StringPrintf(kReconnectSessionScript,
545 session_id.c_str()));
546 std::string reconnected_session_id;
547 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
548 web_contents,
549 "window.domAutomationController.send(reconnectedSession.id)",
550 &reconnected_session_id));
551 ASSERT_EQ(session_id, reconnected_session_id);
552 }
553
514 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_Basic) { 554 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_Basic) {
515 RunBasicTest(); 555 RunBasicTest();
516 } 556 }
517 557
518 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, 558 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
519 MANUAL_SendAndOnMessage) { 559 MANUAL_SendAndOnMessage) {
520 WebContents* web_contents = StartSessionWithTestPageAndChooseSink(); 560 RunSendMessageTest("foo");
521 CheckSessionValidity(web_contents);
522 ExecuteJavaScriptAPI(
523 web_contents,
524 base::StringPrintf(kSendMessageAndExpectResponseScript, "foo"));
525 } 561 }
526 562
527 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_CloseOnError) { 563 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_CloseOnError) {
528 SetTestData(FILE_PATH_LITERAL("close_route_with_error_on_send.json")); 564 SetTestData(FILE_PATH_LITERAL("close_route_with_error_on_send.json"));
529 WebContents* web_contents = StartSessionWithTestPageAndChooseSink(); 565 WebContents* web_contents = StartSessionWithTestPageAndChooseSink();
530 CheckSessionValidity(web_contents); 566 CheckSessionValidity(web_contents);
531 ExecuteJavaScriptAPI(web_contents, 567 ExecuteJavaScriptAPI(web_contents,
532 kSendMessageAndExpectConnectionCloseOnErrorScript); 568 kSendMessageAndExpectConnectionCloseOnErrorScript);
533 } 569 }
534 570
535 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, 571 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
536 MANUAL_Fail_SendMessage) { 572 MANUAL_Fail_SendMessage) {
537 WebContents* web_contents = StartSessionWithTestPageAndChooseSink(); 573 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 } 574 }
547 575
548 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, 576 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
549 MANUAL_Fail_NoProvider) { 577 MANUAL_Fail_NoProvider) {
550 SetTestData(FILE_PATH_LITERAL("no_provider.json")); 578 SetTestData(FILE_PATH_LITERAL("no_provider.json"));
551 WebContents* web_contents = StartSessionWithTestPageAndChooseSink(); 579 WebContents* web_contents = StartSessionWithTestPageAndChooseSink();
552 CheckStartFailed(web_contents, "UnknownError", 580 CheckStartFailed(web_contents, "UnknownError",
553 "No provider supports createRoute with source"); 581 "No provider supports createRoute with source");
554 } 582 }
555 583
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 MANUAL_Basic) { 659 MANUAL_Basic) {
632 RunBasicTest(); 660 RunBasicTest();
633 } 661 }
634 662
635 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationIncognitoBrowserTest, 663 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationIncognitoBrowserTest,
636 MANUAL_ReconnectSession) { 664 MANUAL_ReconnectSession) {
637 RunReconnectSessionTest(); 665 RunReconnectSessionTest();
638 } 666 }
639 667
640 } // namespace media_router 668 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698