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

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

Issue 1223193009: WIP attempt to replace StartWorker/StopWorker IPCs with a new mojo EmbeddedWorker service. Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-event-dispatching-option2
Patch Set: Created 5 years, 5 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 <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/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "content/common/mojo/service_registry_impl.h"
14 #include "ipc/ipc_listener.h" 15 #include "ipc/ipc_listener.h"
15 #include "ipc/ipc_test_sink.h" 16 #include "ipc/ipc_test_sink.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 #include "url/gurl.h" 18 #include "url/gurl.h"
18 19
19 struct EmbeddedWorkerMsg_StartWorker_Params; 20 struct EmbeddedWorkerMsg_StartWorker_Params;
20 class GURL; 21 class GURL;
21 22
22 namespace content { 23 namespace content {
23 24
24 class EmbeddedWorkerRegistry; 25 class EmbeddedWorkerRegistry;
25 class EmbeddedWorkerTestHelper; 26 class EmbeddedWorkerTestHelper;
26 class MessagePortMessageFilter; 27 class MessagePortMessageFilter;
28 class MockRenderProcessHost;
27 class ServiceWorkerContextCore; 29 class ServiceWorkerContextCore;
28 class ServiceWorkerContextWrapper; 30 class ServiceWorkerContextWrapper;
29 struct ServiceWorkerFetchRequest; 31 struct ServiceWorkerFetchRequest;
32 class TestBrowserContext;
30 33
31 // In-Process EmbeddedWorker test helper. 34 // In-Process EmbeddedWorker test helper.
32 // 35 //
33 // Usage: create an instance of this class to test browser-side embedded worker 36 // Usage: create an instance of this class to test browser-side embedded worker
34 // code without creating a child process. This class will create a 37 // code without creating a child process. This class will create a
35 // ServiceWorkerContextWrapper and ServiceWorkerContextCore for you. 38 // ServiceWorkerContextWrapper and ServiceWorkerContextCore for you.
36 // 39 //
37 // By default this class just notifies back WorkerStarted and WorkerStopped 40 // By default this class just notifies back WorkerStarted and WorkerStopped
38 // for StartWorker and StopWorker requests. The default implementation 41 // for StartWorker and StopWorker requests. The default implementation
39 // also returns success for event messages (e.g. InstallEvent, FetchEvent). 42 // also returns success for event messages (e.g. InstallEvent, FetchEvent).
40 // 43 //
41 // Alternatively consumers can subclass this helper and override On*() 44 // Alternatively consumers can subclass this helper and override On*()
42 // methods to add their own logic/verification code. 45 // methods to add their own logic/verification code.
43 // 46 //
44 // See embedded_worker_instance_unittest.cc for example usages. 47 // See embedded_worker_instance_unittest.cc for example usages.
45 // 48 //
46 class EmbeddedWorkerTestHelper : public IPC::Sender, 49 class EmbeddedWorkerTestHelper : public IPC::Sender,
47 public IPC::Listener { 50 public IPC::Listener {
48 public: 51 public:
49 // Initialize this helper for |context|, and enable this as an IPC 52 // Initialize this helper for |context|, and enable this as an IPC
50 // sender for |mock_render_process_id|. If |user_data_directory| is empty, 53 // sender for |mock_render_process_id|. If |user_data_directory| is empty,
51 // the context makes storage stuff in memory. 54 // the context makes storage stuff in memory.
52 EmbeddedWorkerTestHelper(const base::FilePath& user_data_directory, 55 EmbeddedWorkerTestHelper(const base::FilePath& user_data_directory,
53 int mock_render_process_id); 56 int mock_render_process_id);
57 explicit EmbeddedWorkerTestHelper(const base::FilePath& user_data_directory);
54 ~EmbeddedWorkerTestHelper() override; 58 ~EmbeddedWorkerTestHelper() override;
55 59
56 // Call this to simulate add/associate a process to a pattern. 60 // Call this to simulate add/associate a process to a pattern.
57 // This also registers this sender for the process. 61 // This also registers this sender for the process.
58 void SimulateAddProcessToPattern(const GURL& pattern, int process_id); 62 void SimulateAddProcessToPattern(const GURL& pattern, int process_id);
59 63
60 // IPC::Sender implementation. 64 // IPC::Sender implementation.
61 bool Send(IPC::Message* message) override; 65 bool Send(IPC::Message* message) override;
62 66
63 // IPC::Listener implementation. 67 // IPC::Listener implementation.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 void SimulateWorkerReadyForInspection(int embedded_worker_id); 113 void SimulateWorkerReadyForInspection(int embedded_worker_id);
110 void SimulateWorkerScriptCached(int embedded_worker_id); 114 void SimulateWorkerScriptCached(int embedded_worker_id);
111 void SimulateWorkerScriptLoaded(int thread_id, int embedded_worker_id); 115 void SimulateWorkerScriptLoaded(int thread_id, int embedded_worker_id);
112 void SimulateWorkerScriptEvaluated(int embedded_worker_id); 116 void SimulateWorkerScriptEvaluated(int embedded_worker_id);
113 void SimulateWorkerStarted(int embedded_worker_id); 117 void SimulateWorkerStarted(int embedded_worker_id);
114 void SimulateWorkerStopped(int embedded_worker_id); 118 void SimulateWorkerStopped(int embedded_worker_id);
115 void SimulateSend(IPC::Message* message); 119 void SimulateSend(IPC::Message* message);
116 120
117 EmbeddedWorkerRegistry* registry(); 121 EmbeddedWorkerRegistry* registry();
118 122
123 friend class MockEmbeddedWorker;
124
119 private: 125 private:
120 void OnStartWorkerStub(const EmbeddedWorkerMsg_StartWorker_Params& params); 126 void OnStartWorkerStub(const EmbeddedWorkerMsg_StartWorker_Params& params);
121 void OnStopWorkerStub(int embedded_worker_id); 127 void OnStopWorkerStub(int embedded_worker_id);
122 void OnMessageToWorkerStub(int thread_id, 128 void OnMessageToWorkerStub(int thread_id,
123 int embedded_worker_id, 129 int embedded_worker_id,
124 const IPC::Message& message); 130 const IPC::Message& message);
125 void OnActivateEventStub(int request_id); 131 void OnActivateEventStub(int request_id);
126 void OnInstallEventStub(int request_id); 132 void OnInstallEventStub(int request_id);
127 void OnFetchEventStub(int request_id, 133 void OnFetchEventStub(int request_id,
128 const ServiceWorkerFetchRequest& request); 134 const ServiceWorkerFetchRequest& request);
129 void OnPushEventStub(int request_id, const std::string& data); 135 void OnPushEventStub(int request_id, const std::string& data);
130 void OnSyncEventStub(int request_id); 136 void OnSyncEventStub(int request_id);
131 137
132 MessagePortMessageFilter* NewMessagePortMessageFilter(); 138 MessagePortMessageFilter* NewMessagePortMessageFilter();
133 139
134 scoped_refptr<ServiceWorkerContextWrapper> wrapper_; 140 scoped_refptr<ServiceWorkerContextWrapper> wrapper_;
135 141
136 IPC::TestSink sink_; 142 IPC::TestSink sink_;
137 IPC::TestSink inner_sink_; 143 IPC::TestSink inner_sink_;
138 144
139 int next_thread_id_; 145 int next_thread_id_;
140 int mock_render_process_id_; 146 int mock_render_process_id_;
141 147
148 scoped_ptr<TestBrowserContext> browser_context_;
149
150 scoped_ptr<MockRenderProcessHost> render_process_host_;
151
152 ServiceRegistryImpl service_registry_;
153
142 std::map<int, int64> embedded_worker_id_service_worker_version_id_map_; 154 std::map<int, int64> embedded_worker_id_service_worker_version_id_map_;
143 155
144 // Updated each time MessageToWorker message is received. 156 // Updated each time MessageToWorker message is received.
145 int current_embedded_worker_id_; 157 int current_embedded_worker_id_;
146 158
147 std::vector<scoped_refptr<MessagePortMessageFilter>> 159 std::vector<scoped_refptr<MessagePortMessageFilter>>
148 message_port_message_filters_; 160 message_port_message_filters_;
149 161
150 base::WeakPtrFactory<EmbeddedWorkerTestHelper> weak_factory_; 162 base::WeakPtrFactory<EmbeddedWorkerTestHelper> weak_factory_;
151 163
152 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerTestHelper); 164 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerTestHelper);
153 }; 165 };
154 166
155 } // namespace content 167 } // namespace content
156 168
157 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ 169 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698