OLD | NEW |
1 // Copyright (c) 2011 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 // 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 83 |
84 // Delegate class for when we create a backend without a HistoryService. | 84 // Delegate class for when we create a backend without a HistoryService. |
85 class BackendDelegate : public HistoryBackend::Delegate { | 85 class BackendDelegate : public HistoryBackend::Delegate { |
86 public: | 86 public: |
87 explicit BackendDelegate(HistoryTest* history_test) | 87 explicit BackendDelegate(HistoryTest* history_test) |
88 : history_test_(history_test) { | 88 : history_test_(history_test) { |
89 } | 89 } |
90 | 90 |
91 virtual void NotifyProfileError(sql::InitStatus init_status) OVERRIDE {} | 91 virtual void NotifyProfileError(sql::InitStatus init_status) OVERRIDE {} |
92 virtual void SetInMemoryBackend(InMemoryHistoryBackend* backend) OVERRIDE; | 92 virtual void SetInMemoryBackend(InMemoryHistoryBackend* backend) OVERRIDE; |
93 virtual void BroadcastNotifications(NotificationType type, | 93 virtual void BroadcastNotifications(int type, |
94 HistoryDetails* details) OVERRIDE; | 94 HistoryDetails* details) OVERRIDE; |
95 virtual void DBLoaded() OVERRIDE {} | 95 virtual void DBLoaded() OVERRIDE {} |
96 virtual void StartTopSitesMigration() OVERRIDE {} | 96 virtual void StartTopSitesMigration() OVERRIDE {} |
97 private: | 97 private: |
98 HistoryTest* history_test_; | 98 HistoryTest* history_test_; |
99 }; | 99 }; |
100 | 100 |
101 // This must be outside the anonymous namespace for the friend statement in | 101 // This must be outside the anonymous namespace for the friend statement in |
102 // HistoryBackend to work. | 102 // HistoryBackend to work. |
103 class HistoryTest : public testing::Test { | 103 class HistoryTest : public testing::Test { |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 scoped_ptr<InMemoryHistoryBackend> in_mem_backend_; | 283 scoped_ptr<InMemoryHistoryBackend> in_mem_backend_; |
284 HistoryDatabase* db_; // Cached reference to the backend's database. | 284 HistoryDatabase* db_; // Cached reference to the backend's database. |
285 }; | 285 }; |
286 | 286 |
287 void BackendDelegate::SetInMemoryBackend(InMemoryHistoryBackend* backend) { | 287 void BackendDelegate::SetInMemoryBackend(InMemoryHistoryBackend* backend) { |
288 // Save the in-memory backend to the history test object, this happens | 288 // Save the in-memory backend to the history test object, this happens |
289 // synchronously, so we don't have to do anything fancy. | 289 // synchronously, so we don't have to do anything fancy. |
290 history_test_->in_mem_backend_.reset(backend); | 290 history_test_->in_mem_backend_.reset(backend); |
291 } | 291 } |
292 | 292 |
293 void BackendDelegate::BroadcastNotifications(NotificationType type, | 293 void BackendDelegate::BroadcastNotifications(int type, |
294 HistoryDetails* details) { | 294 HistoryDetails* details) { |
295 // Currently, just send the notifications directly to the in-memory database. | 295 // Currently, just send the notifications directly to the in-memory database. |
296 // We may want do do something more fancy in the future. | 296 // We may want do do something more fancy in the future. |
297 Details<HistoryDetails> det(details); | 297 Details<HistoryDetails> det(details); |
298 history_test_->in_mem_backend_->Observe(type, | 298 history_test_->in_mem_backend_->Observe(type, |
299 Source<HistoryTest>(NULL), det); | 299 Source<HistoryTest>(NULL), det); |
300 | 300 |
301 // The backend passes ownership of the details pointer to us. | 301 // The backend passes ownership of the details pointer to us. |
302 delete details; | 302 delete details; |
303 } | 303 } |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 history_service_ = history; | 855 history_service_ = history; |
856 history->ScheduleDBTask(task.get(), &request_consumer); | 856 history->ScheduleDBTask(task.get(), &request_consumer); |
857 request_consumer.CancelAllRequests(); | 857 request_consumer.CancelAllRequests(); |
858 CleanupHistoryService(); | 858 CleanupHistoryService(); |
859 // WARNING: history has now been deleted. | 859 // WARNING: history has now been deleted. |
860 history = NULL; | 860 history = NULL; |
861 ASSERT_FALSE(task->done_invoked); | 861 ASSERT_FALSE(task->done_invoked); |
862 } | 862 } |
863 | 863 |
864 } // namespace history | 864 } // namespace history |
OLD | NEW |