| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 17 #include "base/time/time.h" |
| 17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 18 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 19 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
| 19 #include "content/browser/service_worker/embedded_worker_instance.h" | 20 #include "content/browser/service_worker/embedded_worker_instance.h" |
| 20 #include "content/browser/service_worker/embedded_worker_registry.h" | 21 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 21 #include "content/browser/service_worker/service_worker_context_core.h" | 22 #include "content/browser/service_worker/service_worker_context_core.h" |
| 22 #include "content/browser/service_worker/service_worker_context_observer.h" | 23 #include "content/browser/service_worker/service_worker_context_observer.h" |
| 23 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 24 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 24 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" | 25 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" |
| 25 #include "content/browser/service_worker/service_worker_registration.h" | 26 #include "content/browser/service_worker/service_worker_registration.h" |
| 26 #include "content/browser/service_worker/service_worker_test_utils.h" | 27 #include "content/browser/service_worker/service_worker_test_utils.h" |
| (...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 EXPECT_EQ(expected_headers, response.headers); | 943 EXPECT_EQ(expected_headers, response.headers); |
| 943 | 944 |
| 944 std::string body; | 945 std::string body; |
| 945 RunOnIOThread( | 946 RunOnIOThread( |
| 946 base::Bind(&ReadResponseBody, | 947 base::Bind(&ReadResponseBody, |
| 947 &body, base::Owned(blob_data_handle.release()))); | 948 &body, base::Owned(blob_data_handle.release()))); |
| 948 EXPECT_EQ("This resource is gone. Gone, gone, gone.", body); | 949 EXPECT_EQ("This resource is gone. Gone, gone, gone.", body); |
| 949 } | 950 } |
| 950 | 951 |
| 951 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, | 952 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, |
| 953 FetchEvent_ResponseTime) { |
| 954 ServiceWorkerFetchEventResult result; |
| 955 ServiceWorkerResponse response1; |
| 956 ServiceWorkerResponse response2; |
| 957 scoped_ptr<storage::BlobDataHandle> blob_data_handle; |
| 958 const base::Time start_time(base::Time::Now()); |
| 959 |
| 960 RunOnIOThread( |
| 961 base::Bind(&self::SetUpRegistrationOnIOThread, this, |
| 962 "/service_worker/fetch_event_response_via_cache.js")); |
| 963 |
| 964 FetchOnRegisteredWorker(&result, &response1, &blob_data_handle); |
| 965 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, result); |
| 966 EXPECT_EQ(200, response1.status_code); |
| 967 EXPECT_EQ("OK", response1.status_text); |
| 968 EXPECT_TRUE(response1.response_time >= start_time); |
| 969 |
| 970 FetchOnRegisteredWorker(&result, &response2, &blob_data_handle); |
| 971 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, result); |
| 972 EXPECT_EQ(200, response2.status_code); |
| 973 EXPECT_EQ("OK", response2.status_text); |
| 974 EXPECT_EQ(response1.response_time, response2.response_time); |
| 975 } |
| 976 |
| 977 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, |
| 952 FetchEvent_respondWithRejection) { | 978 FetchEvent_respondWithRejection) { |
| 953 ServiceWorkerFetchEventResult result; | 979 ServiceWorkerFetchEventResult result; |
| 954 ServiceWorkerResponse response; | 980 ServiceWorkerResponse response; |
| 955 scoped_ptr<storage::BlobDataHandle> blob_data_handle; | 981 scoped_ptr<storage::BlobDataHandle> blob_data_handle; |
| 956 | 982 |
| 957 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this, | 983 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this, |
| 958 "/service_worker/fetch_event_rejected.js")); | 984 "/service_worker/fetch_event_rejected.js")); |
| 959 | 985 |
| 960 ConsoleListener console_listener; | 986 ConsoleListener console_listener; |
| 961 version_->embedded_worker()->AddListener(&console_listener); | 987 version_->embedded_worker()->AddListener(&console_listener); |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1312 ASSERT_EQ(SERVICE_WORKER_OK, status); | 1338 ASSERT_EQ(SERVICE_WORKER_OK, status); |
| 1313 // Stop the worker. | 1339 // Stop the worker. |
| 1314 StopWorker(SERVICE_WORKER_OK); | 1340 StopWorker(SERVICE_WORKER_OK); |
| 1315 // Restart the worker. | 1341 // Restart the worker. |
| 1316 StartWorker(SERVICE_WORKER_OK); | 1342 StartWorker(SERVICE_WORKER_OK); |
| 1317 // Stop the worker. | 1343 // Stop the worker. |
| 1318 StopWorker(SERVICE_WORKER_OK); | 1344 StopWorker(SERVICE_WORKER_OK); |
| 1319 } | 1345 } |
| 1320 | 1346 |
| 1321 } // namespace content | 1347 } // namespace content |
| OLD | NEW |