OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "app/sql/connection.h" | 5 #include "app/sql/connection.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/memory/scoped_temp_dir.h" |
10 #include "chrome/browser/history/url_database.h" | 11 #include "chrome/browser/history/url_database.h" |
11 #include "chrome/browser/history/visit_database.h" | 12 #include "chrome/browser/history/visit_database.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "testing/platform_test.h" | 14 #include "testing/platform_test.h" |
14 | 15 |
15 using base::Time; | 16 using base::Time; |
16 using base::TimeDelta; | 17 using base::TimeDelta; |
17 | 18 |
18 namespace history { | 19 namespace history { |
19 | 20 |
(...skipping 15 matching lines...) Expand all Loading... |
35 public URLDatabase, | 36 public URLDatabase, |
36 public VisitDatabase { | 37 public VisitDatabase { |
37 public: | 38 public: |
38 VisitDatabaseTest() { | 39 VisitDatabaseTest() { |
39 } | 40 } |
40 | 41 |
41 private: | 42 private: |
42 // Test setup. | 43 // Test setup. |
43 void SetUp() { | 44 void SetUp() { |
44 PlatformTest::SetUp(); | 45 PlatformTest::SetUp(); |
45 FilePath temp_dir; | 46 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
46 PathService::Get(base::DIR_TEMP, &temp_dir); | 47 FilePath db_file = temp_dir_.path().AppendASCII("VisitTest.db"); |
47 db_file_ = temp_dir.AppendASCII("VisitTest.db"); | |
48 file_util::Delete(db_file_, false); | |
49 | 48 |
50 EXPECT_TRUE(db_.Open(db_file_)); | 49 EXPECT_TRUE(db_.Open(db_file)); |
51 | 50 |
52 // Initialize the tables for this test. | 51 // Initialize the tables for this test. |
53 CreateURLTable(false); | 52 CreateURLTable(false); |
54 CreateMainURLIndex(); | 53 CreateMainURLIndex(); |
55 InitVisitTable(); | 54 InitVisitTable(); |
56 } | 55 } |
57 void TearDown() { | 56 void TearDown() { |
58 db_.Close(); | 57 db_.Close(); |
59 file_util::Delete(db_file_, false); | |
60 PlatformTest::TearDown(); | 58 PlatformTest::TearDown(); |
61 } | 59 } |
62 | 60 |
63 // Provided for URL/VisitDatabase. | 61 // Provided for URL/VisitDatabase. |
64 virtual sql::Connection& GetDB() { | 62 virtual sql::Connection& GetDB() { |
65 return db_; | 63 return db_; |
66 } | 64 } |
67 | 65 |
68 FilePath db_file_; | 66 ScopedTempDir temp_dir_; |
69 sql::Connection db_; | 67 sql::Connection db_; |
70 }; | 68 }; |
71 | 69 |
72 TEST_F(VisitDatabaseTest, Add) { | 70 TEST_F(VisitDatabaseTest, Add) { |
73 // Add one visit. | 71 // Add one visit. |
74 VisitRow visit_info1(1, Time::Now(), 0, PageTransition::LINK, 0); | 72 VisitRow visit_info1(1, Time::Now(), 0, PageTransition::LINK, 0); |
75 EXPECT_TRUE(AddVisit(&visit_info1, SOURCE_BROWSED)); | 73 EXPECT_TRUE(AddVisit(&visit_info1, SOURCE_BROWSED)); |
76 | 74 |
77 // Add second visit for the same page. | 75 // Add second visit for the same page. |
78 VisitRow visit_info2(visit_info1.url_id, | 76 VisitRow visit_info2(visit_info1.url_id, |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 EXPECT_EQ(SOURCE_SYNCED, sources[matches[0].visit_id]); | 251 EXPECT_EQ(SOURCE_SYNCED, sources[matches[0].visit_id]); |
254 | 252 |
255 ASSERT_TRUE(GetVisitsForURL(113, &matches)); | 253 ASSERT_TRUE(GetVisitsForURL(113, &matches)); |
256 ASSERT_EQ(1U, matches.size()); | 254 ASSERT_EQ(1U, matches.size()); |
257 GetVisitsSource(matches, &sources); | 255 GetVisitsSource(matches, &sources); |
258 ASSERT_EQ(1U, sources.size()); | 256 ASSERT_EQ(1U, sources.size()); |
259 EXPECT_EQ(SOURCE_EXTENSION, sources[matches[0].visit_id]); | 257 EXPECT_EQ(SOURCE_EXTENSION, sources[matches[0].visit_id]); |
260 } | 258 } |
261 | 259 |
262 } // namespace history | 260 } // namespace history |
OLD | NEW |