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

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

Issue 10067031: Memory leak fix in FileSystemURLRequestJobTest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // NOTE: These tests are run as part of "unit_tests" (in chrome/test/unit) 5 // NOTE: These tests are run as part of "unit_tests" (in chrome/test/unit)
6 // rather than as part of test_shell_tests because they rely on being able 6 // rather than as part of test_shell_tests because they rely on being able
7 // to instantiate a MessageLoop of type TYPE_IO. test_shell_tests uses 7 // to instantiate a MessageLoop of type TYPE_IO. test_shell_tests uses
8 // TYPE_UI, which URLRequest doesn't allow. 8 // TYPE_UI, which URLRequest doesn't allow.
9 // 9 //
10 10
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 } // namespace 64 } // namespace
65 65
66 class FileSystemURLRequestJobTest : public testing::Test { 66 class FileSystemURLRequestJobTest : public testing::Test {
67 protected: 67 protected:
68 FileSystemURLRequestJobTest() 68 FileSystemURLRequestJobTest()
69 : message_loop_(MessageLoop::TYPE_IO), // simulate an IO thread 69 : message_loop_(MessageLoop::TYPE_IO), // simulate an IO thread
70 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 70 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
71 } 71 }
72 72
73 virtual void SetUp() { 73 virtual void SetUp() OVERRIDE {
74 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 74 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
75 75
76 special_storage_policy_ = new quota::MockSpecialStoragePolicy; 76 special_storage_policy_ = new quota::MockSpecialStoragePolicy;
77 // We use the main thread so that we can get the root path synchronously. 77 // We use the main thread so that we can get the root path synchronously.
78 // TODO(adamk): Run this on the FILE thread we've created as well. 78 // TODO(adamk): Run this on the FILE thread we've created as well.
79 file_system_context_ = 79 file_system_context_ =
80 new FileSystemContext( 80 new FileSystemContext(
81 base::MessageLoopProxy::current(), 81 base::MessageLoopProxy::current(),
82 base::MessageLoopProxy::current(), 82 base::MessageLoopProxy::current(),
83 special_storage_policy_, NULL, 83 special_storage_policy_, NULL,
84 temp_dir_.path(), 84 temp_dir_.path(),
85 CreateDisallowFileAccessOptions()); 85 CreateDisallowFileAccessOptions());
86 86
87 file_system_context_->sandbox_provider()->ValidateFileSystemRoot( 87 file_system_context_->sandbox_provider()->ValidateFileSystemRoot(
88 GURL("http://remote/"), kFileSystemTypeTemporary, true, // create 88 GURL("http://remote/"), kFileSystemTypeTemporary, true, // create
89 base::Bind(&FileSystemURLRequestJobTest::OnValidateFileSystem, 89 base::Bind(&FileSystemURLRequestJobTest::OnValidateFileSystem,
90 weak_factory_.GetWeakPtr())); 90 weak_factory_.GetWeakPtr()));
91 MessageLoop::current()->RunAllPending(); 91 MessageLoop::current()->RunAllPending();
92 92
93 net::URLRequest::Deprecated::RegisterProtocolFactory( 93 net::URLRequest::Deprecated::RegisterProtocolFactory(
94 "filesystem", &FileSystemURLRequestJobFactory); 94 "filesystem", &FileSystemURLRequestJobFactory);
95 } 95 }
96 96
97 virtual void TearDown() { 97 virtual void TearDown() OVERRIDE {
98 net::URLRequest::Deprecated::RegisterProtocolFactory("filesystem", NULL); 98 net::URLRequest::Deprecated::RegisterProtocolFactory("filesystem", NULL);
99 ClearUnusedJob(); 99 ClearUnusedJob();
100 if (pending_job_) {
101 pending_job_->Kill();
102 pending_job_ = NULL;
103 }
104 // FileReader posts a task to close the file in destructor.
105 MessageLoop::current()->RunAllPending();
100 } 106 }
101 107
102 void OnValidateFileSystem(base::PlatformFileError result) { 108 void OnValidateFileSystem(base::PlatformFileError result) {
103 ASSERT_EQ(base::PLATFORM_FILE_OK, result); 109 ASSERT_EQ(base::PLATFORM_FILE_OK, result);
104 } 110 }
105 111
106 void TestRequestHelper(const GURL& url, 112 void TestRequestHelper(const GURL& url,
107 const net::HttpRequestHeaders* headers, 113 const net::HttpRequestHeaders* headers,
108 bool run_to_completion) { 114 bool run_to_completion) {
109 delegate_.reset(new TestDelegate()); 115 delegate_.reset(new TestDelegate());
110 // Make delegate_ exit the MessageLoop when the request is done. 116 // Make delegate_ exit the MessageLoop when the request is done.
111 delegate_->set_quit_on_complete(true); 117 delegate_->set_quit_on_complete(true);
112 delegate_->set_quit_on_redirect(true); 118 delegate_->set_quit_on_redirect(true);
113 request_.reset(new net::URLRequest(url, delegate_.get())); 119 request_.reset(new net::URLRequest(url, delegate_.get()));
114 if (headers) 120 if (headers)
115 request_->SetExtraRequestHeaders(*headers); 121 request_->SetExtraRequestHeaders(*headers);
122 ASSERT_TRUE(!job_);
116 job_ = new FileSystemURLRequestJob( 123 job_ = new FileSystemURLRequestJob(
117 request_.get(), 124 request_.get(),
118 file_system_context_.get(), 125 file_system_context_.get(),
119 base::MessageLoopProxy::current()); 126 base::MessageLoopProxy::current());
127 pending_job_ = job_;
120 128
121 request_->Start(); 129 request_->Start();
122 ASSERT_TRUE(request_->is_pending()); // verify that we're starting async 130 ASSERT_TRUE(request_->is_pending()); // verify that we're starting async
123 if (run_to_completion) 131 if (run_to_completion)
124 MessageLoop::current()->Run(); 132 MessageLoop::current()->Run();
125 } 133 }
126 134
127 void TestRequest(const GURL& url) { 135 void TestRequest(const GURL& url) {
128 TestRequestHelper(url, NULL, true); 136 TestRequestHelper(url, NULL, true);
129 } 137 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 213
206 ScopedTempDir temp_dir_; 214 ScopedTempDir temp_dir_;
207 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy_; 215 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy_;
208 scoped_refptr<FileSystemContext> file_system_context_; 216 scoped_refptr<FileSystemContext> file_system_context_;
209 base::WeakPtrFactory<FileSystemURLRequestJobTest> weak_factory_; 217 base::WeakPtrFactory<FileSystemURLRequestJobTest> weak_factory_;
210 218
211 // NOTE: order matters, request must die before delegate 219 // NOTE: order matters, request must die before delegate
212 scoped_ptr<TestDelegate> delegate_; 220 scoped_ptr<TestDelegate> delegate_;
213 scoped_ptr<net::URLRequest> request_; 221 scoped_ptr<net::URLRequest> request_;
214 222
223 scoped_refptr<net::URLRequestJob> pending_job_;
215 static net::URLRequestJob* job_; 224 static net::URLRequestJob* job_;
216 }; 225 };
217 226
218 // static 227 // static
219 net::URLRequestJob* FileSystemURLRequestJobTest::job_ = NULL; 228 net::URLRequestJob* FileSystemURLRequestJobTest::job_ = NULL;
220 229
221 namespace { 230 namespace {
222 231
223 TEST_F(FileSystemURLRequestJobTest, FileTest) { 232 TEST_F(FileSystemURLRequestJobTest, FileTest) {
224 WriteFile("file1.dat", kTestFileData, arraysize(kTestFileData) - 1); 233 WriteFile("file1.dat", kTestFileData, arraysize(kTestFileData) - 1);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 370
362 TestRequest(CreateFileSystemURL(kFilename)); 371 TestRequest(CreateFileSystemURL(kFilename));
363 372
364 std::string mime_type_from_job; 373 std::string mime_type_from_job;
365 request_->GetMimeType(&mime_type_from_job); 374 request_->GetMimeType(&mime_type_from_job);
366 EXPECT_EQ(mime_type_direct, mime_type_from_job); 375 EXPECT_EQ(mime_type_direct, mime_type_from_job);
367 } 376 }
368 377
369 } // namespace 378 } // namespace
370 } // namespace fileapi 379 } // namespace fileapi
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698