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 "content/browser/background_fetch/background_fetch_data_manager.h" | 5 #include "content/browser/background_fetch/background_fetch_data_manager.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "content/browser/background_fetch/background_fetch_context.h" | 8 #include "content/browser/background_fetch/background_fetch_context.h" |
9 #include "content/browser/background_fetch/background_fetch_job_info.h" | 9 #include "content/browser/background_fetch/background_fetch_job_info.h" |
10 #include "content/browser/background_fetch/background_fetch_request_info.h" | 10 #include "content/browser/background_fetch/background_fetch_request_info.h" |
11 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 11 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
12 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 12 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 13 #include "content/public/browser/download_interrupt_reasons.h" |
| 14 #include "content/public/browser/download_item.h" |
13 #include "content/public/test/test_browser_context.h" | 15 #include "content/public/test/test_browser_context.h" |
14 #include "content/public/test/test_browser_thread_bundle.h" | 16 #include "content/public/test/test_browser_thread_bundle.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
16 | 18 |
17 namespace { | 19 namespace { |
18 | 20 |
19 const char kOrigin[] = "https://example.com/"; | 21 const char kOrigin[] = "https://example.com/"; |
20 const char kResource[] = "https://example.com/resource.html"; | 22 const char kResource[] = "https://example.com/resource.html"; |
21 const char kTag[] = "TestRequestTag"; | 23 const char kTag[] = "TestRequestTag"; |
22 constexpr int64_t kServiceWorkerRegistrationId = 9001; | 24 constexpr int64_t kServiceWorkerRegistrationId = 9001; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 std::unique_ptr<BackgroundFetchJobData> job_data = | 65 std::unique_ptr<BackgroundFetchJobData> job_data = |
64 data_manager->CreateRequest(job_info, request_infos); | 66 data_manager->CreateRequest(job_info, request_infos); |
65 | 67 |
66 // Get all of the fetch requests from the BackgroundFetchJobData. | 68 // Get all of the fetch requests from the BackgroundFetchJobData. |
67 for (int i = 0; i < 10; i++) { | 69 for (int i = 0; i < 10; i++) { |
68 EXPECT_FALSE(job_data->IsComplete()); | 70 EXPECT_FALSE(job_data->IsComplete()); |
69 ASSERT_TRUE(job_data->HasRequestsRemaining()); | 71 ASSERT_TRUE(job_data->HasRequestsRemaining()); |
70 const BackgroundFetchRequestInfo& request_info = | 72 const BackgroundFetchRequestInfo& request_info = |
71 job_data->GetNextBackgroundFetchRequestInfo(); | 73 job_data->GetNextBackgroundFetchRequestInfo(); |
72 EXPECT_EQ(request_info.tag(), kTag); | 74 EXPECT_EQ(request_info.tag(), kTag); |
| 75 EXPECT_EQ(request_info.state(), |
| 76 DownloadItem::DownloadState::MAX_DOWNLOAD_STATE); |
| 77 EXPECT_EQ(request_info.interrupt_reason(), |
| 78 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE); |
73 } | 79 } |
74 | 80 |
75 // At this point, all the fetches have been started, but none finished. | 81 // At this point, all the fetches have been started, but none finished. |
76 EXPECT_FALSE(job_data->HasRequestsRemaining()); | 82 EXPECT_FALSE(job_data->HasRequestsRemaining()); |
77 EXPECT_FALSE(job_data->IsComplete()); | 83 EXPECT_FALSE(job_data->IsComplete()); |
78 | 84 |
79 // Complete all buy one of the fetch requests. | 85 // Complete all but one of the fetch requests. |
80 for (int i = 0; i < 9; i++) { | 86 for (int i = 0; i < 9; i++) { |
81 EXPECT_FALSE( | 87 EXPECT_FALSE(job_data->UpdateBackgroundFetchRequestState( |
82 job_data->BackgroundFetchRequestInfoComplete(request_guids[i])); | 88 request_guids[i], DownloadItem::DownloadState::COMPLETE, |
| 89 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE)); |
83 EXPECT_FALSE(job_data->IsComplete()); | 90 EXPECT_FALSE(job_data->IsComplete()); |
84 } | 91 } |
85 | 92 |
| 93 // Set the state of the last task to be interrupted. This should not complete |
| 94 // the job. |
| 95 EXPECT_FALSE(job_data->UpdateBackgroundFetchRequestState( |
| 96 request_guids[9], DownloadItem::DownloadState::INTERRUPTED, |
| 97 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN)); |
| 98 EXPECT_FALSE(job_data->IsComplete()); |
| 99 |
86 // Complete the final fetch request. | 100 // Complete the final fetch request. |
87 EXPECT_FALSE(job_data->BackgroundFetchRequestInfoComplete(request_guids[9])); | 101 EXPECT_FALSE(job_data->UpdateBackgroundFetchRequestState( |
| 102 request_guids[9], DownloadItem::DownloadState::COMPLETE, |
| 103 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE)); |
88 EXPECT_TRUE(job_data->IsComplete()); | 104 EXPECT_TRUE(job_data->IsComplete()); |
89 } | 105 } |
90 | 106 |
91 } // namespace content | 107 } // namespace content |
OLD | NEW |