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.
7 #include "base/time/time.h"
8 #include "base/values.h"
9 #include "cc/debug/rendering_stats.h"
10 #include "testing/gtest/include/gtest/gtest.h"
15 static std::string
ToString(const RenderingStats::TimeDeltaList
& list
) {
16 scoped_refptr
<base::trace_event::TracedValue
> value
=
17 new base::trace_event::TracedValue();
18 list
.AddToTracedValue("list_value", value
.get());
19 return value
->ToString();
22 TEST(RenderingStatsTest
, TimeDeltaListEmpty
) {
23 RenderingStats::TimeDeltaList time_delta_list
;
24 EXPECT_EQ("{\"list_value\":[]}", ToString(time_delta_list
));
27 TEST(RenderingStatsTest
, TimeDeltaListNonEmpty
) {
28 RenderingStats::TimeDeltaList time_delta_list
;
29 time_delta_list
.Append(base::TimeDelta::FromMilliseconds(234));
30 time_delta_list
.Append(base::TimeDelta::FromMilliseconds(827));
32 EXPECT_EQ("{\"list_value\":[234.0,827.0]}", ToString(time_delta_list
));
35 TEST(RenderingStatsTest
, TimeDeltaListAdd
) {
36 RenderingStats::TimeDeltaList time_delta_list_a
;
37 time_delta_list_a
.Append(base::TimeDelta::FromMilliseconds(810));
38 time_delta_list_a
.Append(base::TimeDelta::FromMilliseconds(32));
40 RenderingStats::TimeDeltaList time_delta_list_b
;
41 time_delta_list_b
.Append(base::TimeDelta::FromMilliseconds(43));
42 time_delta_list_b
.Append(base::TimeDelta::FromMilliseconds(938));
43 time_delta_list_b
.Append(base::TimeDelta::FromMilliseconds(2));
45 time_delta_list_a
.Add(time_delta_list_b
);
46 EXPECT_EQ("{\"list_value\":[810.0,32.0,43.0,938.0,2.0]}",
47 ToString(time_delta_list_a
));