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

Side by Side Diff: chrome/browser/browsing_data_file_system_helper_unittest.cc

Issue 9419033: Move creation of BrowserContext objects that live in content to content, instead of depending on th… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Fix memory leaks in tests Created 8 years, 10 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/platform_file.h" 10 #include "base/platform_file.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/browsing_data_file_system_helper.h" 13 #include "chrome/browser/browsing_data_file_system_helper.h"
14 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
15 #include "content/test/test_browser_thread.h" 15 #include "content/test/test_browser_thread.h"
16 #include "webkit/fileapi/file_system_context.h" 16 #include "webkit/fileapi/file_system_context.h"
17 #include "webkit/fileapi/file_system_types.h" 17 #include "webkit/fileapi/file_system_types.h"
18 #include "webkit/fileapi/file_system_usage_cache.h" 18 #include "webkit/fileapi/file_system_usage_cache.h"
19 #include "webkit/fileapi/sandbox_mount_point_provider.h" 19 #include "webkit/fileapi/sandbox_mount_point_provider.h"
20 20
21 using content::BrowserContext;
21 using content::BrowserThread; 22 using content::BrowserThread;
22 23
23 namespace { 24 namespace {
24 25
25 // Shorter names for fileapi::* constants. 26 // Shorter names for fileapi::* constants.
26 const fileapi::FileSystemType kTemporary = fileapi::kFileSystemTypeTemporary; 27 const fileapi::FileSystemType kTemporary = fileapi::kFileSystemTypeTemporary;
27 const fileapi::FileSystemType kPersistent = fileapi::kFileSystemTypePersistent; 28 const fileapi::FileSystemType kPersistent = fileapi::kFileSystemTypePersistent;
28 29
29 // We'll use these three distinct origins for testing, both as strings and as 30 // We'll use these three distinct origins for testing, both as strings and as
30 // GURLs in appropriate contexts. 31 // GURLs in appropriate contexts.
(...skipping 16 matching lines...) Expand all
47 // The FileSystem APIs are all asynchronous; this testing class wraps up the 48 // The FileSystem APIs are all asynchronous; this testing class wraps up the
48 // boilerplate code necessary to deal with waiting for responses. In a nutshell, 49 // boilerplate code necessary to deal with waiting for responses. In a nutshell,
49 // any async call whose response we want to test ought to be followed by a call 50 // any async call whose response we want to test ought to be followed by a call
50 // to BlockUntilNotified(), which will (shockingly!) block until Notify() is 51 // to BlockUntilNotified(), which will (shockingly!) block until Notify() is
51 // called. For this to work, you'll need to ensure that each async call is 52 // called. For this to work, you'll need to ensure that each async call is
52 // implemented as a class method that that calls Notify() at an appropriate 53 // implemented as a class method that that calls Notify() at an appropriate
53 // point. 54 // point.
54 class BrowsingDataFileSystemHelperTest : public testing::Test { 55 class BrowsingDataFileSystemHelperTest : public testing::Test {
55 public: 56 public:
56 BrowsingDataFileSystemHelperTest() 57 BrowsingDataFileSystemHelperTest()
57 : helper_(BrowsingDataFileSystemHelper::Create(&profile_)), 58 : ui_thread_(BrowserThread::UI, &message_loop_),
58 canned_helper_(new CannedBrowsingDataFileSystemHelper(&profile_)), 59 db_thread_(BrowserThread::DB, &message_loop_),
59 ui_thread_(BrowserThread::UI, &message_loop_), 60 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_),
60 file_thread_(BrowserThread::FILE, &message_loop_), 61 file_thread_(BrowserThread::FILE, &message_loop_),
62 file_user_blocking_thread_(
63 BrowserThread::FILE_USER_BLOCKING, &message_loop_),
61 io_thread_(BrowserThread::IO, &message_loop_) { 64 io_thread_(BrowserThread::IO, &message_loop_) {
65 profile_.reset(new TestingProfile());
66 helper_ = BrowsingDataFileSystemHelper::Create(profile_.get());
67 canned_helper_ = new CannedBrowsingDataFileSystemHelper(profile_.get());
62 } 68 }
63 virtual ~BrowsingDataFileSystemHelperTest() {} 69 virtual ~BrowsingDataFileSystemHelperTest() {
70 // Avoid memory leaks.
71 profile_.reset();
72 message_loop_.RunAllPending();
73 }
64 74
65 TestingProfile* GetProfile() { 75 TestingProfile* GetProfile() {
66 return &profile_; 76 return profile_.get();
67 } 77 }
68 78
69 // Blocks on the current MessageLoop until Notify() is called. 79 // Blocks on the current MessageLoop until Notify() is called.
70 void BlockUntilNotified() { 80 void BlockUntilNotified() {
71 MessageLoop::current()->Run(); 81 MessageLoop::current()->Run();
72 } 82 }
73 83
74 // Unblocks the current MessageLoop. Should be called in response to some sort 84 // Unblocks the current MessageLoop. Should be called in response to some sort
75 // of async activity in a callback method. 85 // of async activity in a callback method.
76 void Notify() { 86 void Notify() {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 void FetchCannedFileSystems() { 134 void FetchCannedFileSystems() {
125 canned_helper_->StartFetching( 135 canned_helper_->StartFetching(
126 base::Bind(&BrowsingDataFileSystemHelperTest::CallbackStartFetching, 136 base::Bind(&BrowsingDataFileSystemHelperTest::CallbackStartFetching,
127 base::Unretained(this))); 137 base::Unretained(this)));
128 BlockUntilNotified(); 138 BlockUntilNotified();
129 } 139 }
130 140
131 // Sets up kOrigin1 with a temporary file system, kOrigin2 with a persistent 141 // Sets up kOrigin1 with a temporary file system, kOrigin2 with a persistent
132 // file system, and kOrigin3 with both. 142 // file system, and kOrigin3 with both.
133 virtual void PopulateTestFileSystemData() { 143 virtual void PopulateTestFileSystemData() {
134 sandbox_ = profile_.GetFileSystemContext()->sandbox_provider(); 144 sandbox_ = BrowserContext::GetFileSystemContext(profile_.get())->
145 sandbox_provider();
135 146
136 CreateDirectoryForOriginAndType(kOrigin1, kTemporary); 147 CreateDirectoryForOriginAndType(kOrigin1, kTemporary);
137 CreateDirectoryForOriginAndType(kOrigin2, kPersistent); 148 CreateDirectoryForOriginAndType(kOrigin2, kPersistent);
138 CreateDirectoryForOriginAndType(kOrigin3, kTemporary); 149 CreateDirectoryForOriginAndType(kOrigin3, kTemporary);
139 CreateDirectoryForOriginAndType(kOrigin3, kPersistent); 150 CreateDirectoryForOriginAndType(kOrigin3, kPersistent);
140 151
141 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin1, kPersistent)); 152 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin1, kPersistent));
142 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin1, kTemporary)); 153 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin1, kTemporary));
143 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin2, kPersistent)); 154 EXPECT_TRUE(FileSystemContainsOriginAndType(kOrigin2, kPersistent));
144 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin2, kTemporary)); 155 EXPECT_FALSE(FileSystemContainsOriginAndType(kOrigin2, kTemporary));
(...skipping 23 matching lines...) Expand all
168 179
169 scoped_refptr<BrowsingDataFileSystemHelper> helper_; 180 scoped_refptr<BrowsingDataFileSystemHelper> helper_;
170 scoped_refptr<CannedBrowsingDataFileSystemHelper> canned_helper_; 181 scoped_refptr<CannedBrowsingDataFileSystemHelper> canned_helper_;
171 182
172 private: 183 private:
173 // message_loop_, as well as all the threads associated with it must be 184 // message_loop_, as well as all the threads associated with it must be
174 // defined before profile_ to prevent explosions. The threads also must be 185 // defined before profile_ to prevent explosions. The threads also must be
175 // defined in the order they're listed here. Oh how I love C++. 186 // defined in the order they're listed here. Oh how I love C++.
176 MessageLoopForUI message_loop_; 187 MessageLoopForUI message_loop_;
177 content::TestBrowserThread ui_thread_; 188 content::TestBrowserThread ui_thread_;
189 content::TestBrowserThread db_thread_;
190 content::TestBrowserThread webkit_thread_;
178 content::TestBrowserThread file_thread_; 191 content::TestBrowserThread file_thread_;
192 content::TestBrowserThread file_user_blocking_thread_;
179 content::TestBrowserThread io_thread_; 193 content::TestBrowserThread io_thread_;
180 TestingProfile profile_; 194 scoped_ptr<TestingProfile> profile_;
181 195
182 // We don't own this pointer: don't delete it. 196 // We don't own this pointer: don't delete it.
183 fileapi::SandboxMountPointProvider* sandbox_; 197 fileapi::SandboxMountPointProvider* sandbox_;
184 198
185 DISALLOW_COPY_AND_ASSIGN(BrowsingDataFileSystemHelperTest); 199 DISALLOW_COPY_AND_ASSIGN(BrowsingDataFileSystemHelperTest);
186 }; 200 };
187 201
188 // Verifies that the BrowsingDataFileSystemHelper correctly finds the test file 202 // Verifies that the BrowsingDataFileSystemHelper correctly finds the test file
189 // system data, and that each file system returned contains the expected data. 203 // system data, and that each file system returned contains the expected data.
190 TEST_F(BrowsingDataFileSystemHelperTest, FetchData) { 204 TEST_F(BrowsingDataFileSystemHelperTest, FetchData) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 292
279 info++; 293 info++;
280 EXPECT_EQ(kOrigin2, info->origin); 294 EXPECT_EQ(kOrigin2, info->origin);
281 EXPECT_FALSE(info->has_persistent); 295 EXPECT_FALSE(info->has_persistent);
282 EXPECT_TRUE(info->has_temporary); 296 EXPECT_TRUE(info->has_temporary);
283 EXPECT_EQ(0, info->usage_persistent); 297 EXPECT_EQ(0, info->usage_persistent);
284 EXPECT_EQ(100, info->usage_temporary); 298 EXPECT_EQ(100, info->usage_temporary);
285 } 299 }
286 300
287 } // namespace 301 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data_file_system_helper.cc ('k') | chrome/browser/browsing_data_indexed_db_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698