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

Side by Side Diff: webkit/fileapi/file_system_file_stream_reader_unittest.cc

Issue 14096022: Make MountPointProvider pluggable from outside webkit/fileapi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: build fix etc Created 7 years, 8 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 (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/file_system_file_stream_reader.h" 5 #include "webkit/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/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/platform_file.h" 13 #include "base/platform_file.h"
14 #include "net/base/io_buffer.h" 14 #include "net/base/io_buffer.h"
15 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.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 #include "webkit/fileapi/external_mount_points.h" 18 #include "webkit/fileapi/external_mount_points.h"
19 #include "webkit/fileapi/file_system_context.h" 19 #include "webkit/fileapi/file_system_context.h"
20 #include "webkit/fileapi/file_system_file_util.h" 20 #include "webkit/fileapi/file_system_file_util.h"
21 #include "webkit/fileapi/file_system_operation_context.h" 21 #include "webkit/fileapi/file_system_operation_context.h"
22 #include "webkit/fileapi/file_system_task_runners.h" 22 #include "webkit/fileapi/mock_file_system_context.h"
23 #include "webkit/fileapi/mock_file_system_options.h"
24 #include "webkit/fileapi/sandbox_mount_point_provider.h" 23 #include "webkit/fileapi/sandbox_mount_point_provider.h"
25 #include "webkit/quota/mock_special_storage_policy.h"
26 24
27 namespace fileapi { 25 namespace fileapi {
28 26
29 namespace { 27 namespace {
30 28
31 const char kURLOrigin[] = "http://remote/"; 29 const char kURLOrigin[] = "http://remote/";
32 const char kTestFileName[] = "test.dat"; 30 const char kTestFileName[] = "test.dat";
33 const char kTestData[] = "0123456789"; 31 const char kTestData[] = "0123456789";
34 const int kTestDataSize = arraysize(kTestData) - 1; 32 const int kTestDataSize = arraysize(kTestData) - 1;
35 33
(...skipping 26 matching lines...) Expand all
62 } // namespace 60 } // namespace
63 61
64 class FileSystemFileStreamReaderTest : public testing::Test { 62 class FileSystemFileStreamReaderTest : public testing::Test {
65 public: 63 public:
66 FileSystemFileStreamReaderTest() 64 FileSystemFileStreamReaderTest()
67 : message_loop_(MessageLoop::TYPE_IO) {} 65 : message_loop_(MessageLoop::TYPE_IO) {}
68 66
69 virtual void SetUp() OVERRIDE { 67 virtual void SetUp() OVERRIDE {
70 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 68 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
71 69
72 special_storage_policy_ = new quota::MockSpecialStoragePolicy; 70 file_system_context_ = CreateFileSystemContextForTesting(
73 file_system_context_ = 71 NULL, temp_dir_.path());
74 new FileSystemContext(
75 FileSystemTaskRunners::CreateMockTaskRunners(),
76 ExternalMountPoints::CreateRefCounted().get(),
77 special_storage_policy_,
78 NULL,
79 temp_dir_.path(),
80 CreateDisallowFileAccessOptions());
81 72
82 file_system_context_->sandbox_provider()->ValidateFileSystemRoot( 73 file_system_context_->sandbox_provider()->ValidateFileSystemRoot(
83 GURL(kURLOrigin), kFileSystemTypeTemporary, true, // create 74 GURL(kURLOrigin), kFileSystemTypeTemporary, true, // create
84 base::Bind(&OnValidateFileSystem)); 75 base::Bind(&OnValidateFileSystem));
85 MessageLoop::current()->RunUntilIdle(); 76 MessageLoop::current()->RunUntilIdle();
86 77
87 WriteFile(kTestFileName, kTestData, kTestDataSize, 78 WriteFile(kTestFileName, kTestData, kTestDataSize,
88 &test_file_modification_time_); 79 &test_file_modification_time_);
89 } 80 }
90 81
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 139
149 FileSystemURL GetFileSystemURL(const std::string& file_name) { 140 FileSystemURL GetFileSystemURL(const std::string& file_name) {
150 return file_system_context_->CreateCrackedFileSystemURL( 141 return file_system_context_->CreateCrackedFileSystemURL(
151 GURL(kURLOrigin), 142 GURL(kURLOrigin),
152 kFileSystemTypeTemporary, 143 kFileSystemTypeTemporary,
153 base::FilePath().AppendASCII(file_name)); 144 base::FilePath().AppendASCII(file_name));
154 } 145 }
155 146
156 MessageLoop message_loop_; 147 MessageLoop message_loop_;
157 base::ScopedTempDir temp_dir_; 148 base::ScopedTempDir temp_dir_;
158 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy_;
159 scoped_refptr<FileSystemContext> file_system_context_; 149 scoped_refptr<FileSystemContext> file_system_context_;
160 base::Time test_file_modification_time_; 150 base::Time test_file_modification_time_;
161 }; 151 };
162 152
163 TEST_F(FileSystemFileStreamReaderTest, NonExistent) { 153 TEST_F(FileSystemFileStreamReaderTest, NonExistent) {
164 const char kFileName[] = "nonexistent"; 154 const char kFileName[] = "nonexistent";
165 scoped_ptr<FileSystemFileStreamReader> reader( 155 scoped_ptr<FileSystemFileStreamReader> reader(
166 CreateFileReader(kFileName, 0, base::Time())); 156 CreateFileReader(kFileName, 0, base::Time()));
167 int result = 0; 157 int result = 0;
168 std::string data; 158 std::string data;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 new net::IOBufferWithSize(kTestDataSize)); 272 new net::IOBufferWithSize(kTestDataSize));
283 int rv = reader->Read(buf, buf->size(), base::Bind(&NeverCalled)); 273 int rv = reader->Read(buf, buf->size(), base::Bind(&NeverCalled));
284 ASSERT_TRUE(rv == net::ERR_IO_PENDING || rv >= 0); 274 ASSERT_TRUE(rv == net::ERR_IO_PENDING || rv >= 0);
285 275
286 // Delete immediately. 276 // Delete immediately.
287 // Should not crash; nor should NeverCalled be callback. 277 // Should not crash; nor should NeverCalled be callback.
288 reader.reset(); 278 reader.reset();
289 } 279 }
290 280
291 } // namespace fileapi 281 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_dir_url_request_job_unittest.cc ('k') | webkit/fileapi/file_system_mount_point_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698