| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/fileapi/upload_file_system_file_element_reader.h" | 5 #include "content/browser/fileapi/upload_file_system_file_element_reader.h" |
| 6 | 6 |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "content/public/test/async_file_test_helper.h" | 10 #include "content/public/test/async_file_test_helper.h" |
| 11 #include "content/public/test/test_file_system_context.h" | 11 #include "content/public/test/test_file_system_context.h" |
| 12 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
| 13 #include "net/base/test_completion_callback.h" | 13 #include "net/base/test_completion_callback.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "webkit/browser/fileapi/file_system_backend.h" | 15 #include "storage/browser/fileapi/file_system_backend.h" |
| 16 #include "webkit/browser/fileapi/file_system_context.h" | 16 #include "storage/browser/fileapi/file_system_context.h" |
| 17 #include "webkit/browser/fileapi/file_system_operation_context.h" | 17 #include "storage/browser/fileapi/file_system_operation_context.h" |
| 18 #include "webkit/browser/fileapi/file_system_url.h" | 18 #include "storage/browser/fileapi/file_system_url.h" |
| 19 | 19 |
| 20 using content::AsyncFileTestHelper; | 20 using content::AsyncFileTestHelper; |
| 21 using fileapi::FileSystemContext; | 21 using storage::FileSystemContext; |
| 22 using fileapi::FileSystemType; | 22 using storage::FileSystemType; |
| 23 using fileapi::FileSystemURL; | 23 using storage::FileSystemURL; |
| 24 | 24 |
| 25 namespace content { | 25 namespace content { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 const char kFileSystemURLOrigin[] = "http://remote"; | 29 const char kFileSystemURLOrigin[] = "http://remote"; |
| 30 const fileapi::FileSystemType kFileSystemType = | 30 const storage::FileSystemType kFileSystemType = |
| 31 fileapi::kFileSystemTypeTemporary; | 31 storage::kFileSystemTypeTemporary; |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 class UploadFileSystemFileElementReaderTest : public testing::Test { | 35 class UploadFileSystemFileElementReaderTest : public testing::Test { |
| 36 public: | 36 public: |
| 37 UploadFileSystemFileElementReaderTest() {} | 37 UploadFileSystemFileElementReaderTest() {} |
| 38 | 38 |
| 39 virtual void SetUp() OVERRIDE { | 39 virtual void SetUp() OVERRIDE { |
| 40 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 40 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 41 | 41 |
| 42 file_system_context_ = CreateFileSystemContextForTesting( | 42 file_system_context_ = CreateFileSystemContextForTesting( |
| 43 NULL, temp_dir_.path()); | 43 NULL, temp_dir_.path()); |
| 44 | 44 |
| 45 file_system_context_->OpenFileSystem( | 45 file_system_context_->OpenFileSystem( |
| 46 GURL(kFileSystemURLOrigin), | 46 GURL(kFileSystemURLOrigin), |
| 47 kFileSystemType, | 47 kFileSystemType, |
| 48 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 48 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 49 base::Bind(&UploadFileSystemFileElementReaderTest::OnOpenFileSystem, | 49 base::Bind(&UploadFileSystemFileElementReaderTest::OnOpenFileSystem, |
| 50 base::Unretained(this))); | 50 base::Unretained(this))); |
| 51 base::RunLoop().RunUntilIdle(); | 51 base::RunLoop().RunUntilIdle(); |
| 52 ASSERT_TRUE(file_system_root_url_.is_valid()); | 52 ASSERT_TRUE(file_system_root_url_.is_valid()); |
| 53 | 53 |
| 54 // Prepare a file on file system. | 54 // Prepare a file on file system. |
| 55 const char kTestData[] = "abcdefghijklmnop0123456789"; | 55 const char kTestData[] = "abcdefghijklmnop0123456789"; |
| 56 file_data_.assign(kTestData, kTestData + arraysize(kTestData) - 1); | 56 file_data_.assign(kTestData, kTestData + arraysize(kTestData) - 1); |
| 57 const char kFilename[] = "File.dat"; | 57 const char kFilename[] = "File.dat"; |
| 58 file_url_ = GetFileSystemURL(kFilename); | 58 file_url_ = GetFileSystemURL(kFilename); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 81 | 81 |
| 82 protected: | 82 protected: |
| 83 GURL GetFileSystemURL(const std::string& filename) { | 83 GURL GetFileSystemURL(const std::string& filename) { |
| 84 return GURL(file_system_root_url_.spec() + filename); | 84 return GURL(file_system_root_url_.spec() + filename); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void WriteFileSystemFile(const std::string& filename, | 87 void WriteFileSystemFile(const std::string& filename, |
| 88 const char* buf, | 88 const char* buf, |
| 89 int buf_size, | 89 int buf_size, |
| 90 base::Time* modification_time) { | 90 base::Time* modification_time) { |
| 91 fileapi::FileSystemURL url = | 91 storage::FileSystemURL url = |
| 92 file_system_context_->CreateCrackedFileSystemURL( | 92 file_system_context_->CreateCrackedFileSystemURL( |
| 93 GURL(kFileSystemURLOrigin), | 93 GURL(kFileSystemURLOrigin), |
| 94 kFileSystemType, | 94 kFileSystemType, |
| 95 base::FilePath().AppendASCII(filename)); | 95 base::FilePath().AppendASCII(filename)); |
| 96 | 96 |
| 97 ASSERT_EQ(base::File::FILE_OK, | 97 ASSERT_EQ(base::File::FILE_OK, |
| 98 AsyncFileTestHelper::CreateFileWithData( | 98 AsyncFileTestHelper::CreateFileWithData( |
| 99 file_system_context_, url, buf, buf_size)); | 99 file_system_context_, url, buf, buf_size)); |
| 100 | 100 |
| 101 base::File::Info file_info; | 101 base::File::Info file_info; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 TEST_F(UploadFileSystemFileElementReaderTest, WrongURL) { | 274 TEST_F(UploadFileSystemFileElementReaderTest, WrongURL) { |
| 275 const GURL wrong_url = GetFileSystemURL("wrong_file_name.dat"); | 275 const GURL wrong_url = GetFileSystemURL("wrong_file_name.dat"); |
| 276 reader_.reset(new UploadFileSystemFileElementReader( | 276 reader_.reset(new UploadFileSystemFileElementReader( |
| 277 file_system_context_.get(), wrong_url, 0, kuint64max, base::Time())); | 277 file_system_context_.get(), wrong_url, 0, kuint64max, base::Time())); |
| 278 net::TestCompletionCallback init_callback; | 278 net::TestCompletionCallback init_callback; |
| 279 ASSERT_EQ(net::ERR_IO_PENDING, reader_->Init(init_callback.callback())); | 279 ASSERT_EQ(net::ERR_IO_PENDING, reader_->Init(init_callback.callback())); |
| 280 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, init_callback.WaitForResult()); | 280 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, init_callback.WaitForResult()); |
| 281 } | 281 } |
| 282 | 282 |
| 283 } // namespace content | 283 } // namespace content |
| OLD | NEW |