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

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: 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
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..d3c75b2ffd012bf711ac2c727f8833777aa9ebff
--- /dev/null
+++ b/chrome/browser/performance_monitor/database_unittest.cc
@@ -0,0 +1,73 @@
+// 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) {
+ }
+ virtual ~TestingClock() {}
+ base::Time GetTime() {
+ return base::Time::FromInternalValue(counter_++);
+ }
+ private:
+ int64 counter_;
+};
+
+////// PerformanceMonitorDatabaseSetupTests ////////////////////////////////////
+TEST(PerformanceMonitorDatabaseSetupTest, OpenCloseDefaultTest) {
+ scoped_refptr<Database> db = Database::InitOnBackgroundThread();
+ ASSERT_TRUE(db.get());
+ ASSERT_TRUE(db->CloseOnBackgroundThread());
+}
+
+TEST(PerformanceMonitorDatabaseSetupTest, OpenCloseAlternatePathTest) {
+ FilePath alternate_path;
+ file_util::CreateNewTempDirectory(std::string(), &alternate_path);
+ scoped_refptr<Database> db =
+ Database::InitOnBackgroundThread(alternate_path);
+ ASSERT_TRUE(db);
+ ASSERT_TRUE(db->CloseOnBackgroundThread());
+}
+
+TEST(PerformanceMonitorDatabaseSetupTest, ActiveIntervalTest) {
+ FilePath alternate_path;
+ file_util::CreateNewTempDirectory(std::string(), &alternate_path);
+ linked_ptr<Database::Clock> clock(new TestingClock());
+ base::Time start_time = clock->GetTime();
+ scoped_refptr<Database> db_1 =
+ Database::InitOnBackgroundThread(alternate_path, clock);
+ ASSERT_TRUE(db_1);
+ ASSERT_TRUE(db_1->CloseOnBackgroundThread());
+ base::Time mid_time = clock->GetTime();
+ scoped_refptr<Database> db_2 =
+ Database::InitOnBackgroundThread(alternate_path, clock);
+ ASSERT_TRUE(db_2);
+ ASSERT_TRUE(db_2->CloseOnBackgroundThread());
+ base::Time end_time = clock->GetTime();
+ scoped_refptr<Database> db_3 =
+ Database::InitOnBackgroundThread(alternate_path, clock);
+ ASSERT_TRUE(db_3);
+ std::vector<TimeRange> active_interval =
+ db_3->GetActiveIntervalOnBackgroundThread(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

Powered by Google App Engine
This is Rietveld 408576698