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

Side by Side Diff: content/browser/background_fetch/background_fetch_embedded_worker_test_helper.cc

Issue 2786973002: Add a full end-to-end test for Background Fetch (Closed)
Patch Set: Created 3 years, 8 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 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"
(...skipping 13 matching lines...) Expand all
24 const mojom::ServiceWorkerEventDispatcher:: 24 const 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 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 callback.Run(SERVICE_WORKER_OK, base::Time::Now());
33 } 33 }
34
35 if (abort_event_closure_)
36 abort_event_closure_.Run();
34 } 37 }
35 38
36 void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchClickEvent( 39 void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchClickEvent(
37 const std::string& tag, 40 const std::string& tag,
38 mojom::BackgroundFetchState state, 41 mojom::BackgroundFetchState state,
39 const mojom::ServiceWorkerEventDispatcher:: 42 const mojom::ServiceWorkerEventDispatcher::
40 DispatchBackgroundFetchClickEventCallback& callback) { 43 DispatchBackgroundFetchClickEventCallback& callback) {
41 last_tag_ = tag; 44 last_tag_ = tag;
42 last_state_ = state; 45 last_state_ = state;
43 46
44 if (fail_click_event_) { 47 if (fail_click_event_) {
45 callback.Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, 48 callback.Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED,
46 base::Time::Now()); 49 base::Time::Now());
47 } else { 50 } else {
48 callback.Run(SERVICE_WORKER_OK, base::Time::Now()); 51 callback.Run(SERVICE_WORKER_OK, base::Time::Now());
49 } 52 }
53
54 if (click_event_closure_)
55 click_event_closure_.Run();
50 } 56 }
51 57
52 void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchFailEvent( 58 void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchFailEvent(
53 const std::string& tag, 59 const std::string& tag,
54 const std::vector<BackgroundFetchSettledFetch>& fetches, 60 const std::vector<BackgroundFetchSettledFetch>& fetches,
55 const mojom::ServiceWorkerEventDispatcher:: 61 const mojom::ServiceWorkerEventDispatcher::
56 DispatchBackgroundFetchFailEventCallback& callback) { 62 DispatchBackgroundFetchFailEventCallback& callback) {
57 last_tag_ = tag; 63 last_tag_ = tag;
58 last_fetches_ = fetches; 64 last_fetches_ = fetches;
59 65
60 if (fail_fetch_fail_event_) { 66 if (fail_fetch_fail_event_) {
61 callback.Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, 67 callback.Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED,
62 base::Time::Now()); 68 base::Time::Now());
63 } else { 69 } else {
64 callback.Run(SERVICE_WORKER_OK, base::Time::Now()); 70 callback.Run(SERVICE_WORKER_OK, base::Time::Now());
65 } 71 }
72
73 if (fetch_fail_event_closure_)
74 fetch_fail_event_closure_.Run();
66 } 75 }
67 76
68 void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchedEvent( 77 void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchedEvent(
69 const std::string& tag, 78 const std::string& tag,
70 const std::vector<BackgroundFetchSettledFetch>& fetches, 79 const std::vector<BackgroundFetchSettledFetch>& fetches,
71 const mojom::ServiceWorkerEventDispatcher:: 80 const mojom::ServiceWorkerEventDispatcher::
72 DispatchBackgroundFetchedEventCallback& callback) { 81 DispatchBackgroundFetchedEventCallback& callback) {
73 last_tag_ = tag; 82 last_tag_ = tag;
74 last_fetches_ = fetches; 83 last_fetches_ = fetches;
75 84
76 if (fail_fetched_event_) { 85 if (fail_fetched_event_) {
77 callback.Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, 86 callback.Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED,
78 base::Time::Now()); 87 base::Time::Now());
79 } else { 88 } else {
80 callback.Run(SERVICE_WORKER_OK, base::Time::Now()); 89 callback.Run(SERVICE_WORKER_OK, base::Time::Now());
81 } 90 }
91
92 if (fetched_event_closure_)
93 fetched_event_closure_.Run();
82 } 94 }
83 95
84 } // namespace content 96 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698