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

Side by Side Diff: content/browser/background_fetch/background_fetch_data_manager_unittest.cc

Issue 2978603003: [Background Fetch] Tidy up getting/activating pending requests (Closed)
Patch Set: Split up MarkRequestAsCompleteAndGetNextRequest and nuke pending_completed_file_acknowledgements_ Created 3 years, 5 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
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 #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 <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 17 matching lines...) Expand all
28 : background_fetch_data_manager_( 28 : background_fetch_data_manager_(
29 base::MakeUnique<BackgroundFetchDataManager>(browser_context())) {} 29 base::MakeUnique<BackgroundFetchDataManager>(browser_context())) {}
30 ~BackgroundFetchDataManagerTest() override = default; 30 ~BackgroundFetchDataManagerTest() override = default;
31 31
32 protected: 32 protected:
33 // Synchronous version of BackgroundFetchDataManager::CreateRegistration(). 33 // Synchronous version of BackgroundFetchDataManager::CreateRegistration().
34 void CreateRegistration( 34 void CreateRegistration(
35 const BackgroundFetchRegistrationId& registration_id, 35 const BackgroundFetchRegistrationId& registration_id,
36 const std::vector<ServiceWorkerFetchRequest>& requests, 36 const std::vector<ServiceWorkerFetchRequest>& requests,
37 const BackgroundFetchOptions& options, 37 const BackgroundFetchOptions& options,
38 blink::mojom::BackgroundFetchError* out_error, 38 blink::mojom::BackgroundFetchError* out_error) {
39 std::vector<scoped_refptr<BackgroundFetchRequestInfo>>*
40 out_initial_requests) {
41 DCHECK(out_error); 39 DCHECK(out_error);
42 40
43 base::RunLoop run_loop; 41 base::RunLoop run_loop;
44 background_fetch_data_manager_->CreateRegistration( 42 background_fetch_data_manager_->CreateRegistration(
45 registration_id, requests, options, 43 registration_id, requests, options,
46 base::BindOnce(&BackgroundFetchDataManagerTest::DidCreateRegistration, 44 base::BindOnce(&BackgroundFetchDataManagerTest::DidCreateRegistration,
47 base::Unretained(this), run_loop.QuitClosure(), 45 base::Unretained(this), run_loop.QuitClosure(),
48 out_error, out_initial_requests)); 46 out_error));
49 run_loop.Run(); 47 run_loop.Run();
50 } 48 }
51 49
52 // Synchronous version of BackgroundFetchDataManager::DeleteRegistration(). 50 // Synchronous version of BackgroundFetchDataManager::DeleteRegistration().
53 void DeleteRegistration(const BackgroundFetchRegistrationId& registration_id, 51 void DeleteRegistration(const BackgroundFetchRegistrationId& registration_id,
54 blink::mojom::BackgroundFetchError* out_error) { 52 blink::mojom::BackgroundFetchError* out_error) {
55 DCHECK(out_error); 53 DCHECK(out_error);
56 54
57 base::RunLoop run_loop; 55 base::RunLoop run_loop;
58 background_fetch_data_manager_->DeleteRegistration( 56 background_fetch_data_manager_->DeleteRegistration(
59 registration_id, 57 registration_id,
60 base::BindOnce(&BackgroundFetchDataManagerTest::DidDeleteRegistration, 58 base::BindOnce(&BackgroundFetchDataManagerTest::DidDeleteRegistration,
61 base::Unretained(this), run_loop.QuitClosure(), 59 base::Unretained(this), run_loop.QuitClosure(),
62 out_error)); 60 out_error));
63 run_loop.Run(); 61 run_loop.Run();
64 } 62 }
65 63
66 private: 64 private:
67 void DidCreateRegistration( 65 void DidCreateRegistration(base::Closure quit_closure,
68 base::Closure quit_closure, 66 blink::mojom::BackgroundFetchError* out_error,
69 blink::mojom::BackgroundFetchError* out_error, 67 blink::mojom::BackgroundFetchError error) {
70 std::vector<scoped_refptr<BackgroundFetchRequestInfo>>*
71 out_initial_requests,
72 blink::mojom::BackgroundFetchError error,
73 std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests) {
74 *out_error = error; 68 *out_error = error;
75 *out_initial_requests = std::move(initial_requests);
76 69
77 quit_closure.Run(); 70 quit_closure.Run();
78 } 71 }
79 72
80 void DidDeleteRegistration(base::Closure quit_closure, 73 void DidDeleteRegistration(base::Closure quit_closure,
81 blink::mojom::BackgroundFetchError* out_error, 74 blink::mojom::BackgroundFetchError* out_error,
82 blink::mojom::BackgroundFetchError error) { 75 blink::mojom::BackgroundFetchError error) {
83 *out_error = error; 76 *out_error = error;
84 77
85 quit_closure.Run(); 78 quit_closure.Run();
86 } 79 }
87 80
88 std::string job_guid_; 81 std::string job_guid_;
89 std::unique_ptr<BackgroundFetchDataManager> background_fetch_data_manager_; 82 std::unique_ptr<BackgroundFetchDataManager> background_fetch_data_manager_;
90 }; 83 };
91 84
92 TEST_F(BackgroundFetchDataManagerTest, NoDuplicateRegistrations) { 85 TEST_F(BackgroundFetchDataManagerTest, NoDuplicateRegistrations) {
93 // Tests that the BackgroundFetchDataManager correctly rejects creating a 86 // Tests that the BackgroundFetchDataManager correctly rejects creating a
94 // registration that's already known to the system. 87 // registration that's already known to the system.
95 88
96 BackgroundFetchRegistrationId registration_id; 89 BackgroundFetchRegistrationId registration_id;
97 ASSERT_TRUE(CreateRegistrationId(kExampleTag, &registration_id)); 90 ASSERT_TRUE(CreateRegistrationId(kExampleTag, &registration_id));
98 91
99 std::vector<ServiceWorkerFetchRequest> requests; 92 std::vector<ServiceWorkerFetchRequest> requests;
100 BackgroundFetchOptions options; 93 BackgroundFetchOptions options;
101 94
102 blink::mojom::BackgroundFetchError error; 95 blink::mojom::BackgroundFetchError error;
103 std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests;
104 96
105 // Deleting the not-yet-created registration should fail. 97 // Deleting the not-yet-created registration should fail.
106 ASSERT_NO_FATAL_FAILURE(DeleteRegistration(registration_id, &error)); 98 ASSERT_NO_FATAL_FAILURE(DeleteRegistration(registration_id, &error));
107 EXPECT_EQ(error, blink::mojom::BackgroundFetchError::INVALID_TAG); 99 EXPECT_EQ(error, blink::mojom::BackgroundFetchError::INVALID_TAG);
108 100
109 // Creating the initial registration should succeed. 101 // Creating the initial registration should succeed.
110 ASSERT_NO_FATAL_FAILURE(CreateRegistration(registration_id, requests, options, 102 ASSERT_NO_FATAL_FAILURE(
111 &error, &initial_requests)); 103 CreateRegistration(registration_id, requests, options, &error));
112 EXPECT_EQ(error, blink::mojom::BackgroundFetchError::NONE); 104 EXPECT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
113 105
114 // Attempting to create it again should yield an error. 106 // Attempting to create it again should yield an error.
115 ASSERT_NO_FATAL_FAILURE(CreateRegistration(registration_id, requests, options, 107 ASSERT_NO_FATAL_FAILURE(
116 &error, &initial_requests)); 108 CreateRegistration(registration_id, requests, options, &error));
117 EXPECT_EQ(error, blink::mojom::BackgroundFetchError::DUPLICATED_TAG); 109 EXPECT_EQ(error, blink::mojom::BackgroundFetchError::DUPLICATED_TAG);
118 110
119 // Deleting the registration should succeed. 111 // Deleting the registration should succeed.
120 ASSERT_NO_FATAL_FAILURE(DeleteRegistration(registration_id, &error)); 112 ASSERT_NO_FATAL_FAILURE(DeleteRegistration(registration_id, &error));
121 EXPECT_EQ(error, blink::mojom::BackgroundFetchError::NONE); 113 EXPECT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
122 114
123 // And then recreating the registration again should work fine. 115 // And then recreating the registration again should work fine.
124 ASSERT_NO_FATAL_FAILURE(CreateRegistration(registration_id, requests, options, 116 ASSERT_NO_FATAL_FAILURE(
125 &error, &initial_requests)); 117 CreateRegistration(registration_id, requests, options, &error));
126 EXPECT_EQ(error, blink::mojom::BackgroundFetchError::NONE); 118 EXPECT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
127 } 119 }
128 120
129 } // namespace content 121 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698