| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 109 |
| 110 // Action used to set mock expectations for CreateDirectory(). | 110 // Action used to set mock expectations for CreateDirectory(). |
| 111 ACTION_P2(MockCreateDirectoryCallback, status, value) { | 111 ACTION_P2(MockCreateDirectoryCallback, status, value) { |
| 112 base::MessageLoopProxy::current()->PostTask(FROM_HERE, | 112 base::MessageLoopProxy::current()->PostTask(FROM_HERE, |
| 113 base::Bind(arg2, status, base::Passed(value))); | 113 base::Bind(arg2, status, base::Passed(value))); |
| 114 } | 114 } |
| 115 | 115 |
| 116 // Action used to set mock expecteations for GetDocuments. | 116 // Action used to set mock expecteations for GetDocuments. |
| 117 ACTION_P2(MockGetDocumentsCallback, status, value) { | 117 ACTION_P2(MockGetDocumentsCallback, status, value) { |
| 118 base::MessageLoopProxy::current()->PostTask(FROM_HERE, | 118 base::MessageLoopProxy::current()->PostTask(FROM_HERE, |
| 119 base::Bind(arg2, status, base::Passed(value))); | 119 base::Bind(arg3, status, base::Passed(value))); |
| 120 } | 120 } |
| 121 | 121 |
| 122 // Creates a cache representation of the test file with predetermined content. | 122 // Creates a cache representation of the test file with predetermined content. |
| 123 void CreateDownloadFile(const FilePath& path) { | 123 void CreateDownloadFile(const FilePath& path) { |
| 124 int file_content_size = static_cast<int>(sizeof(kTestFileContents)); | 124 int file_content_size = static_cast<int>(sizeof(kTestFileContents)); |
| 125 ASSERT_EQ(file_content_size, | 125 ASSERT_EQ(file_content_size, |
| 126 file_util::WriteFile(path, kTestFileContents, file_content_size)); | 126 file_util::WriteFile(path, kTestFileContents, file_content_size)); |
| 127 } | 127 } |
| 128 | 128 |
| 129 // Action used to set mock expectations for DownloadFile(). | 129 // Action used to set mock expectations for DownloadFile(). |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 // First, file browser will try to create new directory. | 260 // First, file browser will try to create new directory. |
| 261 scoped_ptr<base::Value> dir_value(LoadJSONFile(kTestDirectory)); | 261 scoped_ptr<base::Value> dir_value(LoadJSONFile(kTestDirectory)); |
| 262 EXPECT_CALL(*mock_documents_service_, | 262 EXPECT_CALL(*mock_documents_service_, |
| 263 CreateDirectory(_, _, _)) | 263 CreateDirectory(_, _, _)) |
| 264 .WillOnce(MockCreateDirectoryCallback(gdata::HTTP_SUCCESS, &dir_value)); | 264 .WillOnce(MockCreateDirectoryCallback(gdata::HTTP_SUCCESS, &dir_value)); |
| 265 | 265 |
| 266 // Then the test will try to read an existing file file. | 266 // Then the test will try to read an existing file file. |
| 267 // Remote filesystem should first request root feed from gdata server. | 267 // Remote filesystem should first request root feed from gdata server. |
| 268 scoped_ptr<base::Value> documents_value(LoadJSONFile(kTestRootFeed)); | 268 scoped_ptr<base::Value> documents_value(LoadJSONFile(kTestRootFeed)); |
| 269 EXPECT_CALL(*mock_documents_service_, | 269 EXPECT_CALL(*mock_documents_service_, |
| 270 GetDocuments(_, _, _)) | 270 GetDocuments(_, _, _, _)) |
| 271 .WillOnce(MockGetDocumentsCallback(gdata::HTTP_SUCCESS, | 271 .WillOnce(MockGetDocumentsCallback(gdata::HTTP_SUCCESS, |
| 272 &documents_value)); | 272 &documents_value)); |
| 273 | 273 |
| 274 // When file browser tries to read the file, remote filesystem should detect | 274 // When file browser tries to read the file, remote filesystem should detect |
| 275 // that the cached file is not present on the disk and download it. Mocked | 275 // that the cached file is not present on the disk and download it. Mocked |
| 276 // download file will create file with the cached name and predetermined | 276 // download file will create file with the cached name and predetermined |
| 277 // content. This is the file file browser will read content from. | 277 // content. This is the file file browser will read content from. |
| 278 // Later in the test, file handler will try to open the same file on gdata | 278 // Later in the test, file handler will try to open the same file on gdata |
| 279 // mount point. This time, DownloadFile should not be called because local | 279 // mount point. This time, DownloadFile should not be called because local |
| 280 // copy is already present in the cache. | 280 // copy is already present in the cache. |
| 281 EXPECT_CALL(*mock_documents_service_, | 281 EXPECT_CALL(*mock_documents_service_, |
| 282 DownloadFile(_, _, _, _, _)) | 282 DownloadFile(_, _, _, _, _)) |
| 283 .WillOnce(MockDownloadFileCallback(gdata::HTTP_SUCCESS)); | 283 .WillOnce(MockDownloadFileCallback(gdata::HTTP_SUCCESS)); |
| 284 | 284 |
| 285 // On exit, all operations in progress should be cancelled. | 285 // On exit, all operations in progress should be cancelled. |
| 286 EXPECT_CALL(*mock_documents_service_, CancelAll()); | 286 EXPECT_CALL(*mock_documents_service_, CancelAll()); |
| 287 // This one is called on exit, but we don't care much about it, as long as it | 287 // This one is called on exit, but we don't care much about it, as long as it |
| 288 // retunrs something valid (i.e. not NULL). | 288 // retunrs something valid (i.e. not NULL). |
| 289 EXPECT_CALL(*mock_documents_service_, operation_registry()). | 289 EXPECT_CALL(*mock_documents_service_, operation_registry()). |
| 290 WillOnce(Return(operation_registry_.get())); | 290 WillOnce(Return(operation_registry_.get())); |
| 291 | 291 |
| 292 // All is set... RUN THE TEST. | 292 // All is set... RUN THE TEST. |
| 293 EXPECT_TRUE(RunExtensionTest("filesystem_handler")) << message_; | 293 EXPECT_TRUE(RunExtensionTest("filesystem_handler")) << message_; |
| 294 EXPECT_TRUE(RunExtensionSubtest("filebrowser_component", "remote.html", | 294 EXPECT_TRUE(RunExtensionSubtest("filebrowser_component", "remote.html", |
| 295 kComponentFlags)) << message_; | 295 kComponentFlags)) << message_; |
| 296 } | 296 } |
| OLD | NEW |