OLD | NEW |
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 class MockURLRequestContextGetter : public net::URLRequestContextGetter { |
| 37 public: |
| 38 MockURLRequestContextGetter( |
| 39 net::URLRequestContext* context, |
| 40 base::MessageLoopProxy* message_loop_proxy) |
| 41 : context_(context), message_loop_proxy_(message_loop_proxy) { |
| 42 } |
| 43 |
| 44 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE { |
| 45 return context_; |
| 46 } |
| 47 |
| 48 virtual scoped_refptr<base::SingleThreadTaskRunner> |
| 49 GetNetworkTaskRunner() const OVERRIDE { |
| 50 return message_loop_proxy_; |
| 51 } |
| 52 |
| 53 protected: |
| 54 virtual ~MockURLRequestContextGetter() {} |
| 55 |
| 56 private: |
| 57 net::URLRequestContext* context_; |
| 58 scoped_refptr<base::SingleThreadTaskRunner> message_loop_proxy_; |
| 59 }; |
| 60 |
34 } // namespace | 61 } // namespace |
35 | 62 |
36 namespace appcache { | 63 namespace appcache { |
37 | 64 |
38 class ChromeAppCacheServiceTest : public testing::Test { | 65 class ChromeAppCacheServiceTest : public testing::Test { |
39 public: | 66 public: |
40 ChromeAppCacheServiceTest() | 67 ChromeAppCacheServiceTest() |
41 : message_loop_(MessageLoop::TYPE_IO), | 68 : message_loop_(MessageLoop::TYPE_IO), |
42 kProtectedManifestURL(kProtectedManifest), | 69 kProtectedManifestURL(kProtectedManifest), |
43 kNormalManifestURL(kNormalManifest), | 70 kNormalManifestURL(kNormalManifest), |
(...skipping 28 matching lines...) Expand all Loading... |
72 scoped_refptr<ChromeAppCacheService> | 99 scoped_refptr<ChromeAppCacheService> |
73 ChromeAppCacheServiceTest::CreateAppCacheService( | 100 ChromeAppCacheServiceTest::CreateAppCacheService( |
74 const FilePath& appcache_path, | 101 const FilePath& appcache_path, |
75 bool init_storage) { | 102 bool init_storage) { |
76 scoped_refptr<ChromeAppCacheService> appcache_service = | 103 scoped_refptr<ChromeAppCacheService> appcache_service = |
77 new ChromeAppCacheService(NULL); | 104 new ChromeAppCacheService(NULL); |
78 scoped_refptr<quota::MockSpecialStoragePolicy> mock_policy = | 105 scoped_refptr<quota::MockSpecialStoragePolicy> mock_policy = |
79 new quota::MockSpecialStoragePolicy; | 106 new quota::MockSpecialStoragePolicy; |
80 mock_policy->AddProtected(kProtectedManifestURL.GetOrigin()); | 107 mock_policy->AddProtected(kProtectedManifestURL.GetOrigin()); |
81 mock_policy->AddSessionOnly(kSessionOnlyManifestURL.GetOrigin()); | 108 mock_policy->AddSessionOnly(kSessionOnlyManifestURL.GetOrigin()); |
| 109 scoped_refptr<MockURLRequestContextGetter> mock_request_context_getter = |
| 110 new MockURLRequestContextGetter( |
| 111 browser_context_.GetResourceContext()->GetRequestContext(), |
| 112 message_loop_.message_loop_proxy()); |
82 BrowserThread::PostTask( | 113 BrowserThread::PostTask( |
83 BrowserThread::IO, FROM_HERE, | 114 BrowserThread::IO, FROM_HERE, |
84 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, | 115 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, |
85 appcache_service.get(), appcache_path, | 116 appcache_service.get(), appcache_path, |
86 browser_context_.GetResourceContext(), mock_policy)); | 117 browser_context_.GetResourceContext(), |
| 118 mock_request_context_getter, |
| 119 mock_policy)); |
87 // Steps needed to initialize the storage of AppCache data. | 120 // Steps needed to initialize the storage of AppCache data. |
88 message_loop_.RunAllPending(); | 121 message_loop_.RunAllPending(); |
89 if (init_storage) { | 122 if (init_storage) { |
90 appcache::AppCacheStorageImpl* storage = | 123 appcache::AppCacheStorageImpl* storage = |
91 static_cast<appcache::AppCacheStorageImpl*>( | 124 static_cast<appcache::AppCacheStorageImpl*>( |
92 appcache_service->storage()); | 125 appcache_service->storage()); |
93 storage->database_->db_connection(); | 126 storage->database_->db_connection(); |
94 storage->disk_cache(); | 127 storage->disk_cache(); |
95 message_loop_.RunAllPending(); | 128 message_loop_.RunAllPending(); |
96 } | 129 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end()); | 216 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end()); |
184 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) != | 217 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) != |
185 origins.end()); | 218 origins.end()); |
186 | 219 |
187 // Delete and let cleanup tasks run prior to returning. | 220 // Delete and let cleanup tasks run prior to returning. |
188 appcache_service = NULL; | 221 appcache_service = NULL; |
189 message_loop_.RunAllPending(); | 222 message_loop_.RunAllPending(); |
190 } | 223 } |
191 | 224 |
192 } // namespace appcache | 225 } // namespace appcache |
OLD | NEW |