| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 // also returns success for event messages (e.g. InstallEvent, FetchEvent). | 55 // also returns success for event messages (e.g. InstallEvent, FetchEvent). |
| 56 // | 56 // |
| 57 // Alternatively consumers can subclass this helper and override On*() | 57 // Alternatively consumers can subclass this helper and override On*() |
| 58 // methods to add their own logic/verification code. | 58 // methods to add their own logic/verification code. |
| 59 // | 59 // |
| 60 // See embedded_worker_instance_unittest.cc for example usages. | 60 // See embedded_worker_instance_unittest.cc for example usages. |
| 61 // | 61 // |
| 62 class EmbeddedWorkerTestHelper : public IPC::Sender, | 62 class EmbeddedWorkerTestHelper : public IPC::Sender, |
| 63 public IPC::Listener { | 63 public IPC::Listener { |
| 64 public: | 64 public: |
| 65 enum class Event { Activate }; | 65 enum class Event { Install, Activate }; |
| 66 using FetchCallback = | 66 using FetchCallback = |
| 67 base::Callback<void(ServiceWorkerStatusCode, | 67 base::Callback<void(ServiceWorkerStatusCode, |
| 68 base::Time /* dispatch_event_time */)>; | 68 base::Time /* dispatch_event_time */)>; |
| 69 | 69 |
| 70 class MockEmbeddedWorkerInstanceClient | 70 class MockEmbeddedWorkerInstanceClient |
| 71 : public mojom::EmbeddedWorkerInstanceClient { | 71 : public mojom::EmbeddedWorkerInstanceClient { |
| 72 public: | 72 public: |
| 73 explicit MockEmbeddedWorkerInstanceClient( | 73 explicit MockEmbeddedWorkerInstanceClient( |
| 74 base::WeakPtr<EmbeddedWorkerTestHelper> helper); | 74 base::WeakPtr<EmbeddedWorkerTestHelper> helper); |
| 75 ~MockEmbeddedWorkerInstanceClient() override; | 75 ~MockEmbeddedWorkerInstanceClient() override; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 DispatchBackgroundFetchFailEventCallback& callback); | 205 DispatchBackgroundFetchFailEventCallback& callback); |
| 206 virtual void OnBackgroundFetchedEvent( | 206 virtual void OnBackgroundFetchedEvent( |
| 207 const std::string& tag, | 207 const std::string& tag, |
| 208 const std::vector<BackgroundFetchSettledFetch>& fetches, | 208 const std::vector<BackgroundFetchSettledFetch>& fetches, |
| 209 const mojom::ServiceWorkerEventDispatcher:: | 209 const mojom::ServiceWorkerEventDispatcher:: |
| 210 DispatchBackgroundFetchedEventCallback& callback); | 210 DispatchBackgroundFetchedEventCallback& callback); |
| 211 virtual void OnExtendableMessageEvent( | 211 virtual void OnExtendableMessageEvent( |
| 212 mojom::ExtendableMessageEventPtr event, | 212 mojom::ExtendableMessageEventPtr event, |
| 213 const mojom::ServiceWorkerEventDispatcher:: | 213 const mojom::ServiceWorkerEventDispatcher:: |
| 214 DispatchExtendableMessageEventCallback& callback); | 214 DispatchExtendableMessageEventCallback& callback); |
| 215 virtual void OnInstallEvent(int embedded_worker_id, int request_id); | 215 virtual void OnInstallEvent( |
| 216 const mojom::ServiceWorkerEventDispatcher::DispatchInstallEventCallback& |
| 217 callback); |
| 216 virtual void OnFetchEvent( | 218 virtual void OnFetchEvent( |
| 217 int embedded_worker_id, | 219 int embedded_worker_id, |
| 218 int fetch_event_id, | 220 int fetch_event_id, |
| 219 const ServiceWorkerFetchRequest& request, | 221 const ServiceWorkerFetchRequest& request, |
| 220 mojom::FetchEventPreloadHandlePtr preload_handle, | 222 mojom::FetchEventPreloadHandlePtr preload_handle, |
| 221 mojom::ServiceWorkerFetchResponseCallbackPtr response_callback, | 223 mojom::ServiceWorkerFetchResponseCallbackPtr response_callback, |
| 222 const FetchCallback& finish_callback); | 224 const FetchCallback& finish_callback); |
| 223 virtual void OnNotificationClickEvent( | 225 virtual void OnNotificationClickEvent( |
| 224 const std::string& notification_id, | 226 const std::string& notification_id, |
| 225 const PlatformNotificationData& notification_data, | 227 const PlatformNotificationData& notification_data, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 DispatchBackgroundFetchFailEventCallback& callback); | 290 DispatchBackgroundFetchFailEventCallback& callback); |
| 289 void OnBackgroundFetchedEventStub( | 291 void OnBackgroundFetchedEventStub( |
| 290 const std::string& tag, | 292 const std::string& tag, |
| 291 const std::vector<BackgroundFetchSettledFetch>& fetches, | 293 const std::vector<BackgroundFetchSettledFetch>& fetches, |
| 292 const mojom::ServiceWorkerEventDispatcher:: | 294 const mojom::ServiceWorkerEventDispatcher:: |
| 293 DispatchBackgroundFetchedEventCallback& callback); | 295 DispatchBackgroundFetchedEventCallback& callback); |
| 294 void OnExtendableMessageEventStub( | 296 void OnExtendableMessageEventStub( |
| 295 mojom::ExtendableMessageEventPtr event, | 297 mojom::ExtendableMessageEventPtr event, |
| 296 const mojom::ServiceWorkerEventDispatcher:: | 298 const mojom::ServiceWorkerEventDispatcher:: |
| 297 DispatchExtendableMessageEventCallback& callback); | 299 DispatchExtendableMessageEventCallback& callback); |
| 298 void OnInstallEventStub(int request_id); | 300 void OnInstallEventStub( |
| 301 const mojom::ServiceWorkerEventDispatcher::DispatchInstallEventCallback& |
| 302 callback); |
| 299 void OnFetchEventStub( | 303 void OnFetchEventStub( |
| 300 int thread_id, | 304 int thread_id, |
| 301 int fetch_event_id, | 305 int fetch_event_id, |
| 302 const ServiceWorkerFetchRequest& request, | 306 const ServiceWorkerFetchRequest& request, |
| 303 mojom::FetchEventPreloadHandlePtr preload_handle, | 307 mojom::FetchEventPreloadHandlePtr preload_handle, |
| 304 mojom::ServiceWorkerFetchResponseCallbackPtr response_callback, | 308 mojom::ServiceWorkerFetchResponseCallbackPtr response_callback, |
| 305 const FetchCallback& finish_callback); | 309 const FetchCallback& finish_callback); |
| 306 void OnNotificationClickEventStub( | 310 void OnNotificationClickEventStub( |
| 307 const std::string& notification_id, | 311 const std::string& notification_id, |
| 308 const PlatformNotificationData& notification_data, | 312 const PlatformNotificationData& notification_data, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 352 |
| 349 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map_; | 353 std::map<int, int64_t> embedded_worker_id_service_worker_version_id_map_; |
| 350 std::map<int /* thread_id */, int /* embedded_worker_id */> | 354 std::map<int /* thread_id */, int /* embedded_worker_id */> |
| 351 thread_id_embedded_worker_id_map_; | 355 thread_id_embedded_worker_id_map_; |
| 352 | 356 |
| 353 std::map< | 357 std::map< |
| 354 int /* embedded_worker_id */, | 358 int /* embedded_worker_id */, |
| 355 mojom::EmbeddedWorkerInstanceHostAssociatedPtr /* instance_host_ptr */> | 359 mojom::EmbeddedWorkerInstanceHostAssociatedPtr /* instance_host_ptr */> |
| 356 embedded_worker_id_instance_host_ptr_map_; | 360 embedded_worker_id_instance_host_ptr_map_; |
| 357 | 361 |
| 358 // Updated each time MessageToWorker message is received. | |
| 359 int current_embedded_worker_id_; | |
| 360 | |
| 361 std::vector<Event> events_; | 362 std::vector<Event> events_; |
| 362 | 363 |
| 363 base::WeakPtrFactory<EmbeddedWorkerTestHelper> weak_factory_; | 364 base::WeakPtrFactory<EmbeddedWorkerTestHelper> weak_factory_; |
| 364 | 365 |
| 365 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerTestHelper); | 366 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerTestHelper); |
| 366 }; | 367 }; |
| 367 | 368 |
| 368 template <typename MockType, typename... Args> | 369 template <typename MockType, typename... Args> |
| 369 MockType* EmbeddedWorkerTestHelper::CreateAndRegisterMockInstanceClient( | 370 MockType* EmbeddedWorkerTestHelper::CreateAndRegisterMockInstanceClient( |
| 370 Args&&... args) { | 371 Args&&... args) { |
| 371 std::unique_ptr<MockType> mock = | 372 std::unique_ptr<MockType> mock = |
| 372 base::MakeUnique<MockType>(std::forward<Args>(args)...); | 373 base::MakeUnique<MockType>(std::forward<Args>(args)...); |
| 373 MockType* mock_rawptr = mock.get(); | 374 MockType* mock_rawptr = mock.get(); |
| 374 RegisterMockInstanceClient(std::move(mock)); | 375 RegisterMockInstanceClient(std::move(mock)); |
| 375 return mock_rawptr; | 376 return mock_rawptr; |
| 376 } | 377 } |
| 377 | 378 |
| 378 } // namespace content | 379 } // namespace content |
| 379 | 380 |
| 380 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ | 381 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_ |
| OLD | NEW |