| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Test of classes in the tracked_objects.h classes. | 5 // Test of classes in the tracked_objects.h classes. |
| 6 | 6 |
| 7 #include "base/tracked_objects.h" | 7 #include "base/tracked_objects.h" |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace tracked_objects { | 14 namespace tracked_objects { |
| 15 | 15 |
| 16 class TrackedObjectsTest : public testing::Test { | 16 class TrackedObjectsTest : public testing::Test { |
| 17 public: | 17 public: |
| 18 TrackedObjectsTest() { | 18 TrackedObjectsTest() { |
| 19 ThreadData::ShutdownSingleThreadedCleanup(); | 19 // On entry, leak any database structures in case they are still in use by |
| 20 // prior threads. |
| 21 ThreadData::ShutdownSingleThreadedCleanup(true); |
| 20 } | 22 } |
| 21 | 23 |
| 22 ~TrackedObjectsTest() { | 24 ~TrackedObjectsTest() { |
| 23 ThreadData::ShutdownSingleThreadedCleanup(); | 25 // We should not need to leak any structures we create, since we are |
| 26 // single threaded, and carefully accounting for items. |
| 27 ThreadData::ShutdownSingleThreadedCleanup(false); |
| 24 } | 28 } |
| 25 }; | 29 }; |
| 26 | 30 |
| 27 TEST_F(TrackedObjectsTest, MinimalStartupShutdown) { | 31 TEST_F(TrackedObjectsTest, MinimalStartupShutdown) { |
| 28 // Minimal test doesn't even create any tasks. | 32 // Minimal test doesn't even create any tasks. |
| 29 if (!ThreadData::InitializeAndSetTrackingStatus(true)) | 33 if (!ThreadData::InitializeAndSetTrackingStatus(true)) |
| 30 return; | 34 return; |
| 31 | 35 |
| 32 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. | 36 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. |
| 33 ThreadData* data = ThreadData::Get(); | 37 ThreadData* data = ThreadData::Get(); |
| 34 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. | 38 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. |
| 35 EXPECT_TRUE(data); | 39 EXPECT_TRUE(data); |
| 36 EXPECT_TRUE(!data->next()); | 40 EXPECT_TRUE(!data->next()); |
| 37 EXPECT_EQ(data, ThreadData::Get()); | 41 EXPECT_EQ(data, ThreadData::Get()); |
| 38 ThreadData::BirthMap birth_map; | 42 ThreadData::BirthMap birth_map; |
| 39 data->SnapshotBirthMap(&birth_map); | 43 data->SnapshotBirthMap(&birth_map); |
| 40 EXPECT_EQ(0u, birth_map.size()); | 44 EXPECT_EQ(0u, birth_map.size()); |
| 41 ThreadData::DeathMap death_map; | 45 ThreadData::DeathMap death_map; |
| 42 data->SnapshotDeathMap(&death_map); | 46 data->SnapshotDeathMap(&death_map); |
| 43 EXPECT_EQ(0u, death_map.size()); | 47 EXPECT_EQ(0u, death_map.size()); |
| 44 ThreadData::ShutdownSingleThreadedCleanup(); | 48 // Cleanup with no leaking. |
| 49 ThreadData::ShutdownSingleThreadedCleanup(false); |
| 45 | 50 |
| 46 // Do it again, just to be sure we reset state completely. | 51 // Do it again, just to be sure we reset state completely. |
| 47 ThreadData::InitializeAndSetTrackingStatus(true); | 52 ThreadData::InitializeAndSetTrackingStatus(true); |
| 48 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. | 53 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. |
| 49 data = ThreadData::Get(); | 54 data = ThreadData::Get(); |
| 50 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. | 55 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. |
| 51 EXPECT_TRUE(data); | 56 EXPECT_TRUE(data); |
| 52 EXPECT_TRUE(!data->next()); | 57 EXPECT_TRUE(!data->next()); |
| 53 EXPECT_EQ(data, ThreadData::Get()); | 58 EXPECT_EQ(data, ThreadData::Get()); |
| 54 birth_map.clear(); | 59 birth_map.clear(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 EXPECT_EQ(data->queue_duration(), queue_duration + queue_duration); | 136 EXPECT_EQ(data->queue_duration(), queue_duration + queue_duration); |
| 132 EXPECT_EQ(data->AverageMsRunDuration(), run_ms); | 137 EXPECT_EQ(data->AverageMsRunDuration(), run_ms); |
| 133 EXPECT_EQ(data->AverageMsQueueDuration(), queue_ms); | 138 EXPECT_EQ(data->AverageMsQueueDuration(), queue_ms); |
| 134 EXPECT_EQ(data->count(), 2); | 139 EXPECT_EQ(data->count(), 2); |
| 135 | 140 |
| 136 scoped_ptr<base::DictionaryValue> dictionary(data->ToValue()); | 141 scoped_ptr<base::DictionaryValue> dictionary(data->ToValue()); |
| 137 int integer; | 142 int integer; |
| 138 EXPECT_TRUE(dictionary->GetInteger("run_ms", &integer)); | 143 EXPECT_TRUE(dictionary->GetInteger("run_ms", &integer)); |
| 139 EXPECT_EQ(integer, 2 * run_ms); | 144 EXPECT_EQ(integer, 2 * run_ms); |
| 140 EXPECT_TRUE(dictionary->GetInteger("queue_ms", &integer)); | 145 EXPECT_TRUE(dictionary->GetInteger("queue_ms", &integer)); |
| 141 EXPECT_EQ(integer, 2* queue_ms); | 146 EXPECT_EQ(integer, 2 * queue_ms); |
| 142 EXPECT_TRUE(dictionary->GetInteger("count", &integer)); | 147 EXPECT_TRUE(dictionary->GetInteger("count", &integer)); |
| 143 EXPECT_EQ(integer, 2); | 148 EXPECT_EQ(integer, 2); |
| 144 | 149 |
| 145 std::string output; | 150 std::string output; |
| 146 data->WriteHTML(&output); | 151 data->WriteHTML(&output); |
| 147 std::string results = "Lives:2, Run:84ms(42ms/life) Queue:16ms(8ms/life) "; | 152 std::string results = "Lives:2, Run:84ms(42ms/life) Queue:16ms(8ms/life) "; |
| 148 EXPECT_EQ(output, results); | 153 EXPECT_EQ(output, results); |
| 149 | 154 |
| 150 scoped_ptr<base::Value> value(data->ToValue()); | 155 scoped_ptr<base::Value> value(data->ToValue()); |
| 151 std::string json; | 156 std::string json; |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 "\"function_name\":\"DifferentLives\"," | 599 "\"function_name\":\"DifferentLives\"," |
| 595 "\"line_number\":999" | 600 "\"line_number\":999" |
| 596 "}" | 601 "}" |
| 597 "}" | 602 "}" |
| 598 "]" | 603 "]" |
| 599 "}"; | 604 "}"; |
| 600 EXPECT_EQ(one_line_result, json); | 605 EXPECT_EQ(one_line_result, json); |
| 601 } | 606 } |
| 602 | 607 |
| 603 } // namespace tracked_objects | 608 } // namespace tracked_objects |
| OLD | NEW |