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

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

Issue 2487073005: Remove direct usage of BrowserThreadImpl in tests (Closed)
Patch Set: The RDHImpl is actually not even necessary in ResourceSchedulerTest, removed. Created 4 years, 1 month 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
« no previous file with comments | « no previous file | content/browser/browser_thread_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <utility>
6
5 #include "base/bind.h" 7 #include "base/bind.h"
6 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
7 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
8 #include "base/location.h" 10 #include "base/location.h"
9 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
10 #include "base/run_loop.h" 12 #include "base/run_loop.h"
11 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/threading/thread_task_runner_handle.h"
12 #include "content/browser/appcache/appcache_database.h" 15 #include "content/browser/appcache/appcache_database.h"
13 #include "content/browser/appcache/appcache_storage_impl.h" 16 #include "content/browser/appcache/appcache_storage_impl.h"
14 #include "content/browser/appcache/chrome_appcache_service.h" 17 #include "content/browser/appcache/chrome_appcache_service.h"
15 #include "content/browser/browser_thread_impl.h" 18 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/resource_context.h" 19 #include "content/public/browser/resource_context.h"
17 #include "content/public/test/mock_special_storage_policy.h" 20 #include "content/public/test/mock_special_storage_policy.h"
18 #include "content/public/test/test_browser_context.h" 21 #include "content/public/test/test_browser_context.h"
22 #include "content/public/test/test_browser_thread_bundle.h"
19 #include "content/test/appcache_test_helper.h" 23 #include "content/test/appcache_test_helper.h"
20 #include "net/url_request/url_request_context_getter.h" 24 #include "net/url_request/url_request_context_getter.h"
21 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
22 26
23 #include <set> 27 #include <set>
24 28
25 namespace content { 29 namespace content {
26 namespace { 30 namespace {
27 const base::FilePath::CharType kTestingAppCacheDirname[] = 31 const base::FilePath::CharType kTestingAppCacheDirname[] =
28 FILE_PATH_LITERAL("Application Cache"); 32 FILE_PATH_LITERAL("Application Cache");
29 33
30 // Examples of a protected and an unprotected origin, to be used througout the 34 // Examples of a protected and an unprotected origin, to be used througout the
31 // test. 35 // test.
32 const char kProtectedManifest[] = "http://www.protected.com/cache.manifest"; 36 const char kProtectedManifest[] = "http://www.protected.com/cache.manifest";
33 const char kNormalManifest[] = "http://www.normal.com/cache.manifest"; 37 const char kNormalManifest[] = "http://www.normal.com/cache.manifest";
34 const char kSessionOnlyManifest[] = "http://www.sessiononly.com/cache.manifest"; 38 const char kSessionOnlyManifest[] = "http://www.sessiononly.com/cache.manifest";
35 39
36 class MockURLRequestContextGetter : public net::URLRequestContextGetter { 40 class MockURLRequestContextGetter : public net::URLRequestContextGetter {
37 public: 41 public:
38 MockURLRequestContextGetter(net::URLRequestContext* context, 42 MockURLRequestContextGetter(
39 base::SingleThreadTaskRunner* task_runner) 43 net::URLRequestContext* context,
40 : context_(context), task_runner_(task_runner) {} 44 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
45 : context_(context), task_runner_(std::move(task_runner)) {}
41 46
42 net::URLRequestContext* GetURLRequestContext() override { return context_; } 47 net::URLRequestContext* GetURLRequestContext() override { return context_; }
43 48
44 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() 49 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner()
45 const override { 50 const override {
46 return task_runner_; 51 return task_runner_;
47 } 52 }
48 53
49 protected: 54 protected:
50 ~MockURLRequestContextGetter() override {} 55 ~MockURLRequestContextGetter() override {}
51 56
52 private: 57 private:
53 net::URLRequestContext* context_; 58 net::URLRequestContext* context_;
54 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 59 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
55 }; 60 };
56 61
57 } // namespace 62 } // namespace
58 63
59 class ChromeAppCacheServiceTest : public testing::Test { 64 class ChromeAppCacheServiceTest : public testing::Test {
60 public: 65 public:
61 ChromeAppCacheServiceTest() 66 ChromeAppCacheServiceTest()
62 : kProtectedManifestURL(kProtectedManifest), 67 : kProtectedManifestURL(kProtectedManifest),
63 kNormalManifestURL(kNormalManifest), 68 kNormalManifestURL(kNormalManifest),
64 kSessionOnlyManifestURL(kSessionOnlyManifest), 69 kSessionOnlyManifestURL(kSessionOnlyManifest),
65 file_thread_(BrowserThread::FILE, &message_loop_), 70 thread_bundle_(TestBrowserThreadBundle::Options::IO_MAINLOOP) {}
66 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING,
67 &message_loop_),
68 cache_thread_(BrowserThread::CACHE, &message_loop_),
69 io_thread_(BrowserThread::IO, &message_loop_) {}
70 71
71 protected: 72 protected:
72 scoped_refptr<ChromeAppCacheService> CreateAppCacheServiceImpl( 73 scoped_refptr<ChromeAppCacheService> CreateAppCacheServiceImpl(
73 const base::FilePath& appcache_path, 74 const base::FilePath& appcache_path,
74 bool init_storage); 75 bool init_storage);
75 void InsertDataIntoAppCache(ChromeAppCacheService* appcache_service); 76 void InsertDataIntoAppCache(ChromeAppCacheService* appcache_service);
76 77
77 base::MessageLoopForIO message_loop_;
78 base::ScopedTempDir temp_dir_; 78 base::ScopedTempDir temp_dir_;
79 const GURL kProtectedManifestURL; 79 const GURL kProtectedManifestURL;
80 const GURL kNormalManifestURL; 80 const GURL kNormalManifestURL;
81 const GURL kSessionOnlyManifestURL; 81 const GURL kSessionOnlyManifestURL;
82 82
83 private: 83 private:
84 BrowserThreadImpl file_thread_; 84 TestBrowserThreadBundle thread_bundle_;
85 BrowserThreadImpl file_user_blocking_thread_;
86 BrowserThreadImpl cache_thread_;
87 BrowserThreadImpl io_thread_;
88 TestBrowserContext browser_context_; 85 TestBrowserContext browser_context_;
89 }; 86 };
90 87
91 scoped_refptr<ChromeAppCacheService> 88 scoped_refptr<ChromeAppCacheService>
92 ChromeAppCacheServiceTest::CreateAppCacheServiceImpl( 89 ChromeAppCacheServiceTest::CreateAppCacheServiceImpl(
93 const base::FilePath& appcache_path, 90 const base::FilePath& appcache_path,
94 bool init_storage) { 91 bool init_storage) {
95 scoped_refptr<ChromeAppCacheService> appcache_service = 92 scoped_refptr<ChromeAppCacheService> appcache_service =
96 new ChromeAppCacheService(NULL); 93 new ChromeAppCacheService(NULL);
97 scoped_refptr<MockSpecialStoragePolicy> mock_policy = 94 scoped_refptr<MockSpecialStoragePolicy> mock_policy =
98 new MockSpecialStoragePolicy; 95 new MockSpecialStoragePolicy;
99 mock_policy->AddProtected(kProtectedManifestURL.GetOrigin()); 96 mock_policy->AddProtected(kProtectedManifestURL.GetOrigin());
100 mock_policy->AddSessionOnly(kSessionOnlyManifestURL.GetOrigin()); 97 mock_policy->AddSessionOnly(kSessionOnlyManifestURL.GetOrigin());
101 scoped_refptr<MockURLRequestContextGetter> mock_request_context_getter = 98 scoped_refptr<MockURLRequestContextGetter> mock_request_context_getter =
102 new MockURLRequestContextGetter( 99 new MockURLRequestContextGetter(
103 browser_context_.GetResourceContext()->GetRequestContext(), 100 browser_context_.GetResourceContext()->GetRequestContext(),
104 message_loop_.task_runner().get()); 101 base::ThreadTaskRunnerHandle::Get());
105 BrowserThread::PostTask( 102 BrowserThread::PostTask(
106 BrowserThread::IO, FROM_HERE, 103 BrowserThread::IO, FROM_HERE,
107 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, 104 base::Bind(&ChromeAppCacheService::InitializeOnIOThread,
108 appcache_service, appcache_path, 105 appcache_service, appcache_path,
109 browser_context_.GetResourceContext(), 106 browser_context_.GetResourceContext(),
110 base::RetainedRef(mock_request_context_getter), mock_policy)); 107 base::RetainedRef(mock_request_context_getter), mock_policy));
111 // Steps needed to initialize the storage of AppCache data. 108 // Steps needed to initialize the storage of AppCache data.
112 base::RunLoop().RunUntilIdle(); 109 base::RunLoop().RunUntilIdle();
113 if (init_storage) { 110 if (init_storage) {
114 AppCacheStorageImpl* storage = 111 AppCacheStorageImpl* storage =
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end()); 206 EXPECT_TRUE(origins.find(kNormalManifestURL.GetOrigin()) != origins.end());
210 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) != 207 EXPECT_TRUE(origins.find(kSessionOnlyManifestURL.GetOrigin()) !=
211 origins.end()); 208 origins.end());
212 209
213 // Delete and let cleanup tasks run prior to returning. 210 // Delete and let cleanup tasks run prior to returning.
214 appcache_service = NULL; 211 appcache_service = NULL;
215 base::RunLoop().RunUntilIdle(); 212 base::RunLoop().RunUntilIdle();
216 } 213 }
217 214
218 } // namespace content 215 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/browser_thread_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698