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. |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include <stdint.h> | 22 #include <stdint.h> |
23 | 23 |
24 #include "base/files/file_util.h" | 24 #include "base/files/file_util.h" |
25 #include "base/files/scoped_temp_dir.h" | 25 #include "base/files/scoped_temp_dir.h" |
26 #include "base/location.h" | 26 #include "base/location.h" |
27 #include "base/macros.h" | 27 #include "base/macros.h" |
28 #include "base/message_loop/message_loop.h" | 28 #include "base/message_loop/message_loop.h" |
29 #include "base/run_loop.h" | 29 #include "base/run_loop.h" |
30 #include "base/single_thread_task_runner.h" | 30 #include "base/single_thread_task_runner.h" |
31 #include "base/strings/utf_string_conversions.h" | 31 #include "base/strings/utf_string_conversions.h" |
| 32 #include "base/test/scoped_task_environment.h" |
32 #include "base/threading/thread_task_runner_handle.h" | 33 #include "base/threading/thread_task_runner_handle.h" |
33 #include "components/history/core/browser/history_database_params.h" | 34 #include "components/history/core/browser/history_database_params.h" |
34 #include "components/history/core/browser/history_db_task.h" | 35 #include "components/history/core/browser/history_db_task.h" |
35 #include "components/history/core/test/database_test_utils.h" | 36 #include "components/history/core/test/database_test_utils.h" |
36 #include "components/history/core/test/test_history_database.h" | 37 #include "components/history/core/test/test_history_database.h" |
37 #include "components/sync/model/attachments/attachment_id.h" | 38 #include "components/sync/model/attachments/attachment_id.h" |
38 #include "components/sync/model/attachments/attachment_service_proxy_for_test.h" | 39 #include "components/sync/model/attachments/attachment_service_proxy_for_test.h" |
39 #include "components/sync/model/fake_sync_change_processor.h" | 40 #include "components/sync/model/fake_sync_change_processor.h" |
40 #include "components/sync/model/sync_change.h" | 41 #include "components/sync/model/sync_change.h" |
41 #include "components/sync/model/sync_change_processor.h" | 42 #include "components/sync/model/sync_change_processor.h" |
42 #include "components/sync/model/sync_change_processor_wrapper_for_test.h" | 43 #include "components/sync/model/sync_change_processor_wrapper_for_test.h" |
43 #include "components/sync/model/sync_error.h" | 44 #include "components/sync/model/sync_error.h" |
44 #include "components/sync/model/sync_error_factory.h" | 45 #include "components/sync/model/sync_error_factory.h" |
45 #include "components/sync/model/sync_merge_result.h" | 46 #include "components/sync/model/sync_merge_result.h" |
46 #include "components/sync/protocol/history_delete_directive_specifics.pb.h" | 47 #include "components/sync/protocol/history_delete_directive_specifics.pb.h" |
47 #include "components/sync/protocol/sync.pb.h" | 48 #include "components/sync/protocol/sync.pb.h" |
48 #include "testing/gtest/include/gtest/gtest.h" | 49 #include "testing/gtest/include/gtest/gtest.h" |
49 | 50 |
50 namespace history { | 51 namespace history { |
51 | 52 |
52 class HistoryServiceTest : public testing::Test { | 53 class HistoryServiceTest : public testing::Test { |
53 public: | 54 public: |
54 HistoryServiceTest() : query_url_success_(false) {} | 55 HistoryServiceTest() |
| 56 : scoped_task_environment_( |
| 57 base::test::ScopedTaskEnvironment::MainThreadType::UI), |
| 58 query_url_success_(false) {} |
55 | 59 |
56 ~HistoryServiceTest() override {} | 60 ~HistoryServiceTest() override {} |
57 | 61 |
58 void OnMostVisitedURLsAvailable(const MostVisitedURLList* url_list) { | 62 void OnMostVisitedURLsAvailable(const MostVisitedURLList* url_list) { |
59 most_visited_urls_ = *url_list; | 63 most_visited_urls_ = *url_list; |
60 base::MessageLoop::current()->QuitWhenIdle(); | 64 base::MessageLoop::current()->QuitWhenIdle(); |
61 } | 65 } |
62 | 66 |
63 protected: | 67 protected: |
64 friend class BackendDelegate; | 68 friend class BackendDelegate; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 saved_redirects_.clear(); | 151 saved_redirects_.clear(); |
148 if (!redirects->empty()) { | 152 if (!redirects->empty()) { |
149 saved_redirects_.insert( | 153 saved_redirects_.insert( |
150 saved_redirects_.end(), redirects->begin(), redirects->end()); | 154 saved_redirects_.end(), redirects->begin(), redirects->end()); |
151 } | 155 } |
152 base::MessageLoop::current()->QuitWhenIdle(); | 156 base::MessageLoop::current()->QuitWhenIdle(); |
153 } | 157 } |
154 | 158 |
155 base::ScopedTempDir temp_dir_; | 159 base::ScopedTempDir temp_dir_; |
156 | 160 |
157 base::MessageLoopForUI message_loop_; | 161 base::test::ScopedTaskEnvironment scoped_task_environment_; |
158 | 162 |
159 MostVisitedURLList most_visited_urls_; | 163 MostVisitedURLList most_visited_urls_; |
160 | 164 |
161 // When non-NULL, this will be deleted on tear down and we will block until | 165 // When non-NULL, this will be deleted on tear down and we will block until |
162 // the backend thread has completed. This allows tests for the history | 166 // the backend thread has completed. This allows tests for the history |
163 // service to use this feature, but other tests to ignore this. | 167 // service to use this feature, but other tests to ignore this. |
164 std::unique_ptr<history::HistoryService> history_service_; | 168 std::unique_ptr<history::HistoryService> history_service_; |
165 | 169 |
166 // names of the database files | 170 // names of the database files |
167 base::FilePath history_dir_; | 171 base::FilePath history_dir_; |
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 // Expect two sync changes for deleting processed directives. | 898 // Expect two sync changes for deleting processed directives. |
895 const syncer::SyncChangeList& sync_changes = change_processor.changes(); | 899 const syncer::SyncChangeList& sync_changes = change_processor.changes(); |
896 ASSERT_EQ(2u, sync_changes.size()); | 900 ASSERT_EQ(2u, sync_changes.size()); |
897 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, sync_changes[0].change_type()); | 901 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, sync_changes[0].change_type()); |
898 EXPECT_EQ(1, syncer::SyncDataRemote(sync_changes[0].sync_data()).GetId()); | 902 EXPECT_EQ(1, syncer::SyncDataRemote(sync_changes[0].sync_data()).GetId()); |
899 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, sync_changes[1].change_type()); | 903 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, sync_changes[1].change_type()); |
900 EXPECT_EQ(2, syncer::SyncDataRemote(sync_changes[1].sync_data()).GetId()); | 904 EXPECT_EQ(2, syncer::SyncDataRemote(sync_changes[1].sync_data()).GetId()); |
901 } | 905 } |
902 | 906 |
903 } // namespace history | 907 } // namespace history |
OLD | NEW |