Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: content/browser/service_worker/service_worker_browsertest.cc

Issue 313093003: Revert "ServiceWorker: Read the blob from SW's response to a fetch event" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | content/renderer/service_worker/embedded_worker_context_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
10 #include "content/browser/service_worker/embedded_worker_instance.h" 9 #include "content/browser/service_worker/embedded_worker_instance.h"
11 #include "content/browser/service_worker/embedded_worker_registry.h" 10 #include "content/browser/service_worker/embedded_worker_registry.h"
12 #include "content/browser/service_worker/service_worker_context_core.h" 11 #include "content/browser/service_worker/service_worker_context_core.h"
13 #include "content/browser/service_worker/service_worker_context_wrapper.h" 12 #include "content/browser/service_worker/service_worker_context_wrapper.h"
14 #include "content/browser/service_worker/service_worker_registration.h" 13 #include "content/browser/service_worker/service_worker_registration.h"
15 #include "content/browser/service_worker/service_worker_test_utils.h" 14 #include "content/browser/service_worker/service_worker_test_utils.h"
16 #include "content/browser/service_worker/service_worker_version.h" 15 #include "content/browser/service_worker/service_worker_version.h"
17 #include "content/common/service_worker/service_worker_messages.h" 16 #include "content/common/service_worker/service_worker_messages.h"
18 #include "content/common/service_worker/service_worker_status_code.h" 17 #include "content/common/service_worker/service_worker_status_code.h"
19 #include "content/common/service_worker/service_worker_types.h" 18 #include "content/common/service_worker/service_worker_types.h"
20 #include "content/public/browser/browser_context.h" 19 #include "content/public/browser/browser_context.h"
21 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/render_process_host.h" 21 #include "content/public/browser/render_process_host.h"
23 #include "content/public/browser/storage_partition.h" 22 #include "content/public/browser/storage_partition.h"
24 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
25 #include "content/public/common/content_switches.h" 24 #include "content/public/common/content_switches.h"
26 #include "content/public/test/content_browser_test.h" 25 #include "content/public/test/content_browser_test.h"
27 #include "content/public/test/content_browser_test_utils.h" 26 #include "content/public/test/content_browser_test_utils.h"
28 #include "content/shell/browser/shell.h" 27 #include "content/shell/browser/shell.h"
29 #include "net/test/embedded_test_server/embedded_test_server.h" 28 #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"
33 29
34 namespace content { 30 namespace content {
35 31
36 namespace { 32 namespace {
37 33
38 struct FetchResult { 34 struct FetchResult {
39 ServiceWorkerStatusCode status; 35 ServiceWorkerStatusCode status;
40 ServiceWorkerFetchEventResult result; 36 ServiceWorkerFetchEventResult result;
41 ServiceWorkerResponse response; 37 ServiceWorkerResponse response;
42 }; 38 };
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit); 83 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit);
88 } 84 }
89 85
90 ServiceWorkerVersion::FetchCallback CreateResponseReceiver( 86 ServiceWorkerVersion::FetchCallback CreateResponseReceiver(
91 BrowserThread::ID run_quit_thread, 87 BrowserThread::ID run_quit_thread,
92 const base::Closure& quit, 88 const base::Closure& quit,
93 FetchResult* result) { 89 FetchResult* result) {
94 return base::Bind(&ReceiveFetchResult, run_quit_thread, quit, result); 90 return base::Bind(&ReceiveFetchResult, run_quit_thread, quit, result);
95 } 91 }
96 92
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
108 } // namespace 93 } // namespace
109 94
110 class ServiceWorkerBrowserTest : public ContentBrowserTest { 95 class ServiceWorkerBrowserTest : public ContentBrowserTest {
111 protected: 96 protected:
112 typedef ServiceWorkerBrowserTest self; 97 typedef ServiceWorkerBrowserTest self;
113 98
114 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 99 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
115 command_line->AppendSwitch(switches::kEnableServiceWorker); 100 command_line->AppendSwitch(switches::kEnableServiceWorker);
116 } 101 }
117 102
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 ServiceWorkerFetchEventResult result; 467 ServiceWorkerFetchEventResult result;
483 ServiceWorkerResponse response; 468 ServiceWorkerResponse response;
484 FetchTestHelper("/service_worker/fetch_event.js", &result, &response); 469 FetchTestHelper("/service_worker/fetch_event.js", &result, &response);
485 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, result); 470 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, result);
486 EXPECT_EQ(301, response.status_code); 471 EXPECT_EQ(301, response.status_code);
487 EXPECT_EQ("Moved Permanently", response.status_text); 472 EXPECT_EQ("Moved Permanently", response.status_text);
488 std::map<std::string, std::string> expected_headers; 473 std::map<std::string, std::string> expected_headers;
489 expected_headers["Content-Language"] = "fi"; 474 expected_headers["Content-Language"] = "fi";
490 expected_headers["Content-Type"] = "text/html; charset=UTF-8"; 475 expected_headers["Content-Type"] = "text/html; charset=UTF-8";
491 EXPECT_EQ(expected_headers, response.headers); 476 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);
500 } 477 }
501 478
502 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, 479 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,
503 SyncAbortedWithoutFlag) { 496 SyncAbortedWithoutFlag) {
504 RunOnIOThread(base::Bind( 497 RunOnIOThread(base::Bind(
505 &self::SetUpRegistrationOnIOThread, this, "/service_worker/sync.js")); 498 &self::SetUpRegistrationOnIOThread, this, "/service_worker/sync.js"));
506 499
507 // Run the sync event. 500 // Run the sync event.
508 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; 501 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
509 base::RunLoop sync_run_loop; 502 base::RunLoop sync_run_loop;
510 BrowserThread::PostTask(BrowserThread::IO, 503 BrowserThread::PostTask(BrowserThread::IO,
511 FROM_HERE, 504 FROM_HERE,
512 base::Bind(&self::SyncEventOnIOThread, 505 base::Bind(&self::SyncEventOnIOThread,
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, 673 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO,
681 this, 674 this,
682 embedded_test_server()->GetURL("/service_worker/empty.html"), 675 embedded_test_server()->GetURL("/service_worker/empty.html"),
683 &status, 676 &status,
684 &script_url)); 677 &script_url));
685 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); 678 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status);
686 } 679 }
687 } 680 }
688 681
689 } // namespace content 682 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/service_worker/embedded_worker_context_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698