| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
| 9 #include "content/browser/service_worker/embedded_worker_instance.h" | 10 #include "content/browser/service_worker/embedded_worker_instance.h" |
| 10 #include "content/browser/service_worker/embedded_worker_registry.h" | 11 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 11 #include "content/browser/service_worker/service_worker_context_core.h" | 12 #include "content/browser/service_worker/service_worker_context_core.h" |
| 12 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 13 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 13 #include "content/browser/service_worker/service_worker_registration.h" | 14 #include "content/browser/service_worker/service_worker_registration.h" |
| 14 #include "content/browser/service_worker/service_worker_test_utils.h" | 15 #include "content/browser/service_worker/service_worker_test_utils.h" |
| 15 #include "content/browser/service_worker/service_worker_version.h" | 16 #include "content/browser/service_worker/service_worker_version.h" |
| 16 #include "content/common/service_worker/service_worker_messages.h" | 17 #include "content/common/service_worker/service_worker_messages.h" |
| 17 #include "content/common/service_worker/service_worker_status_code.h" | 18 #include "content/common/service_worker/service_worker_status_code.h" |
| 18 #include "content/common/service_worker/service_worker_types.h" | 19 #include "content/common/service_worker/service_worker_types.h" |
| 19 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
| 20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
| 22 #include "content/public/browser/storage_partition.h" | 23 #include "content/public/browser/storage_partition.h" |
| 23 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
| 25 #include "content/public/test/content_browser_test.h" | 26 #include "content/public/test/content_browser_test.h" |
| 26 #include "content/public/test/content_browser_test_utils.h" | 27 #include "content/public/test/content_browser_test_utils.h" |
| 27 #include "content/shell/browser/shell.h" | 28 #include "content/shell/browser/shell.h" |
| 28 #include "net/test/embedded_test_server/embedded_test_server.h" | 29 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 30 #include "webkit/browser/blob/blob_data_handle.h" |
| 31 #include "webkit/browser/blob/blob_storage_context.h" |
| 32 #include "webkit/common/blob/blob_data.h" |
| 29 | 33 |
| 30 namespace content { | 34 namespace content { |
| 31 | 35 |
| 32 namespace { | 36 namespace { |
| 33 | 37 |
| 34 struct FetchResult { | 38 struct FetchResult { |
| 35 ServiceWorkerStatusCode status; | 39 ServiceWorkerStatusCode status; |
| 36 ServiceWorkerFetchEventResult result; | 40 ServiceWorkerFetchEventResult result; |
| 37 ServiceWorkerResponse response; | 41 ServiceWorkerResponse response; |
| 38 }; | 42 }; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit); | 87 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit); |
| 84 } | 88 } |
| 85 | 89 |
| 86 ServiceWorkerVersion::FetchCallback CreateResponseReceiver( | 90 ServiceWorkerVersion::FetchCallback CreateResponseReceiver( |
| 87 BrowserThread::ID run_quit_thread, | 91 BrowserThread::ID run_quit_thread, |
| 88 const base::Closure& quit, | 92 const base::Closure& quit, |
| 89 FetchResult* result) { | 93 FetchResult* result) { |
| 90 return base::Bind(&ReceiveFetchResult, run_quit_thread, quit, result); | 94 return base::Bind(&ReceiveFetchResult, run_quit_thread, quit, result); |
| 91 } | 95 } |
| 92 | 96 |
| 97 void ReadResponseBody(std::string* body, |
| 98 scoped_refptr<ChromeBlobStorageContext> context, |
| 99 std::string blob_uuid) { |
| 100 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle = |
| 101 context->context()->GetBlobDataFromUUID(blob_uuid); |
| 102 ASSERT_EQ(1U, blob_data_handle->data()->items().size()); |
| 103 *body = std::string(blob_data_handle->data()->items()[0].bytes(), |
| 104 blob_data_handle->data()->items()[0].length()); |
| 105 } |
| 106 |
| 93 } // namespace | 107 } // namespace |
| 94 | 108 |
| 95 class ServiceWorkerBrowserTest : public ContentBrowserTest { | 109 class ServiceWorkerBrowserTest : public ContentBrowserTest { |
| 96 protected: | 110 protected: |
| 97 typedef ServiceWorkerBrowserTest self; | 111 typedef ServiceWorkerBrowserTest self; |
| 98 | 112 |
| 99 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 113 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 100 command_line->AppendSwitch(switches::kEnableServiceWorker); | 114 command_line->AppendSwitch(switches::kEnableServiceWorker); |
| 101 } | 115 } |
| 102 | 116 |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 ServiceWorkerFetchEventResult result; | 481 ServiceWorkerFetchEventResult result; |
| 468 ServiceWorkerResponse response; | 482 ServiceWorkerResponse response; |
| 469 FetchTestHelper("/service_worker/fetch_event.js", &result, &response); | 483 FetchTestHelper("/service_worker/fetch_event.js", &result, &response); |
| 470 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, result); | 484 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, result); |
| 471 EXPECT_EQ(301, response.status_code); | 485 EXPECT_EQ(301, response.status_code); |
| 472 EXPECT_EQ("Moved Permanently", response.status_text); | 486 EXPECT_EQ("Moved Permanently", response.status_text); |
| 473 std::map<std::string, std::string> expected_headers; | 487 std::map<std::string, std::string> expected_headers; |
| 474 expected_headers["Content-Language"] = "fi"; | 488 expected_headers["Content-Language"] = "fi"; |
| 475 expected_headers["Content-Type"] = "text/html; charset=UTF-8"; | 489 expected_headers["Content-Type"] = "text/html; charset=UTF-8"; |
| 476 EXPECT_EQ(expected_headers, response.headers); | 490 EXPECT_EQ(expected_headers, response.headers); |
| 491 |
| 492 scoped_refptr<ChromeBlobStorageContext> context = |
| 493 ChromeBlobStorageContext::GetFor( |
| 494 shell()->web_contents()->GetBrowserContext()); |
| 495 std::string body; |
| 496 RunOnIOThread( |
| 497 base::Bind(&ReadResponseBody, &body, context, response.blob_uuid)); |
| 498 EXPECT_EQ("This resource is gone. Gone, gone, gone.", body); |
| 477 } | 499 } |
| 478 | 500 |
| 479 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, | 501 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, |
| 480 FetchEvent_FallbackToNative) { | |
| 481 ServiceWorkerFetchEventResult result; | |
| 482 ServiceWorkerResponse response; | |
| 483 FetchTestHelper( | |
| 484 "/service_worker/fetch_event_fallback.js", &result, &response); | |
| 485 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, result); | |
| 486 } | |
| 487 | |
| 488 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, FetchEvent_Rejected) { | |
| 489 ServiceWorkerFetchEventResult result; | |
| 490 ServiceWorkerResponse response; | |
| 491 FetchTestHelper("/service_worker/fetch_event_error.js", &result, &response); | |
| 492 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, result); | |
| 493 } | |
| 494 | |
| 495 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, | |
| 496 SyncAbortedWithoutFlag) { | 502 SyncAbortedWithoutFlag) { |
| 497 RunOnIOThread(base::Bind( | 503 RunOnIOThread(base::Bind( |
| 498 &self::SetUpRegistrationOnIOThread, this, "/service_worker/sync.js")); | 504 &self::SetUpRegistrationOnIOThread, this, "/service_worker/sync.js")); |
| 499 | 505 |
| 500 // Run the sync event. | 506 // Run the sync event. |
| 501 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | 507 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
| 502 base::RunLoop sync_run_loop; | 508 base::RunLoop sync_run_loop; |
| 503 BrowserThread::PostTask(BrowserThread::IO, | 509 BrowserThread::PostTask(BrowserThread::IO, |
| 504 FROM_HERE, | 510 FROM_HERE, |
| 505 base::Bind(&self::SyncEventOnIOThread, | 511 base::Bind(&self::SyncEventOnIOThread, |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, | 679 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, |
| 674 this, | 680 this, |
| 675 embedded_test_server()->GetURL("/service_worker/empty.html"), | 681 embedded_test_server()->GetURL("/service_worker/empty.html"), |
| 676 &status, | 682 &status, |
| 677 &script_url)); | 683 &script_url)); |
| 678 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); | 684 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); |
| 679 } | 685 } |
| 680 } | 686 } |
| 681 | 687 |
| 682 } // namespace content | 688 } // namespace content |
| OLD | NEW |