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

Side by Side Diff: chrome/browser/sync_file_system/local_file_sync_service_unittest.cc

Issue 17127002: Correctly integrate StoragePartition into TestingProfile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged to ToT Created 7 years, 5 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
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 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/threading/thread.h" 12 #include "base/threading/thread.h"
13 #include "chrome/browser/sync_file_system/local_file_sync_service.h" 13 #include "chrome/browser/sync_file_system/local_file_sync_service.h"
14 #include "chrome/browser/sync_file_system/mock_local_change_processor.h" 14 #include "chrome/browser/sync_file_system/mock_local_change_processor.h"
15 #include "chrome/browser/sync_file_system/sync_file_system_test_util.h" 15 #include "chrome/browser/sync_file_system/sync_file_system_test_util.h"
16 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/test/test_browser_thread_bundle.h"
19 #include "content/public/test/test_utils.h"
17 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
19 #include "webkit/browser/fileapi/file_system_context.h" 22 #include "webkit/browser/fileapi/file_system_context.h"
20 #include "webkit/browser/fileapi/syncable/canned_syncable_file_system.h" 23 #include "webkit/browser/fileapi/syncable/canned_syncable_file_system.h"
21 #include "webkit/browser/fileapi/syncable/file_change.h" 24 #include "webkit/browser/fileapi/syncable/file_change.h"
22 #include "webkit/browser/fileapi/syncable/local_file_change_tracker.h" 25 #include "webkit/browser/fileapi/syncable/local_file_change_tracker.h"
23 #include "webkit/browser/fileapi/syncable/local_file_sync_context.h" 26 #include "webkit/browser/fileapi/syncable/local_file_sync_context.h"
24 #include "webkit/browser/fileapi/syncable/local_file_sync_status.h" 27 #include "webkit/browser/fileapi/syncable/local_file_sync_status.h"
25 #include "webkit/browser/fileapi/syncable/mock_sync_status_observer.h" 28 #include "webkit/browser/fileapi/syncable/mock_sync_status_observer.h"
26 #include "webkit/browser/fileapi/syncable/sync_file_metadata.h" 29 #include "webkit/browser/fileapi/syncable/sync_file_metadata.h"
27 #include "webkit/browser/fileapi/syncable/sync_status_code.h" 30 #include "webkit/browser/fileapi/syncable/sync_status_code.h"
28 #include "webkit/browser/fileapi/syncable/syncable_file_system_util.h" 31 #include "webkit/browser/fileapi/syncable/syncable_file_system_util.h"
29 32
33 using content::BrowserThread;
30 using fileapi::FileSystemURL; 34 using fileapi::FileSystemURL;
31 using ::testing::_; 35 using ::testing::_;
32 using ::testing::AtLeast; 36 using ::testing::AtLeast;
33 using ::testing::InvokeWithoutArgs; 37 using ::testing::InvokeWithoutArgs;
34 using ::testing::StrictMock; 38 using ::testing::StrictMock;
35 39
36 namespace sync_file_system { 40 namespace sync_file_system {
37 41
38 namespace { 42 namespace {
39 43
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 FROM_HERE, base::Bind(arg4, status)); 92 FROM_HERE, base::Bind(arg4, status));
89 changes->push_back(arg0); 93 changes->push_back(arg0);
90 } 94 }
91 95
92 } // namespace 96 } // namespace
93 97
94 class LocalFileSyncServiceTest 98 class LocalFileSyncServiceTest
95 : public testing::Test, 99 : public testing::Test,
96 public LocalFileSyncService::Observer { 100 public LocalFileSyncService::Observer {
97 protected: 101 protected:
98 LocalFileSyncServiceTest() : num_changes_(0) {} 102 LocalFileSyncServiceTest()
99 103 : thread_bundle_(content::TestBrowserThreadBundle::REAL_FILE_THREAD |
100 virtual ~LocalFileSyncServiceTest() {} 104 content::TestBrowserThreadBundle::REAL_IO_THREAD),
kinuko 2013/07/18 04:22:30 nit: indent
105 num_changes_(0) {}
101 106
102 virtual void SetUp() OVERRIDE { 107 virtual void SetUp() OVERRIDE {
103 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 108 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
104 109
105 thread_helper_.SetUp();
106
107 file_system_.reset(new CannedSyncableFileSystem( 110 file_system_.reset(new CannedSyncableFileSystem(
108 GURL(kOrigin), 111 GURL(kOrigin),
109 thread_helper_.io_task_runner(), 112 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
110 thread_helper_.file_task_runner())); 113 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)));
111 114
112 local_service_.reset(new LocalFileSyncService(&profile_)); 115 local_service_.reset(new LocalFileSyncService(&profile_));
113 116
114 file_system_->SetUp(); 117 file_system_->SetUp();
115 118
116 base::RunLoop run_loop; 119 base::RunLoop run_loop;
117 SyncStatusCode status = SYNC_STATUS_UNKNOWN; 120 SyncStatusCode status = SYNC_STATUS_UNKNOWN;
118 local_service_->MaybeInitializeFileSystemContext( 121 local_service_->MaybeInitializeFileSystemContext(
119 GURL(kOrigin), file_system_->file_system_context(), 122 GURL(kOrigin), file_system_->file_system_context(),
120 AssignAndQuitCallback(&run_loop, &status)); 123 AssignAndQuitCallback(&run_loop, &status));
121 run_loop.Run(); 124 run_loop.Run();
122 125
123 local_service_->AddChangeObserver(this); 126 local_service_->AddChangeObserver(this);
124 127
125 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_->OpenFileSystem()); 128 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_->OpenFileSystem());
126 129
127 file_system_->file_system_context()->sync_context()-> 130 file_system_->file_system_context()->sync_context()->
128 set_mock_notify_changes_duration_in_sec(0); 131 set_mock_notify_changes_duration_in_sec(0);
129 } 132 }
130 133
131 virtual void TearDown() OVERRIDE { 134 virtual void TearDown() OVERRIDE {
132 local_service_->Shutdown(); 135 local_service_->Shutdown();
133 file_system_->TearDown(); 136 file_system_->TearDown();
134 RevokeSyncableFileSystem(); 137 RevokeSyncableFileSystem();
135 138 content::RunAllPendingInMessageLoop(BrowserThread::FILE);
136 thread_helper_.TearDown();
137 } 139 }
138 140
139 // LocalChangeObserver overrides. 141 // LocalChangeObserver overrides.
140 virtual void OnLocalChangeAvailable(int64 num_changes) OVERRIDE { 142 virtual void OnLocalChangeAvailable(int64 num_changes) OVERRIDE {
141 num_changes_ = num_changes; 143 num_changes_ = num_changes;
142 } 144 }
143 145
144 void PrepareForProcessRemoteChange( 146 void PrepareForProcessRemoteChange(
145 const FileSystemURL& url, 147 const FileSystemURL& url,
146 const tracked_objects::Location& where, 148 const tracked_objects::Location& where,
(...skipping 19 matching lines...) Expand all
166 change, local_path, url, 168 change, local_path, url,
167 AssignAndQuitCallback(&run_loop, &sync_status)); 169 AssignAndQuitCallback(&run_loop, &sync_status));
168 run_loop.Run(); 170 run_loop.Run();
169 return sync_status; 171 return sync_status;
170 } 172 }
171 173
172 int64 GetNumChangesInTracker() const { 174 int64 GetNumChangesInTracker() const {
173 return file_system_->file_system_context()->change_tracker()->num_changes(); 175 return file_system_->file_system_context()->change_tracker()->num_changes();
174 } 176 }
175 177
178 content::TestBrowserThreadBundle thread_bundle_;
179
176 ScopedEnableSyncFSDirectoryOperation enable_directory_operation_; 180 ScopedEnableSyncFSDirectoryOperation enable_directory_operation_;
177 TestingProfile profile_; 181 TestingProfile profile_;
178 182
179 MultiThreadTestHelper thread_helper_;
180
181 base::ScopedTempDir temp_dir_; 183 base::ScopedTempDir temp_dir_;
182 184
183 scoped_ptr<CannedSyncableFileSystem> file_system_; 185 scoped_ptr<CannedSyncableFileSystem> file_system_;
184 scoped_ptr<LocalFileSyncService> local_service_; 186 scoped_ptr<LocalFileSyncService> local_service_;
185 187
186 int64 num_changes_; 188 int64 num_changes_;
187 }; 189 };
188 190
189 // More complete tests for PrepareForProcessRemoteChange and ApplyRemoteChange 191 // More complete tests for PrepareForProcessRemoteChange and ApplyRemoteChange
190 // are also in content_unittest:LocalFileSyncContextTest. 192 // are also in content_unittest:LocalFileSyncContextTest.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 // Flaky: http://crbug.com/171487 272 // Flaky: http://crbug.com/171487
271 #define MAYBE_LocalChangeObserverMultipleContexts\ 273 #define MAYBE_LocalChangeObserverMultipleContexts\
272 DISABLED_LocalChangeObserverMultipleContexts 274 DISABLED_LocalChangeObserverMultipleContexts
273 #else 275 #else
274 #define MAYBE_LocalChangeObserverMultipleContexts\ 276 #define MAYBE_LocalChangeObserverMultipleContexts\
275 LocalChangeObserverMultipleContexts 277 LocalChangeObserverMultipleContexts
276 #endif 278 #endif
277 279
278 TEST_F(LocalFileSyncServiceTest, MAYBE_LocalChangeObserverMultipleContexts) { 280 TEST_F(LocalFileSyncServiceTest, MAYBE_LocalChangeObserverMultipleContexts) {
279 const char kOrigin2[] = "http://foo"; 281 const char kOrigin2[] = "http://foo";
280 CannedSyncableFileSystem file_system2(GURL(kOrigin2), 282 CannedSyncableFileSystem file_system2(
281 thread_helper_.io_task_runner(), 283 GURL(kOrigin2),
282 thread_helper_.file_task_runner()); 284 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
285 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
283 file_system2.SetUp(); 286 file_system2.SetUp();
284 287
285 base::RunLoop run_loop; 288 base::RunLoop run_loop;
286 SyncStatusCode status = SYNC_STATUS_UNKNOWN; 289 SyncStatusCode status = SYNC_STATUS_UNKNOWN;
287 local_service_->MaybeInitializeFileSystemContext( 290 local_service_->MaybeInitializeFileSystemContext(
288 GURL(kOrigin2), file_system2.file_system_context(), 291 GURL(kOrigin2), file_system2.file_system_context(),
289 AssignAndQuitCallback(&run_loop, &status)); 292 AssignAndQuitCallback(&run_loop, &status));
290 run_loop.Run(); 293 run_loop.Run();
291 294
292 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system2.OpenFileSystem()); 295 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system2.OpenFileSystem());
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 all_origins.insert(kOrigin2); 700 all_origins.insert(kOrigin2);
698 all_origins.insert(kOrigin3); 701 all_origins.insert(kOrigin3);
699 while (!all_origins.empty()) { 702 while (!all_origins.empty()) {
700 ASSERT_TRUE(NextOriginToProcess(&origin)); 703 ASSERT_TRUE(NextOriginToProcess(&origin));
701 ASSERT_TRUE(ContainsKey(all_origins, origin)); 704 ASSERT_TRUE(ContainsKey(all_origins, origin));
702 all_origins.erase(origin); 705 all_origins.erase(origin);
703 } 706 }
704 } 707 }
705 708
706 } // namespace sync_file_system 709 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698