Rename GetIconID to GetIconId
[chromium-blink-merge.git] / chrome / browser / media / router / presentation_media_sinks_observer_unittest.cc
blob29b6ce76be7d1d87fdf162ecee973402260b71c5
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
3 // found in the LICENSE file.
5 #include "base/memory/scoped_ptr.h"
6 #include "base/strings/stringprintf.h"
7 #include "chrome/browser/media/router/media_source_helper.h"
8 #include "chrome/browser/media/router/mock_media_router.h"
9 #include "chrome/browser/media/router/mock_screen_availability_listener.h"
10 #include "chrome/browser/media/router/presentation_media_sinks_observer.h"
11 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
12 #include "content/public/browser/presentation_screen_availability_listener.h"
13 #include "testing/gmock/include/gmock/gmock.h"
15 using testing::_;
16 using testing::Mock;
17 using testing::Return;
19 namespace media_router {
21 class PresentationMediaSinksObserverTest : public ::testing::Test {
22 public:
23 PresentationMediaSinksObserverTest()
24 : listener_("http://example.com/presentation.html") {}
25 ~PresentationMediaSinksObserverTest() override {}
27 void SetUp() override {
28 EXPECT_CALL(router_, RegisterMediaSinksObserver(_)).Times(1);
29 observer_.reset(new PresentationMediaSinksObserver(
30 &router_, &listener_,
31 MediaSourceForPresentationUrl("http://example.com/presentation.html")));
34 void TearDown() override {
35 EXPECT_CALL(router_, UnregisterMediaSinksObserver(_));
36 observer_.reset();
39 MockMediaRouter router_;
40 MockScreenAvailabilityListener listener_;
41 scoped_ptr<PresentationMediaSinksObserver> observer_;
43 private:
44 DISALLOW_COPY_AND_ASSIGN(PresentationMediaSinksObserverTest);
47 TEST_F(PresentationMediaSinksObserverTest, AvailableScreens) {
48 std::vector<MediaSink> result;
49 result.push_back(MediaSink("sinkId", "Sink"));
51 EXPECT_CALL(listener_, OnScreenAvailabilityChanged(true)).Times(1);
52 observer_->OnSinksReceived(result);
55 TEST_F(PresentationMediaSinksObserverTest, NoAvailableScreens) {
56 EXPECT_CALL(listener_, OnScreenAvailabilityChanged(false)).Times(1);
57 observer_->OnSinksReceived(std::vector<MediaSink>());
60 TEST_F(PresentationMediaSinksObserverTest, ConsecutiveResults) {
61 EXPECT_CALL(listener_, OnScreenAvailabilityChanged(false)).Times(1);
62 observer_->OnSinksReceived(std::vector<MediaSink>());
63 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&listener_));
65 // Does not propagate result to |listener_| since result is same.
66 observer_->OnSinksReceived(std::vector<MediaSink>());
67 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&listener_));
69 // |listener_| should get result since it changed to true.
70 std::vector<MediaSink> result;
71 result.push_back(MediaSink("sinkId", "Sink"));
73 EXPECT_CALL(listener_, OnScreenAvailabilityChanged(true)).Times(1);
74 observer_->OnSinksReceived(result);
75 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&listener_));
77 // Does not propagate result to |listener_| since result is same.
78 result.push_back(MediaSink("sinkId2", "Sink 2"));
79 observer_->OnSinksReceived(result);
80 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&listener_));
82 // |listener_| should get result since it changed to false.
83 EXPECT_CALL(listener_, OnScreenAvailabilityChanged(false)).Times(1);
84 observer_->OnSinksReceived(std::vector<MediaSink>());
85 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&listener_));
88 } // namespace media_router