Chromium Code Reviews| 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_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> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 // also returns success for event messages (e.g. InstallEvent, FetchEvent). | 58 // also returns success for event messages (e.g. InstallEvent, FetchEvent). |
| 59 // | 59 // |
| 60 // Alternatively consumers can subclass this helper and override On*() | 60 // Alternatively consumers can subclass this helper and override On*() |
| 61 // methods to add their own logic/verification code. | 61 // methods to add their own logic/verification code. |
| 62 // | 62 // |
| 63 // See embedded_worker_instance_unittest.cc for example usages. | 63 // See embedded_worker_instance_unittest.cc for example usages. |
| 64 // | 64 // |
| 65 class EmbeddedWorkerTestHelper : public IPC::Sender, | 65 class EmbeddedWorkerTestHelper : public IPC::Sender, |
| 66 public IPC::Listener { | 66 public IPC::Listener { |
| 67 public: | 67 public: |
| 68 enum class Event { Activate }; | |
| 68 using FetchCallback = | 69 using FetchCallback = |
| 69 base::Callback<void(ServiceWorkerStatusCode, | 70 base::Callback<void(ServiceWorkerStatusCode, |
| 70 base::Time /* dispatch_event_time */)>; | 71 base::Time /* dispatch_event_time */)>; |
| 72 const std::vector<Event>& dispatched_events() const { return events_; } | |
|
Peter Beverloo
2017/02/14 15:48:13
nit: this should be next to the other getters arou
xiaofengzhang
2017/02/15 01:59:45
Acknowledged.
xiaofengzhang
2017/02/15 06:14:44
Done.
| |
| 71 | 73 |
| 72 class MockEmbeddedWorkerInstanceClient | 74 class MockEmbeddedWorkerInstanceClient |
| 73 : public mojom::EmbeddedWorkerInstanceClient { | 75 : public mojom::EmbeddedWorkerInstanceClient { |
| 74 public: | 76 public: |
| 75 explicit MockEmbeddedWorkerInstanceClient( | 77 explicit MockEmbeddedWorkerInstanceClient( |
| 76 base::WeakPtr<EmbeddedWorkerTestHelper> helper); | 78 base::WeakPtr<EmbeddedWorkerTestHelper> helper); |
| 77 ~MockEmbeddedWorkerInstanceClient() override; | 79 ~MockEmbeddedWorkerInstanceClient() override; |
| 78 | 80 |
| 79 static void Bind(const base::WeakPtr<EmbeddedWorkerTestHelper>& helper, | 81 static void Bind(const base::WeakPtr<EmbeddedWorkerTestHelper>& helper, |
| 80 mojom::EmbeddedWorkerInstanceClientRequest request); | 82 mojom::EmbeddedWorkerInstanceClientRequest request); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 // The legacy IPC message handler. This passes the messages to their | 178 // The legacy IPC message handler. This passes the messages to their |
| 177 // respective On*Event handler by default. | 179 // respective On*Event handler by default. |
| 178 virtual bool OnMessageToWorker(int thread_id, | 180 virtual bool OnMessageToWorker(int thread_id, |
| 179 int embedded_worker_id, | 181 int embedded_worker_id, |
| 180 const IPC::Message& message); | 182 const IPC::Message& message); |
| 181 | 183 |
| 182 // On*Event handlers. Called by the default implementation of | 184 // On*Event handlers. Called by the default implementation of |
| 183 // OnMessageToWorker when events are sent to the embedded | 185 // OnMessageToWorker when events are sent to the embedded |
| 184 // worker. By default they just return success via | 186 // worker. By default they just return success via |
| 185 // SimulateSendReplyToBrowser. | 187 // SimulateSendReplyToBrowser. |
| 186 virtual void OnActivateEvent(int embedded_worker_id, int request_id); | 188 virtual void OnActivateEvent( |
| 189 const mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback& | |
| 190 callback); | |
| 187 virtual void OnExtendableMessageEvent( | 191 virtual void OnExtendableMessageEvent( |
| 188 mojom::ExtendableMessageEventPtr event, | 192 mojom::ExtendableMessageEventPtr event, |
| 189 const mojom::ServiceWorkerEventDispatcher:: | 193 const mojom::ServiceWorkerEventDispatcher:: |
| 190 DispatchExtendableMessageEventCallback& callback); | 194 DispatchExtendableMessageEventCallback& callback); |
| 191 virtual void OnInstallEvent(int embedded_worker_id, int request_id); | 195 virtual void OnInstallEvent(int embedded_worker_id, int request_id); |
| 192 virtual void OnFetchEvent(int embedded_worker_id, | 196 virtual void OnFetchEvent(int embedded_worker_id, |
| 193 int fetch_event_id, | 197 int fetch_event_id, |
| 194 const ServiceWorkerFetchRequest& request, | 198 const ServiceWorkerFetchRequest& request, |
| 195 mojom::FetchEventPreloadHandlePtr preload_handle, | 199 mojom::FetchEventPreloadHandlePtr preload_handle, |
| 196 const FetchCallback& callback); | 200 const FetchCallback& callback); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 220 void SimulateWorkerReadyForInspection(int embedded_worker_id); | 224 void SimulateWorkerReadyForInspection(int embedded_worker_id); |
| 221 void SimulateWorkerScriptCached(int embedded_worker_id); | 225 void SimulateWorkerScriptCached(int embedded_worker_id); |
| 222 void SimulateWorkerScriptLoaded(int embedded_worker_id); | 226 void SimulateWorkerScriptLoaded(int embedded_worker_id); |
| 223 void SimulateWorkerThreadStarted(int thread_id, int embedded_worker_id); | 227 void SimulateWorkerThreadStarted(int thread_id, int embedded_worker_id); |
| 224 void SimulateWorkerScriptEvaluated(int embedded_worker_id, bool success); | 228 void SimulateWorkerScriptEvaluated(int embedded_worker_id, bool success); |
| 225 void SimulateWorkerStarted(int embedded_worker_id); | 229 void SimulateWorkerStarted(int embedded_worker_id); |
| 226 void SimulateWorkerStopped(int embedded_worker_id); | 230 void SimulateWorkerStopped(int embedded_worker_id); |
| 227 void SimulateSend(IPC::Message* message); | 231 void SimulateSend(IPC::Message* message); |
| 228 | 232 |
| 229 EmbeddedWorkerRegistry* registry(); | 233 EmbeddedWorkerRegistry* registry(); |
| 234 std::vector<Event> events_; | |
|
Peter Beverloo
2017/02/14 15:48:13
This has to be with the other members, probably af
shimazu
2017/02/15 01:29:02
+1 for moving; this should be private.
xiaofengzhang
2017/02/15 01:59:45
Acknowledged.
xiaofengzhang
2017/02/15 02:15:30
sorry, it should be not private, because it will b
shimazu
2017/02/15 02:30:11
Ah, I see. How about protected for |events_| inste
xiaofengzhang
2017/02/15 02:39:30
yeah, here is already protected, do you think ok?
falken
2017/02/15 03:13:24
Technically by the style guide this must be privat
shimazu
2017/02/15 03:14:54
Oops, sorry. Yes, it's good:)
nit: could you add
xiaofengzhang
2017/02/15 06:14:44
Done.
| |
| 230 | 235 |
| 231 private: | 236 private: |
| 232 class MockServiceWorkerEventDispatcher; | 237 class MockServiceWorkerEventDispatcher; |
| 233 | 238 |
| 234 void OnStartWorkerStub(const EmbeddedWorkerStartParams& params, | 239 void OnStartWorkerStub(const EmbeddedWorkerStartParams& params, |
| 235 mojom::ServiceWorkerEventDispatcherRequest request); | 240 mojom::ServiceWorkerEventDispatcherRequest request); |
| 236 void OnResumeAfterDownloadStub(int embedded_worker_id); | 241 void OnResumeAfterDownloadStub(int embedded_worker_id); |
| 237 void OnStopWorkerStub( | 242 void OnStopWorkerStub( |
| 238 const mojom::EmbeddedWorkerInstanceClient::StopWorkerCallback& callback); | 243 const mojom::EmbeddedWorkerInstanceClient::StopWorkerCallback& callback); |
| 239 void OnMessageToWorkerStub(int thread_id, | 244 void OnMessageToWorkerStub(int thread_id, |
| 240 int embedded_worker_id, | 245 int embedded_worker_id, |
| 241 const IPC::Message& message); | 246 const IPC::Message& message); |
| 242 void OnActivateEventStub(int request_id); | 247 void OnActivateEventStub( |
| 248 const mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback& | |
| 249 callback); | |
| 243 void OnExtendableMessageEventStub( | 250 void OnExtendableMessageEventStub( |
| 244 mojom::ExtendableMessageEventPtr event, | 251 mojom::ExtendableMessageEventPtr event, |
| 245 const mojom::ServiceWorkerEventDispatcher:: | 252 const mojom::ServiceWorkerEventDispatcher:: |
| 246 DispatchExtendableMessageEventCallback& callback); | 253 DispatchExtendableMessageEventCallback& callback); |
| 247 void OnInstallEventStub(int request_id); | 254 void OnInstallEventStub(int request_id); |
| 248 void OnFetchEventStub(int thread_id, | 255 void OnFetchEventStub(int thread_id, |
| 249 int fetch_event_id, | 256 int fetch_event_id, |
| 250 const ServiceWorkerFetchRequest& request, | 257 const ServiceWorkerFetchRequest& request, |
| 251 mojom::FetchEventPreloadHandlePtr preload_handle, | 258 mojom::FetchEventPreloadHandlePtr preload_handle, |
| 252 const FetchCallback& callback); | 259 const FetchCallback& callback); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 std::unique_ptr<MockType> mock = | 326 std::unique_ptr<MockType> mock = |
| 320 base::MakeUnique<MockType>(std::forward<Args>(args)...); | 327 base::MakeUnique<MockType>(std::forward<Args>(args)...); |
| 321 MockType* mock_rawptr = mock.get(); | 328 MockType* mock_rawptr = mock.get(); |
| 322 RegisterMockInstanceClient(std::move(mock)); | 329 RegisterMockInstanceClient(std::move(mock)); |
| 323 return mock_rawptr; | 330 return mock_rawptr; |
| 324 } | 331 } |
| 325 | 332 |
| 326 } // namespace content | 333 } // namespace content |
| 327 | 334 |
| 328 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ | 335 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ |
| OLD | NEW |