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

Side by Side Diff: content/browser/service_worker/service_worker_test_utils.h

Issue 2396273002: ServiceWorker: Mojofication of ServiceWorkerDispatcherHost (Closed)
Patch Set: Removed GetWeakPtr and moved a method to private Created 4 years, 2 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
OLDNEW
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 "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h"
10 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/common/content_switches.h"
13 #include "testing/gtest/include/gtest/gtest.h"
11 14
12 namespace content { 15 namespace content {
13 16
17 template <class TestClass>
18 class MojoServiceWorkerTestP : public TestClass,
19 public testing::WithParamInterface<bool> {
20 protected:
21 void SetUp() override {
22 is_mojo_enabled_ = GetParam();
23 if (is_mojo_enabled()) {
24 base::CommandLine::ForCurrentProcess()->AppendSwitch(
25 switches::kMojoServiceWorker);
26 }
27 TestClass::SetUp();
28 }
29
30 bool is_mojo_enabled() const { return is_mojo_enabled_; }
31
32 private:
33 bool is_mojo_enabled_ = false;
34 };
35
14 template <typename Arg> 36 template <typename Arg>
15 void ReceiveResult(BrowserThread::ID run_quit_thread, 37 void ReceiveResult(BrowserThread::ID run_quit_thread,
16 const base::Closure& quit, 38 const base::Closure& quit,
17 Arg* out, Arg actual) { 39 Arg* out, Arg actual) {
18 *out = actual; 40 *out = actual;
19 if (!quit.is_null()) 41 if (!quit.is_null())
20 BrowserThread::PostTask(run_quit_thread, FROM_HERE, quit); 42 BrowserThread::PostTask(run_quit_thread, FROM_HERE, quit);
21 } 43 }
22 44
23 template <typename Arg> base::Callback<void(Arg)> 45 template <typename Arg> base::Callback<void(Arg)>
24 CreateReceiver(BrowserThread::ID run_quit_thread, 46 CreateReceiver(BrowserThread::ID run_quit_thread,
25 const base::Closure& quit, Arg* out) { 47 const base::Closure& quit, Arg* out) {
26 return base::Bind(&ReceiveResult<Arg>, run_quit_thread, quit, out); 48 return base::Bind(&ReceiveResult<Arg>, run_quit_thread, quit, out);
27 } 49 }
28 50
29 template <typename Arg> 51 template <typename Arg>
30 base::Callback<void(Arg)> CreateReceiverOnCurrentThread( 52 base::Callback<void(Arg)> CreateReceiverOnCurrentThread(
31 Arg* out, 53 Arg* out,
32 const base::Closure& quit = base::Closure()) { 54 const base::Closure& quit = base::Closure()) {
33 BrowserThread::ID id; 55 BrowserThread::ID id;
34 bool ret = BrowserThread::GetCurrentThreadIdentifier(&id); 56 bool ret = BrowserThread::GetCurrentThreadIdentifier(&id);
35 DCHECK(ret); 57 DCHECK(ret);
36 return base::Bind(&ReceiveResult<Arg>, id, quit, out); 58 return base::Bind(&ReceiveResult<Arg>, id, quit, out);
37 } 59 }
38 60
39 } // namespace content 61 } // namespace content
40 62
41 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_TEST_UTILS_H_ 63 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_TEST_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698