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 // TODO(akalin): This file is basically just a unit test for | 5 // TODO(akalin): This file is basically just a unit test for |
6 // BookmarkChangeProcessor. Write unit tests for | 6 // BookmarkChangeProcessor. Write unit tests for |
7 // BookmarkModelAssociator separately. | 7 // BookmarkModelAssociator separately. |
8 | 8 |
9 #include <stack> | 9 #include <stack> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/location.h" | 15 #include "base/location.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
18 #include "base/string16.h" | 18 #include "base/string16.h" |
19 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
20 #include "base/string_util.h" | 20 #include "base/string_util.h" |
21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
22 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" | 22 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" |
23 #include "chrome/browser/bookmarks/bookmark_model.h" | 23 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 24 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
24 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" | 25 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" |
25 #include "chrome/browser/sync/glue/bookmark_change_processor.h" | 26 #include "chrome/browser/sync/glue/bookmark_change_processor.h" |
26 #include "chrome/browser/sync/glue/bookmark_model_associator.h" | 27 #include "chrome/browser/sync/glue/bookmark_model_associator.h" |
27 #include "chrome/browser/sync/glue/data_type_error_handler.h" | 28 #include "chrome/browser/sync/glue/data_type_error_handler.h" |
28 #include "chrome/browser/sync/glue/data_type_error_handler_mock.h" | 29 #include "chrome/browser/sync/glue/data_type_error_handler_mock.h" |
29 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
30 #include "chrome/test/base/testing_profile.h" | 31 #include "chrome/test/base/testing_profile.h" |
31 #include "content/public/test/test_browser_thread.h" | 32 #include "content/public/test/test_browser_thread.h" |
32 #include "sync/api/sync_error.h" | 33 #include "sync/api/sync_error.h" |
33 #include "sync/internal_api/public/change_record.h" | 34 #include "sync/internal_api/public/change_record.h" |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 virtual void TearDown() { | 344 virtual void TearDown() { |
344 test_user_share_.TearDown(); | 345 test_user_share_.TearDown(); |
345 } | 346 } |
346 | 347 |
347 // Load (or re-load) the bookmark model. |load| controls use of the | 348 // Load (or re-load) the bookmark model. |load| controls use of the |
348 // bookmarks file on disk. |save| controls whether the newly loaded | 349 // bookmarks file on disk. |save| controls whether the newly loaded |
349 // bookmark model will write out a bookmark file as it goes. | 350 // bookmark model will write out a bookmark file as it goes. |
350 void LoadBookmarkModel(LoadOption load, SaveOption save) { | 351 void LoadBookmarkModel(LoadOption load, SaveOption save) { |
351 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE; | 352 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE; |
352 profile_.CreateBookmarkModel(delete_bookmarks); | 353 profile_.CreateBookmarkModel(delete_bookmarks); |
353 model_ = profile_.GetBookmarkModel(); | 354 model_ = BookmarkModelFactory::GetForProfile(&profile_); |
354 // Wait for the bookmarks model to load. | 355 // Wait for the bookmarks model to load. |
355 profile_.BlockUntilBookmarkModelLoaded(); | 356 profile_.BlockUntilBookmarkModelLoaded(); |
356 // This noticeably speeds up the unit tests that request it. | 357 // This noticeably speeds up the unit tests that request it. |
357 if (save == DONT_SAVE_TO_STORAGE) | 358 if (save == DONT_SAVE_TO_STORAGE) |
358 model_->ClearStore(); | 359 model_->ClearStore(); |
359 message_loop_.RunAllPending(); | 360 message_loop_.RunAllPending(); |
360 } | 361 } |
361 | 362 |
362 void StartSync() { | 363 void StartSync() { |
363 // Set up model associator. | 364 // Set up model associator. |
364 model_associator_.reset(new TestBookmarkModelAssociator( | 365 model_associator_.reset(new TestBookmarkModelAssociator( |
365 profile_.GetBookmarkModel(), | 366 BookmarkModelFactory::GetForProfile(&profile_), |
366 test_user_share_.user_share(), | 367 test_user_share_.user_share(), |
367 &mock_error_handler_)); | 368 &mock_error_handler_)); |
368 syncer::SyncError error = model_associator_->AssociateModels(); | 369 syncer::SyncError error = model_associator_->AssociateModels(); |
369 EXPECT_FALSE(error.IsSet()); | 370 EXPECT_FALSE(error.IsSet()); |
370 MessageLoop::current()->RunAllPending(); | 371 MessageLoop::current()->RunAllPending(); |
371 | 372 |
372 // Set up change processor. | 373 // Set up change processor. |
373 change_processor_.reset( | 374 change_processor_.reset( |
374 new BookmarkChangeProcessor(model_associator_.get(), | 375 new BookmarkChangeProcessor(model_associator_.get(), |
375 &mock_error_handler_)); | 376 &mock_error_handler_)); |
(...skipping 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1491 EXPECT_EQ(1, observer.get_started()); | 1492 EXPECT_EQ(1, observer.get_started()); |
1492 EXPECT_EQ(0, observer.get_completed_count_at_started()); | 1493 EXPECT_EQ(0, observer.get_completed_count_at_started()); |
1493 EXPECT_EQ(1, observer.get_completed()); | 1494 EXPECT_EQ(1, observer.get_completed()); |
1494 | 1495 |
1495 model_->RemoveObserver(&observer); | 1496 model_->RemoveObserver(&observer); |
1496 } | 1497 } |
1497 | 1498 |
1498 } // namespace | 1499 } // namespace |
1499 | 1500 |
1500 } // namespace browser_sync | 1501 } // namespace browser_sync |
OLD | NEW |