Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: content/browser/fileapi/file_system_file_stream_reader_unittest.cc

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/file_system_file_stream_reader.h" 5 #include "storage/browser/fileapi/file_system_file_stream_reader.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 9
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "content/public/test/async_file_test_helper.h" 13 #include "content/public/test/async_file_test_helper.h"
14 #include "content/public/test/test_file_system_context.h" 14 #include "content/public/test/test_file_system_context.h"
15 #include "net/base/io_buffer.h" 15 #include "net/base/io_buffer.h"
16 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
17 #include "net/base/test_completion_callback.h" 17 #include "net/base/test_completion_callback.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "webkit/browser/fileapi/external_mount_points.h" 19 #include "storage/browser/fileapi/external_mount_points.h"
20 #include "webkit/browser/fileapi/file_system_context.h" 20 #include "storage/browser/fileapi/file_system_context.h"
21 #include "webkit/browser/fileapi/file_system_file_util.h" 21 #include "storage/browser/fileapi/file_system_file_util.h"
22 22
23 using content::AsyncFileTestHelper; 23 using content::AsyncFileTestHelper;
24 using fileapi::FileSystemContext; 24 using storage::FileSystemContext;
25 using fileapi::FileSystemFileStreamReader; 25 using storage::FileSystemFileStreamReader;
26 using fileapi::FileSystemType; 26 using storage::FileSystemType;
27 using fileapi::FileSystemURL; 27 using storage::FileSystemURL;
28 28
29 namespace content { 29 namespace content {
30 30
31 namespace { 31 namespace {
32 32
33 const char kURLOrigin[] = "http://remote/"; 33 const char kURLOrigin[] = "http://remote/";
34 const char kTestFileName[] = "test.dat"; 34 const char kTestFileName[] = "test.dat";
35 const char kTestData[] = "0123456789"; 35 const char kTestData[] = "0123456789";
36 const int kTestDataSize = arraysize(kTestData) - 1; 36 const int kTestDataSize = arraysize(kTestData) - 1;
37 37
38 void ReadFromReader(fileapi::FileSystemFileStreamReader* reader, 38 void ReadFromReader(storage::FileSystemFileStreamReader* reader,
39 std::string* data, 39 std::string* data,
40 size_t size, 40 size_t size,
41 int* result) { 41 int* result) {
42 ASSERT_TRUE(reader != NULL); 42 ASSERT_TRUE(reader != NULL);
43 ASSERT_TRUE(result != NULL); 43 ASSERT_TRUE(result != NULL);
44 *result = net::OK; 44 *result = net::OK;
45 net::TestCompletionCallback callback; 45 net::TestCompletionCallback callback;
46 size_t total_bytes_read = 0; 46 size_t total_bytes_read = 0;
47 while (total_bytes_read < size) { 47 while (total_bytes_read < size) {
48 scoped_refptr<net::IOBufferWithSize> buf( 48 scoped_refptr<net::IOBufferWithSize> buf(
(...skipping 18 matching lines...) Expand all
67 public: 67 public:
68 FileSystemFileStreamReaderTest() {} 68 FileSystemFileStreamReaderTest() {}
69 69
70 virtual void SetUp() OVERRIDE { 70 virtual void SetUp() OVERRIDE {
71 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 71 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
72 72
73 file_system_context_ = CreateFileSystemContextForTesting( 73 file_system_context_ = CreateFileSystemContextForTesting(
74 NULL, temp_dir_.path()); 74 NULL, temp_dir_.path());
75 75
76 file_system_context_->OpenFileSystem( 76 file_system_context_->OpenFileSystem(
77 GURL(kURLOrigin), fileapi::kFileSystemTypeTemporary, 77 GURL(kURLOrigin),
78 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, 78 storage::kFileSystemTypeTemporary,
79 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT,
79 base::Bind(&OnOpenFileSystem)); 80 base::Bind(&OnOpenFileSystem));
80 base::RunLoop().RunUntilIdle(); 81 base::RunLoop().RunUntilIdle();
81 82
82 WriteFile(kTestFileName, kTestData, kTestDataSize, 83 WriteFile(kTestFileName, kTestData, kTestDataSize,
83 &test_file_modification_time_); 84 &test_file_modification_time_);
84 } 85 }
85 86
86 virtual void TearDown() OVERRIDE { 87 virtual void TearDown() OVERRIDE {
87 base::RunLoop().RunUntilIdle(); 88 base::RunLoop().RunUntilIdle();
88 } 89 }
89 90
90 protected: 91 protected:
91 fileapi::FileSystemFileStreamReader* CreateFileReader( 92 storage::FileSystemFileStreamReader* CreateFileReader(
92 const std::string& file_name, 93 const std::string& file_name,
93 int64 initial_offset, 94 int64 initial_offset,
94 const base::Time& expected_modification_time) { 95 const base::Time& expected_modification_time) {
95 return new FileSystemFileStreamReader(file_system_context_.get(), 96 return new FileSystemFileStreamReader(file_system_context_.get(),
96 GetFileSystemURL(file_name), 97 GetFileSystemURL(file_name),
97 initial_offset, 98 initial_offset,
98 expected_modification_time); 99 expected_modification_time);
99 } 100 }
100 101
101 base::Time test_file_modification_time() const { 102 base::Time test_file_modification_time() const {
(...skipping 21 matching lines...) Expand all
123 private: 124 private:
124 static void OnOpenFileSystem(const GURL& root_url, 125 static void OnOpenFileSystem(const GURL& root_url,
125 const std::string& name, 126 const std::string& name,
126 base::File::Error result) { 127 base::File::Error result) {
127 ASSERT_EQ(base::File::FILE_OK, result); 128 ASSERT_EQ(base::File::FILE_OK, result);
128 } 129 }
129 130
130 FileSystemURL GetFileSystemURL(const std::string& file_name) { 131 FileSystemURL GetFileSystemURL(const std::string& file_name) {
131 return file_system_context_->CreateCrackedFileSystemURL( 132 return file_system_context_->CreateCrackedFileSystemURL(
132 GURL(kURLOrigin), 133 GURL(kURLOrigin),
133 fileapi::kFileSystemTypeTemporary, 134 storage::kFileSystemTypeTemporary,
134 base::FilePath().AppendASCII(file_name)); 135 base::FilePath().AppendASCII(file_name));
135 } 136 }
136 137
137 base::MessageLoopForIO message_loop_; 138 base::MessageLoopForIO message_loop_;
138 base::ScopedTempDir temp_dir_; 139 base::ScopedTempDir temp_dir_;
139 scoped_refptr<FileSystemContext> file_system_context_; 140 scoped_refptr<FileSystemContext> file_system_context_;
140 base::Time test_file_modification_time_; 141 base::Time test_file_modification_time_;
141 }; 142 };
142 143
143 TEST_F(FileSystemFileStreamReaderTest, NonExistent) { 144 TEST_F(FileSystemFileStreamReaderTest, NonExistent) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 new net::IOBufferWithSize(kTestDataSize)); 263 new net::IOBufferWithSize(kTestDataSize));
263 int rv = reader->Read(buf.get(), buf->size(), base::Bind(&NeverCalled)); 264 int rv = reader->Read(buf.get(), buf->size(), base::Bind(&NeverCalled));
264 ASSERT_TRUE(rv == net::ERR_IO_PENDING || rv >= 0); 265 ASSERT_TRUE(rv == net::ERR_IO_PENDING || rv >= 0);
265 266
266 // Delete immediately. 267 // Delete immediately.
267 // Should not crash; nor should NeverCalled be callback. 268 // Should not crash; nor should NeverCalled be callback.
268 reader.reset(); 269 reader.reset();
269 } 270 }
270 271
271 } // namespace content 272 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698