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

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

Issue 2313653002: ServiceWorker: Exchange InterfaceProviders when starting worker thread (Closed)
Patch Set: Indent Created 4 years, 3 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_EMBEDDED_WORKER_TEST_HELPER_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/containers/hash_tables.h" 15 #include "base/containers/hash_tables.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "base/optional.h" 18 #include "base/optional.h"
19 #include "content/common/service_worker/embedded_worker.mojom.h" 19 #include "content/common/service_worker/embedded_worker.mojom.h"
20 #include "ipc/ipc_listener.h" 20 #include "ipc/ipc_listener.h"
21 #include "ipc/ipc_test_sink.h" 21 #include "ipc/ipc_test_sink.h"
22 #include "mojo/public/cpp/bindings/binding.h" 22 #include "mojo/public/cpp/bindings/binding.h"
23 #include "services/shell/public/cpp/interface_provider.h"
23 #include "services/shell/public/interfaces/interface_provider.mojom.h" 24 #include "services/shell/public/interfaces/interface_provider.mojom.h"
24 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 #include "url/gurl.h" 27 #include "url/gurl.h"
27 28
28 class GURL; 29 class GURL;
29 struct EmbeddedWorkerMsg_StartWorker_Params; 30 struct EmbeddedWorkerMsg_StartWorker_Params;
30 struct ServiceWorkerMsg_ExtendableMessageEvent_Params; 31 struct ServiceWorkerMsg_ExtendableMessageEvent_Params;
31 32
32 namespace shell { 33 namespace shell {
33 class InterfaceProvider;
34 class InterfaceRegistry; 34 class InterfaceRegistry;
35 } 35 }
36 36
37 namespace content { 37 namespace content {
38 38
39 class EmbeddedWorkerRegistry; 39 class EmbeddedWorkerRegistry;
40 class EmbeddedWorkerTestHelper; 40 class EmbeddedWorkerTestHelper;
41 class MessagePortMessageFilter; 41 class MessagePortMessageFilter;
42 class MockRenderProcessHost; 42 class MockRenderProcessHost;
43 class ServiceWorkerContextCore; 43 class ServiceWorkerContextCore;
(...skipping 25 matching lines...) Expand all
69 public: 69 public:
70 explicit MockEmbeddedWorkerInstanceClient( 70 explicit MockEmbeddedWorkerInstanceClient(
71 base::WeakPtr<EmbeddedWorkerTestHelper> helper); 71 base::WeakPtr<EmbeddedWorkerTestHelper> helper);
72 ~MockEmbeddedWorkerInstanceClient() override; 72 ~MockEmbeddedWorkerInstanceClient() override;
73 73
74 static void Bind(const base::WeakPtr<EmbeddedWorkerTestHelper>& helper, 74 static void Bind(const base::WeakPtr<EmbeddedWorkerTestHelper>& helper,
75 mojom::EmbeddedWorkerInstanceClientRequest request); 75 mojom::EmbeddedWorkerInstanceClientRequest request);
76 76
77 // MOCK_METHOD cannot be used for StartWorker because the mock method cannot 77 // MOCK_METHOD cannot be used for StartWorker because the mock method cannot
78 // take move-only objects directly. 78 // take move-only objects directly.
79 MOCK_METHOD1(MockStartWorker, 79 MOCK_METHOD2(MockStartWorker,
80 void(mojom::EmbeddedWorkerStartWorkerParams* params)); 80 void(mojom::EmbeddedWorkerStartWorkerParams* params,
81 shell::mojom::InterfaceProviderPtr* remote_interfaces));
81 MOCK_METHOD1(MockStopWorker, void(const StopWorkerCallback& callback)); 82 MOCK_METHOD1(MockStopWorker, void(const StopWorkerCallback& callback));
82 83
83 private: 84 private:
84 // Implementation of mojo interface; they just calls a mock function. 85 // Implementation of mojo interface; they just calls a mock function.
85 void StartWorker( 86 void StartWorker(
86 mojom::EmbeddedWorkerStartWorkerParamsPtr params) override { 87 mojom::EmbeddedWorkerStartWorkerParamsPtr params,
87 MockStartWorker(params.get()); 88 shell::mojom::InterfaceProviderPtr remote_interfaces) override {
89 MockStartWorker(params.get(), &remote_interfaces);
88 } 90 }
89 91
90 void StopWorker(const StopWorkerCallback& callback) override { 92 void StopWorker(const StopWorkerCallback& callback) override {
91 MockStopWorker(callback); 93 MockStopWorker(callback);
92 } 94 }
93 95
94 // Default behavior which can be overridden by using mock interfaces. 96 // Default behavior which can be overridden by using mock interfaces.
95 void DefaultStartWorker(mojom::EmbeddedWorkerStartWorkerParams* params); 97 void DefaultStartWorker(
98 mojom::EmbeddedWorkerStartWorkerParams* params,
99 shell::mojom::InterfaceProviderPtr* remote_interfaces);
96 void DefaultStopWorker(const StopWorkerCallback& callback); 100 void DefaultStopWorker(const StopWorkerCallback& callback);
97 101
98 base::WeakPtr<EmbeddedWorkerTestHelper> helper_; 102 base::WeakPtr<EmbeddedWorkerTestHelper> helper_;
99 mojo::Binding<mojom::EmbeddedWorkerInstanceClient> binding_; 103 mojo::Binding<mojom::EmbeddedWorkerInstanceClient> binding_;
100 104
105 shell::InterfaceProvider remote_interfaces_;
106
101 base::Optional<int> embedded_worker_id_; 107 base::Optional<int> embedded_worker_id_;
102 108
103 DISALLOW_COPY_AND_ASSIGN(MockEmbeddedWorkerInstanceClient); 109 DISALLOW_COPY_AND_ASSIGN(MockEmbeddedWorkerInstanceClient);
104 }; 110 };
105 111
106 // If |user_data_directory| is empty, the context makes storage stuff in 112 // If |user_data_directory| is empty, the context makes storage stuff in
107 // memory. 113 // memory.
108 explicit EmbeddedWorkerTestHelper(const base::FilePath& user_data_directory); 114 explicit EmbeddedWorkerTestHelper(const base::FilePath& user_data_directory);
109 ~EmbeddedWorkerTestHelper() override; 115 ~EmbeddedWorkerTestHelper() override;
110 116
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 message_port_message_filters_; 271 message_port_message_filters_;
266 272
267 base::WeakPtrFactory<EmbeddedWorkerTestHelper> weak_factory_; 273 base::WeakPtrFactory<EmbeddedWorkerTestHelper> weak_factory_;
268 274
269 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerTestHelper); 275 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerTestHelper);
270 }; 276 };
271 277
272 } // namespace content 278 } // namespace content
273 279
274 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ 280 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698