Compute can_use_lcd_text using property trees.
[chromium-blink-merge.git] / cc / debug / frame_timing_tracker_unittest.cc
blob218927cf26ad1451e63304e8290ff0ee57397b64
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 <set>
6 #include <string>
8 #include "base/time/time.h"
9 #include "base/trace_event/trace_event_argument.h"
10 #include "base/values.h"
11 #include "cc/debug/frame_timing_tracker.h"
12 #include "cc/test/fake_impl_proxy.h"
13 #include "cc/test/fake_layer_tree_host_impl.h"
14 #include "cc/test/test_shared_bitmap_manager.h"
15 #include "cc/test/test_task_graph_runner.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 namespace cc {
19 namespace {
21 std::string CompositeToString(
22 scoped_ptr<FrameTimingTracker::CompositeTimingSet> timingset) {
23 scoped_refptr<base::trace_event::TracedValue> value =
24 new base::trace_event::TracedValue();
25 value->BeginArray("values");
26 std::set<int> rect_ids;
27 for (const auto& pair : *timingset)
28 rect_ids.insert(pair.first);
30 for (const auto& rect_id : rect_ids) {
31 auto& events = (*timingset)[rect_id];
32 value->BeginDictionary();
33 value->SetInteger("rect_id", rect_id);
34 value->BeginArray("events");
35 for (const auto& event : events) {
36 value->BeginDictionary();
37 value->SetInteger("frame_id", event.frame_id);
38 value->SetInteger("timestamp", event.timestamp.ToInternalValue());
39 value->EndDictionary();
41 value->EndArray();
42 value->EndDictionary();
44 value->EndArray();
45 return value->ToString();
48 std::string MainFrameToString(
49 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> timingset) {
50 scoped_refptr<base::trace_event::TracedValue> value =
51 new base::trace_event::TracedValue();
52 value->BeginArray("values");
53 std::set<int> rect_ids;
54 for (const auto& pair : *timingset)
55 rect_ids.insert(pair.first);
57 for (const auto& rect_id : rect_ids) {
58 auto& events = (*timingset)[rect_id];
59 value->BeginDictionary();
60 value->SetInteger("rect_id", rect_id);
61 value->BeginArray("events");
62 for (const auto& event : events) {
63 value->BeginDictionary();
64 value->SetInteger("end_time", event.end_time.ToInternalValue());
65 value->SetInteger("frame_id", event.frame_id);
66 value->SetInteger("timestamp", event.timestamp.ToInternalValue());
67 value->EndDictionary();
69 value->EndArray();
70 value->EndDictionary();
72 value->EndArray();
73 return value->ToString();
76 TEST(FrameTimingTrackerTest, DefaultTrackerIsEmpty) {
77 FakeImplProxy proxy;
78 TestSharedBitmapManager shared_bitmap_manager;
79 TestTaskGraphRunner task_graph_runner;
80 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
81 &task_graph_runner);
83 scoped_ptr<FrameTimingTracker> tracker(
84 FrameTimingTracker::Create(&host_impl));
85 EXPECT_EQ("{\"values\":[]}",
86 CompositeToString(tracker->GroupCompositeCountsByRectId()));
87 EXPECT_EQ("{\"values\":[]}",
88 MainFrameToString(tracker->GroupMainFrameCountsByRectId()));
91 TEST(FrameTimingTrackerTest, NoFrameIdsIsEmpty) {
92 FakeImplProxy proxy;
93 TestSharedBitmapManager shared_bitmap_manager;
94 TestTaskGraphRunner task_graph_runner;
95 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
96 &task_graph_runner);
98 scoped_ptr<FrameTimingTracker> tracker(
99 FrameTimingTracker::Create(&host_impl));
100 std::vector<std::pair<int, int64_t>> ids;
101 tracker->SaveTimeStamps(base::TimeTicks::FromInternalValue(100), ids);
102 EXPECT_EQ("{\"values\":[]}",
103 CompositeToString(tracker->GroupCompositeCountsByRectId()));
106 TEST(FrameTimingTrackerTest, NoRectIdsYieldsNoMainFrameEvents) {
107 FakeImplProxy proxy;
108 TestSharedBitmapManager shared_bitmap_manager;
109 TestTaskGraphRunner task_graph_runner;
110 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
111 &task_graph_runner);
113 scoped_ptr<FrameTimingTracker> tracker(
114 FrameTimingTracker::Create(&host_impl));
115 tracker->SaveMainFrameTimeStamps(std::vector<int64_t>(),
116 base::TimeTicks::FromInternalValue(100),
117 base::TimeTicks::FromInternalValue(110), 1);
118 EXPECT_EQ("{\"values\":[]}",
119 MainFrameToString(tracker->GroupMainFrameCountsByRectId()));
122 TEST(FrameTimingTrackerTest, OneFrameId) {
123 FakeImplProxy proxy;
124 TestSharedBitmapManager shared_bitmap_manager;
125 TestTaskGraphRunner task_graph_runner;
126 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
127 &task_graph_runner);
129 scoped_ptr<FrameTimingTracker> tracker(
130 FrameTimingTracker::Create(&host_impl));
131 std::vector<std::pair<int, int64_t>> ids;
132 ids.push_back(std::make_pair(1, 2));
133 tracker->SaveTimeStamps(base::TimeTicks::FromInternalValue(100), ids);
134 EXPECT_EQ(
135 "{\"values\":[{\"events\":["
136 "{\"frame_id\":1,\"timestamp\":100}],\"rect_id\":2}]}",
137 CompositeToString(tracker->GroupCompositeCountsByRectId()));
140 TEST(FrameTimingTrackerTest, OneMainFrameRect) {
141 FakeImplProxy proxy;
142 TestSharedBitmapManager shared_bitmap_manager;
143 TestTaskGraphRunner task_graph_runner;
144 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
145 &task_graph_runner);
147 scoped_ptr<FrameTimingTracker> tracker(
148 FrameTimingTracker::Create(&host_impl));
149 std::vector<int64_t> rect_ids;
150 rect_ids.push_back(1);
151 tracker->SaveMainFrameTimeStamps(rect_ids,
152 base::TimeTicks::FromInternalValue(100),
153 base::TimeTicks::FromInternalValue(110), 2);
154 EXPECT_EQ(
155 "{\"values\":[{\"events\":["
156 "{\"end_time\":110,\"frame_id\":2,\"timestamp\":100}],\"rect_id\":1}]}",
157 MainFrameToString(tracker->GroupMainFrameCountsByRectId()));
160 TEST(FrameTimingTrackerTest, UnsortedTimestampsIds) {
161 FakeImplProxy proxy;
162 TestSharedBitmapManager shared_bitmap_manager;
163 TestTaskGraphRunner task_graph_runner;
164 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
165 &task_graph_runner);
167 scoped_ptr<FrameTimingTracker> tracker(
168 FrameTimingTracker::Create(&host_impl));
169 std::vector<std::pair<int, int64_t>> ids;
170 ids.push_back(std::make_pair(1, 2));
171 tracker->SaveTimeStamps(base::TimeTicks::FromInternalValue(200), ids);
172 tracker->SaveTimeStamps(base::TimeTicks::FromInternalValue(400), ids);
173 tracker->SaveTimeStamps(base::TimeTicks::FromInternalValue(100), ids);
174 EXPECT_EQ(
175 "{\"values\":[{\"events\":["
176 "{\"frame_id\":1,\"timestamp\":100},"
177 "{\"frame_id\":1,\"timestamp\":200},"
178 "{\"frame_id\":1,\"timestamp\":400}],\"rect_id\":2}]}",
179 CompositeToString(tracker->GroupCompositeCountsByRectId()));
182 TEST(FrameTimingTrackerTest, MainFrameUnsortedTimestamps) {
183 FakeImplProxy proxy;
184 TestSharedBitmapManager shared_bitmap_manager;
185 TestTaskGraphRunner task_graph_runner;
186 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
187 &task_graph_runner);
189 scoped_ptr<FrameTimingTracker> tracker(
190 FrameTimingTracker::Create(&host_impl));
191 std::vector<int64_t> rect_ids;
192 rect_ids.push_back(2);
193 tracker->SaveMainFrameTimeStamps(rect_ids,
194 base::TimeTicks::FromInternalValue(200),
195 base::TimeTicks::FromInternalValue(280), 1);
196 tracker->SaveMainFrameTimeStamps(rect_ids,
197 base::TimeTicks::FromInternalValue(400),
198 base::TimeTicks::FromInternalValue(470), 1);
199 tracker->SaveMainFrameTimeStamps(rect_ids,
200 base::TimeTicks::FromInternalValue(100),
201 base::TimeTicks::FromInternalValue(160), 1);
202 EXPECT_EQ(
203 "{\"values\":[{\"events\":["
204 "{\"end_time\":160,\"frame_id\":1,\"timestamp\":100},"
205 "{\"end_time\":280,\"frame_id\":1,\"timestamp\":200},"
206 "{\"end_time\":470,\"frame_id\":1,\"timestamp\":400}],\"rect_id\":2}]}",
207 MainFrameToString(tracker->GroupMainFrameCountsByRectId()));
210 TEST(FrameTimingTrackerTest, MultipleFrameIds) {
211 FakeImplProxy proxy;
212 TestSharedBitmapManager shared_bitmap_manager;
213 TestTaskGraphRunner task_graph_runner;
214 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
215 &task_graph_runner);
217 scoped_ptr<FrameTimingTracker> tracker(
218 FrameTimingTracker::Create(&host_impl));
220 std::vector<std::pair<int, int64_t>> ids200;
221 ids200.push_back(std::make_pair(1, 2));
222 ids200.push_back(std::make_pair(1, 3));
223 tracker->SaveTimeStamps(base::TimeTicks::FromInternalValue(200), ids200);
225 std::vector<std::pair<int, int64_t>> ids400;
226 ids400.push_back(std::make_pair(2, 2));
227 tracker->SaveTimeStamps(base::TimeTicks::FromInternalValue(400), ids400);
229 std::vector<std::pair<int, int64_t>> ids100;
230 ids100.push_back(std::make_pair(3, 2));
231 ids100.push_back(std::make_pair(2, 3));
232 ids100.push_back(std::make_pair(3, 4));
233 tracker->SaveTimeStamps(base::TimeTicks::FromInternalValue(100), ids100);
235 EXPECT_EQ(
236 "{\"values\":[{\"events\":["
237 "{\"frame_id\":3,\"timestamp\":100},"
238 "{\"frame_id\":1,\"timestamp\":200},"
239 "{\"frame_id\":2,\"timestamp\":400}],\"rect_id\":2},"
240 "{\"events\":["
241 "{\"frame_id\":2,\"timestamp\":100},"
242 "{\"frame_id\":1,\"timestamp\":200}],\"rect_id\":3},"
243 "{\"events\":["
244 "{\"frame_id\":3,\"timestamp\":100}],\"rect_id\":4}"
245 "]}",
246 CompositeToString(tracker->GroupCompositeCountsByRectId()));
249 TEST(FrameTimingTrackerTest, MultipleMainFrameEvents) {
250 FakeImplProxy proxy;
251 TestSharedBitmapManager shared_bitmap_manager;
252 TestTaskGraphRunner task_graph_runner;
253 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
254 &task_graph_runner);
256 scoped_ptr<FrameTimingTracker> tracker(
257 FrameTimingTracker::Create(&host_impl));
259 std::vector<int64_t> rect_ids200;
260 rect_ids200.push_back(2);
261 rect_ids200.push_back(3);
262 tracker->SaveMainFrameTimeStamps(rect_ids200,
263 base::TimeTicks::FromInternalValue(200),
264 base::TimeTicks::FromInternalValue(220), 1);
266 std::vector<int64_t> rect_ids400;
267 rect_ids400.push_back(2);
268 tracker->SaveMainFrameTimeStamps(rect_ids400,
269 base::TimeTicks::FromInternalValue(400),
270 base::TimeTicks::FromInternalValue(440), 2);
272 std::vector<int64_t> rect_ids100;
273 rect_ids100.push_back(2);
274 rect_ids100.push_back(3);
275 rect_ids100.push_back(4);
276 tracker->SaveMainFrameTimeStamps(rect_ids100,
277 base::TimeTicks::FromInternalValue(100),
278 base::TimeTicks::FromInternalValue(110), 3);
280 EXPECT_EQ(
281 "{\"values\":[{\"events\":["
282 "{\"end_time\":110,\"frame_id\":3,\"timestamp\":100},"
283 "{\"end_time\":220,\"frame_id\":1,\"timestamp\":200},"
284 "{\"end_time\":440,\"frame_id\":2,\"timestamp\":400}],\"rect_id\":2},"
285 "{\"events\":["
286 "{\"end_time\":110,\"frame_id\":3,\"timestamp\":100},"
287 "{\"end_time\":220,\"frame_id\":1,\"timestamp\":200}],\"rect_id\":3},"
288 "{\"events\":["
289 "{\"end_time\":110,\"frame_id\":3,\"timestamp\":100}],\"rect_id\":4}"
290 "]}",
291 MainFrameToString(tracker->GroupMainFrameCountsByRectId()));
294 } // namespace
295 } // namespace cc