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

Side by Side 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: Removed consolidated all the metric databases into one 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <string>
6 #include <vector>
7
8 #include "base/file_path.h"
9 #include "base/file_util.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/time.h"
12 #include "chrome/browser/performance_monitor/database.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace performance_monitor {
16
17 // A clock that increments every access. Great for testing.
18 class TestingClock : public Database::Clock {
19 public:
20 TestingClock()
21 : counter_(0) {
22 }
23 virtual ~TestingClock() {}
24 base::Time GetTime() {
25 return base::Time::FromInternalValue(counter_++);
26 }
27 private:
28 int64 counter_;
29 };
30
31 ////// PerformanceMonitorDatabaseSetupTests ////////////////////////////////////
32 TEST(PerformanceMonitorDatabaseSetupTest, OpenCloseDefaultTest) {
33 scoped_refptr<Database> db = Database::InitOnBackgroundThread();
34 ASSERT_TRUE(db.get());
35 ASSERT_TRUE(db->CloseOnBackgroundThread());
36 }
37
38 TEST(PerformanceMonitorDatabaseSetupTest, OpenCloseAlternatePathTest) {
39 FilePath alternate_path;
40 file_util::CreateNewTempDirectory(std::string(), &alternate_path);
41 scoped_refptr<Database> db =
42 Database::InitOnBackgroundThread(alternate_path);
43 ASSERT_TRUE(db);
44 ASSERT_TRUE(db->CloseOnBackgroundThread());
45 }
46
47 TEST(PerformanceMonitorDatabaseSetupTest, ActiveIntervalTest) {
48 FilePath alternate_path;
49 file_util::CreateNewTempDirectory(std::string(), &alternate_path);
50 linked_ptr<Database::Clock> clock(new TestingClock());
51 base::Time start_time = clock->GetTime();
52 scoped_refptr<Database> db_1 =
53 Database::InitOnBackgroundThread(alternate_path, clock);
54 ASSERT_TRUE(db_1);
55 ASSERT_TRUE(db_1->CloseOnBackgroundThread());
56 base::Time mid_time = clock->GetTime();
57 scoped_refptr<Database> db_2 =
58 Database::InitOnBackgroundThread(alternate_path, clock);
59 ASSERT_TRUE(db_2);
60 ASSERT_TRUE(db_2->CloseOnBackgroundThread());
61 base::Time end_time = clock->GetTime();
62 scoped_refptr<Database> db_3 =
63 Database::InitOnBackgroundThread(alternate_path, clock);
64 ASSERT_TRUE(db_3);
65 std::vector<TimeRange> active_interval =
66 db_3->GetActiveIntervalOnBackgroundThread(start_time, end_time);
67 ASSERT_EQ(active_interval.size(), static_cast<size_t>(2));
68 ASSERT_TRUE(active_interval[0].start > start_time &&
69 active_interval[0].end < mid_time);
70 ASSERT_TRUE(active_interval[1].start > mid_time &&
71 active_interval[1].end < end_time);
72 }
73 } // namespace performance_monitor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698