Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / media / cast / logging / simple_event_subscriber_unittest.cc
blobbce7f53dd70f6561fd580e800157e304b2b8635b
1 // Copyright 2014 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/ref_counted.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/test/simple_test_tick_clock.h"
8 #include "base/time/tick_clock.h"
9 #include "media/cast/cast_environment.h"
10 #include "media/cast/logging/logging_defines.h"
11 #include "media/cast/logging/simple_event_subscriber.h"
12 #include "media/cast/test/fake_single_thread_task_runner.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 namespace media {
16 namespace cast {
18 class SimpleEventSubscriberTest : public ::testing::Test {
19 protected:
20 SimpleEventSubscriberTest()
21 : testing_clock_(new base::SimpleTestTickClock()),
22 task_runner_(new test::FakeSingleThreadTaskRunner(testing_clock_)),
23 cast_environment_(new CastEnvironment(
24 scoped_ptr<base::TickClock>(testing_clock_).Pass(),
25 task_runner_,
26 task_runner_,
27 task_runner_)) {
28 cast_environment_->Logging()->AddRawEventSubscriber(&event_subscriber_);
31 virtual ~SimpleEventSubscriberTest() {
32 cast_environment_->Logging()->RemoveRawEventSubscriber(&event_subscriber_);
35 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment.
36 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_;
37 scoped_refptr<CastEnvironment> cast_environment_;
38 SimpleEventSubscriber event_subscriber_;
41 TEST_F(SimpleEventSubscriberTest, GetAndResetEvents) {
42 // Log some frame events.
43 cast_environment_->Logging()->InsertEncodedFrameEvent(
44 testing_clock_->NowTicks(), kAudioFrameEncoded, /*rtp_timestamp*/ 100u,
45 /*frame_id*/ 0u, /*frame_size*/ 123, /*key_frame*/ false, 0);
46 cast_environment_->Logging()->InsertFrameEventWithDelay(
47 testing_clock_->NowTicks(), kAudioPlayoutDelay, /*rtp_timestamp*/ 100u,
48 /*frame_id*/ 0u, /*delay*/ base::TimeDelta::FromMilliseconds(100));
49 cast_environment_->Logging()->InsertFrameEvent(
50 testing_clock_->NowTicks(), kAudioFrameDecoded, /*rtp_timestamp*/ 200u,
51 /*frame_id*/ 0u);
53 // Log some packet events.
54 cast_environment_->Logging()->InsertPacketEvent(
55 testing_clock_->NowTicks(), kAudioPacketReceived, /*rtp_timestamp*/ 200u,
56 /*frame_id*/ 0u, /*packet_id*/ 1u, /*max_packet_id*/ 5u, /*size*/ 100u);
57 cast_environment_->Logging()->InsertPacketEvent(
58 testing_clock_->NowTicks(), kVideoFrameDecoded, /*rtp_timestamp*/ 200u,
59 /*frame_id*/ 0u, /*packet_id*/ 1u, /*max_packet_id*/ 5u, /*size*/ 100u);
60 cast_environment_->Logging()->InsertPacketEvent(
61 testing_clock_->NowTicks(), kVideoFrameDecoded, /*rtp_timestamp*/ 300u,
62 /*frame_id*/ 0u, /*packet_id*/ 1u, /*max_packet_id*/ 5u, /*size*/ 100u);
64 std::vector<FrameEvent> frame_events;
65 event_subscriber_.GetFrameEventsAndReset(&frame_events);
66 EXPECT_EQ(3u, frame_events.size());
68 std::vector<PacketEvent> packet_events;
69 event_subscriber_.GetPacketEventsAndReset(&packet_events);
70 EXPECT_EQ(3u, packet_events.size());
72 // Calling this function again should result in empty vector because no events
73 // were logged since last call.
74 event_subscriber_.GetFrameEventsAndReset(&frame_events);
75 event_subscriber_.GetPacketEventsAndReset(&packet_events);
76 EXPECT_TRUE(frame_events.empty());
77 EXPECT_TRUE(packet_events.empty());
80 } // namespace cast
81 } // namespace media