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

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

Issue 1264333002: First step to refactor ServiceWorkerVersion to make event dispatching more modular. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years 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 <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/containers/scoped_ptr_hash_map.h"
13 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "content/common/mojo/service_registry_impl.h"
14 #include "ipc/ipc_listener.h" 16 #include "ipc/ipc_listener.h"
15 #include "ipc/ipc_test_sink.h" 17 #include "ipc/ipc_test_sink.h"
16 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
17 #include "url/gurl.h" 19 #include "url/gurl.h"
18 20
19 struct EmbeddedWorkerMsg_StartWorker_Params; 21 struct EmbeddedWorkerMsg_StartWorker_Params;
20 class GURL; 22 class GURL;
21 23
22 namespace content { 24 namespace content {
23 25
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 // - OnSendMessageToWorker calls the message's respective On*Event handler 91 // - OnSendMessageToWorker calls the message's respective On*Event handler
90 virtual void OnStartWorker(int embedded_worker_id, 92 virtual void OnStartWorker(int embedded_worker_id,
91 int64 service_worker_version_id, 93 int64 service_worker_version_id,
92 const GURL& scope, 94 const GURL& scope,
93 const GURL& script_url); 95 const GURL& script_url);
94 virtual void OnStopWorker(int embedded_worker_id); 96 virtual void OnStopWorker(int embedded_worker_id);
95 virtual bool OnMessageToWorker(int thread_id, 97 virtual bool OnMessageToWorker(int thread_id,
96 int embedded_worker_id, 98 int embedded_worker_id,
97 const IPC::Message& message); 99 const IPC::Message& message);
98 100
101 // Called to setup mojo for a new embedded worker. Override to register
102 // services the worker should expose to the browser.
103 virtual void OnSetupMojo(ServiceRegistry* service_registry);
104
99 // On*Event handlers. Called by the default implementation of 105 // On*Event handlers. Called by the default implementation of
100 // OnMessageToWorker when events are sent to the embedded 106 // OnMessageToWorker when events are sent to the embedded
101 // worker. By default they just return success via 107 // worker. By default they just return success via
102 // SimulateSendReplyToBrowser. 108 // SimulateSendReplyToBrowser.
103 virtual void OnActivateEvent(int embedded_worker_id, int request_id); 109 virtual void OnActivateEvent(int embedded_worker_id, int request_id);
104 virtual void OnInstallEvent(int embedded_worker_id, int request_id); 110 virtual void OnInstallEvent(int embedded_worker_id, int request_id);
105 virtual void OnFetchEvent(int embedded_worker_id, 111 virtual void OnFetchEvent(int embedded_worker_id,
106 int request_id, 112 int request_id,
107 const ServiceWorkerFetchRequest& request); 113 const ServiceWorkerFetchRequest& request);
108 virtual void OnPushEvent(int embedded_worker_id, 114 virtual void OnPushEvent(int embedded_worker_id,
109 int request_id, 115 int request_id,
110 const std::string& data); 116 const std::string& data);
111 117
112 // These functions simulate sending an EmbeddedHostMsg message to the 118 // These functions simulate sending an EmbeddedHostMsg message to the
113 // browser. 119 // browser.
114 void SimulateWorkerReadyForInspection(int embedded_worker_id); 120 void SimulateWorkerReadyForInspection(int embedded_worker_id);
115 void SimulateWorkerScriptCached(int embedded_worker_id); 121 void SimulateWorkerScriptCached(int embedded_worker_id);
116 void SimulateWorkerScriptLoaded(int embedded_worker_id); 122 void SimulateWorkerScriptLoaded(int embedded_worker_id);
117 void SimulateWorkerThreadStarted(int thread_id, int embedded_worker_id); 123 void SimulateWorkerThreadStarted(int thread_id, int embedded_worker_id);
118 void SimulateWorkerScriptEvaluated(int embedded_worker_id); 124 void SimulateWorkerScriptEvaluated(int embedded_worker_id);
119 void SimulateWorkerStarted(int embedded_worker_id); 125 void SimulateWorkerStarted(int embedded_worker_id);
120 void SimulateWorkerStopped(int embedded_worker_id); 126 void SimulateWorkerStopped(int embedded_worker_id);
121 void SimulateSend(IPC::Message* message); 127 void SimulateSend(IPC::Message* message);
122 128
123 EmbeddedWorkerRegistry* registry(); 129 EmbeddedWorkerRegistry* registry();
124 130
125 private: 131 private:
132 class MockEmbeddedWorkerSetup;
133
126 void OnStartWorkerStub(const EmbeddedWorkerMsg_StartWorker_Params& params); 134 void OnStartWorkerStub(const EmbeddedWorkerMsg_StartWorker_Params& params);
127 void OnStopWorkerStub(int embedded_worker_id); 135 void OnStopWorkerStub(int embedded_worker_id);
128 void OnMessageToWorkerStub(int thread_id, 136 void OnMessageToWorkerStub(int thread_id,
129 int embedded_worker_id, 137 int embedded_worker_id,
130 const IPC::Message& message); 138 const IPC::Message& message);
131 void OnActivateEventStub(int request_id); 139 void OnActivateEventStub(int request_id);
132 void OnInstallEventStub(int request_id); 140 void OnInstallEventStub(int request_id);
133 void OnFetchEventStub(int request_id, 141 void OnFetchEventStub(int request_id,
134 const ServiceWorkerFetchRequest& request); 142 const ServiceWorkerFetchRequest& request);
135 void OnPushEventStub(int request_id, const std::string& data); 143 void OnPushEventStub(int request_id, const std::string& data);
144 void OnSetupMojoStub(int thread_id,
145 mojo::InterfaceRequest<mojo::ServiceProvider> services,
146 mojo::ServiceProviderPtr exposed_services);
136 147
137 MessagePortMessageFilter* NewMessagePortMessageFilter(); 148 MessagePortMessageFilter* NewMessagePortMessageFilter();
138 149
139 scoped_ptr<TestBrowserContext> browser_context_; 150 scoped_ptr<TestBrowserContext> browser_context_;
140 scoped_ptr<MockRenderProcessHost> render_process_host_; 151 scoped_ptr<MockRenderProcessHost> render_process_host_;
141 152
142 scoped_refptr<ServiceWorkerContextWrapper> wrapper_; 153 scoped_refptr<ServiceWorkerContextWrapper> wrapper_;
143 154
144 IPC::TestSink sink_; 155 IPC::TestSink sink_;
145 IPC::TestSink inner_sink_; 156 IPC::TestSink inner_sink_;
146 157
147 int next_thread_id_; 158 int next_thread_id_;
148 int mock_render_process_id_; 159 int mock_render_process_id_;
149 160
161 ServiceRegistryImpl render_process_service_registry_;
162
150 std::map<int, int64> embedded_worker_id_service_worker_version_id_map_; 163 std::map<int, int64> embedded_worker_id_service_worker_version_id_map_;
151 164
165 // Stores the ServiceRegistries that are associated with each individual
166 // service worker.
167 base::ScopedPtrHashMap<int, scoped_ptr<ServiceRegistryImpl>>
168 thread_id_service_registry_map_;
169
152 // Updated each time MessageToWorker message is received. 170 // Updated each time MessageToWorker message is received.
153 int current_embedded_worker_id_; 171 int current_embedded_worker_id_;
154 172
155 std::vector<scoped_refptr<MessagePortMessageFilter>> 173 std::vector<scoped_refptr<MessagePortMessageFilter>>
156 message_port_message_filters_; 174 message_port_message_filters_;
157 175
158 base::WeakPtrFactory<EmbeddedWorkerTestHelper> weak_factory_; 176 base::WeakPtrFactory<EmbeddedWorkerTestHelper> weak_factory_;
159 177
160 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerTestHelper); 178 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerTestHelper);
161 }; 179 };
162 180
163 } // namespace content 181 } // namespace content
164 182
165 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ 183 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698