| 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 "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 10 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "content/public/test/browser_test_utils.h" | 28 #include "content/public/test/browser_test_utils.h" |
| 29 #include "content/public/test/content_browser_test.h" | 29 #include "content/public/test/content_browser_test.h" |
| 30 #include "content/public/test/content_browser_test_utils.h" | 30 #include "content/public/test/content_browser_test_utils.h" |
| 31 #include "content/shell/browser/shell.h" | 31 #include "content/shell/browser/shell.h" |
| 32 #include "net/test/embedded_test_server/embedded_test_server.h" | 32 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 33 #include "net/test/embedded_test_server/http_request.h" | 33 #include "net/test/embedded_test_server/http_request.h" |
| 34 #include "net/test/embedded_test_server/http_response.h" | 34 #include "net/test/embedded_test_server/http_response.h" |
| 35 #include "net/url_request/url_request_filter.h" | 35 #include "net/url_request/url_request_filter.h" |
| 36 #include "net/url_request/url_request_interceptor.h" | 36 #include "net/url_request/url_request_interceptor.h" |
| 37 #include "net/url_request/url_request_test_job.h" | 37 #include "net/url_request/url_request_test_job.h" |
| 38 #include "webkit/browser/blob/blob_data_handle.h" | 38 #include "storage/browser/blob/blob_data_handle.h" |
| 39 #include "webkit/browser/blob/blob_storage_context.h" | 39 #include "storage/browser/blob/blob_storage_context.h" |
| 40 #include "webkit/common/blob/blob_data.h" | 40 #include "storage/common/blob/blob_data.h" |
| 41 | 41 |
| 42 namespace content { | 42 namespace content { |
| 43 | 43 |
| 44 namespace { | 44 namespace { |
| 45 | 45 |
| 46 struct FetchResult { | 46 struct FetchResult { |
| 47 ServiceWorkerStatusCode status; | 47 ServiceWorkerStatusCode status; |
| 48 ServiceWorkerFetchEventResult result; | 48 ServiceWorkerFetchEventResult result; |
| 49 ServiceWorkerResponse response; | 49 ServiceWorkerResponse response; |
| 50 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle; | 50 scoped_ptr<storage::BlobDataHandle> blob_data_handle; |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 void RunAndQuit(const base::Closure& closure, | 53 void RunAndQuit(const base::Closure& closure, |
| 54 const base::Closure& quit, | 54 const base::Closure& quit, |
| 55 base::MessageLoopProxy* original_message_loop) { | 55 base::MessageLoopProxy* original_message_loop) { |
| 56 closure.Run(); | 56 closure.Run(); |
| 57 original_message_loop->PostTask(FROM_HERE, quit); | 57 original_message_loop->PostTask(FROM_HERE, quit); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void RunOnIOThread(const base::Closure& closure) { | 60 void RunOnIOThread(const base::Closure& closure) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 BrowserThread::ID run_quit_thread, | 106 BrowserThread::ID run_quit_thread, |
| 107 const base::Closure& quit, | 107 const base::Closure& quit, |
| 108 ChromeBlobStorageContext* blob_context, | 108 ChromeBlobStorageContext* blob_context, |
| 109 FetchResult* result) { | 109 FetchResult* result) { |
| 110 return base::Bind(&ReceiveFetchResult, run_quit_thread, quit, | 110 return base::Bind(&ReceiveFetchResult, run_quit_thread, quit, |
| 111 make_scoped_refptr<ChromeBlobStorageContext>(blob_context), | 111 make_scoped_refptr<ChromeBlobStorageContext>(blob_context), |
| 112 result); | 112 result); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void ReadResponseBody(std::string* body, | 115 void ReadResponseBody(std::string* body, |
| 116 webkit_blob::BlobDataHandle* blob_data_handle) { | 116 storage::BlobDataHandle* blob_data_handle) { |
| 117 ASSERT_TRUE(blob_data_handle); | 117 ASSERT_TRUE(blob_data_handle); |
| 118 ASSERT_EQ(1U, blob_data_handle->data()->items().size()); | 118 ASSERT_EQ(1U, blob_data_handle->data()->items().size()); |
| 119 *body = std::string(blob_data_handle->data()->items()[0].bytes(), | 119 *body = std::string(blob_data_handle->data()->items()[0].bytes(), |
| 120 blob_data_handle->data()->items()[0].length()); | 120 blob_data_handle->data()->items()[0].length()); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void ExpectResultAndRun(bool expected, | 123 void ExpectResultAndRun(bool expected, |
| 124 const base::Closure& continuation, | 124 const base::Closure& continuation, |
| 125 bool actual) { | 125 bool actual) { |
| 126 EXPECT_EQ(expected, actual); | 126 EXPECT_EQ(expected, actual); |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 FROM_HERE, | 456 FROM_HERE, |
| 457 base::Bind( | 457 base::Bind( |
| 458 &self::ActivateOnIOThread, this, run_loop.QuitClosure(), &status)); | 458 &self::ActivateOnIOThread, this, run_loop.QuitClosure(), &status)); |
| 459 run_loop.Run(); | 459 run_loop.Run(); |
| 460 ASSERT_EQ(expected_status, status); | 460 ASSERT_EQ(expected_status, status); |
| 461 } | 461 } |
| 462 | 462 |
| 463 void FetchOnRegisteredWorker( | 463 void FetchOnRegisteredWorker( |
| 464 ServiceWorkerFetchEventResult* result, | 464 ServiceWorkerFetchEventResult* result, |
| 465 ServiceWorkerResponse* response, | 465 ServiceWorkerResponse* response, |
| 466 scoped_ptr<webkit_blob::BlobDataHandle>* blob_data_handle) { | 466 scoped_ptr<storage::BlobDataHandle>* blob_data_handle) { |
| 467 blob_context_ = ChromeBlobStorageContext::GetFor( | 467 blob_context_ = ChromeBlobStorageContext::GetFor( |
| 468 shell()->web_contents()->GetBrowserContext()); | 468 shell()->web_contents()->GetBrowserContext()); |
| 469 FetchResult fetch_result; | 469 FetchResult fetch_result; |
| 470 fetch_result.status = SERVICE_WORKER_ERROR_FAILED; | 470 fetch_result.status = SERVICE_WORKER_ERROR_FAILED; |
| 471 base::RunLoop fetch_run_loop; | 471 base::RunLoop fetch_run_loop; |
| 472 BrowserThread::PostTask(BrowserThread::IO, | 472 BrowserThread::PostTask(BrowserThread::IO, |
| 473 FROM_HERE, | 473 FROM_HERE, |
| 474 base::Bind(&self::FetchOnIOThread, | 474 base::Bind(&self::FetchOnIOThread, |
| 475 this, | 475 this, |
| 476 fetch_run_loop.QuitClosure(), | 476 fetch_run_loop.QuitClosure(), |
| 477 &fetch_result)); | 477 &fetch_result)); |
| 478 fetch_run_loop.Run(); | 478 fetch_run_loop.Run(); |
| 479 *result = fetch_result.result; | 479 *result = fetch_result.result; |
| 480 *response = fetch_result.response; | 480 *response = fetch_result.response; |
| 481 *blob_data_handle = fetch_result.blob_data_handle.Pass(); | 481 *blob_data_handle = fetch_result.blob_data_handle.Pass(); |
| 482 ASSERT_EQ(SERVICE_WORKER_OK, fetch_result.status); | 482 ASSERT_EQ(SERVICE_WORKER_OK, fetch_result.status); |
| 483 } | 483 } |
| 484 | 484 |
| 485 void FetchTestHelper( | 485 void FetchTestHelper(const std::string& worker_url, |
| 486 const std::string& worker_url, | 486 ServiceWorkerFetchEventResult* result, |
| 487 ServiceWorkerFetchEventResult* result, | 487 ServiceWorkerResponse* response, |
| 488 ServiceWorkerResponse* response, | 488 scoped_ptr<storage::BlobDataHandle>* blob_data_handle) { |
| 489 scoped_ptr<webkit_blob::BlobDataHandle>* blob_data_handle) { | |
| 490 RunOnIOThread( | 489 RunOnIOThread( |
| 491 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url)); | 490 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url)); |
| 492 FetchOnRegisteredWorker(result, response, blob_data_handle); | 491 FetchOnRegisteredWorker(result, response, blob_data_handle); |
| 493 } | 492 } |
| 494 | 493 |
| 495 void SetUpRegistrationOnIOThread(const std::string& worker_url) { | 494 void SetUpRegistrationOnIOThread(const std::string& worker_url) { |
| 496 registration_ = new ServiceWorkerRegistration( | 495 registration_ = new ServiceWorkerRegistration( |
| 497 embedded_test_server()->GetURL("/"), | 496 embedded_test_server()->GetURL("/"), |
| 498 embedded_test_server()->GetURL(worker_url), | 497 embedded_test_server()->GetURL(worker_url), |
| 499 wrapper()->context()->storage()->NewRegistrationId(), | 498 wrapper()->context()->storage()->NewRegistrationId(), |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 | 673 |
| 675 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, | 674 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, |
| 676 InstallWithWaitUntil_Rejected) { | 675 InstallWithWaitUntil_Rejected) { |
| 677 InstallTestHelper("/service_worker/worker_install_rejected.js", | 676 InstallTestHelper("/service_worker/worker_install_rejected.js", |
| 678 SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED); | 677 SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED); |
| 679 } | 678 } |
| 680 | 679 |
| 681 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, FetchEvent_Response) { | 680 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, FetchEvent_Response) { |
| 682 ServiceWorkerFetchEventResult result; | 681 ServiceWorkerFetchEventResult result; |
| 683 ServiceWorkerResponse response; | 682 ServiceWorkerResponse response; |
| 684 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle; | 683 scoped_ptr<storage::BlobDataHandle> blob_data_handle; |
| 685 FetchTestHelper("/service_worker/fetch_event.js", | 684 FetchTestHelper("/service_worker/fetch_event.js", |
| 686 &result, &response, &blob_data_handle); | 685 &result, &response, &blob_data_handle); |
| 687 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, result); | 686 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, result); |
| 688 EXPECT_EQ(301, response.status_code); | 687 EXPECT_EQ(301, response.status_code); |
| 689 EXPECT_EQ("Moved Permanently", response.status_text); | 688 EXPECT_EQ("Moved Permanently", response.status_text); |
| 690 std::map<std::string, std::string> expected_headers; | 689 std::map<std::string, std::string> expected_headers; |
| 691 expected_headers["content-language"] = "fi"; | 690 expected_headers["content-language"] = "fi"; |
| 692 expected_headers["content-type"] = "text/html; charset=UTF-8"; | 691 expected_headers["content-type"] = "text/html; charset=UTF-8"; |
| 693 EXPECT_EQ(expected_headers, response.headers); | 692 EXPECT_EQ(expected_headers, response.headers); |
| 694 | 693 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 718 } | 717 } |
| 719 | 718 |
| 720 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, SyncEventHandled) { | 719 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, SyncEventHandled) { |
| 721 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 720 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 722 command_line->AppendSwitch(switches::kEnableServiceWorkerSync); | 721 command_line->AppendSwitch(switches::kEnableServiceWorkerSync); |
| 723 | 722 |
| 724 RunOnIOThread(base::Bind( | 723 RunOnIOThread(base::Bind( |
| 725 &self::SetUpRegistrationOnIOThread, this, "/service_worker/sync.js")); | 724 &self::SetUpRegistrationOnIOThread, this, "/service_worker/sync.js")); |
| 726 ServiceWorkerFetchEventResult result; | 725 ServiceWorkerFetchEventResult result; |
| 727 ServiceWorkerResponse response; | 726 ServiceWorkerResponse response; |
| 728 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle; | 727 scoped_ptr<storage::BlobDataHandle> blob_data_handle; |
| 729 // Should 404 before sync event. | 728 // Should 404 before sync event. |
| 730 FetchOnRegisteredWorker(&result, &response, &blob_data_handle); | 729 FetchOnRegisteredWorker(&result, &response, &blob_data_handle); |
| 731 EXPECT_EQ(404, response.status_code); | 730 EXPECT_EQ(404, response.status_code); |
| 732 | 731 |
| 733 // Run the sync event. | 732 // Run the sync event. |
| 734 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | 733 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
| 735 base::RunLoop sync_run_loop; | 734 base::RunLoop sync_run_loop; |
| 736 BrowserThread::PostTask(BrowserThread::IO, | 735 BrowserThread::PostTask(BrowserThread::IO, |
| 737 FROM_HERE, | 736 FROM_HERE, |
| 738 base::Bind(&self::SyncEventOnIOThread, | 737 base::Bind(&self::SyncEventOnIOThread, |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, | 939 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, |
| 941 this, | 940 this, |
| 942 embedded_test_server()->GetURL("/service_worker/empty.html"), | 941 embedded_test_server()->GetURL("/service_worker/empty.html"), |
| 943 &status, | 942 &status, |
| 944 &script_url)); | 943 &script_url)); |
| 945 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); | 944 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); |
| 946 } | 945 } |
| 947 } | 946 } |
| 948 | 947 |
| 949 } // namespace content | 948 } // namespace content |
| OLD | NEW |