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 0, |
| 105 blob_data_handle->data()->items()[0].length()); |
| 106 } |
| 107 |
93 } // namespace | 108 } // namespace |
94 | 109 |
95 class ServiceWorkerBrowserTest : public ContentBrowserTest { | 110 class ServiceWorkerBrowserTest : public ContentBrowserTest { |
96 protected: | 111 protected: |
97 typedef ServiceWorkerBrowserTest self; | 112 typedef ServiceWorkerBrowserTest self; |
98 | 113 |
99 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 114 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
100 command_line->AppendSwitch(switches::kEnableServiceWorker); | 115 command_line->AppendSwitch(switches::kEnableServiceWorker); |
101 } | 116 } |
102 | 117 |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 ServiceWorkerFetchEventResult result; | 482 ServiceWorkerFetchEventResult result; |
468 ServiceWorkerResponse response; | 483 ServiceWorkerResponse response; |
469 FetchTestHelper("/service_worker/fetch_event.js", &result, &response); | 484 FetchTestHelper("/service_worker/fetch_event.js", &result, &response); |
470 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, result); | 485 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, result); |
471 EXPECT_EQ(301, response.status_code); | 486 EXPECT_EQ(301, response.status_code); |
472 EXPECT_EQ("Moved Permanently", response.status_text); | 487 EXPECT_EQ("Moved Permanently", response.status_text); |
473 std::map<std::string, std::string> expected_headers; | 488 std::map<std::string, std::string> expected_headers; |
474 expected_headers["Content-Language"] = "fi"; | 489 expected_headers["Content-Language"] = "fi"; |
475 expected_headers["Content-Type"] = "text/html; charset=UTF-8"; | 490 expected_headers["Content-Type"] = "text/html; charset=UTF-8"; |
476 EXPECT_EQ(expected_headers, response.headers); | 491 EXPECT_EQ(expected_headers, response.headers); |
| 492 |
| 493 scoped_refptr<ChromeBlobStorageContext> context = |
| 494 ChromeBlobStorageContext::GetFor( |
| 495 shell()->web_contents()->GetBrowserContext()); |
| 496 std::string body; |
| 497 RunOnIOThread( |
| 498 base::Bind(&ReadResponseBody, &body, context, response.blob_uuid)); |
| 499 EXPECT_EQ("This resource is gone. Gone, gone, gone.", body); |
477 } | 500 } |
478 | 501 |
479 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, | 502 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) { | 503 SyncAbortedWithoutFlag) { |
497 RunOnIOThread(base::Bind( | 504 RunOnIOThread(base::Bind( |
498 &self::SetUpRegistrationOnIOThread, this, "/service_worker/sync.js")); | 505 &self::SetUpRegistrationOnIOThread, this, "/service_worker/sync.js")); |
499 | 506 |
500 // Run the sync event. | 507 // Run the sync event. |
501 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | 508 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
502 base::RunLoop sync_run_loop; | 509 base::RunLoop sync_run_loop; |
503 BrowserThread::PostTask(BrowserThread::IO, | 510 BrowserThread::PostTask(BrowserThread::IO, |
504 FROM_HERE, | 511 FROM_HERE, |
505 base::Bind(&self::SyncEventOnIOThread, | 512 base::Bind(&self::SyncEventOnIOThread, |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, | 680 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, |
674 this, | 681 this, |
675 embedded_test_server()->GetURL("/service_worker/empty.html"), | 682 embedded_test_server()->GetURL("/service_worker/empty.html"), |
676 &status, | 683 &status, |
677 &script_url)); | 684 &script_url)); |
678 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); | 685 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); |
679 } | 686 } |
680 } | 687 } |
681 | 688 |
682 } // namespace content | 689 } // namespace content |
OLD | NEW |