| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/fileapi/upload_file_system_file_element_reader.h" | 5 #include "webkit/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.h" | 8 #include "base/message_loop.h" |
| 9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
| 10 #include "net/base/test_completion_callback.h" | 10 #include "net/base/test_completion_callback.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 virtual void SetUp() OVERRIDE { | 34 virtual void SetUp() OVERRIDE { |
| 35 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 35 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 36 | 36 |
| 37 file_system_context_ = fileapi::CreateFileSystemContextForTesting( | 37 file_system_context_ = fileapi::CreateFileSystemContextForTesting( |
| 38 NULL, temp_dir_.path()); | 38 NULL, temp_dir_.path()); |
| 39 | 39 |
| 40 file_system_context_->OpenFileSystem( | 40 file_system_context_->OpenFileSystem( |
| 41 GURL(kFileSystemURLOrigin), | 41 GURL(kFileSystemURLOrigin), |
| 42 kFileSystemType, | 42 kFileSystemType, |
| 43 true, // create | 43 OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 44 base::Bind(&UploadFileSystemFileElementReaderTest::OnValidateFileSystem, | 44 base::Bind(&UploadFileSystemFileElementReaderTest::OnOpenFileSystem, |
| 45 base::Unretained(this))); | 45 base::Unretained(this))); |
| 46 base::MessageLoop::current()->RunUntilIdle(); | 46 base::MessageLoop::current()->RunUntilIdle(); |
| 47 ASSERT_TRUE(file_system_root_url_.is_valid()); | 47 ASSERT_TRUE(file_system_root_url_.is_valid()); |
| 48 | 48 |
| 49 // Prepare a file on file system. | 49 // Prepare a file on file system. |
| 50 const char kTestData[] = "abcdefghijklmnop0123456789"; | 50 const char kTestData[] = "abcdefghijklmnop0123456789"; |
| 51 file_data_.assign(kTestData, kTestData + arraysize(kTestData) - 1); | 51 file_data_.assign(kTestData, kTestData + arraysize(kTestData) - 1); |
| 52 const char kFilename[] = "File.dat"; | 52 const char kFilename[] = "File.dat"; |
| 53 file_url_ = GetFileSystemURL(kFilename); | 53 file_url_ = GetFileSystemURL(kFilename); |
| 54 WriteFileSystemFile(kFilename, &file_data_[0], file_data_.size(), | 54 WriteFileSystemFile(kFilename, &file_data_[0], file_data_.size(), |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 base::ClosePlatformFile(handle); | 102 base::ClosePlatformFile(handle); |
| 103 | 103 |
| 104 base::PlatformFileInfo file_info; | 104 base::PlatformFileInfo file_info; |
| 105 base::FilePath platform_path; | 105 base::FilePath platform_path; |
| 106 ASSERT_EQ(base::PLATFORM_FILE_OK, | 106 ASSERT_EQ(base::PLATFORM_FILE_OK, |
| 107 file_util->GetFileInfo(&context, url, &file_info, | 107 file_util->GetFileInfo(&context, url, &file_info, |
| 108 &platform_path)); | 108 &platform_path)); |
| 109 *modification_time = file_info.last_modified; | 109 *modification_time = file_info.last_modified; |
| 110 } | 110 } |
| 111 | 111 |
| 112 void OnValidateFileSystem(base::PlatformFileError result, | 112 void OnOpenFileSystem(base::PlatformFileError result, |
| 113 const std::string& name, | 113 const std::string& name, |
| 114 const GURL& root) { | 114 const GURL& root) { |
| 115 ASSERT_EQ(base::PLATFORM_FILE_OK, result); | 115 ASSERT_EQ(base::PLATFORM_FILE_OK, result); |
| 116 ASSERT_TRUE(root.is_valid()); | 116 ASSERT_TRUE(root.is_valid()); |
| 117 file_system_root_url_ = root; | 117 file_system_root_url_ = root; |
| 118 } | 118 } |
| 119 | 119 |
| 120 base::MessageLoop message_loop_; | 120 base::MessageLoop message_loop_; |
| 121 base::ScopedTempDir temp_dir_; | 121 base::ScopedTempDir temp_dir_; |
| 122 scoped_refptr<FileSystemContext> file_system_context_; | 122 scoped_refptr<FileSystemContext> file_system_context_; |
| 123 GURL file_system_root_url_; | 123 GURL file_system_root_url_; |
| 124 std::vector<char> file_data_; | 124 std::vector<char> file_data_; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 TEST_F(UploadFileSystemFileElementReaderTest, WrongURL) { | 275 TEST_F(UploadFileSystemFileElementReaderTest, WrongURL) { |
| 276 const GURL wrong_url = GetFileSystemURL("wrong_file_name.dat"); | 276 const GURL wrong_url = GetFileSystemURL("wrong_file_name.dat"); |
| 277 reader_.reset(new UploadFileSystemFileElementReader( | 277 reader_.reset(new UploadFileSystemFileElementReader( |
| 278 file_system_context_, wrong_url, 0, kuint64max, base::Time())); | 278 file_system_context_, wrong_url, 0, kuint64max, base::Time())); |
| 279 net::TestCompletionCallback init_callback; | 279 net::TestCompletionCallback init_callback; |
| 280 ASSERT_EQ(net::ERR_IO_PENDING, reader_->Init(init_callback.callback())); | 280 ASSERT_EQ(net::ERR_IO_PENDING, reader_->Init(init_callback.callback())); |
| 281 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, init_callback.WaitForResult()); | 281 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, init_callback.WaitForResult()); |
| 282 } | 282 } |
| 283 | 283 |
| 284 } // namespace fileapi | 284 } // namespace fileapi |
| OLD | NEW |