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

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

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
« no previous file with comments | « no previous file | content/browser/background_fetch/background_fetch_embedded_worker_test_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_EMBEDDED_WORKER_TEST_H ELPER_H_ 5 #ifndef CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_EMBEDDED_WORKER_TEST_H ELPER_H_
6 #define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_EMBEDDED_WORKER_TEST_H ELPER_H_ 6 #define CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_EMBEDDED_WORKER_TEST_H ELPER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/optional.h" 13 #include "base/optional.h"
13 #include "content/browser/service_worker/embedded_worker_test_helper.h" 14 #include "content/browser/service_worker/embedded_worker_test_helper.h"
14 15
15 namespace content { 16 namespace content {
16 17
17 struct BackgroundFetchSettledFetch; 18 struct BackgroundFetchSettledFetch;
18 19
19 namespace mojom { 20 namespace mojom {
20 enum class BackgroundFetchState; 21 enum class BackgroundFetchState;
21 } 22 }
22 23
23 // Extension of the EmbeddedWorkerTestHelper that enables instrumentation of the 24 // Extension of the EmbeddedWorkerTestHelper that enables instrumentation of the
24 // events related to the Background Fetch API. Storage for these tests will 25 // events related to the Background Fetch API. Storage for these tests will
25 // always be kept in memory, as data persistence is tested elsewhere. 26 // always be kept in memory, as data persistence is tested elsewhere.
26 class BackgroundFetchEmbeddedWorkerTestHelper 27 class BackgroundFetchEmbeddedWorkerTestHelper
27 : public EmbeddedWorkerTestHelper { 28 : public EmbeddedWorkerTestHelper {
28 public: 29 public:
29 BackgroundFetchEmbeddedWorkerTestHelper(); 30 BackgroundFetchEmbeddedWorkerTestHelper();
30 ~BackgroundFetchEmbeddedWorkerTestHelper() override; 31 ~BackgroundFetchEmbeddedWorkerTestHelper() override;
31 32
32 // Toggles whether the named Service Worker event should fail. 33 // Toggles whether the named Service Worker event should fail.
33 void set_fail_abort_event(bool fail) { fail_abort_event_ = fail; } 34 void set_fail_abort_event(bool fail) { fail_abort_event_ = fail; }
34 void set_fail_click_event(bool fail) { fail_click_event_ = fail; } 35 void set_fail_click_event(bool fail) { fail_click_event_ = fail; }
35 void set_fail_fetch_fail_event(bool fail) { fail_fetch_fail_event_ = fail; } 36 void set_fail_fetch_fail_event(bool fail) { fail_fetch_fail_event_ = fail; }
36 void set_fail_fetched_event(bool fail) { fail_fetched_event_ = fail; } 37 void set_fail_fetched_event(bool fail) { fail_fetched_event_ = fail; }
37 38
39 // Sets a base::Callback that should be executed when the named event is ran.
40 void set_abort_event_closure(const base::Closure& closure) {
41 abort_event_closure_ = closure;
42 }
43 void set_click_event_closure(const base::Closure& closure) {
44 click_event_closure_ = closure;
45 }
46 void set_fetch_fail_event_closure(const base::Closure& closure) {
47 fetch_fail_event_closure_ = closure;
48 }
49 void set_fetched_event_closure(const base::Closure& closure) {
50 fetched_event_closure_ = closure;
51 }
52
38 const base::Optional<std::string>& last_tag() const { return last_tag_; } 53 const base::Optional<std::string>& last_tag() const { return last_tag_; }
39 const base::Optional<mojom::BackgroundFetchState>& last_state() const { 54 const base::Optional<mojom::BackgroundFetchState>& last_state() const {
40 return last_state_; 55 return last_state_;
41 } 56 }
42 const base::Optional<std::vector<BackgroundFetchSettledFetch>> last_fetches() 57 const base::Optional<std::vector<BackgroundFetchSettledFetch>> last_fetches()
43 const { 58 const {
44 return last_fetches_; 59 return last_fetches_;
45 } 60 }
46 61
47 protected: 62 protected:
(...skipping 17 matching lines...) Expand all
65 const std::vector<BackgroundFetchSettledFetch>& fetches, 80 const std::vector<BackgroundFetchSettledFetch>& fetches,
66 const mojom::ServiceWorkerEventDispatcher:: 81 const mojom::ServiceWorkerEventDispatcher::
67 DispatchBackgroundFetchedEventCallback& callback) override; 82 DispatchBackgroundFetchedEventCallback& callback) override;
68 83
69 private: 84 private:
70 bool fail_abort_event_ = false; 85 bool fail_abort_event_ = false;
71 bool fail_click_event_ = false; 86 bool fail_click_event_ = false;
72 bool fail_fetch_fail_event_ = false; 87 bool fail_fetch_fail_event_ = false;
73 bool fail_fetched_event_ = false; 88 bool fail_fetched_event_ = false;
74 89
90 base::Closure abort_event_closure_;
91 base::Closure click_event_closure_;
92 base::Closure fetch_fail_event_closure_;
93 base::Closure fetched_event_closure_;
94
75 base::Optional<std::string> last_tag_; 95 base::Optional<std::string> last_tag_;
76 base::Optional<mojom::BackgroundFetchState> last_state_; 96 base::Optional<mojom::BackgroundFetchState> last_state_;
77 base::Optional<std::vector<BackgroundFetchSettledFetch>> last_fetches_; 97 base::Optional<std::vector<BackgroundFetchSettledFetch>> last_fetches_;
78 98
79 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchEmbeddedWorkerTestHelper); 99 DISALLOW_COPY_AND_ASSIGN(BackgroundFetchEmbeddedWorkerTestHelper);
80 }; 100 };
81 101
82 } // namespace content 102 } // namespace content
83 103
84 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_EMBEDDED_WORKER_TES T_HELPER_H_ 104 #endif // CONTENT_BROWSER_BACKGROUND_FETCH_BACKGROUND_FETCH_EMBEDDED_WORKER_TES T_HELPER_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/background_fetch/background_fetch_embedded_worker_test_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698