| 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 "webkit/browser/fileapi/upload_file_system_file_element_reader.h" | 5 #include "webkit/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/test_file_system_context.h" | 10 #include "content/public/test/test_file_system_context.h" |
| 11 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
| 12 #include "net/base/test_completion_callback.h" | 12 #include "net/base/test_completion_callback.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "webkit/browser/fileapi/async_file_test_helper.h" | 14 #include "webkit/browser/fileapi/async_file_test_helper.h" |
| 15 #include "webkit/browser/fileapi/file_system_backend.h" | 15 #include "webkit/browser/fileapi/file_system_backend.h" |
| 16 #include "webkit/browser/fileapi/file_system_context.h" | 16 #include "webkit/browser/fileapi/file_system_context.h" |
| 17 #include "webkit/browser/fileapi/file_system_operation_context.h" | 17 #include "webkit/browser/fileapi/file_system_operation_context.h" |
| 18 #include "webkit/browser/fileapi/file_system_url.h" | 18 #include "webkit/browser/fileapi/file_system_url.h" |
| 19 | 19 |
| 20 namespace fileapi { | 20 using fileapi::AsyncFileTestHelper; |
| 21 using fileapi::FileSystemContext; |
| 22 using fileapi::FileSystemType; |
| 23 using fileapi::FileSystemURL; |
| 24 using fileapi::UploadFileSystemFileElementReader; |
| 25 |
| 26 namespace content { |
| 21 | 27 |
| 22 namespace { | 28 namespace { |
| 23 | 29 |
| 24 const char kFileSystemURLOrigin[] = "http://remote"; | 30 const char kFileSystemURLOrigin[] = "http://remote"; |
| 25 const fileapi::FileSystemType kFileSystemType = | 31 const fileapi::FileSystemType kFileSystemType = |
| 26 fileapi::kFileSystemTypeTemporary; | 32 fileapi::kFileSystemTypeTemporary; |
| 27 | 33 |
| 28 } // namespace | 34 } // namespace |
| 29 | 35 |
| 30 class UploadFileSystemFileElementReaderTest : public testing::Test { | 36 class UploadFileSystemFileElementReaderTest : public testing::Test { |
| 31 public: | 37 public: |
| 32 UploadFileSystemFileElementReaderTest() {} | 38 UploadFileSystemFileElementReaderTest() {} |
| 33 | 39 |
| 34 virtual void SetUp() OVERRIDE { | 40 virtual void SetUp() OVERRIDE { |
| 35 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 41 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 36 | 42 |
| 37 file_system_context_ = fileapi::CreateFileSystemContextForTesting( | 43 file_system_context_ = CreateFileSystemContextForTesting( |
| 38 NULL, temp_dir_.path()); | 44 NULL, temp_dir_.path()); |
| 39 | 45 |
| 40 file_system_context_->OpenFileSystem( | 46 file_system_context_->OpenFileSystem( |
| 41 GURL(kFileSystemURLOrigin), | 47 GURL(kFileSystemURLOrigin), |
| 42 kFileSystemType, | 48 kFileSystemType, |
| 43 OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 49 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 44 base::Bind(&UploadFileSystemFileElementReaderTest::OnOpenFileSystem, | 50 base::Bind(&UploadFileSystemFileElementReaderTest::OnOpenFileSystem, |
| 45 base::Unretained(this))); | 51 base::Unretained(this))); |
| 46 base::RunLoop().RunUntilIdle(); | 52 base::RunLoop().RunUntilIdle(); |
| 47 ASSERT_TRUE(file_system_root_url_.is_valid()); | 53 ASSERT_TRUE(file_system_root_url_.is_valid()); |
| 48 | 54 |
| 49 // Prepare a file on file system. | 55 // Prepare a file on file system. |
| 50 const char kTestData[] = "abcdefghijklmnop0123456789"; | 56 const char kTestData[] = "abcdefghijklmnop0123456789"; |
| 51 file_data_.assign(kTestData, kTestData + arraysize(kTestData) - 1); | 57 file_data_.assign(kTestData, kTestData + arraysize(kTestData) - 1); |
| 52 const char kFilename[] = "File.dat"; | 58 const char kFilename[] = "File.dat"; |
| 53 file_url_ = GetFileSystemURL(kFilename); | 59 file_url_ = GetFileSystemURL(kFilename); |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 | 274 |
| 269 TEST_F(UploadFileSystemFileElementReaderTest, WrongURL) { | 275 TEST_F(UploadFileSystemFileElementReaderTest, WrongURL) { |
| 270 const GURL wrong_url = GetFileSystemURL("wrong_file_name.dat"); | 276 const GURL wrong_url = GetFileSystemURL("wrong_file_name.dat"); |
| 271 reader_.reset(new UploadFileSystemFileElementReader( | 277 reader_.reset(new UploadFileSystemFileElementReader( |
| 272 file_system_context_.get(), wrong_url, 0, kuint64max, base::Time())); | 278 file_system_context_.get(), wrong_url, 0, kuint64max, base::Time())); |
| 273 net::TestCompletionCallback init_callback; | 279 net::TestCompletionCallback init_callback; |
| 274 ASSERT_EQ(net::ERR_IO_PENDING, reader_->Init(init_callback.callback())); | 280 ASSERT_EQ(net::ERR_IO_PENDING, reader_->Init(init_callback.callback())); |
| 275 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, init_callback.WaitForResult()); | 281 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, init_callback.WaitForResult()); |
| 276 } | 282 } |
| 277 | 283 |
| 278 } // namespace fileapi | 284 } // namespace content |
| OLD | NEW |