Remove Unused AsTextButtonBorder RTTI helper.
[chromium-blink-merge.git] / media / cast / logging / simple_event_subscriber_unittest.cc
blob310db9ca4092f6a78dc7559e780e18c3c0041c4d
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(), task_runner_,
25 task_runner_, task_runner_, task_runner_, task_runner_,
26 task_runner_, GetLoggingConfigWithRawEventsAndStatsEnabled())) {
27 cast_environment_->Logging()->AddRawEventSubscriber(&event_subscriber_);
30 virtual ~SimpleEventSubscriberTest() {
31 cast_environment_->Logging()->RemoveRawEventSubscriber(&event_subscriber_);
34 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment.
35 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_;
36 scoped_refptr<CastEnvironment> cast_environment_;
37 SimpleEventSubscriber event_subscriber_;
40 TEST_F(SimpleEventSubscriberTest, GetAndResetEvents) {
41 // Log some frame events.
42 cast_environment_->Logging()->InsertFrameEventWithSize(
43 testing_clock_->NowTicks(), kAudioFrameEncoded, /*rtp_timestamp*/ 100u,
44 /*frame_id*/ 0u, /*frame_size*/ 123);
45 cast_environment_->Logging()->InsertFrameEventWithDelay(
46 testing_clock_->NowTicks(), kAudioPlayoutDelay, /*rtp_timestamp*/ 100u,
47 /*frame_id*/ 0u, /*delay*/ base::TimeDelta::FromMilliseconds(100));
48 cast_environment_->Logging()->InsertFrameEvent(
49 testing_clock_->NowTicks(), kAudioFrameDecoded, /*rtp_timestamp*/ 200u,
50 /*frame_id*/ 0u);
52 // Log some packet events.
53 cast_environment_->Logging()->InsertPacketEvent(
54 testing_clock_->NowTicks(), kAudioPacketReceived, /*rtp_timestamp*/ 200u,
55 /*frame_id*/ 0u, /*packet_id*/ 1u, /*max_packet_id*/ 5u, /*size*/ 100u);
56 cast_environment_->Logging()->InsertPacketEvent(
57 testing_clock_->NowTicks(), kVideoFrameDecoded, /*rtp_timestamp*/ 200u,
58 /*frame_id*/ 0u, /*packet_id*/ 1u, /*max_packet_id*/ 5u, /*size*/ 100u);
59 cast_environment_->Logging()->InsertPacketEvent(
60 testing_clock_->NowTicks(), kVideoFrameDecoded, /*rtp_timestamp*/ 300u,
61 /*frame_id*/ 0u, /*packet_id*/ 1u, /*max_packet_id*/ 5u, /*size*/ 100u);
63 // Log some generic events.
64 cast_environment_->Logging()->InsertGenericEvent(testing_clock_->NowTicks(),
65 kRttMs, /*value*/ 150);
67 std::vector<FrameEvent> frame_events;
68 event_subscriber_.GetFrameEventsAndReset(&frame_events);
69 EXPECT_EQ(3u, frame_events.size());
71 std::vector<PacketEvent> packet_events;
72 event_subscriber_.GetPacketEventsAndReset(&packet_events);
73 EXPECT_EQ(3u, packet_events.size());
75 std::vector<GenericEvent> generic_events;
76 event_subscriber_.GetGenericEventsAndReset(&generic_events);
77 EXPECT_EQ(1u, generic_events.size());
79 // Calling this function again should result in empty vector because no events
80 // were logged since last call.
81 event_subscriber_.GetFrameEventsAndReset(&frame_events);
82 event_subscriber_.GetPacketEventsAndReset(&packet_events);
83 event_subscriber_.GetGenericEventsAndReset(&generic_events);
84 EXPECT_TRUE(frame_events.empty());
85 EXPECT_TRUE(packet_events.empty());
86 EXPECT_TRUE(generic_events.empty());
89 } // namespace cast
90 } // namespace media