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

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

Issue 10916132: AppCache and StoragePartition'ing (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 3 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/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "content/browser/browser_thread_impl.h" 10 #include "content/browser/browser_thread_impl.h"
11 #include "content/browser/appcache/chrome_appcache_service.h" 11 #include "content/browser/appcache/chrome_appcache_service.h"
12 #include "content/public/browser/resource_context.h"
12 #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"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webkit/appcache/appcache_database.h" 16 #include "webkit/appcache/appcache_database.h"
15 #include "webkit/appcache/appcache_storage_impl.h" 17 #include "webkit/appcache/appcache_storage_impl.h"
16 #include "webkit/appcache/appcache_test_helper.h" 18 #include "webkit/appcache/appcache_test_helper.h"
17 #include "webkit/quota/mock_special_storage_policy.h" 19 #include "webkit/quota/mock_special_storage_policy.h"
18 20
19 #include <set> 21 #include <set>
20 22
21 using content::BrowserThread; 23 using content::BrowserThread;
22 using content::BrowserThreadImpl; 24 using content::BrowserThreadImpl;
23 25
24 namespace { 26 namespace {
25 const FilePath::CharType kTestingAppCacheDirname[] = 27 const FilePath::CharType kTestingAppCacheDirname[] =
26 FILE_PATH_LITERAL("Application Cache"); 28 FILE_PATH_LITERAL("Application Cache");
27 29
28 // 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
29 // test. 31 // test.
30 const char kProtectedManifest[] = "http://www.protected.com/cache.manifest"; 32 const char kProtectedManifest[] = "http://www.protected.com/cache.manifest";
31 const char kNormalManifest[] = "http://www.normal.com/cache.manifest"; 33 const char kNormalManifest[] = "http://www.normal.com/cache.manifest";
32 const char kSessionOnlyManifest[] = "http://www.sessiononly.com/cache.manifest"; 34 const char kSessionOnlyManifest[] = "http://www.sessiononly.com/cache.manifest";
33 35
36
awong 2012/09/13 00:45:50 spurious new line.
michaeln 2012/09/13 22:53:08 Done.
37 class MockURLRequestContextGetter : public net::URLRequestContextGetter {
38 public:
39 MockURLRequestContextGetter(
40 net::URLRequestContext* context,
41 base::MessageLoopProxy* message_loop_proxy)
42 : context_(context), message_loop_proxy_(message_loop_proxy) {
43 }
44
45 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE {
46 return context_;
47 }
48
49 virtual scoped_refptr<base::SingleThreadTaskRunner>
50 GetNetworkTaskRunner() const OVERRIDE {
51 return message_loop_proxy_;
52 }
53
54 protected:
55 virtual ~MockURLRequestContextGetter() {}
56
57 private:
58 net::URLRequestContext* context_;
59 scoped_refptr<base::SingleThreadTaskRunner> message_loop_proxy_;
60 };
61
34 } // namespace 62 } // namespace
35 63
36 namespace appcache { 64 namespace appcache {
37 65
38 class ChromeAppCacheServiceTest : public testing::Test { 66 class ChromeAppCacheServiceTest : public testing::Test {
39 public: 67 public:
40 ChromeAppCacheServiceTest() 68 ChromeAppCacheServiceTest()
41 : message_loop_(MessageLoop::TYPE_IO), 69 : message_loop_(MessageLoop::TYPE_IO),
42 kProtectedManifestURL(kProtectedManifest), 70 kProtectedManifestURL(kProtectedManifest),
43 kNormalManifestURL(kNormalManifest), 71 kNormalManifestURL(kNormalManifest),
(...skipping 28 matching lines...) Expand all
72 scoped_refptr<ChromeAppCacheService> 100 scoped_refptr<ChromeAppCacheService>
73 ChromeAppCacheServiceTest::CreateAppCacheService( 101 ChromeAppCacheServiceTest::CreateAppCacheService(
74 const FilePath& appcache_path, 102 const FilePath& appcache_path,
75 bool init_storage) { 103 bool init_storage) {
76 scoped_refptr<ChromeAppCacheService> appcache_service = 104 scoped_refptr<ChromeAppCacheService> appcache_service =
77 new ChromeAppCacheService(NULL); 105 new ChromeAppCacheService(NULL);
78 scoped_refptr<quota::MockSpecialStoragePolicy> mock_policy = 106 scoped_refptr<quota::MockSpecialStoragePolicy> mock_policy =
79 new quota::MockSpecialStoragePolicy; 107 new quota::MockSpecialStoragePolicy;
80 mock_policy->AddProtected(kProtectedManifestURL.GetOrigin()); 108 mock_policy->AddProtected(kProtectedManifestURL.GetOrigin());
81 mock_policy->AddSessionOnly(kSessionOnlyManifestURL.GetOrigin()); 109 mock_policy->AddSessionOnly(kSessionOnlyManifestURL.GetOrigin());
110 scoped_refptr<MockURLRequestContextGetter> mock_request_context_getter =
111 new MockURLRequestContextGetter(
112 browser_context_.GetResourceContext()->GetRequestContext(),
113 message_loop_.message_loop_proxy());
82 BrowserThread::PostTask( 114 BrowserThread::PostTask(
83 BrowserThread::IO, FROM_HERE, 115 BrowserThread::IO, FROM_HERE,
84 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, 116 base::Bind(&ChromeAppCacheService::InitializeOnIOThread,
85 appcache_service.get(), appcache_path, 117 appcache_service.get(), appcache_path,
86 browser_context_.GetResourceContext(), mock_policy)); 118 browser_context_.GetResourceContext(),
119 mock_request_context_getter,
120 mock_policy));
87 // Steps needed to initialize the storage of AppCache data. 121 // Steps needed to initialize the storage of AppCache data.
88 message_loop_.RunAllPending(); 122 message_loop_.RunAllPending();
89 if (init_storage) { 123 if (init_storage) {
90 appcache::AppCacheStorageImpl* storage = 124 appcache::AppCacheStorageImpl* storage =
91 static_cast<appcache::AppCacheStorageImpl*>( 125 static_cast<appcache::AppCacheStorageImpl*>(
92 appcache_service->storage()); 126 appcache_service->storage());
93 storage->database_->db_connection(); 127 storage->database_->db_connection();
94 storage->disk_cache(); 128 storage->disk_cache();
95 message_loop_.RunAllPending(); 129 message_loop_.RunAllPending();
96 } 130 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end()); 217 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end());
184 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) != 218 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) !=
185 origins.end()); 219 origins.end());
186 220
187 // Delete and let cleanup tasks run prior to returning. 221 // Delete and let cleanup tasks run prior to returning.
188 appcache_service = NULL; 222 appcache_service = NULL;
189 message_loop_.RunAllPending(); 223 message_loop_.RunAllPending();
190 } 224 }
191 225
192 } // namespace appcache 226 } // namespace appcache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698