Remove Unused AsTextButtonBorder RTTI helper.
[chromium-blink-merge.git] / media / cast / logging / logging_raw_unittest.cc
blob135aed5ea1b121a9a4792d53dd1cdf5d113190b8
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 "media/cast/logging/logging_defines.h"
6 #include "media/cast/logging/logging_raw.h"
7 #include "media/cast/logging/simple_event_subscriber.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace media {
11 namespace cast {
13 class LoggingRawTest : public ::testing::Test {
14 protected:
15 LoggingRawTest() {
16 raw_.AddSubscriber(&event_subscriber_);
19 virtual ~LoggingRawTest() { raw_.RemoveSubscriber(&event_subscriber_); }
21 LoggingRaw raw_;
22 SimpleEventSubscriber event_subscriber_;
23 std::vector<FrameEvent> frame_events_;
24 std::vector<PacketEvent> packet_events_;
25 std::vector<GenericEvent> generic_events_;
28 TEST_F(LoggingRawTest, FrameEvent) {
29 CastLoggingEvent event_type = kVideoFrameDecoded;
30 uint32 frame_id = 456u;
31 RtpTimestamp rtp_timestamp = 123u;
32 base::TimeTicks timestamp = base::TimeTicks();
33 raw_.InsertFrameEvent(timestamp, event_type, rtp_timestamp, frame_id);
35 event_subscriber_.GetPacketEventsAndReset(&packet_events_);
36 EXPECT_TRUE(packet_events_.empty());
38 event_subscriber_.GetGenericEventsAndReset(&generic_events_);
39 EXPECT_TRUE(generic_events_.empty());
41 event_subscriber_.GetFrameEventsAndReset(&frame_events_);
42 ASSERT_EQ(1u, frame_events_.size());
43 EXPECT_EQ(rtp_timestamp, frame_events_[0].rtp_timestamp);
44 EXPECT_EQ(frame_id, frame_events_[0].frame_id);
45 EXPECT_EQ(0u, frame_events_[0].size);
46 EXPECT_EQ(timestamp, frame_events_[0].timestamp);
47 EXPECT_EQ(event_type, frame_events_[0].type);
48 EXPECT_EQ(base::TimeDelta(), frame_events_[0].delay_delta);
51 TEST_F(LoggingRawTest, FrameEventWithSize) {
52 CastLoggingEvent event_type = kVideoFrameEncoded;
53 uint32 frame_id = 456u;
54 RtpTimestamp rtp_timestamp = 123u;
55 base::TimeTicks timestamp = base::TimeTicks();
56 int size = 1024;
57 raw_.InsertFrameEventWithSize(timestamp, event_type, rtp_timestamp, frame_id,
58 size);
60 event_subscriber_.GetPacketEventsAndReset(&packet_events_);
61 EXPECT_TRUE(packet_events_.empty());
63 event_subscriber_.GetGenericEventsAndReset(&generic_events_);
64 EXPECT_TRUE(generic_events_.empty());
66 event_subscriber_.GetFrameEventsAndReset(&frame_events_);
67 ASSERT_EQ(1u, frame_events_.size());
68 EXPECT_EQ(rtp_timestamp, frame_events_[0].rtp_timestamp);
69 EXPECT_EQ(frame_id, frame_events_[0].frame_id);
70 EXPECT_EQ(size, static_cast<int>(frame_events_[0].size));
71 EXPECT_EQ(timestamp, frame_events_[0].timestamp);
72 EXPECT_EQ(event_type, frame_events_[0].type);
73 EXPECT_EQ(base::TimeDelta(), frame_events_[0].delay_delta);
76 TEST_F(LoggingRawTest, FrameEventWithDelay) {
77 CastLoggingEvent event_type = kVideoRenderDelay;
78 uint32 frame_id = 456u;
79 RtpTimestamp rtp_timestamp = 123u;
80 base::TimeTicks timestamp = base::TimeTicks();
81 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(20);
82 raw_.InsertFrameEventWithDelay(timestamp, event_type, rtp_timestamp, frame_id,
83 delay);
85 event_subscriber_.GetPacketEventsAndReset(&packet_events_);
86 EXPECT_TRUE(packet_events_.empty());
88 event_subscriber_.GetGenericEventsAndReset(&generic_events_);
89 EXPECT_TRUE(generic_events_.empty());
91 event_subscriber_.GetFrameEventsAndReset(&frame_events_);
92 ASSERT_EQ(1u, frame_events_.size());
93 EXPECT_EQ(rtp_timestamp, frame_events_[0].rtp_timestamp);
94 EXPECT_EQ(frame_id, frame_events_[0].frame_id);
95 EXPECT_EQ(0u, frame_events_[0].size);
96 EXPECT_EQ(timestamp, frame_events_[0].timestamp);
97 EXPECT_EQ(event_type, frame_events_[0].type);
98 EXPECT_EQ(delay, frame_events_[0].delay_delta);
101 TEST_F(LoggingRawTest, PacketEvent) {
102 CastLoggingEvent event_type = kVideoPacketReceived;
103 uint32 frame_id = 456u;
104 uint16 packet_id = 1u;
105 uint16 max_packet_id = 10u;
106 RtpTimestamp rtp_timestamp = 123u;
107 base::TimeTicks timestamp = base::TimeTicks();
108 size_t size = 1024u;
109 raw_.InsertPacketEvent(timestamp, event_type, rtp_timestamp, frame_id,
110 packet_id, max_packet_id, size);
112 event_subscriber_.GetFrameEventsAndReset(&frame_events_);
113 EXPECT_TRUE(frame_events_.empty());
115 event_subscriber_.GetGenericEventsAndReset(&generic_events_);
116 EXPECT_TRUE(generic_events_.empty());
118 event_subscriber_.GetPacketEventsAndReset(&packet_events_);
119 ASSERT_EQ(1u, packet_events_.size());
120 EXPECT_EQ(rtp_timestamp, packet_events_[0].rtp_timestamp);
121 EXPECT_EQ(frame_id, packet_events_[0].frame_id);
122 EXPECT_EQ(max_packet_id, packet_events_[0].max_packet_id);
123 EXPECT_EQ(packet_id, packet_events_[0].packet_id);
124 EXPECT_EQ(size, packet_events_[0].size);
125 EXPECT_EQ(timestamp, packet_events_[0].timestamp);
126 EXPECT_EQ(event_type, packet_events_[0].type);
129 TEST_F(LoggingRawTest, GenericEvent) {
130 CastLoggingEvent event_type = kRttMs;
131 base::TimeTicks timestamp = base::TimeTicks();
132 int value = 100;
133 raw_.InsertGenericEvent(timestamp, event_type, value);
135 event_subscriber_.GetFrameEventsAndReset(&frame_events_);
136 EXPECT_TRUE(frame_events_.empty());
138 event_subscriber_.GetPacketEventsAndReset(&packet_events_);
139 EXPECT_TRUE(packet_events_.empty());
141 event_subscriber_.GetGenericEventsAndReset(&generic_events_);
142 ASSERT_EQ(1u, generic_events_.size());
143 EXPECT_EQ(event_type, generic_events_[0].type);
144 EXPECT_EQ(value, generic_events_[0].value);
145 EXPECT_EQ(timestamp, generic_events_[0].timestamp);
148 TEST_F(LoggingRawTest, MultipleSubscribers) {
149 SimpleEventSubscriber event_subscriber_2;
151 // Now raw_ has two subscribers.
152 raw_.AddSubscriber(&event_subscriber_2);
154 CastLoggingEvent event_type = kVideoFrameDecoded;
155 uint32 frame_id = 456u;
156 RtpTimestamp rtp_timestamp = 123u;
157 base::TimeTicks timestamp = base::TimeTicks();
158 raw_.InsertFrameEvent(timestamp, event_type, rtp_timestamp, frame_id);
160 event_subscriber_.GetPacketEventsAndReset(&packet_events_);
161 EXPECT_TRUE(packet_events_.empty());
163 event_subscriber_.GetGenericEventsAndReset(&generic_events_);
164 EXPECT_TRUE(generic_events_.empty());
166 event_subscriber_.GetFrameEventsAndReset(&frame_events_);
167 ASSERT_EQ(1u, frame_events_.size());
168 EXPECT_EQ(rtp_timestamp, frame_events_[0].rtp_timestamp);
169 EXPECT_EQ(frame_id, frame_events_[0].frame_id);
170 EXPECT_EQ(0u, frame_events_[0].size);
171 EXPECT_EQ(timestamp, frame_events_[0].timestamp);
172 EXPECT_EQ(event_type, frame_events_[0].type);
173 EXPECT_EQ(base::TimeDelta(), frame_events_[0].delay_delta);
175 event_subscriber_2.GetPacketEventsAndReset(&packet_events_);
176 EXPECT_TRUE(packet_events_.empty());
178 event_subscriber_2.GetGenericEventsAndReset(&generic_events_);
179 EXPECT_TRUE(generic_events_.empty());
181 event_subscriber_2.GetFrameEventsAndReset(&frame_events_);
182 ASSERT_EQ(1u, frame_events_.size());
183 EXPECT_EQ(rtp_timestamp, frame_events_[0].rtp_timestamp);
184 EXPECT_EQ(frame_id, frame_events_[0].frame_id);
185 EXPECT_EQ(0u, frame_events_[0].size);
186 EXPECT_EQ(timestamp, frame_events_[0].timestamp);
187 EXPECT_EQ(event_type, frame_events_[0].type);
188 EXPECT_EQ(base::TimeDelta(), frame_events_[0].delay_delta);
190 // Remove event_subscriber_2, so it shouldn't receive events after this.
191 raw_.RemoveSubscriber(&event_subscriber_2);
193 event_type = kAudioFrameDecoded;
194 frame_id = 789;
195 rtp_timestamp = 456;
196 timestamp = base::TimeTicks();
197 raw_.InsertFrameEvent(timestamp, event_type, rtp_timestamp, frame_id);
199 // |event_subscriber_| should still receive events.
200 event_subscriber_.GetFrameEventsAndReset(&frame_events_);
201 ASSERT_EQ(1u, frame_events_.size());
202 EXPECT_EQ(rtp_timestamp, frame_events_[0].rtp_timestamp);
203 EXPECT_EQ(frame_id, frame_events_[0].frame_id);
204 EXPECT_EQ(0u, frame_events_[0].size);
205 EXPECT_EQ(timestamp, frame_events_[0].timestamp);
206 EXPECT_EQ(event_type, frame_events_[0].type);
207 EXPECT_EQ(base::TimeDelta(), frame_events_[0].delay_delta);
209 event_subscriber_2.GetFrameEventsAndReset(&frame_events_);
210 EXPECT_TRUE(frame_events_.empty());
213 } // namespace cast
214 } // namespace media