Commit ce4238ca authored by Mugdha Lakhani's avatar Mugdha Lakhani Committed by Commit Bot

[Background Fetch] Update Background Fetch unit tests.

Now that we're passing BackgroundFetchRegistration with
all BackgroundFetch Events, the unit tests can be simplified.

Bug: 876691, 869918
Change-Id: I5137981b32666901cdc6f953b744372695b11d72
Reviewed-on: https://chromium-review.googlesource.com/1186722
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Reviewed-by: default avatarRayan Kanso <rayankans@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585861}
parent 4d19c351
...@@ -22,10 +22,7 @@ BackgroundFetchEmbeddedWorkerTestHelper:: ...@@ -22,10 +22,7 @@ BackgroundFetchEmbeddedWorkerTestHelper::
void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchAbortEvent( void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchAbortEvent(
const BackgroundFetchRegistration& registration, const BackgroundFetchRegistration& registration,
mojom::ServiceWorker::DispatchBackgroundFetchAbortEventCallback callback) { mojom::ServiceWorker::DispatchBackgroundFetchAbortEventCallback callback) {
last_developer_id_ = registration.developer_id; last_registration_ = registration;
last_unique_id_ = registration.unique_id;
last_state_ = registration.state;
last_failure_reason_ = registration.failure_reason;
if (fail_abort_event_) { if (fail_abort_event_) {
std::move(callback).Run(blink::mojom::ServiceWorkerEventStatus::REJECTED, std::move(callback).Run(blink::mojom::ServiceWorkerEventStatus::REJECTED,
...@@ -42,10 +39,7 @@ void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchAbortEvent( ...@@ -42,10 +39,7 @@ void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchAbortEvent(
void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchClickEvent( void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchClickEvent(
const BackgroundFetchRegistration& registration, const BackgroundFetchRegistration& registration,
mojom::ServiceWorker::DispatchBackgroundFetchClickEventCallback callback) { mojom::ServiceWorker::DispatchBackgroundFetchClickEventCallback callback) {
last_developer_id_ = registration.developer_id; last_registration_ = registration;
last_unique_id_ = registration.unique_id;
last_state_ = registration.state;
last_failure_reason_ = registration.failure_reason;
if (fail_click_event_) { if (fail_click_event_) {
std::move(callback).Run(blink::mojom::ServiceWorkerEventStatus::REJECTED, std::move(callback).Run(blink::mojom::ServiceWorkerEventStatus::REJECTED,
...@@ -63,10 +57,7 @@ void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchFailEvent( ...@@ -63,10 +57,7 @@ void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchFailEvent(
const BackgroundFetchRegistration& registration, const BackgroundFetchRegistration& registration,
const std::vector<BackgroundFetchSettledFetch>& fetches, const std::vector<BackgroundFetchSettledFetch>& fetches,
mojom::ServiceWorker::DispatchBackgroundFetchFailEventCallback callback) { mojom::ServiceWorker::DispatchBackgroundFetchFailEventCallback callback) {
last_developer_id_ = registration.developer_id; last_registration_ = registration;
last_unique_id_ = registration.unique_id;
last_state_ = registration.state;
last_failure_reason_ = registration.failure_reason;
last_fetches_ = fetches; last_fetches_ = fetches;
if (fail_fetch_fail_event_) { if (fail_fetch_fail_event_) {
...@@ -86,10 +77,7 @@ void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchSuccessEvent( ...@@ -86,10 +77,7 @@ void BackgroundFetchEmbeddedWorkerTestHelper::OnBackgroundFetchSuccessEvent(
const std::vector<BackgroundFetchSettledFetch>& fetches, const std::vector<BackgroundFetchSettledFetch>& fetches,
mojom::ServiceWorker::DispatchBackgroundFetchSuccessEventCallback mojom::ServiceWorker::DispatchBackgroundFetchSuccessEventCallback
callback) { callback) {
last_developer_id_ = registration.developer_id; last_registration_ = registration;
last_unique_id_ = registration.unique_id;
last_state_ = registration.state;
last_failure_reason_ = registration.failure_reason;
last_fetches_ = fetches; last_fetches_ = fetches;
if (fail_fetched_event_) { if (fail_fetched_event_) {
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
namespace content { namespace content {
struct BackgroundFetchRegistration;
struct BackgroundFetchSettledFetch; struct BackgroundFetchSettledFetch;
// Extension of the EmbeddedWorkerTestHelper that enables instrumentation of the // Extension of the EmbeddedWorkerTestHelper that enables instrumentation of the
...@@ -46,19 +47,10 @@ class BackgroundFetchEmbeddedWorkerTestHelper ...@@ -46,19 +47,10 @@ class BackgroundFetchEmbeddedWorkerTestHelper
fetched_event_closure_ = closure; fetched_event_closure_ = closure;
} }
const base::Optional<std::string>& last_developer_id() const { const base::Optional<BackgroundFetchRegistration>& last_registration() const {
return last_developer_id_; return last_registration_;
}
const base::Optional<std::string>& last_unique_id() const {
return last_unique_id_;
}
const base::Optional<blink::mojom::BackgroundFetchState>& last_state() const {
return last_state_;
}
const base::Optional<blink::mojom::BackgroundFetchFailureReason>&
last_failure_reason() const {
return last_failure_reason_;
} }
const base::Optional<std::vector<BackgroundFetchSettledFetch>> last_fetches() const base::Optional<std::vector<BackgroundFetchSettledFetch>> last_fetches()
const { const {
return last_fetches_; return last_fetches_;
...@@ -96,11 +88,7 @@ class BackgroundFetchEmbeddedWorkerTestHelper ...@@ -96,11 +88,7 @@ class BackgroundFetchEmbeddedWorkerTestHelper
base::Closure fetch_fail_event_closure_; base::Closure fetch_fail_event_closure_;
base::Closure fetched_event_closure_; base::Closure fetched_event_closure_;
base::Optional<std::string> last_developer_id_; base::Optional<BackgroundFetchRegistration> last_registration_;
base::Optional<std::string> last_unique_id_;
base::Optional<blink::mojom::BackgroundFetchState> last_state_;
base::Optional<blink::mojom::BackgroundFetchFailureReason>
last_failure_reason_;
base::Optional<std::vector<BackgroundFetchSettledFetch>> last_fetches_; base::Optional<std::vector<BackgroundFetchSettledFetch>> last_fetches_;
DISALLOW_COPY_AND_ASSIGN(BackgroundFetchEmbeddedWorkerTestHelper); DISALLOW_COPY_AND_ASSIGN(BackgroundFetchEmbeddedWorkerTestHelper);
......
...@@ -87,15 +87,13 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchAbortEvent) { ...@@ -87,15 +87,13 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchAbortEvent) {
run_loop.Run(); run_loop.Run();
} }
ASSERT_TRUE(embedded_worker_test_helper()->last_developer_id().has_value()); ASSERT_TRUE(embedded_worker_test_helper()->last_registration().has_value());
EXPECT_EQ(kExampleDeveloperId, EXPECT_EQ(kExampleDeveloperId,
embedded_worker_test_helper()->last_developer_id().value()); embedded_worker_test_helper()->last_registration()->developer_id);
ASSERT_TRUE(embedded_worker_test_helper()->last_unique_id().has_value());
EXPECT_EQ(kExampleUniqueId, EXPECT_EQ(kExampleUniqueId,
embedded_worker_test_helper()->last_unique_id().value()); embedded_worker_test_helper()->last_registration()->unique_id);
ASSERT_TRUE(embedded_worker_test_helper()->last_failure_reason().has_value());
EXPECT_EQ(blink::mojom::BackgroundFetchFailureReason::CANCELLED_FROM_UI, EXPECT_EQ(blink::mojom::BackgroundFetchFailureReason::CANCELLED_FROM_UI,
embedded_worker_test_helper()->last_failure_reason()); embedded_worker_test_helper()->last_registration()->failure_reason);
histogram_tester_.ExpectUniqueSample( histogram_tester_.ExpectUniqueSample(
"BackgroundFetch.EventDispatchResult.AbortEvent", "BackgroundFetch.EventDispatchResult.AbortEvent",
...@@ -120,12 +118,11 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchAbortEvent) { ...@@ -120,12 +118,11 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchAbortEvent) {
run_loop.Run(); run_loop.Run();
} }
ASSERT_TRUE(embedded_worker_test_helper()->last_developer_id().has_value()); ASSERT_TRUE(embedded_worker_test_helper()->last_registration().has_value());
EXPECT_EQ(kExampleDeveloperId2, EXPECT_EQ(kExampleDeveloperId2,
embedded_worker_test_helper()->last_developer_id().value()); embedded_worker_test_helper()->last_registration()->developer_id);
ASSERT_TRUE(embedded_worker_test_helper()->last_unique_id().has_value());
EXPECT_EQ(kExampleUniqueId2, EXPECT_EQ(kExampleUniqueId2,
embedded_worker_test_helper()->last_unique_id().value()); embedded_worker_test_helper()->last_registration()->unique_id);
histogram_tester_.ExpectBucketCount( histogram_tester_.ExpectBucketCount(
"BackgroundFetch.EventDispatchResult.AbortEvent", "BackgroundFetch.EventDispatchResult.AbortEvent",
...@@ -159,12 +156,11 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchClickEvent) { ...@@ -159,12 +156,11 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchClickEvent) {
run_loop.Run(); run_loop.Run();
} }
ASSERT_TRUE(embedded_worker_test_helper()->last_developer_id().has_value()); ASSERT_TRUE(embedded_worker_test_helper()->last_registration().has_value());
EXPECT_EQ(kExampleDeveloperId, EXPECT_EQ(kExampleDeveloperId,
embedded_worker_test_helper()->last_developer_id().value()); embedded_worker_test_helper()->last_registration()->developer_id);
ASSERT_TRUE(embedded_worker_test_helper()->last_state().has_value());
EXPECT_EQ(blink::mojom::BackgroundFetchState::PENDING, EXPECT_EQ(blink::mojom::BackgroundFetchState::PENDING,
embedded_worker_test_helper()->last_state()); embedded_worker_test_helper()->last_registration()->state);
histogram_tester_.ExpectUniqueSample( histogram_tester_.ExpectUniqueSample(
"BackgroundFetch.EventDispatchResult.ClickEvent", "BackgroundFetch.EventDispatchResult.ClickEvent",
...@@ -189,12 +185,11 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchClickEvent) { ...@@ -189,12 +185,11 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchClickEvent) {
run_loop.Run(); run_loop.Run();
} }
ASSERT_TRUE(embedded_worker_test_helper()->last_developer_id().has_value()); ASSERT_TRUE(embedded_worker_test_helper()->last_registration().has_value());
EXPECT_EQ(kExampleDeveloperId2, EXPECT_EQ(kExampleDeveloperId2,
embedded_worker_test_helper()->last_developer_id().value()); embedded_worker_test_helper()->last_registration()->developer_id);
ASSERT_TRUE(embedded_worker_test_helper()->last_state().has_value());
EXPECT_EQ(blink::mojom::BackgroundFetchState::FAILURE, EXPECT_EQ(blink::mojom::BackgroundFetchState::FAILURE,
embedded_worker_test_helper()->last_state()); embedded_worker_test_helper()->last_registration()->state);
histogram_tester_.ExpectBucketCount( histogram_tester_.ExpectBucketCount(
"BackgroundFetch.EventDispatchResult.ClickEvent", "BackgroundFetch.EventDispatchResult.ClickEvent",
...@@ -232,9 +227,9 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchFailEvent) { ...@@ -232,9 +227,9 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchFailEvent) {
run_loop.Run(); run_loop.Run();
} }
ASSERT_TRUE(embedded_worker_test_helper()->last_developer_id().has_value()); ASSERT_TRUE(embedded_worker_test_helper()->last_registration().has_value());
EXPECT_EQ(kExampleDeveloperId, EXPECT_EQ(kExampleDeveloperId,
embedded_worker_test_helper()->last_developer_id().value()); embedded_worker_test_helper()->last_registration()->developer_id);
ASSERT_TRUE(embedded_worker_test_helper()->last_fetches().has_value()); ASSERT_TRUE(embedded_worker_test_helper()->last_fetches().has_value());
EXPECT_EQ(fetches.size(), EXPECT_EQ(fetches.size(),
...@@ -265,9 +260,9 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchFailEvent) { ...@@ -265,9 +260,9 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchFailEvent) {
run_loop.Run(); run_loop.Run();
} }
ASSERT_TRUE(embedded_worker_test_helper()->last_developer_id().has_value()); ASSERT_TRUE(embedded_worker_test_helper()->last_registration().has_value());
EXPECT_EQ(kExampleDeveloperId2, EXPECT_EQ(kExampleDeveloperId2,
embedded_worker_test_helper()->last_developer_id().value()); embedded_worker_test_helper()->last_registration()->developer_id);
ASSERT_TRUE(embedded_worker_test_helper()->last_fetches().has_value()); ASSERT_TRUE(embedded_worker_test_helper()->last_fetches().has_value());
EXPECT_EQ(fetches.size(), EXPECT_EQ(fetches.size(),
...@@ -309,13 +304,12 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchFetchSuccessEvent) { ...@@ -309,13 +304,12 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchFetchSuccessEvent) {
run_loop.Run(); run_loop.Run();
} }
ASSERT_TRUE(embedded_worker_test_helper()->last_developer_id().has_value()); ASSERT_TRUE(embedded_worker_test_helper()->last_registration().has_value());
EXPECT_EQ(kExampleDeveloperId, EXPECT_EQ(kExampleDeveloperId,
embedded_worker_test_helper()->last_developer_id().value()); embedded_worker_test_helper()->last_registration()->developer_id);
ASSERT_TRUE(embedded_worker_test_helper()->last_unique_id().has_value());
EXPECT_EQ(kExampleUniqueId, EXPECT_EQ(kExampleUniqueId,
embedded_worker_test_helper()->last_unique_id().value()); embedded_worker_test_helper()->last_registration()->unique_id);
ASSERT_TRUE(embedded_worker_test_helper()->last_fetches().has_value()); ASSERT_TRUE(embedded_worker_test_helper()->last_fetches().has_value());
EXPECT_EQ(fetches.size(), EXPECT_EQ(fetches.size(),
...@@ -346,13 +340,11 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchFetchSuccessEvent) { ...@@ -346,13 +340,11 @@ TEST_F(BackgroundFetchEventDispatcherTest, DispatchFetchSuccessEvent) {
run_loop.Run(); run_loop.Run();
} }
ASSERT_TRUE(embedded_worker_test_helper()->last_developer_id().has_value()); ASSERT_TRUE(embedded_worker_test_helper()->last_registration().has_value());
EXPECT_EQ(kExampleDeveloperId2, EXPECT_EQ(kExampleDeveloperId2,
embedded_worker_test_helper()->last_developer_id().value()); embedded_worker_test_helper()->last_registration()->developer_id);
ASSERT_TRUE(embedded_worker_test_helper()->last_unique_id().has_value());
EXPECT_EQ(kExampleUniqueId2, EXPECT_EQ(kExampleUniqueId2,
embedded_worker_test_helper()->last_unique_id().value()); embedded_worker_test_helper()->last_registration()->unique_id);
ASSERT_TRUE(embedded_worker_test_helper()->last_fetches().has_value()); ASSERT_TRUE(embedded_worker_test_helper()->last_fetches().has_value());
EXPECT_EQ(fetches.size(), EXPECT_EQ(fetches.size(),
......
...@@ -530,9 +530,9 @@ TEST_F(BackgroundFetchServiceTest, FetchSuccessEventDispatch) { ...@@ -530,9 +530,9 @@ TEST_F(BackgroundFetchServiceTest, FetchSuccessEventDispatch) {
// Spin the |event_dispatched_loop| to wait for the dispatched event. // Spin the |event_dispatched_loop| to wait for the dispatched event.
event_dispatched_loop.Run(); event_dispatched_loop.Run();
ASSERT_TRUE(embedded_worker_test_helper()->last_developer_id().has_value()); ASSERT_TRUE(embedded_worker_test_helper()->last_registration().has_value());
EXPECT_EQ(kExampleDeveloperId, EXPECT_EQ(kExampleDeveloperId,
embedded_worker_test_helper()->last_developer_id().value()); embedded_worker_test_helper()->last_registration()->developer_id);
ASSERT_TRUE(embedded_worker_test_helper()->last_fetches().has_value()); ASSERT_TRUE(embedded_worker_test_helper()->last_fetches().has_value());
...@@ -633,9 +633,9 @@ TEST_F(BackgroundFetchServiceTest, FetchFailEventDispatch) { ...@@ -633,9 +633,9 @@ TEST_F(BackgroundFetchServiceTest, FetchFailEventDispatch) {
// Spin the |event_dispatched_loop| to wait for the dispatched event. // Spin the |event_dispatched_loop| to wait for the dispatched event.
event_dispatched_loop.Run(); event_dispatched_loop.Run();
ASSERT_TRUE(embedded_worker_test_helper()->last_developer_id().has_value()); ASSERT_TRUE(embedded_worker_test_helper()->last_registration().has_value());
EXPECT_EQ(kExampleDeveloperId, EXPECT_EQ(kExampleDeveloperId,
embedded_worker_test_helper()->last_developer_id().value()); embedded_worker_test_helper()->last_registration()->developer_id);
ASSERT_TRUE(embedded_worker_test_helper()->last_fetches().has_value()); ASSERT_TRUE(embedded_worker_test_helper()->last_fetches().has_value());
...@@ -842,9 +842,9 @@ TEST_F(BackgroundFetchServiceTest, AbortEventDispatch) { ...@@ -842,9 +842,9 @@ TEST_F(BackgroundFetchServiceTest, AbortEventDispatch) {
event_dispatched_loop.Run(); event_dispatched_loop.Run();
ASSERT_TRUE(embedded_worker_test_helper()->last_developer_id().has_value()); ASSERT_TRUE(embedded_worker_test_helper()->last_registration().has_value());
EXPECT_EQ(kExampleDeveloperId, EXPECT_EQ(kExampleDeveloperId,
embedded_worker_test_helper()->last_developer_id().value()); embedded_worker_test_helper()->last_registration()->developer_id);
} }
TEST_F(BackgroundFetchServiceTest, UniqueId) { TEST_F(BackgroundFetchServiceTest, UniqueId) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment