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

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

Issue 12093036: Move Extension Location and Type enums to Manifest, and move InstallWarning to its own file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
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"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "chrome/browser/performance_monitor/database.h" 14 #include "chrome/browser/performance_monitor/database.h"
15 #include "chrome/browser/performance_monitor/key_builder.h" 15 #include "chrome/browser/performance_monitor/key_builder.h"
16 #include "chrome/browser/performance_monitor/metric.h" 16 #include "chrome/browser/performance_monitor/metric.h"
17 #include "chrome/browser/performance_monitor/performance_monitor_util.h" 17 #include "chrome/browser/performance_monitor/performance_monitor_util.h"
18 #include "chrome/common/extensions/extension.h" 18 #include "chrome/common/extensions/extension.h"
19 #include "chrome/common/extensions/manifest.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 #include "third_party/leveldatabase/src/include/leveldb/db.h" 21 #include "third_party/leveldatabase/src/include/leveldb/db.h"
21 #include "third_party/leveldatabase/src/include/leveldb/iterator.h" 22 #include "third_party/leveldatabase/src/include/leveldb/iterator.h"
22 23
23 using extensions::Extension; 24 using extensions::Extension;
25 using extensions::Manifest;
24 26
25 namespace performance_monitor { 27 namespace performance_monitor {
26 28
27 // A class which is friended by Database, in order to hold the private methods 29 // A class which is friended by Database, in order to hold the private methods
28 // and avoid friending all the different test classes. 30 // and avoid friending all the different test classes.
29 class DatabaseTestHelper { 31 class DatabaseTestHelper {
30 public: 32 public:
31 explicit DatabaseTestHelper(Database* database) : database_(database) { }; 33 explicit DatabaseTestHelper(Database* database) : database_(database) { };
32 ~DatabaseTestHelper() { }; 34 ~DatabaseTestHelper() { };
33 35
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 base::ScopedTempDir temp_dir_; 125 base::ScopedTempDir temp_dir_;
124 scoped_ptr<Event> install_event_1_; 126 scoped_ptr<Event> install_event_1_;
125 scoped_ptr<Event> install_event_2_; 127 scoped_ptr<Event> install_event_2_;
126 scoped_ptr<Event> uninstall_event_1_; 128 scoped_ptr<Event> uninstall_event_1_;
127 scoped_ptr<Event> uninstall_event_2_; 129 scoped_ptr<Event> uninstall_event_2_;
128 130
129 private: 131 private:
130 void InitEvents() { 132 void InitEvents() {
131 install_event_1_ = util::CreateExtensionEvent( 133 install_event_1_ = util::CreateExtensionEvent(
132 EVENT_EXTENSION_INSTALL, clock_->GetTime(), "a", "extension 1", 134 EVENT_EXTENSION_INSTALL, clock_->GetTime(), "a", "extension 1",
133 "http://foo.com", static_cast<int>(Extension::LOAD), "0.1", 135 "http://foo.com", static_cast<int>(Manifest::LOAD), "0.1",
134 "Test Test"); 136 "Test Test");
135 install_event_2_ = util::CreateExtensionEvent( 137 install_event_2_ = util::CreateExtensionEvent(
136 EVENT_EXTENSION_INSTALL, clock_->GetTime(), "b", "extension 2", 138 EVENT_EXTENSION_INSTALL, clock_->GetTime(), "b", "extension 2",
137 "http://bar.com", static_cast<int>(Extension::LOAD), "0.1", 139 "http://bar.com", static_cast<int>(Manifest::LOAD), "0.1",
138 "Test Test"); 140 "Test Test");
139 uninstall_event_1_ = util::CreateExtensionEvent( 141 uninstall_event_1_ = util::CreateExtensionEvent(
140 EVENT_EXTENSION_UNINSTALL, clock_->GetTime(), "a", "extension 1", 142 EVENT_EXTENSION_UNINSTALL, clock_->GetTime(), "a", "extension 1",
141 "http://foo.com", static_cast<int>(Extension::LOAD), "0.1", 143 "http://foo.com", static_cast<int>(Manifest::LOAD), "0.1",
142 "Test Test"); 144 "Test Test");
143 uninstall_event_2_ = util::CreateExtensionEvent( 145 uninstall_event_2_ = util::CreateExtensionEvent(
144 EVENT_EXTENSION_UNINSTALL, clock_->GetTime(), "b", "extension 2", 146 EVENT_EXTENSION_UNINSTALL, clock_->GetTime(), "b", "extension 2",
145 "http://bar.com", static_cast<int>(Extension::LOAD), "0.1", 147 "http://bar.com", static_cast<int>(Manifest::LOAD), "0.1",
146 "Test Test"); 148 "Test Test");
147 } 149 }
148 }; 150 };
149 151
150 class PerformanceMonitorDatabaseMetricTest : public ::testing::Test { 152 class PerformanceMonitorDatabaseMetricTest : public ::testing::Test {
151 protected: 153 protected:
152 PerformanceMonitorDatabaseMetricTest() { 154 PerformanceMonitorDatabaseMetricTest() {
153 clock_ = new TestingClock(); 155 clock_ = new TestingClock();
154 CHECK(temp_dir_.CreateUniqueTempDir()); 156 CHECK(temp_dir_.CreateUniqueTempDir());
155 db_ = Database::Create(temp_dir_.path()); 157 db_ = Database::Create(temp_dir_.path());
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 events = db_->GetEvents(EVENT_EXTENSION_DISABLE, clock_->GetTime(), 351 events = db_->GetEvents(EVENT_EXTENSION_DISABLE, clock_->GetTime(),
350 clock_->GetTime()); 352 clock_->GetTime());
351 ASSERT_TRUE(events.empty()); 353 ASSERT_TRUE(events.empty());
352 } 354 }
353 355
354 TEST_F(PerformanceMonitorDatabaseEventTest, GetEventsTimeRange) { 356 TEST_F(PerformanceMonitorDatabaseEventTest, GetEventsTimeRange) {
355 base::Time start_time = clock_->GetTime(); 357 base::Time start_time = clock_->GetTime();
356 scoped_ptr<Event> new_install_event = 358 scoped_ptr<Event> new_install_event =
357 util::CreateExtensionEvent(EVENT_EXTENSION_INSTALL, clock_->GetTime(), 359 util::CreateExtensionEvent(EVENT_EXTENSION_INSTALL, clock_->GetTime(),
358 "c", "test extension", "http://foo.com", 360 "c", "test extension", "http://foo.com",
359 static_cast<int>(Extension::LOAD), "0.1", 361 static_cast<int>(Manifest::LOAD), "0.1",
360 "Test Test"); 362 "Test Test");
361 scoped_ptr<Event> new_uninstall_event = 363 scoped_ptr<Event> new_uninstall_event =
362 util::CreateExtensionEvent(EVENT_EXTENSION_UNINSTALL, clock_->GetTime(), 364 util::CreateExtensionEvent(EVENT_EXTENSION_UNINSTALL, clock_->GetTime(),
363 "c", "test extension", "http://foo.com", 365 "c", "test extension", "http://foo.com",
364 static_cast<int>(Extension::LOAD), "0.1", 366 static_cast<int>(Manifest::LOAD), "0.1",
365 "Test Test"); 367 "Test Test");
366 base::Time end_time = clock_->GetTime(); 368 base::Time end_time = clock_->GetTime();
367 db_->AddEvent(*new_install_event.get()); 369 db_->AddEvent(*new_install_event.get());
368 db_->AddEvent(*new_uninstall_event.get()); 370 db_->AddEvent(*new_uninstall_event.get());
369 Database::EventVector events = db_->GetEvents(start_time, end_time); 371 Database::EventVector events = db_->GetEvents(start_time, end_time);
370 ASSERT_EQ(2u, events.size()); 372 ASSERT_EQ(2u, events.size());
371 EXPECT_TRUE(events[0]->data()->Equals(new_install_event->data())); 373 EXPECT_TRUE(events[0]->data()->Equals(new_install_event->data()));
372 EXPECT_TRUE(events[1]->data()->Equals(new_uninstall_event->data())); 374 EXPECT_TRUE(events[1]->data()->Equals(new_uninstall_event->data()));
373 events = db_->GetEvents( 375 events = db_->GetEvents(
374 EVENT_EXTENSION_INSTALL, start_time, end_time); 376 EVENT_EXTENSION_INSTALL, start_time, end_time);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 db_->AddMetric(kProcessChromeAggregate, 526 db_->AddMetric(kProcessChromeAggregate,
525 Metric(METRIC_CPU_USAGE, clock_->GetTime(), 21.0)); 527 Metric(METRIC_CPU_USAGE, clock_->GetTime(), 21.0));
526 Database::MetricVector stats = 528 Database::MetricVector stats =
527 *db_->GetStatsForActivityAndMetric(METRIC_CPU_USAGE, start, end); 529 *db_->GetStatsForActivityAndMetric(METRIC_CPU_USAGE, start, end);
528 ASSERT_EQ(2u, stats.size()); 530 ASSERT_EQ(2u, stats.size());
529 ASSERT_EQ(3, stats[0].value); 531 ASSERT_EQ(3, stats[0].value);
530 ASSERT_EQ(9, stats[1].value); 532 ASSERT_EQ(9, stats[1].value);
531 } 533 }
532 534
533 } // namespace performance_monitor 535 } // namespace performance_monitor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698