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/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/location.h" |
8 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
9 #include "base/message_loop/message_loop.h" | 10 #include "base/single_thread_task_runner.h" |
10 #include "content/browser/appcache/appcache_database.h" | 11 #include "content/browser/appcache/appcache_database.h" |
11 #include "content/browser/appcache/appcache_storage_impl.h" | 12 #include "content/browser/appcache/appcache_storage_impl.h" |
12 #include "content/browser/appcache/chrome_appcache_service.h" | 13 #include "content/browser/appcache/chrome_appcache_service.h" |
13 #include "content/browser/browser_thread_impl.h" | 14 #include "content/browser/browser_thread_impl.h" |
14 #include "content/public/browser/resource_context.h" | 15 #include "content/public/browser/resource_context.h" |
15 #include "content/public/test/mock_special_storage_policy.h" | 16 #include "content/public/test/mock_special_storage_policy.h" |
16 #include "content/public/test/test_browser_context.h" | 17 #include "content/public/test/test_browser_context.h" |
17 #include "content/test/appcache_test_helper.h" | 18 #include "content/test/appcache_test_helper.h" |
18 #include "net/url_request/url_request_context_getter.h" | 19 #include "net/url_request/url_request_context_getter.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 #include <set> | 22 #include <set> |
22 | 23 |
23 namespace content { | 24 namespace content { |
24 namespace { | 25 namespace { |
25 const base::FilePath::CharType kTestingAppCacheDirname[] = | 26 const base::FilePath::CharType kTestingAppCacheDirname[] = |
26 FILE_PATH_LITERAL("Application Cache"); | 27 FILE_PATH_LITERAL("Application Cache"); |
27 | 28 |
28 // Examples of a protected and an unprotected origin, to be used througout the | 29 // Examples of a protected and an unprotected origin, to be used througout the |
29 // test. | 30 // test. |
30 const char kProtectedManifest[] = "http://www.protected.com/cache.manifest"; | 31 const char kProtectedManifest[] = "http://www.protected.com/cache.manifest"; |
31 const char kNormalManifest[] = "http://www.normal.com/cache.manifest"; | 32 const char kNormalManifest[] = "http://www.normal.com/cache.manifest"; |
32 const char kSessionOnlyManifest[] = "http://www.sessiononly.com/cache.manifest"; | 33 const char kSessionOnlyManifest[] = "http://www.sessiononly.com/cache.manifest"; |
33 | 34 |
34 class MockURLRequestContextGetter : public net::URLRequestContextGetter { | 35 class MockURLRequestContextGetter : public net::URLRequestContextGetter { |
35 public: | 36 public: |
36 MockURLRequestContextGetter( | 37 MockURLRequestContextGetter(net::URLRequestContext* context, |
37 net::URLRequestContext* context, | 38 base::SingleThreadTaskRunner* task_runner) |
38 base::MessageLoopProxy* message_loop_proxy) | 39 : context_(context), task_runner_(task_runner) {} |
39 : context_(context), message_loop_proxy_(message_loop_proxy) { | |
40 } | |
41 | 40 |
42 net::URLRequestContext* GetURLRequestContext() override { return context_; } | 41 net::URLRequestContext* GetURLRequestContext() override { return context_; } |
43 | 42 |
44 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() | 43 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() |
45 const override { | 44 const override { |
46 return message_loop_proxy_; | 45 return task_runner_; |
47 } | 46 } |
48 | 47 |
49 protected: | 48 protected: |
50 ~MockURLRequestContextGetter() override {} | 49 ~MockURLRequestContextGetter() override {} |
51 | 50 |
52 private: | 51 private: |
53 net::URLRequestContext* context_; | 52 net::URLRequestContext* context_; |
54 scoped_refptr<base::SingleThreadTaskRunner> message_loop_proxy_; | 53 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
55 }; | 54 }; |
56 | 55 |
57 } // namespace | 56 } // namespace |
58 | 57 |
59 class ChromeAppCacheServiceTest : public testing::Test { | 58 class ChromeAppCacheServiceTest : public testing::Test { |
60 public: | 59 public: |
61 ChromeAppCacheServiceTest() | 60 ChromeAppCacheServiceTest() |
62 : kProtectedManifestURL(kProtectedManifest), | 61 : kProtectedManifestURL(kProtectedManifest), |
63 kNormalManifestURL(kNormalManifest), | 62 kNormalManifestURL(kNormalManifest), |
64 kSessionOnlyManifestURL(kSessionOnlyManifest), | 63 kSessionOnlyManifestURL(kSessionOnlyManifest), |
(...skipping 29 matching lines...) Expand all Loading... |
94 bool init_storage) { | 93 bool init_storage) { |
95 scoped_refptr<ChromeAppCacheService> appcache_service = | 94 scoped_refptr<ChromeAppCacheService> appcache_service = |
96 new ChromeAppCacheService(NULL); | 95 new ChromeAppCacheService(NULL); |
97 scoped_refptr<MockSpecialStoragePolicy> mock_policy = | 96 scoped_refptr<MockSpecialStoragePolicy> mock_policy = |
98 new MockSpecialStoragePolicy; | 97 new MockSpecialStoragePolicy; |
99 mock_policy->AddProtected(kProtectedManifestURL.GetOrigin()); | 98 mock_policy->AddProtected(kProtectedManifestURL.GetOrigin()); |
100 mock_policy->AddSessionOnly(kSessionOnlyManifestURL.GetOrigin()); | 99 mock_policy->AddSessionOnly(kSessionOnlyManifestURL.GetOrigin()); |
101 scoped_refptr<MockURLRequestContextGetter> mock_request_context_getter = | 100 scoped_refptr<MockURLRequestContextGetter> mock_request_context_getter = |
102 new MockURLRequestContextGetter( | 101 new MockURLRequestContextGetter( |
103 browser_context_.GetResourceContext()->GetRequestContext(), | 102 browser_context_.GetResourceContext()->GetRequestContext(), |
104 message_loop_.message_loop_proxy().get()); | 103 message_loop_.task_runner().get()); |
105 BrowserThread::PostTask( | 104 BrowserThread::PostTask( |
106 BrowserThread::IO, | 105 BrowserThread::IO, |
107 FROM_HERE, | 106 FROM_HERE, |
108 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, | 107 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, |
109 appcache_service.get(), | 108 appcache_service.get(), |
110 appcache_path, | 109 appcache_path, |
111 browser_context_.GetResourceContext(), | 110 browser_context_.GetResourceContext(), |
112 mock_request_context_getter, | 111 mock_request_context_getter, |
113 mock_policy)); | 112 mock_policy)); |
114 // Steps needed to initialize the storage of AppCache data. | 113 // Steps needed to initialize the storage of AppCache data. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end()); | 211 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end()); |
213 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) != | 212 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) != |
214 origins.end()); | 213 origins.end()); |
215 | 214 |
216 // Delete and let cleanup tasks run prior to returning. | 215 // Delete and let cleanup tasks run prior to returning. |
217 appcache_service = NULL; | 216 appcache_service = NULL; |
218 message_loop_.RunUntilIdle(); | 217 message_loop_.RunUntilIdle(); |
219 } | 218 } |
220 | 219 |
221 } // namespace content | 220 } // namespace content |
OLD | NEW |