Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "content/browser/service_worker/service_worker_controllee_request_handl er.h" | 5 #include "content/browser/service_worker/service_worker_controllee_request_handl er.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 } | 124 } |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 TEST_F(ServiceWorkerControlleeRequestHandlerTest, DisallowServiceWorker) { | 127 TEST_F(ServiceWorkerControlleeRequestHandlerTest, DisallowServiceWorker) { |
| 128 ServiceWorkerTestContentBrowserClient test_browser_client; | 128 ServiceWorkerTestContentBrowserClient test_browser_client; |
| 129 ContentBrowserClient* old_browser_client = | 129 ContentBrowserClient* old_browser_client = |
| 130 SetBrowserClientForTesting(&test_browser_client); | 130 SetBrowserClientForTesting(&test_browser_client); |
| 131 | 131 |
| 132 // Store an activated worker. | 132 // Store an activated worker. |
| 133 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); | 133 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); |
| 134 version_->set_has_fetch_handler(true); | |
| 134 registration_->SetActiveVersion(version_); | 135 registration_->SetActiveVersion(version_); |
| 135 context()->storage()->StoreRegistration( | 136 context()->storage()->StoreRegistration( |
| 136 registration_.get(), | 137 registration_.get(), |
| 137 version_.get(), | 138 version_.get(), |
| 138 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 139 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 139 base::RunLoop().RunUntilIdle(); | 140 base::RunLoop().RunUntilIdle(); |
| 140 | 141 |
| 141 // Conduct a main resource load. | 142 // Conduct a main resource load. |
| 142 const GURL kDocUrl("http://host/scope/doc"); | 143 const GURL kDocUrl("http://host/scope/doc"); |
| 143 std::unique_ptr<net::URLRequest> request = url_request_context_.CreateRequest( | 144 std::unique_ptr<net::URLRequest> request = url_request_context_.CreateRequest( |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 164 EXPECT_TRUE(sw_job->ShouldFallbackToNetwork()); | 165 EXPECT_TRUE(sw_job->ShouldFallbackToNetwork()); |
| 165 EXPECT_FALSE(sw_job->ShouldForwardToServiceWorker()); | 166 EXPECT_FALSE(sw_job->ShouldForwardToServiceWorker()); |
| 166 EXPECT_FALSE(version_->HasControllee()); | 167 EXPECT_FALSE(version_->HasControllee()); |
| 167 | 168 |
| 168 SetBrowserClientForTesting(old_browser_client); | 169 SetBrowserClientForTesting(old_browser_client); |
| 169 } | 170 } |
| 170 | 171 |
| 171 TEST_F(ServiceWorkerControlleeRequestHandlerTest, ActivateWaitingVersion) { | 172 TEST_F(ServiceWorkerControlleeRequestHandlerTest, ActivateWaitingVersion) { |
| 172 // Store a registration that is installed but not activated yet. | 173 // Store a registration that is installed but not activated yet. |
| 173 version_->SetStatus(ServiceWorkerVersion::INSTALLED); | 174 version_->SetStatus(ServiceWorkerVersion::INSTALLED); |
| 175 version_->set_has_fetch_handler(true); | |
| 174 registration_->SetWaitingVersion(version_); | 176 registration_->SetWaitingVersion(version_); |
| 175 context()->storage()->StoreRegistration( | 177 context()->storage()->StoreRegistration( |
| 176 registration_.get(), | 178 registration_.get(), |
| 177 version_.get(), | 179 version_.get(), |
| 178 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 180 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 179 base::RunLoop().RunUntilIdle(); | 181 base::RunLoop().RunUntilIdle(); |
| 180 | 182 |
| 181 // Conduct a main resource load. | 183 // Conduct a main resource load. |
| 182 const GURL kDocUrl("http://host/scope/doc"); | 184 const GURL kDocUrl("http://host/scope/doc"); |
| 183 std::unique_ptr<net::URLRequest> request = url_request_context_.CreateRequest( | 185 std::unique_ptr<net::URLRequest> request = url_request_context_.CreateRequest( |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 209 | 211 |
| 210 // Navigations should trigger an update too. | 212 // Navigations should trigger an update too. |
| 211 handler.reset(NULL); | 213 handler.reset(NULL); |
| 212 EXPECT_TRUE(version_->update_timer_.IsRunning()); | 214 EXPECT_TRUE(version_->update_timer_.IsRunning()); |
| 213 } | 215 } |
| 214 | 216 |
| 215 // Test that an installing registration is associated with a provider host. | 217 // Test that an installing registration is associated with a provider host. |
| 216 TEST_F(ServiceWorkerControlleeRequestHandlerTest, InstallingRegistration) { | 218 TEST_F(ServiceWorkerControlleeRequestHandlerTest, InstallingRegistration) { |
| 217 // Create an installing registration. | 219 // Create an installing registration. |
| 218 version_->SetStatus(ServiceWorkerVersion::INSTALLING); | 220 version_->SetStatus(ServiceWorkerVersion::INSTALLING); |
| 221 version_->set_has_fetch_handler(true); | |
| 219 registration_->SetInstallingVersion(version_); | 222 registration_->SetInstallingVersion(version_); |
| 220 context()->storage()->NotifyInstallingRegistration(registration_.get()); | 223 context()->storage()->NotifyInstallingRegistration(registration_.get()); |
| 221 | 224 |
| 222 // Conduct a main resource load. | 225 // Conduct a main resource load. |
| 223 const GURL kDocUrl("http://host/scope/doc"); | 226 const GURL kDocUrl("http://host/scope/doc"); |
| 224 std::unique_ptr<net::URLRequest> request = url_request_context_.CreateRequest( | 227 std::unique_ptr<net::URLRequest> request = url_request_context_.CreateRequest( |
| 225 kDocUrl, net::DEFAULT_PRIORITY, &url_request_delegate_); | 228 kDocUrl, net::DEFAULT_PRIORITY, &url_request_delegate_); |
| 226 std::unique_ptr<ServiceWorkerControlleeRequestHandler> handler( | 229 std::unique_ptr<ServiceWorkerControlleeRequestHandler> handler( |
| 227 new ServiceWorkerControlleeRequestHandler( | 230 new ServiceWorkerControlleeRequestHandler( |
| 228 context()->AsWeakPtr(), provider_host_, | 231 context()->AsWeakPtr(), provider_host_, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 243 EXPECT_EQ(version_.get(), provider_host_->installing_version()); | 246 EXPECT_EQ(version_.get(), provider_host_->installing_version()); |
| 244 EXPECT_FALSE(version_->HasControllee()); | 247 EXPECT_FALSE(version_->HasControllee()); |
| 245 EXPECT_FALSE(provider_host_->controlling_version()); | 248 EXPECT_FALSE(provider_host_->controlling_version()); |
| 246 } | 249 } |
| 247 | 250 |
| 248 // Test to not regress crbug/414118. | 251 // Test to not regress crbug/414118. |
| 249 TEST_F(ServiceWorkerControlleeRequestHandlerTest, DeletedProviderHost) { | 252 TEST_F(ServiceWorkerControlleeRequestHandlerTest, DeletedProviderHost) { |
| 250 // Store a registration so the call to FindRegistrationForDocument will read | 253 // Store a registration so the call to FindRegistrationForDocument will read |
| 251 // from the database. | 254 // from the database. |
| 252 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); | 255 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); |
| 256 version_->set_has_fetch_handler(true); | |
| 253 registration_->SetActiveVersion(version_); | 257 registration_->SetActiveVersion(version_); |
| 254 context()->storage()->StoreRegistration( | 258 context()->storage()->StoreRegistration( |
| 255 registration_.get(), | 259 registration_.get(), |
| 256 version_.get(), | 260 version_.get(), |
| 257 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 261 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 258 base::RunLoop().RunUntilIdle(); | 262 base::RunLoop().RunUntilIdle(); |
| 259 version_ = NULL; | 263 version_ = NULL; |
| 260 registration_ = NULL; | 264 registration_ = NULL; |
| 261 | 265 |
| 262 // Conduct a main resource load. | 266 // Conduct a main resource load. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 282 // Shouldn't crash if the ProviderHost is deleted prior to completion of | 286 // Shouldn't crash if the ProviderHost is deleted prior to completion of |
| 283 // the database lookup. | 287 // the database lookup. |
| 284 context()->RemoveProviderHost(helper_->mock_render_process_id(), | 288 context()->RemoveProviderHost(helper_->mock_render_process_id(), |
| 285 kMockProviderId); | 289 kMockProviderId); |
| 286 EXPECT_FALSE(provider_host_.get()); | 290 EXPECT_FALSE(provider_host_.get()); |
| 287 base::RunLoop().RunUntilIdle(); | 291 base::RunLoop().RunUntilIdle(); |
| 288 EXPECT_TRUE(sw_job->ShouldFallbackToNetwork()); | 292 EXPECT_TRUE(sw_job->ShouldFallbackToNetwork()); |
| 289 EXPECT_FALSE(sw_job->ShouldForwardToServiceWorker()); | 293 EXPECT_FALSE(sw_job->ShouldForwardToServiceWorker()); |
| 290 } | 294 } |
| 291 | 295 |
| 296 TEST_F(ServiceWorkerControlleeRequestHandlerTest, FallbackWithNoFetchHandler) { | |
| 297 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); | |
| 298 version_->set_has_fetch_handler(false); | |
| 299 registration_->SetActiveVersion(version_); | |
| 300 context()->storage()->StoreRegistration( | |
| 301 registration_.get(), version_.get(), | |
| 302 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | |
| 303 base::RunLoop().RunUntilIdle(); | |
| 304 | |
| 305 // Conduct a main resource load. | |
| 306 const GURL kDocUrl("http://host/scope/doc"); | |
| 307 std::unique_ptr<net::URLRequest> request = url_request_context_.CreateRequest( | |
| 308 kDocUrl, net::DEFAULT_PRIORITY, &url_request_delegate_); | |
| 309 std::unique_ptr<ServiceWorkerControlleeRequestHandler> handler( | |
| 310 new ServiceWorkerControlleeRequestHandler( | |
| 311 context()->AsWeakPtr(), provider_host_, | |
| 312 base::WeakPtr<storage::BlobStorageContext>(), | |
| 313 FETCH_REQUEST_MODE_NO_CORS, FETCH_CREDENTIALS_MODE_OMIT, | |
| 314 FetchRedirectMode::FOLLOW_MODE, RESOURCE_TYPE_MAIN_FRAME, | |
| 315 REQUEST_CONTEXT_TYPE_HYPERLINK, REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL, | |
| 316 scoped_refptr<ResourceRequestBody>())); | |
| 317 std::unique_ptr<net::URLRequestJob> job( | |
| 318 handler->MaybeCreateJob(request.get(), nullptr, &mock_resource_context_)); | |
| 319 ServiceWorkerURLRequestJob* sw_job = | |
| 320 static_cast<ServiceWorkerURLRequestJob*>(job.get()); | |
| 321 | |
| 322 EXPECT_FALSE(sw_job->ShouldFallbackToNetwork()); | |
| 323 EXPECT_FALSE(sw_job->ShouldForwardToServiceWorker()); | |
| 324 EXPECT_FALSE(version_->HasControllee()); | |
| 325 | |
| 326 base::RunLoop().RunUntilIdle(); | |
| 327 | |
| 328 EXPECT_TRUE(sw_job->ShouldFallbackToNetwork()); | |
| 329 EXPECT_FALSE(sw_job->ShouldForwardToServiceWorker()); | |
| 330 EXPECT_TRUE(version_->HasControllee()); | |
| 331 EXPECT_EQ(version_, provider_host_->controlling_version()); | |
|
falken
2016/05/30 06:11:29
Would it be possible to add a test for the subreso
shimazu
2016/05/30 09:45:33
Done.
Could you take a look if this null check is
| |
| 332 } | |
|
falken
2016/05/30 06:11:29
We usually add a blink line here, but I won't comp
shimazu
2016/05/30 09:45:33
git-cl format accepts w/ and w/o a blank line.
Ad
| |
| 292 } // namespace content | 333 } // namespace content |
| OLD | NEW |