Chromium Code Reviews| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 base::Bind(base::IgnoreResult(&base::MessageLoopProxy::PostTask), | 73 base::Bind(base::IgnoreResult(&base::MessageLoopProxy::PostTask), |
| 74 base::MessageLoopProxy::current().get(), | 74 base::MessageLoopProxy::current().get(), |
| 75 FROM_HERE, | 75 FROM_HERE, |
| 76 run_loop.QuitClosure()); | 76 run_loop.QuitClosure()); |
| 77 BrowserThread::PostTask(BrowserThread::IO, | 77 BrowserThread::PostTask(BrowserThread::IO, |
| 78 FROM_HERE, | 78 FROM_HERE, |
| 79 base::Bind(closure, quit_on_original_thread)); | 79 base::Bind(closure, quit_on_original_thread)); |
| 80 run_loop.Run(); | 80 run_loop.Run(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void ReceivePrepareResult(bool* is_prepared) { | |
| 84 *is_prepared = true; | |
| 85 } | |
| 86 | |
| 87 base::Closure CreatePrepareReceiver(bool* is_prepared) { | |
| 88 return base::Bind(&ReceivePrepareResult, is_prepared); | |
| 89 } | |
| 90 | |
| 83 // Contrary to the style guide, the output parameter of this function comes | 91 // Contrary to the style guide, the output parameter of this function comes |
| 84 // before input parameters so Bind can be used on it to create a FetchCallback | 92 // before input parameters so Bind can be used on it to create a FetchCallback |
| 85 // to pass to DispatchFetchEvent. | 93 // to pass to DispatchFetchEvent. |
| 86 void ReceiveFetchResult(BrowserThread::ID run_quit_thread, | 94 void ReceiveFetchResult(BrowserThread::ID run_quit_thread, |
| 87 const base::Closure& quit, | 95 const base::Closure& quit, |
| 88 ChromeBlobStorageContext* blob_context, | 96 ChromeBlobStorageContext* blob_context, |
| 89 FetchResult* out_result, | 97 FetchResult* out_result, |
| 90 ServiceWorkerStatusCode actual_status, | 98 ServiceWorkerStatusCode actual_status, |
| 91 ServiceWorkerFetchEventResult actual_result, | 99 ServiceWorkerFetchEventResult actual_result, |
| 92 const ServiceWorkerResponse& actual_response) { | 100 const ServiceWorkerResponse& actual_response) { |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 run_loop.Run(); | 467 run_loop.Run(); |
| 460 ASSERT_EQ(expected_status, status); | 468 ASSERT_EQ(expected_status, status); |
| 461 } | 469 } |
| 462 | 470 |
| 463 void FetchOnRegisteredWorker( | 471 void FetchOnRegisteredWorker( |
| 464 ServiceWorkerFetchEventResult* result, | 472 ServiceWorkerFetchEventResult* result, |
| 465 ServiceWorkerResponse* response, | 473 ServiceWorkerResponse* response, |
| 466 scoped_ptr<storage::BlobDataHandle>* blob_data_handle) { | 474 scoped_ptr<storage::BlobDataHandle>* blob_data_handle) { |
| 467 blob_context_ = ChromeBlobStorageContext::GetFor( | 475 blob_context_ = ChromeBlobStorageContext::GetFor( |
| 468 shell()->web_contents()->GetBrowserContext()); | 476 shell()->web_contents()->GetBrowserContext()); |
| 477 bool prepare_result = false; | |
| 469 FetchResult fetch_result; | 478 FetchResult fetch_result; |
| 470 fetch_result.status = SERVICE_WORKER_ERROR_FAILED; | 479 fetch_result.status = SERVICE_WORKER_ERROR_FAILED; |
| 471 base::RunLoop fetch_run_loop; | 480 base::RunLoop fetch_run_loop; |
| 472 BrowserThread::PostTask(BrowserThread::IO, | 481 BrowserThread::PostTask(BrowserThread::IO, |
| 473 FROM_HERE, | 482 FROM_HERE, |
| 474 base::Bind(&self::FetchOnIOThread, | 483 base::Bind(&self::FetchOnIOThread, |
| 475 this, | 484 this, |
| 476 fetch_run_loop.QuitClosure(), | 485 fetch_run_loop.QuitClosure(), |
| 486 &prepare_result, | |
| 477 &fetch_result)); | 487 &fetch_result)); |
| 478 fetch_run_loop.Run(); | 488 fetch_run_loop.Run(); |
| 489 ASSERT_TRUE(prepare_result); | |
| 479 *result = fetch_result.result; | 490 *result = fetch_result.result; |
| 480 *response = fetch_result.response; | 491 *response = fetch_result.response; |
| 481 *blob_data_handle = fetch_result.blob_data_handle.Pass(); | 492 *blob_data_handle = fetch_result.blob_data_handle.Pass(); |
| 482 ASSERT_EQ(SERVICE_WORKER_OK, fetch_result.status); | 493 ASSERT_EQ(SERVICE_WORKER_OK, fetch_result.status); |
| 483 } | 494 } |
| 484 | 495 |
| 485 void FetchTestHelper(const std::string& worker_url, | 496 void FetchTestHelper(const std::string& worker_url, |
| 486 ServiceWorkerFetchEventResult* result, | 497 ServiceWorkerFetchEventResult* result, |
| 487 ServiceWorkerResponse* response, | 498 ServiceWorkerResponse* response, |
| 488 scoped_ptr<storage::BlobDataHandle>* blob_data_handle) { | 499 scoped_ptr<storage::BlobDataHandle>* blob_data_handle) { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 519 } | 530 } |
| 520 | 531 |
| 521 void ActivateOnIOThread(const base::Closure& done, | 532 void ActivateOnIOThread(const base::Closure& done, |
| 522 ServiceWorkerStatusCode* result) { | 533 ServiceWorkerStatusCode* result) { |
| 523 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 534 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 524 version_->SetStatus(ServiceWorkerVersion::ACTIVATING); | 535 version_->SetStatus(ServiceWorkerVersion::ACTIVATING); |
| 525 version_->DispatchActivateEvent( | 536 version_->DispatchActivateEvent( |
| 526 CreateReceiver(BrowserThread::UI, done, result)); | 537 CreateReceiver(BrowserThread::UI, done, result)); |
| 527 } | 538 } |
| 528 | 539 |
| 529 void FetchOnIOThread(const base::Closure& done, FetchResult* result) { | 540 void FetchOnIOThread(const base::Closure& done, |
| 541 bool* prepare_result, | |
| 542 FetchResult* result) { | |
| 530 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 543 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 531 ServiceWorkerFetchRequest request( | 544 ServiceWorkerFetchRequest request( |
| 532 embedded_test_server()->GetURL("/service_worker/empty.html"), | 545 embedded_test_server()->GetURL("/service_worker/empty.html"), |
| 533 "GET", | 546 "GET", |
| 534 std::map<std::string, std::string>(), | 547 std::map<std::string, std::string>(), |
| 535 GURL(""), | 548 GURL(""), |
| 536 false); | 549 false); |
| 537 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); | 550 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); |
| 538 version_->DispatchFetchEvent( | 551 version_->DispatchFetchEvent( |
| 539 request, | 552 request, |
| 553 CreatePrepareReceiver(prepare_result), | |
|
nhiroki
2014/08/27 05:05:38
nit: I think we don't have to use this indirect ca
| |
| 540 CreateResponseReceiver( | 554 CreateResponseReceiver( |
| 541 BrowserThread::UI, done, blob_context_.get(), result)); | 555 BrowserThread::UI, done, blob_context_.get(), result)); |
| 542 } | 556 } |
| 543 | 557 |
| 544 void StopOnIOThread(const base::Closure& done, | 558 void StopOnIOThread(const base::Closure& done, |
| 545 ServiceWorkerStatusCode* result) { | 559 ServiceWorkerStatusCode* result) { |
| 546 ASSERT_TRUE(version_.get()); | 560 ASSERT_TRUE(version_.get()); |
| 547 version_->StopWorker(CreateReceiver(BrowserThread::UI, done, result)); | 561 version_->StopWorker(CreateReceiver(BrowserThread::UI, done, result)); |
| 548 } | 562 } |
| 549 | 563 |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 932 RunOnIOThread( | 946 RunOnIOThread( |
| 933 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, | 947 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, |
| 934 this, | 948 this, |
| 935 embedded_test_server()->GetURL("/service_worker/empty.html"), | 949 embedded_test_server()->GetURL("/service_worker/empty.html"), |
| 936 &status)); | 950 &status)); |
| 937 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); | 951 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); |
| 938 } | 952 } |
| 939 } | 953 } |
| 940 | 954 |
| 941 } // namespace content | 955 } // namespace content |
| OLD | NEW |