| 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 "webkit/fileapi/local_file_stream_writer.h" | 5 #include "webkit/fileapi/local_file_stream_writer.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 13 #include "base/scoped_temp_dir.h" | |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
| 16 #include "net/base/test_completion_callback.h" | 16 #include "net/base/test_completion_callback.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 using fileapi::LocalFileStreamWriter; | 21 using fileapi::LocalFileStreamWriter; |
| 22 | 22 |
| 23 class LocalFileStreamWriterTest : public testing::Test { | 23 class LocalFileStreamWriterTest : public testing::Test { |
| 24 public: | 24 public: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 FilePath CreateFileWithContent(const std::string& name, | 61 FilePath CreateFileWithContent(const std::string& name, |
| 62 const std::string& data) { | 62 const std::string& data) { |
| 63 FilePath path = Path(name); | 63 FilePath path = Path(name); |
| 64 file_util::WriteFile(path, data.c_str(), data.size()); | 64 file_util::WriteFile(path, data.c_str(), data.size()); |
| 65 return path; | 65 return path; |
| 66 } | 66 } |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 MessageLoop message_loop_; | 69 MessageLoop message_loop_; |
| 70 ScopedTempDir temp_dir_; | 70 base::ScopedTempDir temp_dir_; |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 void NeverCalled(int unused) { | 73 void NeverCalled(int unused) { |
| 74 ADD_FAILURE(); | 74 ADD_FAILURE(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 } // namespace | 77 } // namespace |
| 78 | 78 |
| 79 TEST_F(LocalFileStreamWriterTest, Write) { | 79 TEST_F(LocalFileStreamWriterTest, Write) { |
| 80 FilePath path = CreateFileWithContent("file_a", ""); | 80 FilePath path = CreateFileWithContent("file_a", ""); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 147 |
| 148 scoped_refptr<net::StringIOBuffer> buffer(new net::StringIOBuffer("xxx")); | 148 scoped_refptr<net::StringIOBuffer> buffer(new net::StringIOBuffer("xxx")); |
| 149 int result = writer->Write(buffer, buffer->size(), base::Bind(&NeverCalled)); | 149 int result = writer->Write(buffer, buffer->size(), base::Bind(&NeverCalled)); |
| 150 ASSERT_EQ(net::ERR_IO_PENDING, result); | 150 ASSERT_EQ(net::ERR_IO_PENDING, result); |
| 151 | 151 |
| 152 net::TestCompletionCallback callback; | 152 net::TestCompletionCallback callback; |
| 153 writer->Cancel(callback.callback()); | 153 writer->Cancel(callback.callback()); |
| 154 int cancel_result = callback.WaitForResult(); | 154 int cancel_result = callback.WaitForResult(); |
| 155 EXPECT_EQ(net::OK, cancel_result); | 155 EXPECT_EQ(net::OK, cancel_result); |
| 156 } | 156 } |
| OLD | NEW |