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

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: 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/performance_monitor/database.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 explicit TestingClock(const TestingClock& other)
24 : counter_(other.counter_) {
25 }
26 virtual ~TestingClock() {}
27 base::Time GetTime() {
28 return base::Time::FromInternalValue(counter_++);
29 }
30 private:
31 int64 counter_;
32 };
33
34 ////// PerformanceMonitorDatabaseSetupTests ////////////////////////////////////
35 TEST(PerformanceMonitorDatabaseSetupTest, OpenCloseTest) {
36 FilePath alternate_path;
37 file_util::CreateNewTempDirectory(std::string(), &alternate_path);
38 scoped_refptr<Database> db = Database::Create(alternate_path);
39 ASSERT_TRUE(db);
40 ASSERT_TRUE(db->Close());
41 }
42
43 TEST(PerformanceMonitorDatabaseSetupTest, ActiveIntervalTest) {
44 FilePath alternate_path;
45 file_util::CreateNewTempDirectory(std::string(), &alternate_path);
46 TestingClock* clock_1 = new TestingClock();
47 base::Time start_time = clock_1->GetTime();
48
49 scoped_refptr<Database> db_1 = Database::Create(alternate_path);
50 db_1->set_clock(scoped_ptr<Database::Clock>(clock_1));
51 ASSERT_TRUE(db_1);
52 ASSERT_TRUE(db_1->Close());
53
54 TestingClock* clock_2 = new TestingClock(*clock_1);
55 base::Time mid_time = clock_2->GetTime();
56 scoped_refptr<Database> db_2 = Database::Create(alternate_path);
57 db_2->set_clock(scoped_ptr<Database::Clock>(clock_2));
58 ASSERT_TRUE(db_2);
59 ASSERT_TRUE(db_2->Close());
60
61 TestingClock* clock_3 = new TestingClock(*clock_2);
62 base::Time end_time = clock_3->GetTime();
63 scoped_refptr<Database> db_3 = Database::Create(alternate_path);
64 db_3->set_clock(scoped_ptr<Database::Clock>(clock_3));
65 ASSERT_TRUE(db_3);
66
67 std::vector<TimeRange> active_interval = db_3->GetActiveInterval(start_time,
68 end_time);
69 ASSERT_EQ(active_interval.size(), static_cast<size_t>(2));
70 ASSERT_TRUE(active_interval[0].start > start_time &&
71 active_interval[0].end < mid_time);
72 ASSERT_TRUE(active_interval[1].start > mid_time &&
73 active_interval[1].end < end_time);
74 }
75 } // namespace performance_monitor
OLDNEW
« 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