Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: chrome/browser/sync/profile_sync_service_bookmark_unittest.cc

Issue 340643002: Use TestBrowserThreadBundle instead of TestBrowserThread in sync code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/glue/typed_url_model_associator_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <map> 9 #include <map>
10 #include <queue> 10 #include <queue>
(...skipping 16 matching lines...) Expand all
27 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" 27 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h"
28 #include "chrome/browser/sync/glue/bookmark_change_processor.h" 28 #include "chrome/browser/sync/glue/bookmark_change_processor.h"
29 #include "chrome/browser/sync/glue/bookmark_model_associator.h" 29 #include "chrome/browser/sync/glue/bookmark_model_associator.h"
30 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
31 #include "chrome/test/base/testing_profile.h" 31 #include "chrome/test/base/testing_profile.h"
32 #include "components/bookmarks/browser/base_bookmark_model_observer.h" 32 #include "components/bookmarks/browser/base_bookmark_model_observer.h"
33 #include "components/bookmarks/browser/bookmark_model.h" 33 #include "components/bookmarks/browser/bookmark_model.h"
34 #include "components/bookmarks/test/bookmark_test_helpers.h" 34 #include "components/bookmarks/test/bookmark_test_helpers.h"
35 #include "components/sync_driver/data_type_error_handler.h" 35 #include "components/sync_driver/data_type_error_handler.h"
36 #include "components/sync_driver/data_type_error_handler_mock.h" 36 #include "components/sync_driver/data_type_error_handler_mock.h"
37 #include "content/public/test/test_browser_thread.h" 37 #include "content/public/test/test_browser_thread_bundle.h"
38 #include "sync/api/sync_error.h" 38 #include "sync/api/sync_error.h"
39 #include "sync/internal_api/public/change_record.h" 39 #include "sync/internal_api/public/change_record.h"
40 #include "sync/internal_api/public/read_node.h" 40 #include "sync/internal_api/public/read_node.h"
41 #include "sync/internal_api/public/read_transaction.h" 41 #include "sync/internal_api/public/read_transaction.h"
42 #include "sync/internal_api/public/test/test_user_share.h" 42 #include "sync/internal_api/public/test/test_user_share.h"
43 #include "sync/internal_api/public/write_node.h" 43 #include "sync/internal_api/public/write_node.h"
44 #include "sync/internal_api/public/write_transaction.h" 44 #include "sync/internal_api/public/write_transaction.h"
45 #include "sync/internal_api/syncapi_internal.h" 45 #include "sync/internal_api/syncapi_internal.h"
46 #include "sync/syncable/mutable_entry.h" // TODO(tim): Remove. Bug 131130. 46 #include "sync/syncable/mutable_entry.h" // TODO(tim): Remove. Bug 131130.
47 #include "testing/gmock/include/gmock/gmock.h" 47 #include "testing/gmock/include/gmock/gmock.h"
48 #include "testing/gtest/include/gtest/gtest.h" 48 #include "testing/gtest/include/gtest/gtest.h"
49 49
50 namespace browser_sync { 50 namespace browser_sync {
51 51
52 using content::BrowserThread;
53 using syncer::BaseNode; 52 using syncer::BaseNode;
54 using testing::_; 53 using testing::_;
55 using testing::InvokeWithoutArgs; 54 using testing::InvokeWithoutArgs;
56 using testing::Mock; 55 using testing::Mock;
57 using testing::StrictMock; 56 using testing::StrictMock;
58 57
59 #if defined(OS_ANDROID) 58 #if defined(OS_ANDROID)
60 static const bool kExpectMobileBookmarks = true; 59 static const bool kExpectMobileBookmarks = true;
61 #else 60 #else
62 static const bool kExpectMobileBookmarks = false; 61 static const bool kExpectMobileBookmarks = false;
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 }; 312 };
314 313
315 314
316 class ProfileSyncServiceBookmarkTest : public testing::Test { 315 class ProfileSyncServiceBookmarkTest : public testing::Test {
317 protected: 316 protected:
318 enum LoadOption { LOAD_FROM_STORAGE, DELETE_EXISTING_STORAGE }; 317 enum LoadOption { LOAD_FROM_STORAGE, DELETE_EXISTING_STORAGE };
319 enum SaveOption { SAVE_TO_STORAGE, DONT_SAVE_TO_STORAGE }; 318 enum SaveOption { SAVE_TO_STORAGE, DONT_SAVE_TO_STORAGE };
320 319
321 ProfileSyncServiceBookmarkTest() 320 ProfileSyncServiceBookmarkTest()
322 : model_(NULL), 321 : model_(NULL),
323 ui_thread_(BrowserThread::UI, &message_loop_), 322 thread_bundle_(content::TestBrowserThreadBundle::DEFAULT),
324 file_thread_(BrowserThread::FILE, &message_loop_),
325 local_merge_result_(syncer::BOOKMARKS), 323 local_merge_result_(syncer::BOOKMARKS),
326 syncer_merge_result_(syncer::BOOKMARKS) { 324 syncer_merge_result_(syncer::BOOKMARKS) {}
327 }
328 325
329 virtual ~ProfileSyncServiceBookmarkTest() { 326 virtual ~ProfileSyncServiceBookmarkTest() {
330 StopSync(); 327 StopSync();
331 UnloadBookmarkModel(); 328 UnloadBookmarkModel();
332 } 329 }
333 330
334 virtual void SetUp() { 331 virtual void SetUp() {
335 test_user_share_.SetUp(); 332 test_user_share_.SetUp();
336 } 333 }
337 334
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 // bookmarks file on disk. |save| controls whether the newly loaded 393 // bookmarks file on disk. |save| controls whether the newly loaded
397 // bookmark model will write out a bookmark file as it goes. 394 // bookmark model will write out a bookmark file as it goes.
398 void LoadBookmarkModel(LoadOption load, SaveOption save) { 395 void LoadBookmarkModel(LoadOption load, SaveOption save) {
399 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE; 396 bool delete_bookmarks = load == DELETE_EXISTING_STORAGE;
400 profile_.CreateBookmarkModel(delete_bookmarks); 397 profile_.CreateBookmarkModel(delete_bookmarks);
401 model_ = BookmarkModelFactory::GetForProfile(&profile_); 398 model_ = BookmarkModelFactory::GetForProfile(&profile_);
402 test::WaitForBookmarkModelToLoad(model_); 399 test::WaitForBookmarkModelToLoad(model_);
403 // This noticeably speeds up the unit tests that request it. 400 // This noticeably speeds up the unit tests that request it.
404 if (save == DONT_SAVE_TO_STORAGE) 401 if (save == DONT_SAVE_TO_STORAGE)
405 model_->ClearStore(); 402 model_->ClearStore();
406 message_loop_.RunUntilIdle(); 403 base::MessageLoop::current()->RunUntilIdle();
407 } 404 }
408 405
409 int GetSyncBookmarkCount() { 406 int GetSyncBookmarkCount() {
410 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 407 syncer::ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
411 syncer::ReadNode node(&trans); 408 syncer::ReadNode node(&trans);
412 if (node.InitTypeRoot(syncer::BOOKMARKS) != syncer::BaseNode::INIT_OK) 409 if (node.InitTypeRoot(syncer::BOOKMARKS) != syncer::BaseNode::INIT_OK)
413 return 0; 410 return 0;
414 return node.GetTotalNodeCount(); 411 return node.GetTotalNodeCount();
415 } 412 }
416 413
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 } 532 }
536 533
537 void StopSync() { 534 void StopSync() {
538 change_processor_.reset(); 535 change_processor_.reset();
539 if (model_associator_) { 536 if (model_associator_) {
540 syncer::SyncError error = model_associator_->DisassociateModels(); 537 syncer::SyncError error = model_associator_->DisassociateModels();
541 EXPECT_FALSE(error.IsSet()); 538 EXPECT_FALSE(error.IsSet());
542 } 539 }
543 model_associator_.reset(); 540 model_associator_.reset();
544 541
545 message_loop_.RunUntilIdle(); 542 base::MessageLoop::current()->RunUntilIdle();
546 543
547 // TODO(akalin): Actually close the database and flush it to disk 544 // TODO(akalin): Actually close the database and flush it to disk
548 // (and make StartSync reload from disk). This would require 545 // (and make StartSync reload from disk). This would require
549 // refactoring TestUserShare. 546 // refactoring TestUserShare.
550 } 547 }
551 548
552 void UnloadBookmarkModel() { 549 void UnloadBookmarkModel() {
553 profile_.CreateBookmarkModel(false /* delete_bookmarks */); 550 profile_.CreateBookmarkModel(false /* delete_bookmarks */);
554 model_ = NULL; 551 model_ = NULL;
555 message_loop_.RunUntilIdle(); 552 base::MessageLoop::current()->RunUntilIdle();
556 } 553 }
557 554
558 bool InitSyncNodeFromChromeNode(const BookmarkNode* bnode, 555 bool InitSyncNodeFromChromeNode(const BookmarkNode* bnode,
559 syncer::BaseNode* sync_node) { 556 syncer::BaseNode* sync_node) {
560 return model_associator_->InitSyncNodeFromChromeId(bnode->id(), 557 return model_associator_->InitSyncNodeFromChromeId(bnode->id(),
561 sync_node); 558 sync_node);
562 } 559 }
563 560
564 void ExpectSyncerNodeMatching(syncer::BaseTransaction* trans, 561 void ExpectSyncerNodeMatching(syncer::BaseTransaction* trans,
565 const BookmarkNode* bnode) { 562 const BookmarkNode* bnode) {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 731
735 protected: 732 protected:
736 TestingProfile profile_; 733 TestingProfile profile_;
737 BookmarkModel* model_; 734 BookmarkModel* model_;
738 syncer::TestUserShare test_user_share_; 735 syncer::TestUserShare test_user_share_;
739 scoped_ptr<BookmarkChangeProcessor> change_processor_; 736 scoped_ptr<BookmarkChangeProcessor> change_processor_;
740 StrictMock<DataTypeErrorHandlerMock> mock_error_handler_; 737 StrictMock<DataTypeErrorHandlerMock> mock_error_handler_;
741 scoped_ptr<BookmarkModelAssociator> model_associator_; 738 scoped_ptr<BookmarkModelAssociator> model_associator_;
742 739
743 private: 740 private:
744 // Used by both |ui_thread_| and |file_thread_|. 741 content::TestBrowserThreadBundle thread_bundle_;
745 base::MessageLoop message_loop_;
746 content::TestBrowserThread ui_thread_;
747 // Needed by |model_|.
748 content::TestBrowserThread file_thread_;
749
750 syncer::SyncMergeResult local_merge_result_; 742 syncer::SyncMergeResult local_merge_result_;
751 syncer::SyncMergeResult syncer_merge_result_; 743 syncer::SyncMergeResult syncer_merge_result_;
752 }; 744 };
753 745
754 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) { 746 TEST_F(ProfileSyncServiceBookmarkTest, InitialState) {
755 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 747 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
756 StartSync(); 748 StartSync();
757 749
758 EXPECT_TRUE(other_bookmarks_id()); 750 EXPECT_TRUE(other_bookmarks_id());
759 EXPECT_TRUE(bookmark_bar_id()); 751 EXPECT_TRUE(bookmark_bar_id());
(...skipping 1423 matching lines...) Expand 10 before | Expand all | Expand 10 after
2183 ExpectModelMatch(); 2175 ExpectModelMatch();
2184 2176
2185 // Then simulate the add call arriving late. 2177 // Then simulate the add call arriving late.
2186 change_processor_->BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 0); 2178 change_processor_->BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 0);
2187 ExpectModelMatch(); 2179 ExpectModelMatch();
2188 } 2180 }
2189 2181
2190 } // namespace 2182 } // namespace
2191 2183
2192 } // namespace browser_sync 2184 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/typed_url_model_associator_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698