Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: chrome/browser/performance_monitor/database_unittest.cc

Issue 10837003: CPM Refactor and Cleanup (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_startup_times
Patch Set: Merged with latest master Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/performance_monitor/event.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 scoped_ptr<Database> db_; 64 scoped_ptr<Database> db_;
65 Database::Clock* clock_; 65 Database::Clock* clock_;
66 ScopedTempDir temp_dir_; 66 ScopedTempDir temp_dir_;
67 scoped_ptr<Event> install_event_1_; 67 scoped_ptr<Event> install_event_1_;
68 scoped_ptr<Event> install_event_2_; 68 scoped_ptr<Event> install_event_2_;
69 scoped_ptr<Event> uninstall_event_1_; 69 scoped_ptr<Event> uninstall_event_1_;
70 scoped_ptr<Event> uninstall_event_2_; 70 scoped_ptr<Event> uninstall_event_2_;
71 71
72 private: 72 private:
73 void InitEvents() { 73 void InitEvents() {
74 install_event_1_ = util::CreateExtensionInstallEvent( 74 install_event_1_ = util::CreateExtensionEvent(
75 clock_->GetTime(), "a", "extension 1", "http://foo.com", 75 EVENT_EXTENSION_INSTALL, clock_->GetTime(), "a", "extension 1",
76 static_cast<int>(Extension::LOAD), "0.1", "Test Test"); 76 "http://foo.com", static_cast<int>(Extension::LOAD), "0.1",
77 install_event_2_ = util::CreateExtensionInstallEvent( 77 "Test Test");
78 clock_->GetTime(), "b", "extension 2", "http://bar.com", 78 install_event_2_ = util::CreateExtensionEvent(
79 static_cast<int>(Extension::LOAD), "0.1", "Test Test"); 79 EVENT_EXTENSION_INSTALL, clock_->GetTime(), "b", "extension 2",
80 uninstall_event_1_ = util::CreateExtensionUninstallEvent( 80 "http://bar.com", static_cast<int>(Extension::LOAD), "0.1",
81 clock_->GetTime(), "a", "extension 1", "http://foo.com", 81 "Test Test");
82 static_cast<int>(Extension::LOAD), "0.1", "Test Test"); 82 uninstall_event_1_ = util::CreateExtensionEvent(
83 uninstall_event_2_ = util::CreateExtensionUninstallEvent( 83 EVENT_EXTENSION_UNINSTALL, clock_->GetTime(), "a", "extension 1",
84 clock_->GetTime(), "b", "extension 2", "http://bar.com", 84 "http://foo.com", static_cast<int>(Extension::LOAD), "0.1",
85 static_cast<int>(Extension::LOAD), "0.1", "Test Test"); 85 "Test Test");
86 uninstall_event_2_ = util::CreateExtensionEvent(
87 EVENT_EXTENSION_UNINSTALL, clock_->GetTime(), "b", "extension 2",
88 "http://bar.com", static_cast<int>(Extension::LOAD), "0.1",
89 "Test Test");
86 } 90 }
87 }; 91 };
88 92
89 class PerformanceMonitorDatabaseMetricTest : public ::testing::Test { 93 class PerformanceMonitorDatabaseMetricTest : public ::testing::Test {
90 protected: 94 protected:
91 PerformanceMonitorDatabaseMetricTest() { 95 PerformanceMonitorDatabaseMetricTest() {
92 clock_ = new TestingClock(); 96 clock_ = new TestingClock();
93 CHECK(temp_dir_.CreateUniqueTempDir()); 97 CHECK(temp_dir_.CreateUniqueTempDir());
94 db_ = Database::Create(temp_dir_.path()); 98 db_ = Database::Create(temp_dir_.path());
95 CHECK(db_.get()); 99 CHECK(db_.get());
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 TEST_F(PerformanceMonitorDatabaseEventTest, GetInstallEvents) { 238 TEST_F(PerformanceMonitorDatabaseEventTest, GetInstallEvents) {
235 std::vector<linked_ptr<Event> > events = 239 std::vector<linked_ptr<Event> > events =
236 db_->GetEvents(EVENT_EXTENSION_INSTALL); 240 db_->GetEvents(EVENT_EXTENSION_INSTALL);
237 ASSERT_EQ(2u, events.size()); 241 ASSERT_EQ(2u, events.size());
238 EXPECT_TRUE(events[0]->data()->Equals(install_event_1_->data())); 242 EXPECT_TRUE(events[0]->data()->Equals(install_event_1_->data()));
239 EXPECT_TRUE(events[1]->data()->Equals(install_event_2_->data())); 243 EXPECT_TRUE(events[1]->data()->Equals(install_event_2_->data()));
240 } 244 }
241 245
242 TEST_F(PerformanceMonitorDatabaseEventTest, GetUnusedEventType) { 246 TEST_F(PerformanceMonitorDatabaseEventTest, GetUnusedEventType) {
243 std::vector<linked_ptr<Event> > events = 247 std::vector<linked_ptr<Event> > events =
244 db_->GetEvents(EVENT_EXTENSION_UNLOAD); 248 db_->GetEvents(EVENT_EXTENSION_DISABLE);
245 ASSERT_TRUE(events.empty()); 249 ASSERT_TRUE(events.empty());
246 events = db_->GetEvents(EVENT_EXTENSION_UNLOAD, clock_->GetTime(), 250 events = db_->GetEvents(EVENT_EXTENSION_DISABLE, clock_->GetTime(),
247 clock_->GetTime()); 251 clock_->GetTime());
248 ASSERT_TRUE(events.empty()); 252 ASSERT_TRUE(events.empty());
249 } 253 }
250 254
251 TEST_F(PerformanceMonitorDatabaseEventTest, GetEventsTimeRange) { 255 TEST_F(PerformanceMonitorDatabaseEventTest, GetEventsTimeRange) {
252 base::Time start_time = clock_->GetTime(); 256 base::Time start_time = clock_->GetTime();
253 scoped_ptr<Event> new_install_event = 257 scoped_ptr<Event> new_install_event =
254 util::CreateExtensionInstallEvent( 258 util::CreateExtensionEvent(EVENT_EXTENSION_INSTALL, clock_->GetTime(),
255 clock_->GetTime(), "c", "test extension", "http://foo.com", 259 "c", "test extension", "http://foo.com",
256 static_cast<int>(Extension::LOAD), "0.1", "Test Test"); 260 static_cast<int>(Extension::LOAD), "0.1",
261 "Test Test");
257 scoped_ptr<Event> new_uninstall_event = 262 scoped_ptr<Event> new_uninstall_event =
258 util::CreateExtensionUninstallEvent( 263 util::CreateExtensionEvent(EVENT_EXTENSION_UNINSTALL, clock_->GetTime(),
259 clock_->GetTime(), "c", "test extension", "http://foo.com", 264 "c", "test extension", "http://foo.com",
260 static_cast<int>(Extension::LOAD), "0.1", "Test Test"); 265 static_cast<int>(Extension::LOAD), "0.1",
266 "Test Test");
261 base::Time end_time = clock_->GetTime(); 267 base::Time end_time = clock_->GetTime();
262 db_->AddEvent(*new_install_event.get()); 268 db_->AddEvent(*new_install_event.get());
263 db_->AddEvent(*new_uninstall_event.get()); 269 db_->AddEvent(*new_uninstall_event.get());
264 std::vector<linked_ptr<Event> > events = 270 std::vector<linked_ptr<Event> > events =
265 db_->GetEvents(start_time, end_time); 271 db_->GetEvents(start_time, end_time);
266 ASSERT_EQ(2u, events.size()); 272 ASSERT_EQ(2u, events.size());
267 EXPECT_TRUE(events[0]->data()->Equals(new_install_event->data())); 273 EXPECT_TRUE(events[0]->data()->Equals(new_install_event->data()));
268 EXPECT_TRUE(events[1]->data()->Equals(new_uninstall_event->data())); 274 EXPECT_TRUE(events[1]->data()->Equals(new_uninstall_event->data()));
269 events = db_->GetEvents( 275 events = db_->GetEvents(
270 EVENT_EXTENSION_INSTALL, start_time, end_time); 276 EVENT_EXTENSION_INSTALL, start_time, end_time);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 base::Time end = clock_->GetTime(); 389 base::Time end = clock_->GetTime();
384 db_->AddMetric(kProcessChromeAggregate, METRIC_CPU_USAGE, std::string("21")); 390 db_->AddMetric(kProcessChromeAggregate, METRIC_CPU_USAGE, std::string("21"));
385 Database::MetricInfoVector stats = 391 Database::MetricInfoVector stats =
386 db_->GetStatsForActivityAndMetric(METRIC_CPU_USAGE, start, end); 392 db_->GetStatsForActivityAndMetric(METRIC_CPU_USAGE, start, end);
387 ASSERT_EQ(2u, stats.size()); 393 ASSERT_EQ(2u, stats.size());
388 ASSERT_EQ(3, stats[0].value); 394 ASSERT_EQ(3, stats[0].value);
389 ASSERT_EQ(9, stats[1].value); 395 ASSERT_EQ(9, stats[1].value);
390 } 396 }
391 397
392 } // namespace performance_monitor 398 } // namespace performance_monitor
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/performance_monitor/event.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698