| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/foreign_fetch_request_handler.h" | 5 #include "content/browser/service_worker/foreign_fetch_request_handler.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/test/simple_test_tick_clock.h" | 9 #include "base/test/simple_test_tick_clock.h" |
| 10 #include "content/browser/browser_thread_impl.h" | 10 #include "content/browser/browser_thread_impl.h" |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 TEST_F(ForeignFetchRequestHandlerTest, InitializeHandler_TimeoutBehavior) { | 329 TEST_F(ForeignFetchRequestHandlerTest, InitializeHandler_TimeoutBehavior) { |
| 330 ForeignFetchRequestHandler* handler = | 330 ForeignFetchRequestHandler* handler = |
| 331 InitializeHandler("https://valid.example.com/foo", RESOURCE_TYPE_IMAGE, | 331 InitializeHandler("https://valid.example.com/foo", RESOURCE_TYPE_IMAGE, |
| 332 nullptr /* initiator */); | 332 nullptr /* initiator */); |
| 333 ASSERT_TRUE(handler); | 333 ASSERT_TRUE(handler); |
| 334 | 334 |
| 335 EXPECT_EQ(base::nullopt, timeout_for_request(handler)); | 335 EXPECT_EQ(base::nullopt, timeout_for_request(handler)); |
| 336 | 336 |
| 337 CreateServiceWorkerTypeProviderHost(); | 337 CreateServiceWorkerTypeProviderHost(); |
| 338 ServiceWorkerVersion* version = provider_host()->running_hosted_version(); | 338 ServiceWorkerVersion* version = provider_host()->running_hosted_version(); |
| 339 std::unique_ptr<net::HttpResponseInfo> http_info( |
| 340 CreateTestHttpResponseInfo()); |
| 341 version->SetMainScriptHttpResponseInfo(*http_info); |
| 339 | 342 |
| 340 // Set mock clock on version to check timeout behavior. | 343 // Set mock clock on version to check timeout behavior. |
| 341 base::SimpleTestTickClock* tick_clock = new base::SimpleTestTickClock(); | 344 base::SimpleTestTickClock* tick_clock = new base::SimpleTestTickClock(); |
| 342 tick_clock->SetNowTicks(base::TimeTicks::Now()); | 345 tick_clock->SetNowTicks(base::TimeTicks::Now()); |
| 343 version->SetTickClockForTesting(base::WrapUnique(tick_clock)); | 346 version->SetTickClockForTesting(base::WrapUnique(tick_clock)); |
| 344 | 347 |
| 345 // Make sure worker has a non-zero timeout. | 348 // Make sure worker has a non-zero timeout. |
| 346 version->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, | 349 version->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, |
| 347 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 350 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 348 base::RunLoop().RunUntilIdle(); | 351 base::RunLoop().RunUntilIdle(); |
| 349 version->StartRequestWithCustomTimeout( | 352 version->StartRequestWithCustomTimeout( |
| 350 ServiceWorkerMetrics::EventType::ACTIVATE, | 353 ServiceWorkerMetrics::EventType::ACTIVATE, |
| 351 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback), | 354 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback), |
| 352 base::TimeDelta::FromSeconds(10), ServiceWorkerVersion::KILL_ON_TIMEOUT); | 355 base::TimeDelta::FromSeconds(10), ServiceWorkerVersion::KILL_ON_TIMEOUT); |
| 353 | 356 |
| 354 // Advance clock by a couple seconds. | 357 // Advance clock by a couple seconds. |
| 355 tick_clock->Advance(base::TimeDelta::FromSeconds(4)); | 358 tick_clock->Advance(base::TimeDelta::FromSeconds(4)); |
| 356 base::TimeDelta remaining_time = version->remaining_timeout(); | 359 base::TimeDelta remaining_time = version->remaining_timeout(); |
| 357 EXPECT_EQ(base::TimeDelta::FromSeconds(6), remaining_time); | 360 EXPECT_EQ(base::TimeDelta::FromSeconds(6), remaining_time); |
| 358 | 361 |
| 359 // Make sure new request only gets remaining timeout. | 362 // Make sure new request only gets remaining timeout. |
| 360 handler = InitializeHandler("https://valid.example.com/foo", | 363 handler = InitializeHandler("https://valid.example.com/foo", |
| 361 RESOURCE_TYPE_IMAGE, nullptr /* initiator */); | 364 RESOURCE_TYPE_IMAGE, nullptr /* initiator */); |
| 362 ASSERT_TRUE(handler); | 365 ASSERT_TRUE(handler); |
| 363 EXPECT_EQ(remaining_time, timeout_for_request(handler)); | 366 EXPECT_EQ(remaining_time, timeout_for_request(handler)); |
| 364 } | 367 } |
| 365 | 368 |
| 366 } // namespace content | 369 } // namespace content |
| OLD | NEW |