| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #include "content/browser/background_fetch/background_fetch_embedded_worker_test
_helper.h" | 5 #include "content/browser/background_fetch/background_fetch_embedded_worker_test
_helper.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "content/common/background_fetch/background_fetch_types.h" | 9 #include "content/common/background_fetch/background_fetch_types.h" |
| 10 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h" | 10 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h" |
| 11 #include "content/common/service_worker/service_worker_status_code.h" | 11 #include "content/common/service_worker/service_worker_status_code.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 BackgroundFetchEmbeddedWorkerTestHelper:: | 15 BackgroundFetchEmbeddedWorkerTestHelper:: |
| 16 BackgroundFetchEmbeddedWorkerTestHelper() | 16 BackgroundFetchEmbeddedWorkerTestHelper() |
| 17 : EmbeddedWorkerTestHelper(base::FilePath() /* in memory */) {} | 17 : EmbeddedWorkerTestHelper(base::FilePath() /* in memory */) {} |
| 18 | 18 |
| 19 BackgroundFetchEmbeddedWorkerTestHelper:: | 19 BackgroundFetchEmbeddedWorkerTestHelper:: |
| 20 ~BackgroundFetchEmbeddedWorkerTestHelper() = default; | 20 ~BackgroundFetchEmbeddedWorkerTestHelper() = default; |
| 21 | 21 |
| 22 void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchAbortEvent( | 22 void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchAbortEvent( |
| 23 const std::string& tag, | 23 const std::string& tag, |
| 24 const mojom::ServiceWorkerEventDispatcher:: | 24 mojom::ServiceWorkerEventDispatcher:: |
| 25 DispatchBackgroundFetchAbortEventCallback& callback) { | 25 DispatchBackgroundFetchAbortEventCallback callback) { |
| 26 last_tag_ = tag; | 26 last_tag_ = tag; |
| 27 | 27 |
| 28 if (fail_abort_event_) { | 28 if (fail_abort_event_) { |
| 29 callback.Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, | 29 std::move(callback).Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, |
| 30 base::Time::Now()); | 30 base::Time::Now()); |
| 31 } else { | 31 } else { |
| 32 callback.Run(SERVICE_WORKER_OK, base::Time::Now()); | 32 std::move(callback).Run(SERVICE_WORKER_OK, base::Time::Now()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 if (abort_event_closure_) | 35 if (abort_event_closure_) |
| 36 abort_event_closure_.Run(); | 36 abort_event_closure_.Run(); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchClickEvent( | 39 void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchClickEvent( |
| 40 const std::string& tag, | 40 const std::string& tag, |
| 41 mojom::BackgroundFetchState state, | 41 mojom::BackgroundFetchState state, |
| 42 const mojom::ServiceWorkerEventDispatcher:: | 42 mojom::ServiceWorkerEventDispatcher:: |
| 43 DispatchBackgroundFetchClickEventCallback& callback) { | 43 DispatchBackgroundFetchClickEventCallback callback) { |
| 44 last_tag_ = tag; | 44 last_tag_ = tag; |
| 45 last_state_ = state; | 45 last_state_ = state; |
| 46 | 46 |
| 47 if (fail_click_event_) { | 47 if (fail_click_event_) { |
| 48 callback.Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, | 48 std::move(callback).Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, |
| 49 base::Time::Now()); | 49 base::Time::Now()); |
| 50 } else { | 50 } else { |
| 51 callback.Run(SERVICE_WORKER_OK, base::Time::Now()); | 51 std::move(callback).Run(SERVICE_WORKER_OK, base::Time::Now()); |
| 52 } | 52 } |
| 53 | 53 |
| 54 if (click_event_closure_) | 54 if (click_event_closure_) |
| 55 click_event_closure_.Run(); | 55 click_event_closure_.Run(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchFailEvent( | 58 void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchFailEvent( |
| 59 const std::string& tag, | 59 const std::string& tag, |
| 60 const std::vector<BackgroundFetchSettledFetch>& fetches, | 60 const std::vector<BackgroundFetchSettledFetch>& fetches, |
| 61 const mojom::ServiceWorkerEventDispatcher:: | 61 mojom::ServiceWorkerEventDispatcher:: |
| 62 DispatchBackgroundFetchFailEventCallback& callback) { | 62 DispatchBackgroundFetchFailEventCallback callback) { |
| 63 last_tag_ = tag; | 63 last_tag_ = tag; |
| 64 last_fetches_ = fetches; | 64 last_fetches_ = fetches; |
| 65 | 65 |
| 66 if (fail_fetch_fail_event_) { | 66 if (fail_fetch_fail_event_) { |
| 67 callback.Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, | 67 std::move(callback).Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, |
| 68 base::Time::Now()); | 68 base::Time::Now()); |
| 69 } else { | 69 } else { |
| 70 callback.Run(SERVICE_WORKER_OK, base::Time::Now()); | 70 std::move(callback).Run(SERVICE_WORKER_OK, base::Time::Now()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 if (fetch_fail_event_closure_) | 73 if (fetch_fail_event_closure_) |
| 74 fetch_fail_event_closure_.Run(); | 74 fetch_fail_event_closure_.Run(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchedEvent( | 77 void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchedEvent( |
| 78 const std::string& tag, | 78 const std::string& tag, |
| 79 const std::vector<BackgroundFetchSettledFetch>& fetches, | 79 const std::vector<BackgroundFetchSettledFetch>& fetches, |
| 80 const mojom::ServiceWorkerEventDispatcher:: | 80 mojom::ServiceWorkerEventDispatcher::DispatchBackgroundFetchedEventCallback |
| 81 DispatchBackgroundFetchedEventCallback& callback) { | 81 callback) { |
| 82 last_tag_ = tag; | 82 last_tag_ = tag; |
| 83 last_fetches_ = fetches; | 83 last_fetches_ = fetches; |
| 84 | 84 |
| 85 if (fail_fetched_event_) { | 85 if (fail_fetched_event_) { |
| 86 callback.Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, | 86 std::move(callback).Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, |
| 87 base::Time::Now()); | 87 base::Time::Now()); |
| 88 } else { | 88 } else { |
| 89 callback.Run(SERVICE_WORKER_OK, base::Time::Now()); | 89 std::move(callback).Run(SERVICE_WORKER_OK, base::Time::Now()); |
| 90 } | 90 } |
| 91 | 91 |
| 92 if (fetched_event_closure_) | 92 if (fetched_event_closure_) |
| 93 fetched_event_closure_.Run(); | 93 fetched_event_closure_.Run(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace content | 96 } // namespace content |
| OLD | NEW |