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

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

Issue 810403004: [Storage] Blob Storage Refactoring pt 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: memory leak fixed Created 5 years, 11 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
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 "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 30 matching lines...) Expand all
41 #include "storage/common/blob/blob_data.h" 41 #include "storage/common/blob/blob_data.h"
42 42
43 namespace content { 43 namespace content {
44 44
45 namespace { 45 namespace {
46 46
47 struct FetchResult { 47 struct FetchResult {
48 ServiceWorkerStatusCode status; 48 ServiceWorkerStatusCode status;
49 ServiceWorkerFetchEventResult result; 49 ServiceWorkerFetchEventResult result;
50 ServiceWorkerResponse response; 50 ServiceWorkerResponse response;
51 scoped_ptr<storage::BlobDataHandle> blob_data_handle; 51 scoped_ptr<storage::BlobDataSnapshotHandle> blob_data_handle;
52 }; 52 };
53 53
54 void RunAndQuit(const base::Closure& closure, 54 void RunAndQuit(const base::Closure& closure,
55 const base::Closure& quit, 55 const base::Closure& quit,
56 base::MessageLoopProxy* original_message_loop) { 56 base::MessageLoopProxy* original_message_loop) {
57 closure.Run(); 57 closure.Run();
58 original_message_loop->PostTask(FROM_HERE, quit); 58 original_message_loop->PostTask(FROM_HERE, quit);
59 } 59 }
60 60
61 void RunOnIOThread(const base::Closure& closure) { 61 void RunOnIOThread(const base::Closure& closure) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 BrowserThread::ID run_quit_thread, 115 BrowserThread::ID run_quit_thread,
116 const base::Closure& quit, 116 const base::Closure& quit,
117 ChromeBlobStorageContext* blob_context, 117 ChromeBlobStorageContext* blob_context,
118 FetchResult* result) { 118 FetchResult* result) {
119 return base::Bind(&ReceiveFetchResult, run_quit_thread, quit, 119 return base::Bind(&ReceiveFetchResult, run_quit_thread, quit,
120 make_scoped_refptr<ChromeBlobStorageContext>(blob_context), 120 make_scoped_refptr<ChromeBlobStorageContext>(blob_context),
121 result); 121 result);
122 } 122 }
123 123
124 void ReadResponseBody(std::string* body, 124 void ReadResponseBody(std::string* body,
125 storage::BlobDataHandle* blob_data_handle) { 125 storage::BlobDataSnapshotHandle* blob_data_handle) {
126 ASSERT_TRUE(blob_data_handle); 126 ASSERT_TRUE(blob_data_handle);
127 ASSERT_EQ(1U, blob_data_handle->data()->items().size()); 127 ASSERT_EQ(1U, blob_data_handle->data()->items().size());
128 *body = std::string(blob_data_handle->data()->items()[0].bytes(), 128 *body = std::string(blob_data_handle->data()->items()[0]->bytes(),
129 blob_data_handle->data()->items()[0].length()); 129 blob_data_handle->data()->items()[0]->length());
130 } 130 }
131 131
132 void ExpectResultAndRun(bool expected, 132 void ExpectResultAndRun(bool expected,
133 const base::Closure& continuation, 133 const base::Closure& continuation,
134 bool actual) { 134 bool actual) {
135 EXPECT_EQ(expected, actual); 135 EXPECT_EQ(expected, actual);
136 continuation.Run(); 136 continuation.Run();
137 } 137 }
138 138
139 class WorkerActivatedObserver 139 class WorkerActivatedObserver
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 FROM_HERE, 465 FROM_HERE,
466 base::Bind( 466 base::Bind(
467 &self::ActivateOnIOThread, this, run_loop.QuitClosure(), &status)); 467 &self::ActivateOnIOThread, this, run_loop.QuitClosure(), &status));
468 run_loop.Run(); 468 run_loop.Run();
469 ASSERT_EQ(expected_status, status); 469 ASSERT_EQ(expected_status, status);
470 } 470 }
471 471
472 void FetchOnRegisteredWorker( 472 void FetchOnRegisteredWorker(
473 ServiceWorkerFetchEventResult* result, 473 ServiceWorkerFetchEventResult* result,
474 ServiceWorkerResponse* response, 474 ServiceWorkerResponse* response,
475 scoped_ptr<storage::BlobDataHandle>* blob_data_handle) { 475 scoped_ptr<storage::BlobDataSnapshotHandle>* blob_data_handle) {
476 blob_context_ = ChromeBlobStorageContext::GetFor( 476 blob_context_ = ChromeBlobStorageContext::GetFor(
477 shell()->web_contents()->GetBrowserContext()); 477 shell()->web_contents()->GetBrowserContext());
478 bool prepare_result = false; 478 bool prepare_result = false;
479 FetchResult fetch_result; 479 FetchResult fetch_result;
480 fetch_result.status = SERVICE_WORKER_ERROR_FAILED; 480 fetch_result.status = SERVICE_WORKER_ERROR_FAILED;
481 base::RunLoop fetch_run_loop; 481 base::RunLoop fetch_run_loop;
482 BrowserThread::PostTask(BrowserThread::IO, 482 BrowserThread::PostTask(BrowserThread::IO,
483 FROM_HERE, 483 FROM_HERE,
484 base::Bind(&self::FetchOnIOThread, 484 base::Bind(&self::FetchOnIOThread,
485 this, 485 this,
486 fetch_run_loop.QuitClosure(), 486 fetch_run_loop.QuitClosure(),
487 &prepare_result, 487 &prepare_result,
488 &fetch_result)); 488 &fetch_result));
489 fetch_run_loop.Run(); 489 fetch_run_loop.Run();
490 ASSERT_TRUE(prepare_result); 490 ASSERT_TRUE(prepare_result);
491 *result = fetch_result.result; 491 *result = fetch_result.result;
492 *response = fetch_result.response; 492 *response = fetch_result.response;
493 *blob_data_handle = fetch_result.blob_data_handle.Pass(); 493 *blob_data_handle = fetch_result.blob_data_handle.Pass();
494 ASSERT_EQ(SERVICE_WORKER_OK, fetch_result.status); 494 ASSERT_EQ(SERVICE_WORKER_OK, fetch_result.status);
495 } 495 }
496 496
497 void FetchTestHelper(const std::string& worker_url, 497 void FetchTestHelper(
498 ServiceWorkerFetchEventResult* result, 498 const std::string& worker_url,
499 ServiceWorkerResponse* response, 499 ServiceWorkerFetchEventResult* result,
500 scoped_ptr<storage::BlobDataHandle>* blob_data_handle) { 500 ServiceWorkerResponse* response,
501 scoped_ptr<storage::BlobDataSnapshotHandle>* blob_data_handle) {
501 RunOnIOThread( 502 RunOnIOThread(
502 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url)); 503 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url));
503 FetchOnRegisteredWorker(result, response, blob_data_handle); 504 FetchOnRegisteredWorker(result, response, blob_data_handle);
504 } 505 }
505 506
506 void SetUpRegistrationOnIOThread(const std::string& worker_url) { 507 void SetUpRegistrationOnIOThread(const std::string& worker_url) {
507 const GURL pattern = embedded_test_server()->GetURL("/"); 508 const GURL pattern = embedded_test_server()->GetURL("/");
508 registration_ = new ServiceWorkerRegistration( 509 registration_ = new ServiceWorkerRegistration(
509 pattern, 510 pattern,
510 wrapper()->context()->storage()->NewRegistrationId(), 511 wrapper()->context()->storage()->NewRegistrationId(),
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 691
691 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, 692 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
692 InstallWithWaitUntil_Rejected) { 693 InstallWithWaitUntil_Rejected) {
693 InstallTestHelper("/service_worker/worker_install_rejected.js", 694 InstallTestHelper("/service_worker/worker_install_rejected.js",
694 SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED); 695 SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED);
695 } 696 }
696 697
697 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, FetchEvent_Response) { 698 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, FetchEvent_Response) {
698 ServiceWorkerFetchEventResult result; 699 ServiceWorkerFetchEventResult result;
699 ServiceWorkerResponse response; 700 ServiceWorkerResponse response;
700 scoped_ptr<storage::BlobDataHandle> blob_data_handle; 701 scoped_ptr<storage::BlobDataSnapshotHandle> blob_data_handle;
701 FetchTestHelper("/service_worker/fetch_event.js", 702 FetchTestHelper("/service_worker/fetch_event.js",
702 &result, &response, &blob_data_handle); 703 &result, &response, &blob_data_handle);
703 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, result); 704 ASSERT_EQ(SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, result);
704 EXPECT_EQ(301, response.status_code); 705 EXPECT_EQ(301, response.status_code);
705 EXPECT_EQ("Moved Permanently", response.status_text); 706 EXPECT_EQ("Moved Permanently", response.status_text);
706 ServiceWorkerHeaderMap expected_headers; 707 ServiceWorkerHeaderMap expected_headers;
707 expected_headers["content-language"] = "fi"; 708 expected_headers["content-language"] = "fi";
708 expected_headers["content-type"] = "text/html; charset=UTF-8"; 709 expected_headers["content-type"] = "text/html; charset=UTF-8";
709 EXPECT_EQ(expected_headers, response.headers); 710 EXPECT_EQ(expected_headers, response.headers);
710 711
(...skipping 23 matching lines...) Expand all
734 } 735 }
735 736
736 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, SyncEventHandled) { 737 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, SyncEventHandled) {
737 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 738 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
738 command_line->AppendSwitch(switches::kEnableServiceWorkerSync); 739 command_line->AppendSwitch(switches::kEnableServiceWorkerSync);
739 740
740 RunOnIOThread(base::Bind( 741 RunOnIOThread(base::Bind(
741 &self::SetUpRegistrationOnIOThread, this, "/service_worker/sync.js")); 742 &self::SetUpRegistrationOnIOThread, this, "/service_worker/sync.js"));
742 ServiceWorkerFetchEventResult result; 743 ServiceWorkerFetchEventResult result;
743 ServiceWorkerResponse response; 744 ServiceWorkerResponse response;
744 scoped_ptr<storage::BlobDataHandle> blob_data_handle; 745 scoped_ptr<storage::BlobDataSnapshotHandle> blob_data_handle;
745 // Should 404 before sync event. 746 // Should 404 before sync event.
746 FetchOnRegisteredWorker(&result, &response, &blob_data_handle); 747 FetchOnRegisteredWorker(&result, &response, &blob_data_handle);
747 EXPECT_EQ(404, response.status_code); 748 EXPECT_EQ(404, response.status_code);
748 749
749 // Run the sync event. 750 // Run the sync event.
750 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; 751 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
751 base::RunLoop sync_run_loop; 752 base::RunLoop sync_run_loop;
752 BrowserThread::PostTask(BrowserThread::IO, 753 BrowserThread::PostTask(BrowserThread::IO,
753 FROM_HERE, 754 FROM_HERE,
754 base::Bind(&self::SyncEventOnIOThread, 755 base::Bind(&self::SyncEventOnIOThread,
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 const base::string16 kOKTitle2(base::ASCIIToUTF16("OK_2")); 970 const base::string16 kOKTitle2(base::ASCIIToUTF16("OK_2"));
970 const base::string16 kFailTitle2(base::ASCIIToUTF16("FAIL_2")); 971 const base::string16 kFailTitle2(base::ASCIIToUTF16("FAIL_2"));
971 content::TitleWatcher title_watcher2(shell()->web_contents(), kOKTitle2); 972 content::TitleWatcher title_watcher2(shell()->web_contents(), kOKTitle2);
972 title_watcher2.AlsoWaitForTitle(kFailTitle2); 973 title_watcher2.AlsoWaitForTitle(kFailTitle2);
973 974
974 NavigateToURL(shell(), embedded_test_server()->GetURL(kConfirmPageUrl)); 975 NavigateToURL(shell(), embedded_test_server()->GetURL(kConfirmPageUrl));
975 EXPECT_EQ(kOKTitle2, title_watcher2.WaitAndGetTitle()); 976 EXPECT_EQ(kOKTitle2, title_watcher2.WaitAndGetTitle());
976 } 977 }
977 978
978 } // namespace content 979 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698