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

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

Issue 7053029: Leak fix in FileSystemOperationUnitTest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years, 7 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 | « tools/valgrind/memcheck/suppressions.txt ('k') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_operation.h" 5 #include "webkit/fileapi/file_system_operation.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 const StorageType type_; 81 const StorageType type_;
82 int64 usage_; 82 int64 usage_;
83 int64 quota_; 83 int64 quota_;
84 int accessed_; 84 int accessed_;
85 }; 85 };
86 86
87 class MockQuotaManagerProxy : public QuotaManagerProxy { 87 class MockQuotaManagerProxy : public QuotaManagerProxy {
88 public: 88 public:
89 explicit MockQuotaManagerProxy(QuotaManager* quota_manager) 89 explicit MockQuotaManagerProxy(QuotaManager* quota_manager)
90 : QuotaManagerProxy(quota_manager, 90 : QuotaManagerProxy(quota_manager,
91 base::MessageLoopProxy::CreateForCurrentThread()) {} 91 base::MessageLoopProxy::CreateForCurrentThread()),
92 registered_client_(NULL) {
93 }
94
95 virtual ~MockQuotaManagerProxy() {
96 EXPECT_FALSE(registered_client_);
97 }
98
99 virtual void RegisterClient(QuotaClient* client) {
100 EXPECT_FALSE(registered_client_);
101 registered_client_ = client;
102 }
103
104 void SimulateQuotaManagerDestroyed() {
105 if (registered_client_) {
106 // We cannot call this in the destructor as the client (indirectly)
107 // holds a refptr of the proxy.
108 registered_client_->OnQuotaManagerDestroyed();
109 registered_client_ = NULL;
110 }
111 }
92 112
93 // We don't mock them. 113 // We don't mock them.
94 virtual void RegisterClient(QuotaClient* client) OVERRIDE {}
95 virtual void NotifyOriginInUse(const GURL& origin) OVERRIDE {} 114 virtual void NotifyOriginInUse(const GURL& origin) OVERRIDE {}
96 virtual void NotifyOriginNoLongerInUse(const GURL& origin) OVERRIDE {} 115 virtual void NotifyOriginNoLongerInUse(const GURL& origin) OVERRIDE {}
97 116
98 virtual void NotifyStorageAccessed(QuotaClient::ID client_id, 117 virtual void NotifyStorageAccessed(QuotaClient::ID client_id,
99 const GURL& origin, 118 const GURL& origin,
100 StorageType type) OVERRIDE { 119 StorageType type) OVERRIDE {
101 mock_manager()->RecordStorageAccessed(origin, type); 120 mock_manager()->RecordStorageAccessed(origin, type);
102 } 121 }
103 122
104 virtual void NotifyStorageModified(QuotaClient::ID client_id, 123 virtual void NotifyStorageModified(QuotaClient::ID client_id,
105 const GURL& origin, 124 const GURL& origin,
106 StorageType type, 125 StorageType type,
107 int64 delta) OVERRIDE { 126 int64 delta) OVERRIDE {
108 mock_manager()->UpdateUsage(origin, type, delta); 127 mock_manager()->UpdateUsage(origin, type, delta);
109 } 128 }
110 129
111 int storage_accessed_count() const { 130 int storage_accessed_count() const {
112 return mock_manager()->accessed_; 131 return mock_manager()->accessed_;
113 } 132 }
114 133
115 void SetQuota(const GURL& origin, StorageType type, int64 quota) { 134 void SetQuota(const GURL& origin, StorageType type, int64 quota) {
116 mock_manager()->SetQuota(origin, type, quota); 135 mock_manager()->SetQuota(origin, type, quota);
117 } 136 }
118 137
119 private: 138 private:
120 MockQuotaManager* mock_manager() const { 139 MockQuotaManager* mock_manager() const {
121 return static_cast<MockQuotaManager*>(quota_manager()); 140 return static_cast<MockQuotaManager*>(quota_manager());
122 } 141 }
142 QuotaClient* registered_client_;
123 }; 143 };
124 144
125 FilePath ASCIIToFilePath(const std::string& str) { 145 FilePath ASCIIToFilePath(const std::string& str) {
126 return FilePath().AppendASCII(str); 146 return FilePath().AppendASCII(str);
127 } 147 }
128 148
129 } // namespace (anonymous) 149 } // namespace (anonymous)
130 150
131 // Test class for FileSystemOperation. Note that this just tests low-level 151 // Test class for FileSystemOperation. Note that this just tests low-level
132 // operations but doesn't test OpenFileSystem. 152 // operations but doesn't test OpenFileSystem.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 base_dir, test_helper_.origin(), test_helper_.storage_type()); 300 base_dir, test_helper_.origin(), test_helper_.storage_type());
281 quota_manager_proxy_ = new MockQuotaManagerProxy(quota_manager_.get()); 301 quota_manager_proxy_ = new MockQuotaManagerProxy(quota_manager_.get());
282 test_helper_.SetUp(base_dir, 302 test_helper_.SetUp(base_dir,
283 false /* incognito */, 303 false /* incognito */,
284 false /* unlimited quota */, 304 false /* unlimited quota */,
285 quota_manager_proxy_.get(), 305 quota_manager_proxy_.get(),
286 LocalFileSystemFileUtil::GetInstance()); 306 LocalFileSystemFileUtil::GetInstance());
287 } 307 }
288 308
289 void FileSystemOperationTest::TearDown() { 309 void FileSystemOperationTest::TearDown() {
310 // Let the client go away before dropping a ref of the quota manager proxy.
311 quota_manager_proxy()->SimulateQuotaManagerDestroyed();
290 quota_manager_ = NULL; 312 quota_manager_ = NULL;
291 quota_manager_proxy_ = NULL; 313 quota_manager_proxy_ = NULL;
292 test_helper_.TearDown(); 314 test_helper_.TearDown();
293 } 315 }
294 316
295 FileSystemOperation* FileSystemOperationTest::operation() { 317 FileSystemOperation* FileSystemOperationTest::operation() {
296 return test_helper_.NewOperation(new MockDispatcher(this)); 318 return test_helper_.NewOperation(new MockDispatcher(this));
297 } 319 }
298 320
299 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) { 321 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) {
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 946
925 operation()->Truncate(URLForPath(file_path), 11); 947 operation()->Truncate(URLForPath(file_path), 11);
926 MessageLoop::current()->RunAllPending(); 948 MessageLoop::current()->RunAllPending();
927 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); 949 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status());
928 950
929 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); 951 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info));
930 EXPECT_EQ(10, info.size); 952 EXPECT_EQ(10, info.size);
931 } 953 }
932 954
933 } // namespace fileapi 955 } // namespace fileapi
OLDNEW
« no previous file with comments | « tools/valgrind/memcheck/suppressions.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698