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

Side by Side Diff: content/browser/appcache/chrome_appcache_service_unittest.cc

Issue 12213066: Use base namespace for FilePath in content/browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "content/browser/appcache/chrome_appcache_service.h" 10 #include "content/browser/appcache/chrome_appcache_service.h"
11 #include "content/browser/browser_thread_impl.h" 11 #include "content/browser/browser_thread_impl.h"
12 #include "content/public/browser/resource_context.h" 12 #include "content/public/browser/resource_context.h"
13 #include "content/public/test/test_browser_context.h" 13 #include "content/public/test/test_browser_context.h"
14 #include "net/url_request/url_request_context_getter.h" 14 #include "net/url_request/url_request_context_getter.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "webkit/appcache/appcache_database.h" 16 #include "webkit/appcache/appcache_database.h"
17 #include "webkit/appcache/appcache_storage_impl.h" 17 #include "webkit/appcache/appcache_storage_impl.h"
18 #include "webkit/appcache/appcache_test_helper.h" 18 #include "webkit/appcache/appcache_test_helper.h"
19 #include "webkit/quota/mock_special_storage_policy.h" 19 #include "webkit/quota/mock_special_storage_policy.h"
20 20
21 #include <set> 21 #include <set>
22 22
23 using appcache::AppCacheTestHelper; 23 using appcache::AppCacheTestHelper;
24 24
25 namespace content { 25 namespace content {
26 namespace { 26 namespace {
27 const FilePath::CharType kTestingAppCacheDirname[] = 27 const base::FilePath::CharType kTestingAppCacheDirname[] =
28 FILE_PATH_LITERAL("Application Cache"); 28 FILE_PATH_LITERAL("Application Cache");
29 29
30 // Examples of a protected and an unprotected origin, to be used througout the 30 // Examples of a protected and an unprotected origin, to be used througout the
31 // test. 31 // test.
32 const char kProtectedManifest[] = "http://www.protected.com/cache.manifest"; 32 const char kProtectedManifest[] = "http://www.protected.com/cache.manifest";
33 const char kNormalManifest[] = "http://www.normal.com/cache.manifest"; 33 const char kNormalManifest[] = "http://www.normal.com/cache.manifest";
34 const char kSessionOnlyManifest[] = "http://www.sessiononly.com/cache.manifest"; 34 const char kSessionOnlyManifest[] = "http://www.sessiononly.com/cache.manifest";
35 35
36 class MockURLRequestContextGetter : public net::URLRequestContextGetter { 36 class MockURLRequestContextGetter : public net::URLRequestContextGetter {
37 public: 37 public:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 kSessionOnlyManifestURL(kSessionOnlyManifest), 69 kSessionOnlyManifestURL(kSessionOnlyManifest),
70 file_thread_(BrowserThread::FILE, &message_loop_), 70 file_thread_(BrowserThread::FILE, &message_loop_),
71 file_user_blocking_thread_( 71 file_user_blocking_thread_(
72 BrowserThread::FILE_USER_BLOCKING, &message_loop_), 72 BrowserThread::FILE_USER_BLOCKING, &message_loop_),
73 cache_thread_(BrowserThread::CACHE, &message_loop_), 73 cache_thread_(BrowserThread::CACHE, &message_loop_),
74 io_thread_(BrowserThread::IO, &message_loop_) { 74 io_thread_(BrowserThread::IO, &message_loop_) {
75 } 75 }
76 76
77 protected: 77 protected:
78 scoped_refptr<ChromeAppCacheService> CreateAppCacheService( 78 scoped_refptr<ChromeAppCacheService> CreateAppCacheService(
79 const FilePath& appcache_path, 79 const base::FilePath& appcache_path,
80 bool init_storage); 80 bool init_storage);
81 void InsertDataIntoAppCache(ChromeAppCacheService* appcache_service); 81 void InsertDataIntoAppCache(ChromeAppCacheService* appcache_service);
82 82
83 MessageLoop message_loop_; 83 MessageLoop message_loop_;
84 base::ScopedTempDir temp_dir_; 84 base::ScopedTempDir temp_dir_;
85 const GURL kProtectedManifestURL; 85 const GURL kProtectedManifestURL;
86 const GURL kNormalManifestURL; 86 const GURL kNormalManifestURL;
87 const GURL kSessionOnlyManifestURL; 87 const GURL kSessionOnlyManifestURL;
88 88
89 private: 89 private:
90 BrowserThreadImpl file_thread_; 90 BrowserThreadImpl file_thread_;
91 BrowserThreadImpl file_user_blocking_thread_; 91 BrowserThreadImpl file_user_blocking_thread_;
92 BrowserThreadImpl cache_thread_; 92 BrowserThreadImpl cache_thread_;
93 BrowserThreadImpl io_thread_; 93 BrowserThreadImpl io_thread_;
94 TestBrowserContext browser_context_; 94 TestBrowserContext browser_context_;
95 }; 95 };
96 96
97 scoped_refptr<ChromeAppCacheService> 97 scoped_refptr<ChromeAppCacheService>
98 ChromeAppCacheServiceTest::CreateAppCacheService( 98 ChromeAppCacheServiceTest::CreateAppCacheService(
99 const FilePath& appcache_path, 99 const base::FilePath& appcache_path,
100 bool init_storage) { 100 bool init_storage) {
101 scoped_refptr<ChromeAppCacheService> appcache_service = 101 scoped_refptr<ChromeAppCacheService> appcache_service =
102 new ChromeAppCacheService(NULL); 102 new ChromeAppCacheService(NULL);
103 scoped_refptr<quota::MockSpecialStoragePolicy> mock_policy = 103 scoped_refptr<quota::MockSpecialStoragePolicy> mock_policy =
104 new quota::MockSpecialStoragePolicy; 104 new quota::MockSpecialStoragePolicy;
105 mock_policy->AddProtected(kProtectedManifestURL.GetOrigin()); 105 mock_policy->AddProtected(kProtectedManifestURL.GetOrigin());
106 mock_policy->AddSessionOnly(kSessionOnlyManifestURL.GetOrigin()); 106 mock_policy->AddSessionOnly(kSessionOnlyManifestURL.GetOrigin());
107 scoped_refptr<MockURLRequestContextGetter> mock_request_context_getter = 107 scoped_refptr<MockURLRequestContextGetter> mock_request_context_getter =
108 new MockURLRequestContextGetter( 108 new MockURLRequestContextGetter(
109 browser_context_.GetResourceContext()->GetRequestContext(), 109 browser_context_.GetResourceContext()->GetRequestContext(),
(...skipping 30 matching lines...) Expand all
140 appcache_helper.GetOriginsWithCaches(appcache_service, &origins); 140 appcache_helper.GetOriginsWithCaches(appcache_service, &origins);
141 ASSERT_EQ(3UL, origins.size()); 141 ASSERT_EQ(3UL, origins.size());
142 ASSERT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end()); 142 ASSERT_TRUE(origins.find(kProtectedManifestURL.GetOrigin()) != origins.end());
143 ASSERT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end()); 143 ASSERT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end());
144 ASSERT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) != 144 ASSERT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) !=
145 origins.end()); 145 origins.end());
146 } 146 }
147 147
148 TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) { 148 TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) {
149 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 149 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
150 FilePath appcache_path = temp_dir_.path().Append(kTestingAppCacheDirname); 150 base::FilePath appcache_path =
151 temp_dir_.path().Append(kTestingAppCacheDirname);
151 152
152 // Create a ChromeAppCacheService and insert data into it 153 // Create a ChromeAppCacheService and insert data into it
153 scoped_refptr<ChromeAppCacheService> appcache_service = 154 scoped_refptr<ChromeAppCacheService> appcache_service =
154 CreateAppCacheService(appcache_path, true); 155 CreateAppCacheService(appcache_path, true);
155 ASSERT_TRUE(file_util::PathExists(appcache_path)); 156 ASSERT_TRUE(file_util::PathExists(appcache_path));
156 ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index"))); 157 ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index")));
157 InsertDataIntoAppCache(appcache_service); 158 InsertDataIntoAppCache(appcache_service);
158 159
159 // Test: delete the ChromeAppCacheService 160 // Test: delete the ChromeAppCacheService
160 appcache_service = NULL; 161 appcache_service = NULL;
(...skipping 15 matching lines...) Expand all
176 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) == 177 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) ==
177 origins.end()); 178 origins.end());
178 179
179 // Delete and let cleanup tasks run prior to returning. 180 // Delete and let cleanup tasks run prior to returning.
180 appcache_service = NULL; 181 appcache_service = NULL;
181 message_loop_.RunUntilIdle(); 182 message_loop_.RunUntilIdle();
182 } 183 }
183 184
184 TEST_F(ChromeAppCacheServiceTest, SaveSessionState) { 185 TEST_F(ChromeAppCacheServiceTest, SaveSessionState) {
185 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 186 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
186 FilePath appcache_path = temp_dir_.path().Append(kTestingAppCacheDirname); 187 base::FilePath appcache_path =
188 temp_dir_.path().Append(kTestingAppCacheDirname);
187 189
188 // Create a ChromeAppCacheService and insert data into it 190 // Create a ChromeAppCacheService and insert data into it
189 scoped_refptr<ChromeAppCacheService> appcache_service = 191 scoped_refptr<ChromeAppCacheService> appcache_service =
190 CreateAppCacheService(appcache_path, true); 192 CreateAppCacheService(appcache_path, true);
191 ASSERT_TRUE(file_util::PathExists(appcache_path)); 193 ASSERT_TRUE(file_util::PathExists(appcache_path));
192 ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index"))); 194 ASSERT_TRUE(file_util::PathExists(appcache_path.AppendASCII("Index")));
193 InsertDataIntoAppCache(appcache_service); 195 InsertDataIntoAppCache(appcache_service);
194 196
195 // Save session state. This should bypass the destruction-time deletion. 197 // Save session state. This should bypass the destruction-time deletion.
196 appcache_service->set_force_keep_session_state(); 198 appcache_service->set_force_keep_session_state();
(...skipping 17 matching lines...) Expand all
214 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end()); 216 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end());
215 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) != 217 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) !=
216 origins.end()); 218 origins.end());
217 219
218 // Delete and let cleanup tasks run prior to returning. 220 // Delete and let cleanup tasks run prior to returning.
219 appcache_service = NULL; 221 appcache_service = NULL;
220 message_loop_.RunUntilIdle(); 222 message_loop_.RunUntilIdle();
221 } 223 }
222 224
223 } // namespace content 225 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/appcache/chrome_appcache_service.cc ('k') | content/browser/browser_child_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698