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

Unified Diff: content/browser/background_fetch/background_fetch_service_unittest.cc

Issue 2824223002: Fire the `backgroundfetchabort` event for aborted fetches (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/background_fetch/background_fetch_context.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/background_fetch/background_fetch_service_unittest.cc
diff --git a/content/browser/background_fetch/background_fetch_service_unittest.cc b/content/browser/background_fetch/background_fetch_service_unittest.cc
index db4111194c8acef674d35be7377549552ca5b80d..07e9e27495dff405ebb8f6019562341330eda4dd 100644
--- a/content/browser/background_fetch/background_fetch_service_unittest.cc
+++ b/content/browser/background_fetch/background_fetch_service_unittest.cc
@@ -477,6 +477,56 @@ TEST_F(BackgroundFetchServiceTest, AbortInvalidTag) {
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::INVALID_TAG);
}
+TEST_F(BackgroundFetchServiceTest, AbortEventDispatch) {
+ // Tests that the `backgroundfetchabort` event will be fired when a Background
+ // Fetch registration has been aborted by either the user or developer.
+
+ BackgroundFetchRegistrationId registration_id;
+ ASSERT_TRUE(CreateRegistrationId(kExampleTag, &registration_id));
+
+ // base::RunLoop that we'll run until the event has been dispatched. If this
+ // test times out, it means that the event could not be dispatched.
+ base::RunLoop event_dispatched_loop;
+ embedded_worker_test_helper()->set_abort_event_closure(
+ event_dispatched_loop.QuitClosure());
+
+ constexpr int kResponseCode = 200;
+
+ std::vector<ServiceWorkerFetchRequest> requests;
+ requests.push_back(CreateRequestWithProvidedResponse(
+ "GET", "https://example.com/funny_cat.txt",
+ TestResponseBuilder(kResponseCode)
+ .SetResponseData("Random data about a funny cat.")
+ .Build()));
+
+ // Create the registration with the given |requests|.
+ {
+ BackgroundFetchOptions options;
+
+ blink::mojom::BackgroundFetchError error;
+ BackgroundFetchRegistration registration;
+
+ // Create the first registration. This must succeed.
+ ASSERT_NO_FATAL_FAILURE(
+ Fetch(registration_id, requests, options, &error, &registration));
+ ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
+ }
+
+ // Immediately abort the request created for the |registration_id|. Then wait
+ // for the `backgroundfetchabort` event to have been invoked.
+ {
+ blink::mojom::BackgroundFetchError error;
+
+ ASSERT_NO_FATAL_FAILURE(Abort(registration_id, &error));
+ ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
+ }
+
+ event_dispatched_loop.Run();
+
+ ASSERT_TRUE(embedded_worker_test_helper()->last_tag().has_value());
+ EXPECT_EQ(kExampleTag, embedded_worker_test_helper()->last_tag().value());
+}
+
TEST_F(BackgroundFetchServiceTest, GetTags) {
// This test verifies that the list of active tags can be retrieved from the
// service for a given Service Worker, as extracted from a registration.
« no previous file with comments | « content/browser/background_fetch/background_fetch_context.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698