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

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

Issue 501453002: Decouple script_url from ServiceWorkerRegistration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync after major collision Created 6 years, 3 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
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 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 ServiceWorkerResponse* response, 487 ServiceWorkerResponse* response,
488 scoped_ptr<storage::BlobDataHandle>* blob_data_handle) { 488 scoped_ptr<storage::BlobDataHandle>* blob_data_handle) {
489 RunOnIOThread( 489 RunOnIOThread(
490 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url)); 490 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url));
491 FetchOnRegisteredWorker(result, response, blob_data_handle); 491 FetchOnRegisteredWorker(result, response, blob_data_handle);
492 } 492 }
493 493
494 void SetUpRegistrationOnIOThread(const std::string& worker_url) { 494 void SetUpRegistrationOnIOThread(const std::string& worker_url) {
495 registration_ = new ServiceWorkerRegistration( 495 registration_ = new ServiceWorkerRegistration(
496 embedded_test_server()->GetURL("/"), 496 embedded_test_server()->GetURL("/"),
497 embedded_test_server()->GetURL(worker_url),
498 wrapper()->context()->storage()->NewRegistrationId(), 497 wrapper()->context()->storage()->NewRegistrationId(),
499 wrapper()->context()->AsWeakPtr()); 498 wrapper()->context()->AsWeakPtr());
500 version_ = new ServiceWorkerVersion( 499 version_ = new ServiceWorkerVersion(
501 registration_.get(), 500 registration_.get(),
501 embedded_test_server()->GetURL(worker_url),
502 wrapper()->context()->storage()->NewVersionId(), 502 wrapper()->context()->storage()->NewVersionId(),
503 wrapper()->context()->AsWeakPtr()); 503 wrapper()->context()->AsWeakPtr());
504 AssociateRendererProcessToWorker(version_->embedded_worker()); 504 AssociateRendererProcessToWorker(version_->embedded_worker());
505 } 505 }
506 506
507 void StartOnIOThread(const base::Closure& done, 507 void StartOnIOThread(const base::Closure& done,
508 ServiceWorkerStatusCode* result) { 508 ServiceWorkerStatusCode* result) {
509 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 509 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
510 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result)); 510 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result));
511 } 511 }
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.get()) { 842 if (!registration.get())
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698