OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/history/core/browser/android/android_cache_database.h" | 5 #include "components/history/core/browser/android/android_cache_database.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 class AndroidCacheDatabaseTest : public testing::Test { | 21 class AndroidCacheDatabaseTest : public testing::Test { |
22 public: | 22 public: |
23 AndroidCacheDatabaseTest() {} | 23 AndroidCacheDatabaseTest() {} |
24 ~AndroidCacheDatabaseTest() override {} | 24 ~AndroidCacheDatabaseTest() override {} |
25 | 25 |
26 protected: | 26 protected: |
27 void SetUp() override { | 27 void SetUp() override { |
28 // Get a temporary directory for the test DB files. | 28 // Get a temporary directory for the test DB files. |
29 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 29 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
30 base::FilePath history_db_name_ = | 30 base::FilePath history_db_name_ = |
31 temp_dir_.path().AppendASCII("history.db"); | 31 temp_dir_.GetPath().AppendASCII("history.db"); |
32 android_cache_db_name_ = temp_dir_.path().AppendASCII( | 32 android_cache_db_name_ = |
33 "TestAndroidCache.db"); | 33 temp_dir_.GetPath().AppendASCII("TestAndroidCache.db"); |
34 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_)); | 34 ASSERT_EQ(sql::INIT_OK, history_db_.Init(history_db_name_)); |
35 ASSERT_EQ(sql::INIT_OK, | 35 ASSERT_EQ(sql::INIT_OK, |
36 history_db_.InitAndroidCacheDatabase(android_cache_db_name_)); | 36 history_db_.InitAndroidCacheDatabase(android_cache_db_name_)); |
37 } | 37 } |
38 | 38 |
39 base::ScopedTempDir temp_dir_; | 39 base::ScopedTempDir temp_dir_; |
40 base::FilePath android_cache_db_name_; | 40 base::FilePath android_cache_db_name_; |
41 TestHistoryDatabase history_db_; | 41 TestHistoryDatabase history_db_; |
42 }; | 42 }; |
43 | 43 |
44 TEST(AndroidCacheDatabaseAttachTest, AttachDatabaseInTransactionNesting) { | 44 TEST(AndroidCacheDatabaseAttachTest, AttachDatabaseInTransactionNesting) { |
45 base::ScopedTempDir temp_dir; | 45 base::ScopedTempDir temp_dir; |
46 base::FilePath android_cache_db_name; | 46 base::FilePath android_cache_db_name; |
47 TestHistoryDatabase history_db; | 47 TestHistoryDatabase history_db; |
48 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 48 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
49 base::FilePath history_db_name = temp_dir.path().AppendASCII("history.db"); | 49 base::FilePath history_db_name = temp_dir.GetPath().AppendASCII("history.db"); |
50 android_cache_db_name = temp_dir.path().AppendASCII( | 50 android_cache_db_name = temp_dir.GetPath().AppendASCII("TestAndroidCache.db"); |
51 "TestAndroidCache.db"); | |
52 ASSERT_EQ(sql::INIT_OK, history_db.Init(history_db_name)); | 51 ASSERT_EQ(sql::INIT_OK, history_db.Init(history_db_name)); |
53 // Create nested transactions. | 52 // Create nested transactions. |
54 history_db.BeginTransaction(); | 53 history_db.BeginTransaction(); |
55 history_db.BeginTransaction(); | 54 history_db.BeginTransaction(); |
56 history_db.BeginTransaction(); | 55 history_db.BeginTransaction(); |
57 int transaction_nesting = history_db.transaction_nesting(); | 56 int transaction_nesting = history_db.transaction_nesting(); |
58 ASSERT_EQ(sql::INIT_OK, | 57 ASSERT_EQ(sql::INIT_OK, |
59 history_db.InitAndroidCacheDatabase(android_cache_db_name)); | 58 history_db.InitAndroidCacheDatabase(android_cache_db_name)); |
60 // The count of nested transaction is still same. | 59 // The count of nested transaction is still same. |
61 EXPECT_EQ(transaction_nesting, history_db.transaction_nesting()); | 60 EXPECT_EQ(transaction_nesting, history_db.transaction_nesting()); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 EXPECT_FALSE(history_db_.GetSearchTerm(update_row1.term, NULL)); | 105 EXPECT_FALSE(history_db_.GetSearchTerm(update_row1.term, NULL)); |
107 // The search_term2 should still in the table. | 106 // The search_term2 should still in the table. |
108 ASSERT_EQ(id2, history_db_.GetSearchTerm(search_term2, &row1)); | 107 ASSERT_EQ(id2, history_db_.GetSearchTerm(search_term2, &row1)); |
109 EXPECT_EQ(id2, row1.id); | 108 EXPECT_EQ(id2, row1.id); |
110 EXPECT_EQ(ToDatabaseTime(search_time2), | 109 EXPECT_EQ(ToDatabaseTime(search_time2), |
111 ToDatabaseTime(row1.last_visit_time)); | 110 ToDatabaseTime(row1.last_visit_time)); |
112 EXPECT_EQ(search_term2, row1.term); | 111 EXPECT_EQ(search_term2, row1.term); |
113 } | 112 } |
114 | 113 |
115 } // namespace history | 114 } // namespace history |
OLD | NEW |