| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_TEST_UTILS_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_TEST_UTILS_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_TEST_UTILS_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_TEST_UTILS_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/bind.h" | 10 #include "base/bind.h" |
| 9 #include "base/callback.h" | 11 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 11 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 17 |
| 15 namespace content { | 18 namespace content { |
| 16 | 19 |
| 20 class ServiceWorkerContextCore; |
| 21 class ServiceWorkerDispatcherHost; |
| 22 class ServiceWorkerProviderHost; |
| 23 |
| 17 template <typename Arg> | 24 template <typename Arg> |
| 18 void ReceiveResult(BrowserThread::ID run_quit_thread, | 25 void ReceiveResult(BrowserThread::ID run_quit_thread, |
| 19 const base::Closure& quit, | 26 const base::Closure& quit, |
| 20 Arg* out, Arg actual) { | 27 Arg* out, Arg actual) { |
| 21 *out = actual; | 28 *out = actual; |
| 22 if (!quit.is_null()) | 29 if (!quit.is_null()) |
| 23 BrowserThread::PostTask(run_quit_thread, FROM_HERE, quit); | 30 BrowserThread::PostTask(run_quit_thread, FROM_HERE, quit); |
| 24 } | 31 } |
| 25 | 32 |
| 26 template <typename Arg> base::Callback<void(Arg)> | 33 template <typename Arg> base::Callback<void(Arg)> |
| 27 CreateReceiver(BrowserThread::ID run_quit_thread, | 34 CreateReceiver(BrowserThread::ID run_quit_thread, |
| 28 const base::Closure& quit, Arg* out) { | 35 const base::Closure& quit, Arg* out) { |
| 29 return base::Bind(&ReceiveResult<Arg>, run_quit_thread, quit, out); | 36 return base::Bind(&ReceiveResult<Arg>, run_quit_thread, quit, out); |
| 30 } | 37 } |
| 31 | 38 |
| 32 template <typename Arg> | 39 template <typename Arg> |
| 33 base::Callback<void(Arg)> CreateReceiverOnCurrentThread( | 40 base::Callback<void(Arg)> CreateReceiverOnCurrentThread( |
| 34 Arg* out, | 41 Arg* out, |
| 35 const base::Closure& quit = base::Closure()) { | 42 const base::Closure& quit = base::Closure()) { |
| 36 BrowserThread::ID id; | 43 BrowserThread::ID id; |
| 37 bool ret = BrowserThread::GetCurrentThreadIdentifier(&id); | 44 bool ret = BrowserThread::GetCurrentThreadIdentifier(&id); |
| 38 DCHECK(ret); | 45 DCHECK(ret); |
| 39 return base::Bind(&ReceiveResult<Arg>, id, quit, out); | 46 return base::Bind(&ReceiveResult<Arg>, id, quit, out); |
| 40 } | 47 } |
| 41 | 48 |
| 49 std::unique_ptr<ServiceWorkerProviderHost> CreateProviderHostForWindow( |
| 50 int process_id, |
| 51 int provider_id, |
| 52 bool is_parent_frame_secure, |
| 53 base::WeakPtr<ServiceWorkerContextCore> context); |
| 54 |
| 55 std::unique_ptr<ServiceWorkerProviderHost> |
| 56 CreateProviderHostForServiceWorkerContext( |
| 57 int process_id, |
| 58 int provider_id, |
| 59 bool is_parent_frame_secure, |
| 60 base::WeakPtr<ServiceWorkerContextCore> context); |
| 61 |
| 62 std::unique_ptr<ServiceWorkerProviderHost> CreateProviderHostWithDispatcherHost( |
| 63 int process_id, |
| 64 int provider_id, |
| 65 base::WeakPtr<ServiceWorkerContextCore> context, |
| 66 int route_id, |
| 67 ServiceWorkerDispatcherHost* dispatcher_host); |
| 68 |
| 42 } // namespace content | 69 } // namespace content |
| 43 | 70 |
| 44 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_TEST_UTILS_H_ | 71 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_TEST_UTILS_H_ |
| OLD | NEW |