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 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/json/json_file_value_serializer.h" | 8 #include "base/json/json_file_value_serializer.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 private: | 186 private: |
187 FilePath test_mount_point_; | 187 FilePath test_mount_point_; |
188 }; | 188 }; |
189 | 189 |
190 class RemoteFileSystemExtensionApiTest : public ExtensionApiTest { | 190 class RemoteFileSystemExtensionApiTest : public ExtensionApiTest { |
191 public: | 191 public: |
192 RemoteFileSystemExtensionApiTest() {} | 192 RemoteFileSystemExtensionApiTest() {} |
193 | 193 |
194 virtual ~RemoteFileSystemExtensionApiTest() {} | 194 virtual ~RemoteFileSystemExtensionApiTest() {} |
195 | 195 |
196 // Sets up GDataFileSystem that will be used in the test. | 196 virtual void SetUp() OVERRIDE { |
197 // NOTE: Remote mount point should get added to mount point provider when | 197 // Set up cache root and documents service to be used when creating gdata |
198 // getLocalFileSystem is called from filebrowser_component extension. | 198 // system service. This has to be done early on (before the browser is |
199 virtual void SetupGDataFileSystemForTest() { | 199 // created) because the system service instance is initialized very early |
200 // |mock_documents_service_| is owned by |system_service|. | 200 // by FileBrowserEventRouter. |
| 201 FilePath tmp_dir_path; |
| 202 PathService::Get(base::DIR_TEMP, &tmp_dir_path); |
| 203 ASSERT_TRUE(test_cache_root_.CreateUniqueTempDirUnderPath(tmp_dir_path)); |
| 204 gdata::GDataSystemServiceFactory::set_cache_root_for_test( |
| 205 test_cache_root_.path().value()); |
| 206 |
201 mock_documents_service_ = new gdata::MockDocumentsService(); | 207 mock_documents_service_ = new gdata::MockDocumentsService(); |
| 208 |
202 operation_registry_.reset(new gdata::GDataOperationRegistry()); | 209 operation_registry_.reset(new gdata::GDataOperationRegistry()); |
203 gdata::GDataSystemService* system_service = | 210 // FileBrowserEventRouter will add and remove itself from operation registry |
204 gdata::GDataSystemServiceFactory::GetInstance()-> | 211 // observer list. |
205 GetWithCustomDocumentsServiceForTesting( | 212 EXPECT_CALL(*mock_documents_service_, operation_registry()). |
206 browser()->profile(), mock_documents_service_); | 213 WillRepeatedly(Return(operation_registry_.get())); |
207 EXPECT_TRUE(system_service); | 214 |
| 215 // |mock_documents_service_| will eventually get owned by a system service. |
| 216 gdata::GDataSystemServiceFactory::set_documents_service_for_test( |
| 217 mock_documents_service_); |
| 218 |
| 219 ExtensionApiTest::SetUp(); |
| 220 } |
| 221 |
| 222 virtual void TearDown() OVERRIDE { |
| 223 // Let's make sure we don't leak documents service. |
| 224 gdata::GDataSystemServiceFactory::set_documents_service_for_test(NULL); |
| 225 gdata::GDataSystemServiceFactory::set_cache_root_for_test(std::string()); |
| 226 ExtensionApiTest::TearDown(); |
208 } | 227 } |
209 | 228 |
210 protected: | 229 protected: |
| 230 ScopedTempDir test_cache_root_; |
211 gdata::MockDocumentsService* mock_documents_service_; | 231 gdata::MockDocumentsService* mock_documents_service_; |
212 scoped_ptr<gdata::GDataOperationRegistry> operation_registry_; | 232 scoped_ptr<gdata::GDataOperationRegistry> operation_registry_; |
213 }; | 233 }; |
214 | 234 |
215 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, LocalFileSystem) { | 235 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, LocalFileSystem) { |
216 AddTmpMountPoint(); | 236 AddTmpMountPoint(); |
217 ASSERT_TRUE(RunComponentExtensionTest("local_filesystem")) << message_; | 237 ASSERT_TRUE(RunComponentExtensionTest("local_filesystem")) << message_; |
218 } | 238 } |
219 | 239 |
220 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, FileBrowserTest) { | 240 IN_PROC_BROWSER_TEST_F(FileSystemExtensionApiTest, FileBrowserTest) { |
(...skipping 30 matching lines...) Expand all Loading... |
251 FileBrowserTestWriteComponent) { | 271 FileBrowserTestWriteComponent) { |
252 AddTmpMountPoint(); | 272 AddTmpMountPoint(); |
253 ASSERT_TRUE(RunComponentExtensionTest("filesystem_handler_write")) | 273 ASSERT_TRUE(RunComponentExtensionTest("filesystem_handler_write")) |
254 << message_; | 274 << message_; |
255 ASSERT_TRUE(RunExtensionSubtest( | 275 ASSERT_TRUE(RunExtensionSubtest( |
256 "filebrowser_component", "write.html", kComponentFlags)) << message_; | 276 "filebrowser_component", "write.html", kComponentFlags)) << message_; |
257 } | 277 } |
258 | 278 |
259 IN_PROC_BROWSER_TEST_F(RemoteFileSystemExtensionApiTest, | 279 IN_PROC_BROWSER_TEST_F(RemoteFileSystemExtensionApiTest, |
260 RemoteMountPoint) { | 280 RemoteMountPoint) { |
261 SetupGDataFileSystemForTest(); | |
262 | |
263 EXPECT_CALL(*mock_documents_service_, GetAccountMetadata(_)).Times(1); | 281 EXPECT_CALL(*mock_documents_service_, GetAccountMetadata(_)).Times(1); |
264 | 282 |
265 // First, file browser will try to create new directory. | 283 // First, file browser will try to create new directory. |
266 scoped_ptr<base::Value> dir_value(LoadJSONFile(kTestDirectory)); | 284 scoped_ptr<base::Value> dir_value(LoadJSONFile(kTestDirectory)); |
267 EXPECT_CALL(*mock_documents_service_, | 285 EXPECT_CALL(*mock_documents_service_, |
268 CreateDirectory(_, _, _)) | 286 CreateDirectory(_, _, _)) |
269 .WillOnce(MockCreateDirectoryCallback(gdata::HTTP_SUCCESS, &dir_value)); | 287 .WillOnce(MockCreateDirectoryCallback(gdata::HTTP_SUCCESS, &dir_value)); |
270 | 288 |
271 // Then the test will try to read an existing file file. | 289 // Then the test will try to read an existing file file. |
272 // Remote filesystem should first request root feed from gdata server. | 290 // Remote filesystem should first request root feed from gdata server. |
(...skipping 19 matching lines...) Expand all Loading... |
292 | 310 |
293 // We expect to download url defined in document entry returned by | 311 // We expect to download url defined in document entry returned by |
294 // GetDocumentEntry mock implementation. | 312 // GetDocumentEntry mock implementation. |
295 EXPECT_CALL(*mock_documents_service_, | 313 EXPECT_CALL(*mock_documents_service_, |
296 DownloadFile(_, _, GURL("https://file_content_url_changed"), | 314 DownloadFile(_, _, GURL("https://file_content_url_changed"), |
297 _, _)) | 315 _, _)) |
298 .WillOnce(MockDownloadFileCallback(gdata::HTTP_SUCCESS)); | 316 .WillOnce(MockDownloadFileCallback(gdata::HTTP_SUCCESS)); |
299 | 317 |
300 // On exit, all operations in progress should be cancelled. | 318 // On exit, all operations in progress should be cancelled. |
301 EXPECT_CALL(*mock_documents_service_, CancelAll()); | 319 EXPECT_CALL(*mock_documents_service_, CancelAll()); |
302 // This one is called on exit, but we don't care much about it, as long as it | |
303 // retunrs something valid (i.e. not NULL). | |
304 EXPECT_CALL(*mock_documents_service_, operation_registry()). | |
305 WillRepeatedly(Return(operation_registry_.get())); | |
306 | 320 |
307 // All is set... RUN THE TEST. | 321 // All is set... RUN THE TEST. |
308 EXPECT_TRUE(RunExtensionTest("filesystem_handler")) << message_; | 322 EXPECT_TRUE(RunExtensionTest("filesystem_handler")) << message_; |
309 EXPECT_TRUE(RunExtensionSubtest("filebrowser_component", "remote.html", | 323 EXPECT_TRUE(RunExtensionSubtest("filebrowser_component", "remote.html", |
310 kComponentFlags)) << message_; | 324 kComponentFlags)) << message_; |
311 } | 325 } |
312 | 326 |
313 // This test fails under AddressSanitizer, see http://crbug.com/136169. | 327 // This test fails under AddressSanitizer, see http://crbug.com/136169. |
314 #if defined(ADDRESS_SANITIZER) | 328 #if defined(ADDRESS_SANITIZER) |
315 #define MAYBE_ContentSearch DISABLED_ContentSearch | 329 #define MAYBE_ContentSearch DISABLED_ContentSearch |
316 #else | 330 #else |
317 #define MAYBE_ContentSearch ContentSearch | 331 #define MAYBE_ContentSearch ContentSearch |
318 #endif | 332 #endif |
319 IN_PROC_BROWSER_TEST_F(RemoteFileSystemExtensionApiTest, | 333 IN_PROC_BROWSER_TEST_F(RemoteFileSystemExtensionApiTest, |
320 MAYBE_ContentSearch) { | 334 MAYBE_ContentSearch) { |
321 SetupGDataFileSystemForTest(); | |
322 | |
323 EXPECT_CALL(*mock_documents_service_, GetAccountMetadata(_)).Times(1); | 335 EXPECT_CALL(*mock_documents_service_, GetAccountMetadata(_)).Times(1); |
324 | 336 |
325 // First, test will get drive root directory, to init file system. | 337 // First, test will get drive root directory, to init file system. |
326 scoped_ptr<base::Value> documents_value(LoadJSONFile(kTestRootFeed)); | 338 scoped_ptr<base::Value> documents_value(LoadJSONFile(kTestRootFeed)); |
327 EXPECT_CALL(*mock_documents_service_, | 339 EXPECT_CALL(*mock_documents_service_, |
328 GetDocuments(_, _, "", _, _)) | 340 GetDocuments(_, _, "", _, _)) |
329 .WillOnce(MockGetDocumentsCallback(gdata::HTTP_SUCCESS, | 341 .WillOnce(MockGetDocumentsCallback(gdata::HTTP_SUCCESS, |
330 &documents_value)); | 342 &documents_value)); |
331 | 343 |
332 // We return the whole test file system in serch results. | 344 // We return the whole test file system in serch results. |
(...skipping 13 matching lines...) Expand all Loading... |
346 | 358 |
347 // We expect to download url defined in document entry returned by | 359 // We expect to download url defined in document entry returned by |
348 // GetDocumentEntry mock implementation. | 360 // GetDocumentEntry mock implementation. |
349 EXPECT_CALL(*mock_documents_service_, | 361 EXPECT_CALL(*mock_documents_service_, |
350 DownloadFile(_, _, GURL("https://file_content_url_changed"), | 362 DownloadFile(_, _, GURL("https://file_content_url_changed"), |
351 _, _)) | 363 _, _)) |
352 .WillOnce(MockDownloadFileCallback(gdata::HTTP_SUCCESS)); | 364 .WillOnce(MockDownloadFileCallback(gdata::HTTP_SUCCESS)); |
353 | 365 |
354 // On exit, all operations in progress should be cancelled. | 366 // On exit, all operations in progress should be cancelled. |
355 EXPECT_CALL(*mock_documents_service_, CancelAll()); | 367 EXPECT_CALL(*mock_documents_service_, CancelAll()); |
356 // This one is called on exit, but we don't care much about it, as long as it | |
357 // retunrs something valid (i.e. not NULL). | |
358 EXPECT_CALL(*mock_documents_service_, operation_registry()). | |
359 WillRepeatedly(Return(operation_registry_.get())); | |
360 | 368 |
361 // All is set... RUN THE TEST. | 369 // All is set... RUN THE TEST. |
362 EXPECT_TRUE(RunExtensionSubtest("filebrowser_component", "remote_search.html", | 370 EXPECT_TRUE(RunExtensionSubtest("filebrowser_component", "remote_search.html", |
363 kComponentFlags)) << message_; | 371 kComponentFlags)) << message_; |
364 } | 372 } |
OLD | NEW |