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

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: address comments. merge to ToT. Murder a DB thread and more TestBrowserThreads. 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"
17 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
19 #include "webkit/browser/fileapi/file_system_context.h" 21 #include "webkit/browser/fileapi/file_system_context.h"
20 #include "webkit/browser/fileapi/syncable/canned_syncable_file_system.h" 22 #include "webkit/browser/fileapi/syncable/canned_syncable_file_system.h"
21 #include "webkit/browser/fileapi/syncable/file_change.h" 23 #include "webkit/browser/fileapi/syncable/file_change.h"
22 #include "webkit/browser/fileapi/syncable/local_file_change_tracker.h" 24 #include "webkit/browser/fileapi/syncable/local_file_change_tracker.h"
23 #include "webkit/browser/fileapi/syncable/local_file_sync_context.h" 25 #include "webkit/browser/fileapi/syncable/local_file_sync_context.h"
24 #include "webkit/browser/fileapi/syncable/local_file_sync_status.h" 26 #include "webkit/browser/fileapi/syncable/local_file_sync_status.h"
25 #include "webkit/browser/fileapi/syncable/mock_sync_status_observer.h" 27 #include "webkit/browser/fileapi/syncable/mock_sync_status_observer.h"
26 #include "webkit/browser/fileapi/syncable/sync_file_metadata.h" 28 #include "webkit/browser/fileapi/syncable/sync_file_metadata.h"
27 #include "webkit/browser/fileapi/syncable/sync_status_code.h" 29 #include "webkit/browser/fileapi/syncable/sync_status_code.h"
28 #include "webkit/browser/fileapi/syncable/syncable_file_system_util.h" 30 #include "webkit/browser/fileapi/syncable/syncable_file_system_util.h"
29 31
32 using content::BrowserThread;
30 using fileapi::FileSystemURL; 33 using fileapi::FileSystemURL;
31 using ::testing::_; 34 using ::testing::_;
32 using ::testing::AtLeast; 35 using ::testing::AtLeast;
33 using ::testing::InvokeWithoutArgs; 36 using ::testing::InvokeWithoutArgs;
34 using ::testing::StrictMock; 37 using ::testing::StrictMock;
35 38
36 namespace sync_file_system { 39 namespace sync_file_system {
37 40
38 namespace { 41 namespace {
39 42
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 : public testing::Test, 98 : public testing::Test,
96 public LocalFileSyncService::Observer { 99 public LocalFileSyncService::Observer {
97 protected: 100 protected:
98 LocalFileSyncServiceTest() : num_changes_(0) {} 101 LocalFileSyncServiceTest() : num_changes_(0) {}
99 102
100 virtual ~LocalFileSyncServiceTest() {} 103 virtual ~LocalFileSyncServiceTest() {}
101 104
102 virtual void SetUp() OVERRIDE { 105 virtual void SetUp() OVERRIDE {
103 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 106 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
104 107
105 thread_helper_.SetUp();
106
107 file_system_.reset(new CannedSyncableFileSystem( 108 file_system_.reset(new CannedSyncableFileSystem(
108 GURL(kOrigin), 109 GURL(kOrigin),
109 thread_helper_.io_task_runner(), 110 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
110 thread_helper_.file_task_runner())); 111 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)));
111 112
112 local_service_.reset(new LocalFileSyncService(&profile_)); 113 local_service_.reset(new LocalFileSyncService(&profile_));
113 114
114 file_system_->SetUp(); 115 file_system_->SetUp();
115 116
116 base::RunLoop run_loop; 117 base::RunLoop run_loop;
117 SyncStatusCode status = SYNC_STATUS_UNKNOWN; 118 SyncStatusCode status = SYNC_STATUS_UNKNOWN;
118 local_service_->MaybeInitializeFileSystemContext( 119 local_service_->MaybeInitializeFileSystemContext(
119 GURL(kOrigin), file_system_->file_system_context(), 120 GURL(kOrigin), file_system_->file_system_context(),
120 AssignAndQuitCallback(&run_loop, &status)); 121 AssignAndQuitCallback(&run_loop, &status));
121 run_loop.Run(); 122 run_loop.Run();
122 123
123 local_service_->AddChangeObserver(this); 124 local_service_->AddChangeObserver(this);
124 125
125 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_->OpenFileSystem()); 126 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_->OpenFileSystem());
126 127
127 file_system_->file_system_context()->sync_context()-> 128 file_system_->file_system_context()->sync_context()->
128 set_mock_notify_changes_duration_in_sec(0); 129 set_mock_notify_changes_duration_in_sec(0);
129 } 130 }
130 131
131 virtual void TearDown() OVERRIDE { 132 virtual void TearDown() OVERRIDE {
132 local_service_->Shutdown(); 133 local_service_->Shutdown();
133 file_system_->TearDown(); 134 file_system_->TearDown();
134 RevokeSyncableFileSystem(); 135 RevokeSyncableFileSystem();
135
136 thread_helper_.TearDown();
137 } 136 }
138 137
139 // LocalChangeObserver overrides. 138 // LocalChangeObserver overrides.
140 virtual void OnLocalChangeAvailable(int64 num_changes) OVERRIDE { 139 virtual void OnLocalChangeAvailable(int64 num_changes) OVERRIDE {
141 num_changes_ = num_changes; 140 num_changes_ = num_changes;
142 } 141 }
143 142
144 void PrepareForProcessRemoteChange( 143 void PrepareForProcessRemoteChange(
145 const FileSystemURL& url, 144 const FileSystemURL& url,
146 const tracked_objects::Location& where, 145 const tracked_objects::Location& where,
(...skipping 19 matching lines...) Expand all
166 change, local_path, url, 165 change, local_path, url,
167 AssignAndQuitCallback(&run_loop, &sync_status)); 166 AssignAndQuitCallback(&run_loop, &sync_status));
168 run_loop.Run(); 167 run_loop.Run();
169 return sync_status; 168 return sync_status;
170 } 169 }
171 170
172 int64 GetNumChangesInTracker() const { 171 int64 GetNumChangesInTracker() const {
173 return file_system_->file_system_context()->change_tracker()->num_changes(); 172 return file_system_->file_system_context()->change_tracker()->num_changes();
174 } 173 }
175 174
175 content::TestBrowserThreadBundle thread_bundle_;
kinuko 2013/07/12 04:35:44 MultiThreadTestHelper internally uses TestBrowserT
awong 2013/07/12 07:17:39 Nope...it's not required. I thought it was just ex
kinuko 2013/07/12 07:28:27 Right, in most cases I'd agree with you and just u
176
176 ScopedEnableSyncFSDirectoryOperation enable_directory_operation_; 177 ScopedEnableSyncFSDirectoryOperation enable_directory_operation_;
177 TestingProfile profile_; 178 TestingProfile profile_;
178 179
179 MultiThreadTestHelper thread_helper_;
180
181 base::ScopedTempDir temp_dir_; 180 base::ScopedTempDir temp_dir_;
182 181
183 scoped_ptr<CannedSyncableFileSystem> file_system_; 182 scoped_ptr<CannedSyncableFileSystem> file_system_;
184 scoped_ptr<LocalFileSyncService> local_service_; 183 scoped_ptr<LocalFileSyncService> local_service_;
185 184
186 int64 num_changes_; 185 int64 num_changes_;
187 }; 186 };
188 187
189 // More complete tests for PrepareForProcessRemoteChange and ApplyRemoteChange 188 // More complete tests for PrepareForProcessRemoteChange and ApplyRemoteChange
190 // are also in content_unittest:LocalFileSyncContextTest. 189 // are also in content_unittest:LocalFileSyncContextTest.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 // Flaky: http://crbug.com/171487 269 // Flaky: http://crbug.com/171487
271 #define MAYBE_LocalChangeObserverMultipleContexts\ 270 #define MAYBE_LocalChangeObserverMultipleContexts\
272 DISABLED_LocalChangeObserverMultipleContexts 271 DISABLED_LocalChangeObserverMultipleContexts
273 #else 272 #else
274 #define MAYBE_LocalChangeObserverMultipleContexts\ 273 #define MAYBE_LocalChangeObserverMultipleContexts\
275 LocalChangeObserverMultipleContexts 274 LocalChangeObserverMultipleContexts
276 #endif 275 #endif
277 276
278 TEST_F(LocalFileSyncServiceTest, MAYBE_LocalChangeObserverMultipleContexts) { 277 TEST_F(LocalFileSyncServiceTest, MAYBE_LocalChangeObserverMultipleContexts) {
279 const char kOrigin2[] = "http://foo"; 278 const char kOrigin2[] = "http://foo";
280 CannedSyncableFileSystem file_system2(GURL(kOrigin2), 279 CannedSyncableFileSystem file_system2(
281 thread_helper_.io_task_runner(), 280 GURL(kOrigin2),
282 thread_helper_.file_task_runner()); 281 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
282 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
283 file_system2.SetUp(); 283 file_system2.SetUp();
284 284
285 base::RunLoop run_loop; 285 base::RunLoop run_loop;
286 SyncStatusCode status = SYNC_STATUS_UNKNOWN; 286 SyncStatusCode status = SYNC_STATUS_UNKNOWN;
287 local_service_->MaybeInitializeFileSystemContext( 287 local_service_->MaybeInitializeFileSystemContext(
288 GURL(kOrigin2), file_system2.file_system_context(), 288 GURL(kOrigin2), file_system2.file_system_context(),
289 AssignAndQuitCallback(&run_loop, &status)); 289 AssignAndQuitCallback(&run_loop, &status));
290 run_loop.Run(); 290 run_loop.Run();
291 291
292 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system2.OpenFileSystem()); 292 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); 697 all_origins.insert(kOrigin2);
698 all_origins.insert(kOrigin3); 698 all_origins.insert(kOrigin3);
699 while (!all_origins.empty()) { 699 while (!all_origins.empty()) {
700 ASSERT_TRUE(NextOriginToProcess(&origin)); 700 ASSERT_TRUE(NextOriginToProcess(&origin));
701 ASSERT_TRUE(ContainsKey(all_origins, origin)); 701 ASSERT_TRUE(ContainsKey(all_origins, origin));
702 all_origins.erase(origin); 702 all_origins.erase(origin);
703 } 703 }
704 } 704 }
705 705
706 } // namespace sync_file_system 706 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698