| 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 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 ServiceWorkerResponse* response, | 488 ServiceWorkerResponse* response, |
| 489 scoped_ptr<webkit_blob::BlobDataHandle>* blob_data_handle) { | 489 scoped_ptr<webkit_blob::BlobDataHandle>* blob_data_handle) { |
| 490 RunOnIOThread( | 490 RunOnIOThread( |
| 491 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url)); | 491 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url)); |
| 492 FetchOnRegisteredWorker(result, response, blob_data_handle); | 492 FetchOnRegisteredWorker(result, response, blob_data_handle); |
| 493 } | 493 } |
| 494 | 494 |
| 495 void SetUpRegistrationOnIOThread(const std::string& worker_url) { | 495 void SetUpRegistrationOnIOThread(const std::string& worker_url) { |
| 496 registration_ = new ServiceWorkerRegistration( | 496 registration_ = new ServiceWorkerRegistration( |
| 497 embedded_test_server()->GetURL("/"), | 497 embedded_test_server()->GetURL("/"), |
| 498 embedded_test_server()->GetURL(worker_url), | |
| 499 wrapper()->context()->storage()->NewRegistrationId(), | 498 wrapper()->context()->storage()->NewRegistrationId(), |
| 500 wrapper()->context()->AsWeakPtr()); | 499 wrapper()->context()->AsWeakPtr()); |
| 501 version_ = new ServiceWorkerVersion( | 500 version_ = new ServiceWorkerVersion( |
| 502 registration_, | 501 registration_, |
| 502 embedded_test_server()->GetURL(worker_url), |
| 503 wrapper()->context()->storage()->NewVersionId(), | 503 wrapper()->context()->storage()->NewVersionId(), |
| 504 wrapper()->context()->AsWeakPtr()); | 504 wrapper()->context()->AsWeakPtr()); |
| 505 AssociateRendererProcessToWorker(version_->embedded_worker()); | 505 AssociateRendererProcessToWorker(version_->embedded_worker()); |
| 506 } | 506 } |
| 507 | 507 |
| 508 void StartOnIOThread(const base::Closure& done, | 508 void StartOnIOThread(const base::Closure& done, |
| 509 ServiceWorkerStatusCode* result) { | 509 ServiceWorkerStatusCode* result) { |
| 510 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 510 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 511 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result)); | 511 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result)); |
| 512 } | 512 } |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 &num_resources)); | 817 &num_resources)); |
| 818 EXPECT_EQ(kExpectedNumResources, num_resources); | 818 EXPECT_EQ(kExpectedNumResources, num_resources); |
| 819 } | 819 } |
| 820 | 820 |
| 821 class ServiceWorkerBlackBoxBrowserTest : public ServiceWorkerBrowserTest { | 821 class ServiceWorkerBlackBoxBrowserTest : public ServiceWorkerBrowserTest { |
| 822 public: | 822 public: |
| 823 typedef ServiceWorkerBlackBoxBrowserTest self; | 823 typedef ServiceWorkerBlackBoxBrowserTest self; |
| 824 | 824 |
| 825 void FindRegistrationOnIO(const GURL& document_url, | 825 void FindRegistrationOnIO(const GURL& document_url, |
| 826 ServiceWorkerStatusCode* status, | 826 ServiceWorkerStatusCode* status, |
| 827 GURL* script_url, | |
| 828 const base::Closure& continuation) { | 827 const base::Closure& continuation) { |
| 829 wrapper()->context()->storage()->FindRegistrationForDocument( | 828 wrapper()->context()->storage()->FindRegistrationForDocument( |
| 830 document_url, | 829 document_url, |
| 831 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO2, | 830 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO2, |
| 832 this, | 831 this, |
| 833 status, | 832 status, |
| 834 script_url, | |
| 835 continuation)); | 833 continuation)); |
| 836 } | 834 } |
| 837 | 835 |
| 838 void FindRegistrationOnIO2( | 836 void FindRegistrationOnIO2( |
| 839 ServiceWorkerStatusCode* out_status, | 837 ServiceWorkerStatusCode* out_status, |
| 840 GURL* script_url, | |
| 841 const base::Closure& continuation, | 838 const base::Closure& continuation, |
| 842 ServiceWorkerStatusCode status, | 839 ServiceWorkerStatusCode status, |
| 843 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 840 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| 844 *out_status = status; | 841 *out_status = status; |
| 845 if (registration) { | 842 if (!registration) |
| 846 *script_url = registration->script_url(); | |
| 847 } else { | |
| 848 EXPECT_NE(SERVICE_WORKER_OK, status); | 843 EXPECT_NE(SERVICE_WORKER_OK, status); |
| 849 } | |
| 850 continuation.Run(); | 844 continuation.Run(); |
| 851 } | 845 } |
| 852 }; | 846 }; |
| 853 | 847 |
| 854 static int CountRenderProcessHosts() { | 848 static int CountRenderProcessHosts() { |
| 855 int result = 0; | 849 int result = 0; |
| 856 for (RenderProcessHost::iterator iter(RenderProcessHost::AllHostsIterator()); | 850 for (RenderProcessHost::iterator iter(RenderProcessHost::AllHostsIterator()); |
| 857 !iter.IsAtEnd(); | 851 !iter.IsAtEnd(); |
| 858 iter.Advance()) { | 852 iter.Advance()) { |
| 859 result++; | 853 result++; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); | 922 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); |
| 929 run_loop.Run(); | 923 run_loop.Run(); |
| 930 } | 924 } |
| 931 EXPECT_GE(1, CountRenderProcessHosts()) << "Unregistering doesn't stop the " | 925 EXPECT_GE(1, CountRenderProcessHosts()) << "Unregistering doesn't stop the " |
| 932 "workers eagerly, so their RPHs " | 926 "workers eagerly, so their RPHs " |
| 933 "can still be running."; | 927 "can still be running."; |
| 934 | 928 |
| 935 // Should not be able to find it. | 929 // Should not be able to find it. |
| 936 { | 930 { |
| 937 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | 931 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
| 938 GURL script_url; | |
| 939 RunOnIOThread( | 932 RunOnIOThread( |
| 940 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, | 933 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, |
| 941 this, | 934 this, |
| 942 embedded_test_server()->GetURL("/service_worker/empty.html"), | 935 embedded_test_server()->GetURL("/service_worker/empty.html"), |
| 943 &status, | 936 &status)); |
| 944 &script_url)); | |
| 945 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); | 937 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); |
| 946 } | 938 } |
| 947 } | 939 } |
| 948 | 940 |
| 949 } // namespace content | 941 } // namespace content |
| OLD | NEW |