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/browser/fileapi/file_system_dir_url_request_job.h" | 5 #include "webkit/browser/fileapi/file_system_dir_url_request_job.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 net::URLRequest::Deprecated::RegisterProtocolFactory("filesystem", NULL); | 71 net::URLRequest::Deprecated::RegisterProtocolFactory("filesystem", NULL); |
72 ClearUnusedJob(); | 72 ClearUnusedJob(); |
73 } | 73 } |
74 | 74 |
75 void OnOpenFileSystem(base::PlatformFileError result, | 75 void OnOpenFileSystem(base::PlatformFileError result, |
76 const std::string& name, | 76 const std::string& name, |
77 const GURL& root_url) { | 77 const GURL& root_url) { |
78 ASSERT_EQ(base::PLATFORM_FILE_OK, result); | 78 ASSERT_EQ(base::PLATFORM_FILE_OK, result); |
79 } | 79 } |
80 | 80 |
81 void TestRequestHelper(const GURL& url, bool run_to_completion) { | 81 void TestRequestHelper(const GURL& url, bool run_to_completion, |
| 82 FileSystemContext* file_system_context) { |
82 delegate_.reset(new net::TestDelegate()); | 83 delegate_.reset(new net::TestDelegate()); |
83 delegate_->set_quit_on_redirect(true); | 84 delegate_->set_quit_on_redirect(true); |
84 request_.reset(empty_context_.CreateRequest(url, delegate_.get())); | 85 request_.reset(empty_context_.CreateRequest(url, delegate_.get())); |
85 job_ = new FileSystemDirURLRequestJob( | 86 job_ = new FileSystemDirURLRequestJob( |
86 request_.get(), NULL, file_system_context_.get()); | 87 request_.get(), NULL, file_system_context); |
87 | 88 |
88 request_->Start(); | 89 request_->Start(); |
89 ASSERT_TRUE(request_->is_pending()); // verify that we're starting async | 90 ASSERT_TRUE(request_->is_pending()); // verify that we're starting async |
90 if (run_to_completion) | 91 if (run_to_completion) |
91 base::MessageLoop::current()->Run(); | 92 base::MessageLoop::current()->Run(); |
92 } | 93 } |
93 | 94 |
94 void TestRequest(const GURL& url) { | 95 void TestRequest(const GURL& url) { |
95 TestRequestHelper(url, true); | 96 TestRequestHelper(url, true, file_system_context_.get()); |
| 97 } |
| 98 |
| 99 void TestRequestWithContext(const GURL& url, |
| 100 FileSystemContext* file_system_context) { |
| 101 TestRequestHelper(url, true, file_system_context); |
96 } | 102 } |
97 | 103 |
98 void TestRequestNoRun(const GURL& url) { | 104 void TestRequestNoRun(const GURL& url) { |
99 TestRequestHelper(url, false); | 105 TestRequestHelper(url, false, file_system_context_.get()); |
100 } | 106 } |
101 | 107 |
102 FileSystemURL CreateURL(const base::FilePath& file_path) { | 108 FileSystemURL CreateURL(const base::FilePath& file_path) { |
103 return file_system_context_->CreateCrackedFileSystemURL( | 109 return file_system_context_->CreateCrackedFileSystemURL( |
104 GURL("http://remote"), | 110 GURL("http://remote"), |
105 fileapi::kFileSystemTypeTemporary, | 111 fileapi::kFileSystemTypeTemporary, |
106 file_path); | 112 file_path); |
107 } | 113 } |
108 | 114 |
109 FileSystemOperationContext* NewOperationContext() { | 115 FileSystemOperationContext* NewOperationContext() { |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 285 |
280 TEST_F(FileSystemDirURLRequestJobTest, Cancel) { | 286 TEST_F(FileSystemDirURLRequestJobTest, Cancel) { |
281 CreateDirectory("foo"); | 287 CreateDirectory("foo"); |
282 TestRequestNoRun(CreateFileSystemURL("foo/")); | 288 TestRequestNoRun(CreateFileSystemURL("foo/")); |
283 // Run StartAsync() and only StartAsync(). | 289 // Run StartAsync() and only StartAsync(). |
284 base::MessageLoop::current()->DeleteSoon(FROM_HERE, request_.release()); | 290 base::MessageLoop::current()->DeleteSoon(FROM_HERE, request_.release()); |
285 base::MessageLoop::current()->RunUntilIdle(); | 291 base::MessageLoop::current()->RunUntilIdle(); |
286 // If we get here, success! we didn't crash! | 292 // If we get here, success! we didn't crash! |
287 } | 293 } |
288 | 294 |
| 295 TEST_F(FileSystemDirURLRequestJobTest, Incognito) { |
| 296 CreateDirectory("foo"); |
| 297 |
| 298 scoped_refptr<FileSystemContext> file_system_context = |
| 299 CreateIncognitoFileSystemContextForTesting(NULL, temp_dir_.path()); |
| 300 |
| 301 TestRequestWithContext(CreateFileSystemURL("/"), |
| 302 file_system_context.get()); |
| 303 ASSERT_FALSE(request_->is_pending()); |
| 304 ASSERT_TRUE(request_->status().is_success()); |
| 305 |
| 306 std::istringstream in(delegate_->data_received()); |
| 307 std::string line; |
| 308 EXPECT_TRUE(std::getline(in, line)); |
| 309 EXPECT_FALSE(std::getline(in, line)); |
| 310 |
| 311 TestRequestWithContext(CreateFileSystemURL("foo"), |
| 312 file_system_context.get()); |
| 313 ASSERT_FALSE(request_->is_pending()); |
| 314 ASSERT_FALSE(request_->status().is_success()); |
| 315 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, request_->status().error()); |
| 316 } |
| 317 |
289 } // namespace (anonymous) | 318 } // namespace (anonymous) |
290 } // namespace fileapi | 319 } // namespace fileapi |
OLD | NEW |