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

Unified Diff: chrome/browser/performance_monitor/database_unittest.cc

Issue 10443092: Performance Monitor Database (Closed) Base URL: http://git.chromium.org/chromium/src.git@cpm_event_construction
Patch Set: Re-Up Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/performance_monitor/database.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/performance_monitor/database_unittest.cc
diff --git a/chrome/browser/performance_monitor/database_unittest.cc b/chrome/browser/performance_monitor/database_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..77a2f38ee5de993ef49d25cf83e2ddd739ef9fd1
--- /dev/null
+++ b/chrome/browser/performance_monitor/database_unittest.cc
@@ -0,0 +1,75 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+#include <vector>
+
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/time.h"
+#include "chrome/browser/performance_monitor/database.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace performance_monitor {
+
+// A clock that increments every access. Great for testing.
+class TestingClock : public Database::Clock {
+ public:
+ TestingClock()
+ : counter_(0) {
+ }
+ explicit TestingClock(const TestingClock& other)
+ : counter_(other.counter_) {
+ }
+ virtual ~TestingClock() {}
+ base::Time GetTime() {
+ return base::Time::FromInternalValue(counter_++);
+ }
+ private:
+ int64 counter_;
+};
+
+////// PerformanceMonitorDatabaseSetupTests ////////////////////////////////////
+TEST(PerformanceMonitorDatabaseSetupTest, OpenCloseTest) {
+ FilePath alternate_path;
+ file_util::CreateNewTempDirectory(std::string(), &alternate_path);
+ scoped_refptr<Database> db = Database::Create(alternate_path);
+ ASSERT_TRUE(db);
+ ASSERT_TRUE(db->Close());
+}
+
+TEST(PerformanceMonitorDatabaseSetupTest, ActiveIntervalTest) {
+ FilePath alternate_path;
+ file_util::CreateNewTempDirectory(std::string(), &alternate_path);
+ TestingClock* clock_1 = new TestingClock();
+ base::Time start_time = clock_1->GetTime();
+
+ scoped_refptr<Database> db_1 = Database::Create(alternate_path);
+ db_1->set_clock(scoped_ptr<Database::Clock>(clock_1));
+ ASSERT_TRUE(db_1);
+ ASSERT_TRUE(db_1->Close());
+
+ TestingClock* clock_2 = new TestingClock(*clock_1);
+ base::Time mid_time = clock_2->GetTime();
+ scoped_refptr<Database> db_2 = Database::Create(alternate_path);
+ db_2->set_clock(scoped_ptr<Database::Clock>(clock_2));
+ ASSERT_TRUE(db_2);
+ ASSERT_TRUE(db_2->Close());
+
+ TestingClock* clock_3 = new TestingClock(*clock_2);
+ base::Time end_time = clock_3->GetTime();
+ scoped_refptr<Database> db_3 = Database::Create(alternate_path);
+ db_3->set_clock(scoped_ptr<Database::Clock>(clock_3));
+ ASSERT_TRUE(db_3);
+
+ std::vector<TimeRange> active_interval = db_3->GetActiveInterval(start_time,
+ end_time);
+ ASSERT_EQ(active_interval.size(), static_cast<size_t>(2));
+ ASSERT_TRUE(active_interval[0].start > start_time &&
+ active_interval[0].end < mid_time);
+ ASSERT_TRUE(active_interval[1].start > mid_time &&
+ active_interval[1].end < end_time);
+}
+} // namespace performance_monitor
« no previous file with comments | « chrome/browser/performance_monitor/database.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698