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

Side by Side Diff: chrome/browser/media/router/presentation_service_delegate_impl_unittest.cc

Issue 2517833004: [MR] Cancel auto-switching from tab mirroring to Cast SDK at page navigation based on user pref (Closed)
Patch Set: Rebase Created 4 years 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/browser/media/router/presentation_service_delegate_impl.h" 5 #include "chrome/browser/media/router/presentation_service_delegate_impl.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "chrome/browser/media/router/media_source.h" 8 #include "chrome/browser/media/router/media_source.h"
9 #include "chrome/browser/media/router/media_source_helper.h" 9 #include "chrome/browser/media/router/media_source_helper.h"
10 #include "chrome/browser/media/router/mock_media_router.h" 10 #include "chrome/browser/media/router/mock_media_router.h"
11 #include "chrome/browser/media/router/mock_screen_availability_listener.h" 11 #include "chrome/browser/media/router/mock_screen_availability_listener.h"
12 #include "chrome/browser/media/router/route_request_result.h" 12 #include "chrome/browser/media/router/route_request_result.h"
13 #include "chrome/browser/media/router/test_helper.h" 13 #include "chrome/browser/media/router/test_helper.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/pref_names.h"
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 16 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
16 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
18 #include "components/prefs/scoped_user_pref_update.h"
17 #include "content/public/browser/presentation_screen_availability_listener.h" 19 #include "content/public/browser/presentation_screen_availability_listener.h"
18 #include "content/public/browser/presentation_session.h" 20 #include "content/public/browser/presentation_session.h"
19 #include "content/public/browser/render_process_host.h" 21 #include "content/public/browser/render_process_host.h"
20 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
21 #include "content/public/test/web_contents_tester.h" 23 #include "content/public/test/web_contents_tester.h"
22 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
25 #include "url/origin.h"
23 26
24 using ::testing::_; 27 using ::testing::_;
25 using ::testing::Mock; 28 using ::testing::Mock;
26 using ::testing::Return; 29 using ::testing::Return;
27 using ::testing::SaveArg; 30 using ::testing::SaveArg;
28 using ::testing::StrictMock; 31 using ::testing::StrictMock;
29 32
30 namespace { 33 namespace {
31 34
32 const char kPresentationUrl1[] = "http://foo.fakeurl.com/"; 35 const char kPresentationUrl1[] = "http://foo.fakeurl.com/";
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 ASSERT_TRUE(main_frame); 469 ASSERT_TRUE(main_frame);
467 int render_process_id = main_frame->GetProcess()->GetID(); 470 int render_process_id = main_frame->GetProcess()->GetID();
468 int render_frame_id = main_frame->GetRoutingID(); 471 int render_frame_id = main_frame->GetRoutingID();
469 472
470 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false)); 473 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).WillOnce(Return(false));
471 EXPECT_CALL(listener, OnScreenAvailabilityNotSupported()); 474 EXPECT_CALL(listener, OnScreenAvailabilityNotSupported());
472 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener( 475 EXPECT_FALSE(delegate_impl_->AddScreenAvailabilityListener(
473 render_process_id, render_frame_id, &listener)); 476 render_process_id, render_frame_id, &listener));
474 } 477 }
475 478
479 #if !defined(OS_ANDROID)
480 TEST_F(PresentationServiceDelegateImplTest, AutoJoinRequest) {
481 GURL frame_url(kFrameUrl);
482 std::string origin(url::Origin(frame_url).Serialize());
483 content::WebContentsTester::For(GetWebContents())
484 ->NavigateAndCommit(frame_url);
485 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame();
486 ASSERT_TRUE(main_frame);
487 int render_process_id = main_frame->GetProcess()->GetID();
488 int routing_id = main_frame->GetRoutingID();
mark a. foltz 2016/12/09 04:07:42 A lot of this setup code seems to be duplicated be
takumif 2016/12/09 19:18:12 I'll do that in a separate patch.
489
490 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks;
491 const std::string kPresentationId("auto-join");
492 ASSERT_TRUE(IsAutoJoinPresentationId(kPresentationId));
493
494 // Set the user preference for |origin| to prefer tab mirroring.
495 std::unique_ptr<ListPrefUpdate> update = base::MakeUnique<ListPrefUpdate>(
496 profile()->GetPrefs(), prefs::kMediaRouterTabMirroringSources);
497 (*update.get())
498 ->AppendIfNotPresent(base::MakeUnique<base::StringValue>(origin));
499 update.reset();
mark a. foltz 2016/12/09 04:07:42 Instead of manually resetting the unique_ptr, slig
takumif 2016/12/09 19:18:12 Done.
500
501 // Auto-join requests should be rejected.
502 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionError(_));
503 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(0);
504 delegate_impl_->JoinSession(
505 render_process_id, routing_id, presentation_urls_, kPresentationId,
506 base::Bind(&MockCreatePresentationConnnectionCallbacks::
507 OnCreateConnectionSuccess,
508 base::Unretained(&mock_create_connection_callbacks)),
509 base::Bind(
510 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError,
511 base::Unretained(&mock_create_connection_callbacks)));
512
513 // Remove the user preference for |origin|.
514 update = base::MakeUnique<ListPrefUpdate>(
515 profile()->GetPrefs(), prefs::kMediaRouterTabMirroringSources);
516 (*update.get())->Remove(base::StringValue(origin), nullptr);
517 update.reset();
518
519 // Auto-join requests should now go through.
520 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(1);
521 delegate_impl_->JoinSession(
522 render_process_id, routing_id, presentation_urls_, kPresentationId,
523 base::Bind(&MockCreatePresentationConnnectionCallbacks::
524 OnCreateConnectionSuccess,
525 base::Unretained(&mock_create_connection_callbacks)),
526 base::Bind(
527 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError,
528 base::Unretained(&mock_create_connection_callbacks)));
529 }
530
531 TEST_F(PresentationServiceDelegateImplIncognitoTest, AutoJoinRequest) {
532 GURL frame_url(kFrameUrl);
533 std::string origin(url::Origin(frame_url).Serialize());
534 content::WebContentsTester::For(GetWebContents())
535 ->NavigateAndCommit(frame_url);
536 content::RenderFrameHost* main_frame = GetWebContents()->GetMainFrame();
537 ASSERT_TRUE(main_frame);
538 int render_process_id = main_frame->GetProcess()->GetID();
539 int routing_id = main_frame->GetRoutingID();
540
541 MockCreatePresentationConnnectionCallbacks mock_create_connection_callbacks;
542 const std::string kPresentationId("auto-join");
543 ASSERT_TRUE(IsAutoJoinPresentationId(kPresentationId));
544
545 // Set the user preference for |origin| to prefer tab mirroring.
546 std::unique_ptr<ListPrefUpdate> update = base::MakeUnique<ListPrefUpdate>(
547 profile()->GetOffTheRecordProfile()->GetPrefs(),
548 prefs::kMediaRouterTabMirroringSources);
549 (*update.get())
550 ->AppendIfNotPresent(base::MakeUnique<base::StringValue>(origin));
551 update.reset();
552
553 // Setting the pref in incognito shouldn't set it for the non-incognito
554 // profile.
555 const base::ListValue* non_incognito_origins =
556 profile()->GetPrefs()->GetList(prefs::kMediaRouterTabMirroringSources);
557 EXPECT_EQ(non_incognito_origins->Find(base::StringValue(origin)),
558 non_incognito_origins->end());
559
560 // Auto-join requests should be rejected.
561 EXPECT_CALL(mock_create_connection_callbacks, OnCreateConnectionError(_));
562 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(0);
563 delegate_impl_->JoinSession(
564 render_process_id, routing_id, presentation_urls_, kPresentationId,
565 base::Bind(&MockCreatePresentationConnnectionCallbacks::
566 OnCreateConnectionSuccess,
567 base::Unretained(&mock_create_connection_callbacks)),
568 base::Bind(
569 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError,
570 base::Unretained(&mock_create_connection_callbacks)));
571
572 // Remove the user preference for |origin| in incognito.
573 update = base::MakeUnique<ListPrefUpdate>(
574 profile()->GetOffTheRecordProfile()->GetPrefs(),
575 prefs::kMediaRouterTabMirroringSources);
576 (*update.get())->Remove(base::StringValue(origin), nullptr);
577 update.reset();
578
579 // Auto-join requests should now go through.
580 EXPECT_CALL(router_, JoinRoute(_, kPresentationId, _, _, _, _, _)).Times(1);
581 delegate_impl_->JoinSession(
582 render_process_id, routing_id, presentation_urls_, kPresentationId,
583 base::Bind(&MockCreatePresentationConnnectionCallbacks::
584 OnCreateConnectionSuccess,
585 base::Unretained(&mock_create_connection_callbacks)),
586 base::Bind(
587 &MockCreatePresentationConnnectionCallbacks::OnCreateConnectionError,
588 base::Unretained(&mock_create_connection_callbacks)));
589 }
590 #endif // !defined(OS_ANDROID)
591
476 } // namespace media_router 592 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698