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

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

Issue 2796933003: Store BackgroundFetchRequestInfo in a refcounted pointer (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 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 18 matching lines...) Expand all
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<BackgroundFetchRequestInfo>* out_initial_requests) { 39 std::vector<scoped_refptr<BackgroundFetchRequestInfo>>*
40 out_initial_requests) {
40 DCHECK(out_error); 41 DCHECK(out_error);
41 42
42 base::RunLoop run_loop; 43 base::RunLoop run_loop;
43 background_fetch_data_manager_->CreateRegistration( 44 background_fetch_data_manager_->CreateRegistration(
44 registration_id, requests, options, 45 registration_id, requests, options,
45 base::BindOnce(&BackgroundFetchDataManagerTest::DidCreateRegistration, 46 base::BindOnce(&BackgroundFetchDataManagerTest::DidCreateRegistration,
46 base::Unretained(this), run_loop.QuitClosure(), 47 base::Unretained(this), run_loop.QuitClosure(),
47 out_error, out_initial_requests)); 48 out_error, out_initial_requests));
48 run_loop.Run(); 49 run_loop.Run();
49 } 50 }
50 51
51 // Synchronous version of BackgroundFetchDataManager::DeleteRegistration(). 52 // Synchronous version of BackgroundFetchDataManager::DeleteRegistration().
52 void DeleteRegistration(const BackgroundFetchRegistrationId& registration_id, 53 void DeleteRegistration(const BackgroundFetchRegistrationId& registration_id,
53 blink::mojom::BackgroundFetchError* out_error) { 54 blink::mojom::BackgroundFetchError* out_error) {
54 DCHECK(out_error); 55 DCHECK(out_error);
55 56
56 base::RunLoop run_loop; 57 base::RunLoop run_loop;
57 background_fetch_data_manager_->DeleteRegistration( 58 background_fetch_data_manager_->DeleteRegistration(
58 registration_id, 59 registration_id,
59 base::BindOnce(&BackgroundFetchDataManagerTest::DidDeleteRegistration, 60 base::BindOnce(&BackgroundFetchDataManagerTest::DidDeleteRegistration,
60 base::Unretained(this), run_loop.QuitClosure(), 61 base::Unretained(this), run_loop.QuitClosure(),
61 out_error)); 62 out_error));
62 run_loop.Run(); 63 run_loop.Run();
63 } 64 }
64 65
65 private: 66 private:
66 void DidCreateRegistration( 67 void DidCreateRegistration(
67 base::Closure quit_closure, 68 base::Closure quit_closure,
68 blink::mojom::BackgroundFetchError* out_error, 69 blink::mojom::BackgroundFetchError* out_error,
69 std::vector<BackgroundFetchRequestInfo>* out_initial_requests, 70 std::vector<scoped_refptr<BackgroundFetchRequestInfo>>*
71 out_initial_requests,
70 blink::mojom::BackgroundFetchError error, 72 blink::mojom::BackgroundFetchError error,
71 std::vector<BackgroundFetchRequestInfo> initial_requests) { 73 std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests) {
72 *out_error = error; 74 *out_error = error;
73 *out_initial_requests = std::move(initial_requests); 75 *out_initial_requests = std::move(initial_requests);
74 76
75 quit_closure.Run(); 77 quit_closure.Run();
76 } 78 }
77 79
78 void DidDeleteRegistration(base::Closure quit_closure, 80 void DidDeleteRegistration(base::Closure quit_closure,
79 blink::mojom::BackgroundFetchError* out_error, 81 blink::mojom::BackgroundFetchError* out_error,
80 blink::mojom::BackgroundFetchError error) { 82 blink::mojom::BackgroundFetchError error) {
81 *out_error = error; 83 *out_error = error;
82 84
83 quit_closure.Run(); 85 quit_closure.Run();
84 } 86 }
85 87
86 std::string job_guid_; 88 std::string job_guid_;
87 std::unique_ptr<BackgroundFetchDataManager> background_fetch_data_manager_; 89 std::unique_ptr<BackgroundFetchDataManager> background_fetch_data_manager_;
88 }; 90 };
89 91
90 TEST_F(BackgroundFetchDataManagerTest, NoDuplicateRegistrations) { 92 TEST_F(BackgroundFetchDataManagerTest, NoDuplicateRegistrations) {
91 // Tests that the BackgroundFetchDataManager correctly rejects creating a 93 // Tests that the BackgroundFetchDataManager correctly rejects creating a
92 // registration that's already known to the system. 94 // registration that's already known to the system.
93 95
94 BackgroundFetchRegistrationId registration_id; 96 BackgroundFetchRegistrationId registration_id;
95 ASSERT_TRUE(CreateRegistrationId(kExampleTag, &registration_id)); 97 ASSERT_TRUE(CreateRegistrationId(kExampleTag, &registration_id));
96 98
97 std::vector<ServiceWorkerFetchRequest> requests; 99 std::vector<ServiceWorkerFetchRequest> requests;
98 BackgroundFetchOptions options; 100 BackgroundFetchOptions options;
99 101
100 blink::mojom::BackgroundFetchError error; 102 blink::mojom::BackgroundFetchError error;
101 std::vector<BackgroundFetchRequestInfo> initial_requests; 103 std::vector<scoped_refptr<BackgroundFetchRequestInfo>> initial_requests;
102 104
103 // Deleting the not-yet-created registration should fail. 105 // Deleting the not-yet-created registration should fail.
104 ASSERT_NO_FATAL_FAILURE(DeleteRegistration(registration_id, &error)); 106 ASSERT_NO_FATAL_FAILURE(DeleteRegistration(registration_id, &error));
105 EXPECT_EQ(error, blink::mojom::BackgroundFetchError::INVALID_TAG); 107 EXPECT_EQ(error, blink::mojom::BackgroundFetchError::INVALID_TAG);
106 108
107 // Creating the initial registration should succeed. 109 // Creating the initial registration should succeed.
108 ASSERT_NO_FATAL_FAILURE(CreateRegistration(registration_id, requests, options, 110 ASSERT_NO_FATAL_FAILURE(CreateRegistration(registration_id, requests, options,
109 &error, &initial_requests)); 111 &error, &initial_requests));
110 EXPECT_EQ(error, blink::mojom::BackgroundFetchError::NONE); 112 EXPECT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
111 113
112 // Attempting to create it again should yield an error. 114 // Attempting to create it again should yield an error.
113 ASSERT_NO_FATAL_FAILURE(CreateRegistration(registration_id, requests, options, 115 ASSERT_NO_FATAL_FAILURE(CreateRegistration(registration_id, requests, options,
114 &error, &initial_requests)); 116 &error, &initial_requests));
115 EXPECT_EQ(error, blink::mojom::BackgroundFetchError::DUPLICATED_TAG); 117 EXPECT_EQ(error, blink::mojom::BackgroundFetchError::DUPLICATED_TAG);
116 118
117 // Deleting the registration should succeed. 119 // Deleting the registration should succeed.
118 ASSERT_NO_FATAL_FAILURE(DeleteRegistration(registration_id, &error)); 120 ASSERT_NO_FATAL_FAILURE(DeleteRegistration(registration_id, &error));
119 EXPECT_EQ(error, blink::mojom::BackgroundFetchError::NONE); 121 EXPECT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
120 122
121 // And then recreating the registration again should work fine. 123 // And then recreating the registration again should work fine.
122 ASSERT_NO_FATAL_FAILURE(CreateRegistration(registration_id, requests, options, 124 ASSERT_NO_FATAL_FAILURE(CreateRegistration(registration_id, requests, options,
123 &error, &initial_requests)); 125 &error, &initial_requests));
124 EXPECT_EQ(error, blink::mojom::BackgroundFetchError::NONE); 126 EXPECT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
125 } 127 }
126 128
127 } // namespace content 129 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698