OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include <string> |
| 6 |
5 #include "base/time/time.h" | 7 #include "base/time/time.h" |
6 #include "base/values.h" | 8 #include "base/values.h" |
7 #include "cc/debug/rendering_stats.h" | 9 #include "cc/debug/rendering_stats.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
9 | 11 |
10 namespace cc { | 12 namespace cc { |
11 namespace { | 13 namespace { |
12 | 14 |
13 void CompareDoubleValue(const base::ListValue& list_value, | 15 static std::string ToString(const RenderingStats::TimeDeltaList& list) { |
14 int index, | 16 scoped_refptr<base::debug::TracedValue> value = |
15 double expected_value) { | 17 new base::debug::TracedValue(); |
16 double value; | 18 value->BeginArray("list_value"); |
17 EXPECT_TRUE(list_value.GetDouble(index, &value)); | 19 list.AddToTracedValue(value.get()); |
18 EXPECT_EQ(expected_value, value); | 20 value->EndArray(); |
| 21 return value->ToString(); |
19 } | 22 } |
20 | 23 |
21 TEST(RenderingStatsTest, TimeDeltaListEmpty) { | 24 TEST(RenderingStatsTest, TimeDeltaListEmpty) { |
22 RenderingStats::TimeDeltaList time_delta_list; | 25 RenderingStats::TimeDeltaList time_delta_list; |
23 scoped_ptr<base::ListValue> list_value = | 26 EXPECT_EQ("{\"list_value\":[]}", ToString(time_delta_list)); |
24 time_delta_list.AsListValueInMilliseconds(); | |
25 EXPECT_TRUE(list_value->empty()); | |
26 EXPECT_EQ(0ul, list_value->GetSize()); | |
27 } | 27 } |
28 | 28 |
29 TEST(RenderingStatsTest, TimeDeltaListNonEmpty) { | 29 TEST(RenderingStatsTest, TimeDeltaListNonEmpty) { |
30 RenderingStats::TimeDeltaList time_delta_list; | 30 RenderingStats::TimeDeltaList time_delta_list; |
31 time_delta_list.Append(base::TimeDelta::FromMilliseconds(234)); | 31 time_delta_list.Append(base::TimeDelta::FromMilliseconds(234)); |
32 time_delta_list.Append(base::TimeDelta::FromMilliseconds(827)); | 32 time_delta_list.Append(base::TimeDelta::FromMilliseconds(827)); |
33 | 33 |
34 scoped_ptr<base::ListValue> list_value = | 34 EXPECT_EQ("{\"list_value\":[234.0,827.0]}", ToString(time_delta_list)); |
35 time_delta_list.AsListValueInMilliseconds(); | |
36 EXPECT_FALSE(list_value->empty()); | |
37 EXPECT_EQ(2ul, list_value->GetSize()); | |
38 | |
39 CompareDoubleValue(*list_value.get(), 0, 234); | |
40 CompareDoubleValue(*list_value.get(), 1, 827); | |
41 } | 35 } |
42 | 36 |
43 TEST(RenderingStatsTest, TimeDeltaListAdd) { | 37 TEST(RenderingStatsTest, TimeDeltaListAdd) { |
44 RenderingStats::TimeDeltaList time_delta_list_a; | 38 RenderingStats::TimeDeltaList time_delta_list_a; |
45 time_delta_list_a.Append(base::TimeDelta::FromMilliseconds(810)); | 39 time_delta_list_a.Append(base::TimeDelta::FromMilliseconds(810)); |
46 time_delta_list_a.Append(base::TimeDelta::FromMilliseconds(32)); | 40 time_delta_list_a.Append(base::TimeDelta::FromMilliseconds(32)); |
47 | 41 |
48 RenderingStats::TimeDeltaList time_delta_list_b; | 42 RenderingStats::TimeDeltaList time_delta_list_b; |
49 time_delta_list_b.Append(base::TimeDelta::FromMilliseconds(43)); | 43 time_delta_list_b.Append(base::TimeDelta::FromMilliseconds(43)); |
50 time_delta_list_b.Append(base::TimeDelta::FromMilliseconds(938)); | 44 time_delta_list_b.Append(base::TimeDelta::FromMilliseconds(938)); |
51 time_delta_list_b.Append(base::TimeDelta::FromMilliseconds(2)); | 45 time_delta_list_b.Append(base::TimeDelta::FromMilliseconds(2)); |
52 | 46 |
53 time_delta_list_a.Add(time_delta_list_b); | 47 time_delta_list_a.Add(time_delta_list_b); |
54 scoped_ptr<base::ListValue> list_value = | 48 EXPECT_EQ("{\"list_value\":[810.0,32.0,43.0,938.0,2.0]}", |
55 time_delta_list_a.AsListValueInMilliseconds(); | 49 ToString(time_delta_list_a)); |
56 EXPECT_FALSE(list_value->empty()); | |
57 EXPECT_EQ(5ul, list_value->GetSize()); | |
58 | |
59 CompareDoubleValue(*list_value.get(), 0, 810); | |
60 CompareDoubleValue(*list_value.get(), 1, 32); | |
61 CompareDoubleValue(*list_value.get(), 2, 43); | |
62 CompareDoubleValue(*list_value.get(), 3, 938); | |
63 CompareDoubleValue(*list_value.get(), 4, 2); | |
64 } | 50 } |
65 | 51 |
66 } // namespace | 52 } // namespace |
67 } // namespace cc | 53 } // namespace cc |
OLD | NEW |