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

Side by Side Diff: content/browser/service_worker/service_worker_provider_host_unittest.cc

Issue 477593007: ServiceWorker: Make '.ready' return a promise to be resolved with ServiceWorkerRegistration (2/3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/memory/weak_ptr.h" 6 #include "base/memory/weak_ptr.h"
7 #include "base/thread_task_runner_handle.h" 7 #include "base/thread_task_runner_handle.h"
8 #include "content/browser/service_worker/embedded_worker_test_helper.h" 8 #include "content/browser/service_worker/embedded_worker_test_helper.h"
9 #include "content/browser/service_worker/service_worker_context_core.h" 9 #include "content/browser/service_worker/service_worker_context_core.h"
10 #include "content/browser/service_worker/service_worker_provider_host.h" 10 #include "content/browser/service_worker/service_worker_provider_host.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // add the provider_host's process ref to the version. 90 // add the provider_host's process ref to the version.
91 registration_->SetActiveVersion(version_.get()); 91 registration_->SetActiveVersion(version_.get());
92 ASSERT_TRUE(HasProcessToRun()); 92 ASSERT_TRUE(HasProcessToRun());
93 93
94 // Re-associating the same version and provider_host should just work too. 94 // Re-associating the same version and provider_host should just work too.
95 registration_->SetActiveVersion(version_.get()); 95 registration_->SetActiveVersion(version_.get());
96 ASSERT_TRUE(HasProcessToRun()); 96 ASSERT_TRUE(HasProcessToRun());
97 97
98 // Resetting the provider_host's active version should remove process refs 98 // Resetting the provider_host's active version should remove process refs
99 // from the version. 99 // from the version.
100 provider_host1_->UnassociateRegistration(); 100 provider_host1_->DisassociateRegistration();
101 ASSERT_FALSE(HasProcessToRun()); 101 ASSERT_FALSE(HasProcessToRun());
102 } 102 }
103 103
104 TEST_F(ServiceWorkerProviderHostTest, 104 TEST_F(ServiceWorkerProviderHostTest,
105 SetActiveVersion_MultipleHostsForSameProcess) { 105 SetActiveVersion_MultipleHostsForSameProcess) {
106 provider_host1_->AssociateRegistration(registration_.get()); 106 provider_host1_->AssociateRegistration(registration_.get());
107 provider_host2_->AssociateRegistration(registration_.get()); 107 provider_host2_->AssociateRegistration(registration_.get());
108 ASSERT_TRUE(HasProcessToRun()); 108 ASSERT_TRUE(HasProcessToRun());
109 109
110 // Associating version_ to two providers as active version. 110 // Associating version_ to two providers as active version.
111 registration_->SetActiveVersion(version_.get()); 111 registration_->SetActiveVersion(version_.get());
112 ASSERT_TRUE(HasProcessToRun()); 112 ASSERT_TRUE(HasProcessToRun());
113 113
114 // Disassociating one provider_host shouldn't remove all process refs 114 // Disassociating one provider_host shouldn't remove all process refs
115 // from the version yet. 115 // from the version yet.
116 provider_host1_->UnassociateRegistration(); 116 provider_host1_->DisassociateRegistration();
117 ASSERT_TRUE(HasProcessToRun()); 117 ASSERT_TRUE(HasProcessToRun());
118 118
119 // Disassociating the other provider_host will remove all process refs. 119 // Disassociating the other provider_host will remove all process refs.
120 provider_host2_->UnassociateRegistration(); 120 provider_host2_->DisassociateRegistration();
121 ASSERT_FALSE(HasProcessToRun()); 121 ASSERT_FALSE(HasProcessToRun());
122 } 122 }
123 123
124 TEST_F(ServiceWorkerProviderHostTest, SetWaitingVersion_ProcessStatus) { 124 TEST_F(ServiceWorkerProviderHostTest, SetWaitingVersion_ProcessStatus) {
125 provider_host1_->AssociateRegistration(registration_.get()); 125 provider_host1_->AssociateRegistration(registration_.get());
126 ASSERT_TRUE(HasProcessToRun()); 126 ASSERT_TRUE(HasProcessToRun());
127 127
128 // Associating version_ to a provider_host's waiting version will internally 128 // Associating version_ to a provider_host's waiting version will internally
129 // add the provider_host's process ref to the version. 129 // add the provider_host's process ref to the version.
130 registration_->SetWaitingVersion(version_.get()); 130 registration_->SetWaitingVersion(version_.get());
131 ASSERT_TRUE(HasProcessToRun()); 131 ASSERT_TRUE(HasProcessToRun());
132 132
133 // Re-associating the same version and provider_host should just work too. 133 // Re-associating the same version and provider_host should just work too.
134 registration_->SetWaitingVersion(version_.get()); 134 registration_->SetWaitingVersion(version_.get());
135 ASSERT_TRUE(HasProcessToRun()); 135 ASSERT_TRUE(HasProcessToRun());
136 136
137 // Resetting the provider_host's waiting version should remove process refs 137 // Resetting the provider_host's waiting version should remove process refs
138 // from the version. 138 // from the version.
139 provider_host1_->UnassociateRegistration(); 139 provider_host1_->DisassociateRegistration();
140 ASSERT_FALSE(HasProcessToRun()); 140 ASSERT_FALSE(HasProcessToRun());
141 } 141 }
142 142
143 TEST_F(ServiceWorkerProviderHostTest, 143 TEST_F(ServiceWorkerProviderHostTest,
144 SetWaitingVersion_MultipleHostsForSameProcess) { 144 SetWaitingVersion_MultipleHostsForSameProcess) {
145 provider_host1_->AssociateRegistration(registration_.get()); 145 provider_host1_->AssociateRegistration(registration_.get());
146 provider_host2_->AssociateRegistration(registration_.get()); 146 provider_host2_->AssociateRegistration(registration_.get());
147 ASSERT_TRUE(HasProcessToRun()); 147 ASSERT_TRUE(HasProcessToRun());
148 148
149 // Associating version_ to two providers as waiting version. 149 // Associating version_ to two providers as waiting version.
150 registration_->SetWaitingVersion(version_.get()); 150 registration_->SetWaitingVersion(version_.get());
151 ASSERT_TRUE(HasProcessToRun()); 151 ASSERT_TRUE(HasProcessToRun());
152 152
153 // Disassociating one provider_host shouldn't remove all process refs 153 // Disassociating one provider_host shouldn't remove all process refs
154 // from the version yet. 154 // from the version yet.
155 provider_host1_->UnassociateRegistration(); 155 provider_host1_->DisassociateRegistration();
156 ASSERT_TRUE(HasProcessToRun()); 156 ASSERT_TRUE(HasProcessToRun());
157 157
158 // Disassociating the other provider_host will remove all process refs. 158 // Disassociating the other provider_host will remove all process refs.
159 provider_host2_->UnassociateRegistration(); 159 provider_host2_->DisassociateRegistration();
160 ASSERT_FALSE(HasProcessToRun()); 160 ASSERT_FALSE(HasProcessToRun());
161 } 161 }
162 162
163 TEST_F(ServiceWorkerProviderHostTest, 163 TEST_F(ServiceWorkerProviderHostTest,
164 ObserveVersionAttributesChanged_Basic) { 164 ObserveVersionAttributesChanged_Basic) {
165 provider_host1_->AssociateRegistration(registration_.get()); 165 provider_host1_->AssociateRegistration(registration_.get());
166 provider_host2_->AssociateRegistration(registration_.get()); 166 provider_host2_->AssociateRegistration(registration_.get());
167 VerifyVersionAttributes(provider_host1_, NULL, NULL, NULL); 167 VerifyVersionAttributes(provider_host1_, NULL, NULL, NULL);
168 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL); 168 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL);
169 169
170 registration_->SetInstallingVersion(version_.get()); 170 registration_->SetInstallingVersion(version_.get());
171 VerifyVersionAttributes(provider_host1_, version_.get(), NULL, NULL); 171 VerifyVersionAttributes(provider_host1_, version_.get(), NULL, NULL);
172 VerifyVersionAttributes(provider_host2_, version_.get(), NULL, NULL); 172 VerifyVersionAttributes(provider_host2_, version_.get(), NULL, NULL);
173 173
174 registration_->SetWaitingVersion(version_.get()); 174 registration_->SetWaitingVersion(version_.get());
175 VerifyVersionAttributes(provider_host1_, NULL, version_.get(), NULL); 175 VerifyVersionAttributes(provider_host1_, NULL, version_.get(), NULL);
176 VerifyVersionAttributes(provider_host2_, NULL, version_.get(), NULL); 176 VerifyVersionAttributes(provider_host2_, NULL, version_.get(), NULL);
177 177
178 // Disassociating the registration should clear all version attributes. 178 // Disassociating the registration should clear all version attributes.
179 provider_host2_->UnassociateRegistration(); 179 provider_host2_->DisassociateRegistration();
180 VerifyVersionAttributes(provider_host1_, NULL, version_.get(), NULL); 180 VerifyVersionAttributes(provider_host1_, NULL, version_.get(), NULL);
181 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL); 181 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL);
182 182
183 // Shouldn't notify the disassociated provider of the change. 183 // Shouldn't notify the disassociated provider of the change.
184 registration_->SetActiveVersion(version_.get()); 184 registration_->SetActiveVersion(version_.get());
185 VerifyVersionAttributes(provider_host1_, NULL, NULL, version_.get()); 185 VerifyVersionAttributes(provider_host1_, NULL, NULL, version_.get());
186 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL); 186 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL);
187 } 187 }
188 188
189 TEST_F(ServiceWorkerProviderHostTest, 189 TEST_F(ServiceWorkerProviderHostTest,
(...skipping 16 matching lines...) Expand all
206 VerifyVersionAttributes(provider_host1_, NULL, version1.get(), NULL); 206 VerifyVersionAttributes(provider_host1_, NULL, version1.get(), NULL);
207 VerifyVersionAttributes(provider_host2_, NULL, version1.get(), NULL); 207 VerifyVersionAttributes(provider_host2_, NULL, version1.get(), NULL);
208 208
209 registration_->SetInstallingVersion(version2.get()); 209 registration_->SetInstallingVersion(version2.get());
210 VerifyVersionAttributes( 210 VerifyVersionAttributes(
211 provider_host1_, version2.get(), version1.get(), NULL); 211 provider_host1_, version2.get(), version1.get(), NULL);
212 VerifyVersionAttributes( 212 VerifyVersionAttributes(
213 provider_host2_, version2.get(), version1.get(), NULL); 213 provider_host2_, version2.get(), version1.get(), NULL);
214 214
215 // Disassociating the registration should clear all version attributes. 215 // Disassociating the registration should clear all version attributes.
216 provider_host2_->UnassociateRegistration(); 216 provider_host2_->DisassociateRegistration();
217 VerifyVersionAttributes( 217 VerifyVersionAttributes(
218 provider_host1_, version2.get(), version1.get(), NULL); 218 provider_host1_, version2.get(), version1.get(), NULL);
219 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL); 219 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL);
220 220
221 // Shouldn't notify the disassociated provider of the change. 221 // Shouldn't notify the disassociated provider of the change.
222 registration_->SetActiveVersion(version1.get()); 222 registration_->SetActiveVersion(version1.get());
223 VerifyVersionAttributes( 223 VerifyVersionAttributes(
224 provider_host1_, version2.get(), NULL, version1.get()); 224 provider_host1_, version2.get(), NULL, version1.get());
225 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL); 225 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL);
226 226
227 registration_->SetActiveVersion(version2.get()); 227 registration_->SetActiveVersion(version2.get());
228 VerifyVersionAttributes(provider_host1_, NULL, NULL, version2.get()); 228 VerifyVersionAttributes(provider_host1_, NULL, NULL, version2.get());
229 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL); 229 VerifyVersionAttributes(provider_host2_, NULL, NULL, NULL);
230 } 230 }
231 231
232 } // namespace content 232 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698