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

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

Issue 137923003: Change fileapi namespace to content for files that are moved under content/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: build fix Created 6 years, 11 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 "webkit/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/platform_file.h" 12 #include "base/platform_file.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.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/async_file_test_helper.h" 19 #include "webkit/browser/fileapi/async_file_test_helper.h"
20 #include "webkit/browser/fileapi/external_mount_points.h" 20 #include "webkit/browser/fileapi/external_mount_points.h"
21 #include "webkit/browser/fileapi/file_system_context.h" 21 #include "webkit/browser/fileapi/file_system_context.h"
22 #include "webkit/browser/fileapi/file_system_file_util.h" 22 #include "webkit/browser/fileapi/file_system_file_util.h"
23 23
24 namespace fileapi { 24 using fileapi::AsyncFileTestHelper;
25 using fileapi::FileSystemContext;
26 using fileapi::FileSystemFileStreamReader;
27 using fileapi::FileSystemType;
28 using fileapi::FileSystemURL;
29
30 namespace content {
25 31
26 namespace { 32 namespace {
27 33
28 const char kURLOrigin[] = "http://remote/"; 34 const char kURLOrigin[] = "http://remote/";
29 const char kTestFileName[] = "test.dat"; 35 const char kTestFileName[] = "test.dat";
30 const char kTestData[] = "0123456789"; 36 const char kTestData[] = "0123456789";
31 const int kTestDataSize = arraysize(kTestData) - 1; 37 const int kTestDataSize = arraysize(kTestData) - 1;
32 38
33 void ReadFromReader(FileSystemFileStreamReader* reader, 39 void ReadFromReader(fileapi::FileSystemFileStreamReader* reader,
34 std::string* data, 40 std::string* data,
35 size_t size, 41 size_t size,
36 int* result) { 42 int* result) {
37 ASSERT_TRUE(reader != NULL); 43 ASSERT_TRUE(reader != NULL);
38 ASSERT_TRUE(result != NULL); 44 ASSERT_TRUE(result != NULL);
39 *result = net::OK; 45 *result = net::OK;
40 net::TestCompletionCallback callback; 46 net::TestCompletionCallback callback;
41 size_t total_bytes_read = 0; 47 size_t total_bytes_read = 0;
42 while (total_bytes_read < size) { 48 while (total_bytes_read < size) {
43 scoped_refptr<net::IOBufferWithSize> buf( 49 scoped_refptr<net::IOBufferWithSize> buf(
(...skipping 18 matching lines...) Expand all
62 public: 68 public:
63 FileSystemFileStreamReaderTest() {} 69 FileSystemFileStreamReaderTest() {}
64 70
65 virtual void SetUp() OVERRIDE { 71 virtual void SetUp() OVERRIDE {
66 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 72 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
67 73
68 file_system_context_ = CreateFileSystemContextForTesting( 74 file_system_context_ = CreateFileSystemContextForTesting(
69 NULL, temp_dir_.path()); 75 NULL, temp_dir_.path());
70 76
71 file_system_context_->OpenFileSystem( 77 file_system_context_->OpenFileSystem(
72 GURL(kURLOrigin), kFileSystemTypeTemporary, 78 GURL(kURLOrigin), fileapi::kFileSystemTypeTemporary,
73 OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, 79 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT,
74 base::Bind(&OnOpenFileSystem)); 80 base::Bind(&OnOpenFileSystem));
75 base::RunLoop().RunUntilIdle(); 81 base::RunLoop().RunUntilIdle();
76 82
77 WriteFile(kTestFileName, kTestData, kTestDataSize, 83 WriteFile(kTestFileName, kTestData, kTestDataSize,
78 &test_file_modification_time_); 84 &test_file_modification_time_);
79 } 85 }
80 86
81 virtual void TearDown() OVERRIDE { 87 virtual void TearDown() OVERRIDE {
82 base::RunLoop().RunUntilIdle(); 88 base::RunLoop().RunUntilIdle();
83 } 89 }
84 90
85 protected: 91 protected:
86 FileSystemFileStreamReader* CreateFileReader( 92 fileapi::FileSystemFileStreamReader* CreateFileReader(
87 const std::string& file_name, 93 const std::string& file_name,
88 int64 initial_offset, 94 int64 initial_offset,
89 const base::Time& expected_modification_time) { 95 const base::Time& expected_modification_time) {
90 return new FileSystemFileStreamReader(file_system_context_.get(), 96 return new FileSystemFileStreamReader(file_system_context_.get(),
91 GetFileSystemURL(file_name), 97 GetFileSystemURL(file_name),
92 initial_offset, 98 initial_offset,
93 expected_modification_time); 99 expected_modification_time);
94 } 100 }
95 101
96 base::Time test_file_modification_time() const { 102 base::Time test_file_modification_time() const {
(...skipping 21 matching lines...) Expand all
118 private: 124 private:
119 static void OnOpenFileSystem(const GURL& root_url, 125 static void OnOpenFileSystem(const GURL& root_url,
120 const std::string& name, 126 const std::string& name,
121 base::PlatformFileError result) { 127 base::PlatformFileError result) {
122 ASSERT_EQ(base::PLATFORM_FILE_OK, result); 128 ASSERT_EQ(base::PLATFORM_FILE_OK, result);
123 } 129 }
124 130
125 FileSystemURL GetFileSystemURL(const std::string& file_name) { 131 FileSystemURL GetFileSystemURL(const std::string& file_name) {
126 return file_system_context_->CreateCrackedFileSystemURL( 132 return file_system_context_->CreateCrackedFileSystemURL(
127 GURL(kURLOrigin), 133 GURL(kURLOrigin),
128 kFileSystemTypeTemporary, 134 fileapi::kFileSystemTypeTemporary,
129 base::FilePath().AppendASCII(file_name)); 135 base::FilePath().AppendASCII(file_name));
130 } 136 }
131 137
132 base::MessageLoopForIO message_loop_; 138 base::MessageLoopForIO message_loop_;
133 base::ScopedTempDir temp_dir_; 139 base::ScopedTempDir temp_dir_;
134 scoped_refptr<FileSystemContext> file_system_context_; 140 scoped_refptr<FileSystemContext> file_system_context_;
135 base::Time test_file_modification_time_; 141 base::Time test_file_modification_time_;
136 }; 142 };
137 143
138 TEST_F(FileSystemFileStreamReaderTest, NonExistent) { 144 TEST_F(FileSystemFileStreamReaderTest, NonExistent) {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 scoped_refptr<net::IOBufferWithSize> buf( 262 scoped_refptr<net::IOBufferWithSize> buf(
257 new net::IOBufferWithSize(kTestDataSize)); 263 new net::IOBufferWithSize(kTestDataSize));
258 int rv = reader->Read(buf.get(), buf->size(), base::Bind(&NeverCalled)); 264 int rv = reader->Read(buf.get(), buf->size(), base::Bind(&NeverCalled));
259 ASSERT_TRUE(rv == net::ERR_IO_PENDING || rv >= 0); 265 ASSERT_TRUE(rv == net::ERR_IO_PENDING || rv >= 0);
260 266
261 // Delete immediately. 267 // Delete immediately.
262 // Should not crash; nor should NeverCalled be callback. 268 // Should not crash; nor should NeverCalled be callback.
263 reader.reset(); 269 reader.reset();
264 } 270 }
265 271
266 } // namespace fileapi 272 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698