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 // History unit tests come in two flavors: | 5 // History unit tests come in two flavors: |
6 // | 6 // |
7 // 1. The more complicated style is that the unit test creates a full history | 7 // 1. The more complicated style is that the unit test creates a full history |
8 // service. This spawns a background thread for the history backend, and | 8 // service. This spawns a background thread for the history backend, and |
9 // all communication is asynchronous. This is useful for testing more | 9 // all communication is asynchronous. This is useful for testing more |
10 // complicated things or end-to-end behavior. | 10 // complicated things or end-to-end behavior. |
11 // | 11 // |
12 // 2. The simpler style is to create a history backend on this thread and | 12 // 2. The simpler style is to create a history backend on this thread and |
13 // access it directly without a HistoryService object. This is much simpler | 13 // access it directly without a HistoryService object. This is much simpler |
14 // because communication is synchronous. Generally, sets should go through | 14 // because communication is synchronous. Generally, sets should go through |
15 // the history backend (since there is a lot of logic) but gets can come | 15 // the history backend (since there is a lot of logic) but gets can come |
16 // directly from the HistoryDatabase. This is because the backend generally | 16 // directly from the HistoryDatabase. This is because the backend generally |
17 // has no logic in the getter except threading stuff, which we don't want | 17 // has no logic in the getter except threading stuff, which we don't want |
18 // to run. | 18 // to run. |
19 | 19 |
20 #include "components/history/core/browser/history_backend.h" | 20 #include "components/history/core/browser/history_backend.h" |
21 | 21 |
22 #include <stdint.h> | 22 #include <stdint.h> |
23 | 23 |
24 #include <string> | 24 #include <string> |
25 #include <unordered_set> | 25 #include <unordered_set> |
26 | 26 |
27 #include "base/format_macros.h" | 27 #include "base/format_macros.h" |
28 #include "base/guid.h" | 28 #include "base/guid.h" |
| 29 #include "base/run_loop.h" |
29 #include "base/strings/string_util.h" | 30 #include "base/strings/string_util.h" |
30 #include "base/strings/stringprintf.h" | 31 #include "base/strings/stringprintf.h" |
31 #include "base/strings/utf_string_conversions.h" | 32 #include "base/strings/utf_string_conversions.h" |
32 #include "base/time/time.h" | 33 #include "base/time/time.h" |
33 #include "components/history/core/browser/download_constants.h" | 34 #include "components/history/core/browser/download_constants.h" |
34 #include "components/history/core/browser/download_row.h" | 35 #include "components/history/core/browser/download_row.h" |
35 #include "components/history/core/browser/history_constants.h" | 36 #include "components/history/core/browser/history_constants.h" |
36 #include "components/history/core/browser/history_database.h" | 37 #include "components/history/core/browser/history_database.h" |
37 #include "components/history/core/browser/page_usage_data.h" | 38 #include "components/history/core/browser/page_usage_data.h" |
38 #include "components/history/core/test/history_backend_db_base_test.h" | 39 #include "components/history/core/test/history_backend_db_base_test.h" |
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 // right transformation was returned. | 976 // right transformation was returned. |
976 CreateBackendAndDatabase(); | 977 CreateBackendAndDatabase(); |
977 std::vector<DownloadRow> results; | 978 std::vector<DownloadRow> results; |
978 db_->QueryDownloads(&results); | 979 db_->QueryDownloads(&results); |
979 ASSERT_EQ(1u, results.size()); | 980 ASSERT_EQ(1u, results.size()); |
980 EXPECT_EQ(DownloadState::INTERRUPTED, results[0].state); | 981 EXPECT_EQ(DownloadState::INTERRUPTED, results[0].state); |
981 EXPECT_EQ(kTestDownloadInterruptReasonCrash, results[0].interrupt_reason); | 982 EXPECT_EQ(kTestDownloadInterruptReasonCrash, results[0].interrupt_reason); |
982 | 983 |
983 // Allow the update to propagate, shut down the DB, and confirm that | 984 // Allow the update to propagate, shut down the DB, and confirm that |
984 // the query updated the on disk database as well. | 985 // the query updated the on disk database as well. |
985 base::MessageLoop::current()->RunUntilIdle(); | 986 base::RunLoop().RunUntilIdle(); |
986 DeleteBackend(); | 987 DeleteBackend(); |
987 { | 988 { |
988 sql::Connection db; | 989 sql::Connection db; |
989 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); | 990 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); |
990 sql::Statement statement(db.GetUniqueStatement( | 991 sql::Statement statement(db.GetUniqueStatement( |
991 "Select Count(*) from downloads")); | 992 "Select Count(*) from downloads")); |
992 EXPECT_TRUE(statement.Step()); | 993 EXPECT_TRUE(statement.Step()); |
993 EXPECT_EQ(1, statement.ColumnInt(0)); | 994 EXPECT_EQ(1, statement.ColumnInt(0)); |
994 | 995 |
995 sql::Statement statement1(db.GetUniqueStatement( | 996 sql::Statement statement1(db.GetUniqueStatement( |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 // URL should win instead. | 1148 // URL should win instead. |
1148 std::vector<std::unique_ptr<PageUsageData>> results2 = | 1149 std::vector<std::unique_ptr<PageUsageData>> results2 = |
1149 db_->QuerySegmentUsage(time, 1, base::Bind(&FilterURL)); | 1150 db_->QuerySegmentUsage(time, 1, base::Bind(&FilterURL)); |
1150 ASSERT_EQ(1u, results2.size()); | 1151 ASSERT_EQ(1u, results2.size()); |
1151 EXPECT_EQ(url2, results2[0]->GetURL()); | 1152 EXPECT_EQ(url2, results2[0]->GetURL()); |
1152 EXPECT_EQ(segment_id2, results2[0]->GetID()); | 1153 EXPECT_EQ(segment_id2, results2[0]->GetID()); |
1153 } | 1154 } |
1154 | 1155 |
1155 } // namespace | 1156 } // namespace |
1156 } // namespace history | 1157 } // namespace history |
OLD | NEW |