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

Side by Side Diff: chrome/browser/sync/glue/shared_change_processor_unittest.cc

Issue 9307079: [Sync] Fix thread-ordering-dependent NULL dereference in NewNonFrontendDTC (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync to head Created 8 years, 10 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sync/glue/shared_change_processor.h"
6
7 #include <cstddef>
8
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/compiler_specific.h"
12 #include "base/message_loop.h"
13 #include "chrome/browser/sync/api/syncable_service_mock.h"
14 #include "chrome/browser/sync/profile_sync_components_factory_impl.h"
15 #include "chrome/browser/sync/profile_sync_service_mock.h"
16 #include "content/test/test_browser_thread.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 namespace browser_sync {
21
22 namespace {
23
24 using content::BrowserThread;
25 using ::testing::NiceMock;
26
27 class SyncSharedChangeProcessorTest : public testing::Test {
28 public:
29 SyncSharedChangeProcessorTest()
30 : ui_thread_(BrowserThread::UI, &ui_loop_),
31 db_thread_(BrowserThread::DB),
32 sync_factory_(NULL, NULL),
33 db_syncable_service_(NULL) {}
34
35 virtual ~SyncSharedChangeProcessorTest() {
36 EXPECT_FALSE(db_syncable_service_);
37 }
38
39 protected:
40 virtual void SetUp() OVERRIDE {
41 shared_change_processor_ = new SharedChangeProcessor();
42 db_thread_.Start();
43 EXPECT_TRUE(BrowserThread::PostTask(
44 BrowserThread::DB,
45 FROM_HERE,
46 base::Bind(&SyncSharedChangeProcessorTest::SetUpDBSyncableService,
47 base::Unretained(this))));
48 }
49
50 virtual void TearDown() OVERRIDE {
51 EXPECT_TRUE(BrowserThread::PostTask(
52 BrowserThread::DB,
53 FROM_HERE,
54 base::Bind(&SyncSharedChangeProcessorTest::TearDownDBSyncableService,
55 base::Unretained(this))));
56 db_thread_.Stop();
57 shared_change_processor_ = NULL;
58 }
59
60 // Connect |shared_change_processor_| on the DB thread.
61 void Connect() {
62 EXPECT_TRUE(BrowserThread::PostTask(
63 BrowserThread::DB,
64 FROM_HERE,
65 base::Bind(&SyncSharedChangeProcessorTest::ConnectOnDBThread,
66 base::Unretained(this))));
67 }
68
69 private:
70 // Used by SetUp().
71 void SetUpDBSyncableService() {
72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
73 DCHECK(!db_syncable_service_);
74 db_syncable_service_ = new NiceMock<SyncableServiceMock>();
75 }
76
77 // Used by TearDown().
78 void TearDownDBSyncableService() {
79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
80 DCHECK(db_syncable_service_);
81 delete db_syncable_service_;
82 db_syncable_service_ = NULL;
83 }
84
85 // Used by Connect().
86 void ConnectOnDBThread() {
87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
88 EXPECT_TRUE(
89 shared_change_processor_->Connect(&sync_factory_,
90 &sync_service_,
91 &sync_service_,
92 db_syncable_service_->AsWeakPtr()));
93 }
94
95 MessageLoopForUI ui_loop_;
96 content::TestBrowserThread ui_thread_;
97 content::TestBrowserThread db_thread_;
98
99 scoped_refptr<SharedChangeProcessor> shared_change_processor_;
100 ProfileSyncComponentsFactoryImpl sync_factory_;
101 NiceMock<ProfileSyncServiceMock> sync_service_;
102
103 // Used only on DB thread.
104 NiceMock<SyncableServiceMock>* db_syncable_service_;
105 };
106
107 // Simply connect the shared change processor. It should succeed, and
108 // nothing further should happen.
109 TEST_F(SyncSharedChangeProcessorTest, Basic) {
110 Connect();
111 }
112
113 } // namespace
114
115 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/shared_change_processor_mock.h ('k') | chrome/browser/sync/test/integration/migration_errors_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698