| 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "content/browser/background_fetch/background_fetch_context.h" | 10 #include "content/browser/background_fetch/background_fetch_context.h" |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 // Now try to get the created registration, which is expected to fail. | 340 // Now try to get the created registration, which is expected to fail. |
| 341 ASSERT_NO_FATAL_FAILURE( | 341 ASSERT_NO_FATAL_FAILURE( |
| 342 GetRegistration(registration_id, &second_error, &second_registration)); | 342 GetRegistration(registration_id, &second_error, &second_registration)); |
| 343 ASSERT_EQ(second_error, blink::mojom::BackgroundFetchError::INVALID_TAG); | 343 ASSERT_EQ(second_error, blink::mojom::BackgroundFetchError::INVALID_TAG); |
| 344 } | 344 } |
| 345 | 345 |
| 346 TEST_F(BackgroundFetchServiceTest, AbortInvalidArguments) { | 346 TEST_F(BackgroundFetchServiceTest, AbortInvalidArguments) { |
| 347 // This test verifies that the Abort() function will kill the renderer and | 347 // This test verifies that the Abort() function will kill the renderer and |
| 348 // return INVALID_ARGUMENT when invalid data is send over the Mojo channel. | 348 // return INVALID_ARGUMENT when invalid data is send over the Mojo channel. |
| 349 | 349 |
| 350 BackgroundFetchOptions options; | 350 BackgroundFetchRegistrationId registration_id( |
| 351 42 /* service_worker_registration_id */, origin(), "" /* tag */); |
| 351 | 352 |
| 352 // The `tag` must be a non-empty string. | 353 blink::mojom::BackgroundFetchError error; |
| 353 { | |
| 354 BackgroundFetchRegistrationId registration_id( | |
| 355 42 /* service_worker_registration_id */, origin(), "" /* tag */); | |
| 356 | 354 |
| 357 blink::mojom::BackgroundFetchError error; | 355 ASSERT_NO_FATAL_FAILURE(Abort(registration_id, &error)); |
| 356 ASSERT_EQ(error, blink::mojom::BackgroundFetchError::INVALID_ARGUMENT); |
| 357 } |
| 358 | 358 |
| 359 ASSERT_NO_FATAL_FAILURE(Abort(registration_id, &error)); | 359 TEST_F(BackgroundFetchServiceTest, AbortInvalidTag) { |
| 360 ASSERT_EQ(error, blink::mojom::BackgroundFetchError::INVALID_ARGUMENT); | 360 // This test verifies that aborting a Background Fetch registration with a |
| 361 } | 361 // tag that does not correspond to an active fetch kindly tells us so. |
| 362 |
| 363 BackgroundFetchRegistrationId registration_id; |
| 364 ASSERT_TRUE(CreateRegistrationId(kExampleTag, ®istration_id)); |
| 365 |
| 366 // Deliberate do *not* create a fetch for the |registration_id|. |
| 367 |
| 368 blink::mojom::BackgroundFetchError error; |
| 369 |
| 370 ASSERT_NO_FATAL_FAILURE(Abort(registration_id, &error)); |
| 371 ASSERT_EQ(error, blink::mojom::BackgroundFetchError::INVALID_TAG); |
| 362 } | 372 } |
| 363 | 373 |
| 364 TEST_F(BackgroundFetchServiceTest, GetTags) { | 374 TEST_F(BackgroundFetchServiceTest, GetTags) { |
| 365 // This test verifies that the list of active tags can be retrieved from the | 375 // This test verifies that the list of active tags can be retrieved from the |
| 366 // service for a given Service Worker, as extracted from a registration. | 376 // service for a given Service Worker, as extracted from a registration. |
| 367 | 377 |
| 368 BackgroundFetchRegistrationId registration_id; | 378 BackgroundFetchRegistrationId registration_id; |
| 369 ASSERT_TRUE(CreateRegistrationId(kExampleTag, ®istration_id)); | 379 ASSERT_TRUE(CreateRegistrationId(kExampleTag, ®istration_id)); |
| 370 | 380 |
| 371 BackgroundFetchRegistrationId second_registration_id; | 381 BackgroundFetchRegistrationId second_registration_id; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 const bool has_alternative_tag = | 445 const bool has_alternative_tag = |
| 436 tags[0] == kAlternativeTag || tags[1] == kAlternativeTag; | 446 tags[0] == kAlternativeTag || tags[1] == kAlternativeTag; |
| 437 | 447 |
| 438 EXPECT_TRUE(has_example_tag); | 448 EXPECT_TRUE(has_example_tag); |
| 439 EXPECT_TRUE(has_alternative_tag); | 449 EXPECT_TRUE(has_alternative_tag); |
| 440 } | 450 } |
| 441 } | 451 } |
| 442 | 452 |
| 443 } // namespace | 453 } // namespace |
| 444 } // namespace content | 454 } // namespace content |
| OLD | NEW |