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

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: review comments and add unittests 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_, 500 registration_,
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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 &num_resources)); 816 &num_resources));
817 EXPECT_EQ(kExpectedNumResources, num_resources); 817 EXPECT_EQ(kExpectedNumResources, num_resources);
818 } 818 }
819 819
820 class ServiceWorkerBlackBoxBrowserTest : public ServiceWorkerBrowserTest { 820 class ServiceWorkerBlackBoxBrowserTest : public ServiceWorkerBrowserTest {
821 public: 821 public:
822 typedef ServiceWorkerBlackBoxBrowserTest self; 822 typedef ServiceWorkerBlackBoxBrowserTest self;
823 823
824 void FindRegistrationOnIO(const GURL& document_url, 824 void FindRegistrationOnIO(const GURL& document_url,
825 ServiceWorkerStatusCode* status, 825 ServiceWorkerStatusCode* status,
826 GURL* script_url,
827 const base::Closure& continuation) { 826 const base::Closure& continuation) {
828 wrapper()->context()->storage()->FindRegistrationForDocument( 827 wrapper()->context()->storage()->FindRegistrationForDocument(
829 document_url, 828 document_url,
830 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO2, 829 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO2,
831 this, 830 this,
832 status, 831 status,
833 script_url,
834 continuation)); 832 continuation));
835 } 833 }
836 834
837 void FindRegistrationOnIO2( 835 void FindRegistrationOnIO2(
838 ServiceWorkerStatusCode* out_status, 836 ServiceWorkerStatusCode* out_status,
839 GURL* script_url,
840 const base::Closure& continuation, 837 const base::Closure& continuation,
841 ServiceWorkerStatusCode status, 838 ServiceWorkerStatusCode status,
842 const scoped_refptr<ServiceWorkerRegistration>& registration) { 839 const scoped_refptr<ServiceWorkerRegistration>& registration) {
843 *out_status = status; 840 *out_status = status;
844 if (registration) { 841 if (!registration)
845 *script_url = registration->script_url();
846 } else {
847 EXPECT_NE(SERVICE_WORKER_OK, status); 842 EXPECT_NE(SERVICE_WORKER_OK, status);
848 }
849 continuation.Run(); 843 continuation.Run();
850 } 844 }
851 }; 845 };
852 846
853 static int CountRenderProcessHosts() { 847 static int CountRenderProcessHosts() {
854 int result = 0; 848 int result = 0;
855 for (RenderProcessHost::iterator iter(RenderProcessHost::AllHostsIterator()); 849 for (RenderProcessHost::iterator iter(RenderProcessHost::AllHostsIterator());
856 !iter.IsAtEnd(); 850 !iter.IsAtEnd();
857 iter.Advance()) { 851 iter.Advance()) {
858 result++; 852 result++;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); 921 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure()));
928 run_loop.Run(); 922 run_loop.Run();
929 } 923 }
930 EXPECT_GE(1, CountRenderProcessHosts()) << "Unregistering doesn't stop the " 924 EXPECT_GE(1, CountRenderProcessHosts()) << "Unregistering doesn't stop the "
931 "workers eagerly, so their RPHs " 925 "workers eagerly, so their RPHs "
932 "can still be running."; 926 "can still be running.";
933 927
934 // Should not be able to find it. 928 // Should not be able to find it.
935 { 929 {
936 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; 930 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
937 GURL script_url;
938 RunOnIOThread( 931 RunOnIOThread(
939 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, 932 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO,
940 this, 933 this,
941 embedded_test_server()->GetURL("/service_worker/empty.html"), 934 embedded_test_server()->GetURL("/service_worker/empty.html"),
942 &status, 935 &status));
943 &script_url));
944 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); 936 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status);
945 } 937 }
946 } 938 }
947 939
948 } // namespace content 940 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698