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

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

Issue 435873002: ServiceWorker: Remove wildcard from scope matching (Chromium) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comment Created 6 years, 4 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 237
238 void StartOnIOThread() { 238 void StartOnIOThread() {
239 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 239 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
240 worker_ = wrapper()->context()->embedded_worker_registry()->CreateWorker(); 240 worker_ = wrapper()->context()->embedded_worker_registry()->CreateWorker();
241 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker_->status()); 241 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker_->status());
242 worker_->AddListener(this); 242 worker_->AddListener(this);
243 243
244 AssociateRendererProcessToWorker(worker_.get()); 244 AssociateRendererProcessToWorker(worker_.get());
245 245
246 const int64 service_worker_version_id = 33L; 246 const int64 service_worker_version_id = 33L;
247 const GURL scope = embedded_test_server()->GetURL("/*"); 247 const GURL scope = embedded_test_server()->GetURL("/");
248 const GURL script_url = embedded_test_server()->GetURL( 248 const GURL script_url = embedded_test_server()->GetURL(
249 "/service_worker/worker.js"); 249 "/service_worker/worker.js");
250 std::vector<int> processes; 250 std::vector<int> processes;
251 processes.push_back( 251 processes.push_back(
252 shell()->web_contents()->GetRenderProcessHost()->GetID()); 252 shell()->web_contents()->GetRenderProcessHost()->GetID());
253 worker_->Start( 253 worker_->Start(
254 service_worker_version_id, 254 service_worker_version_id,
255 scope, 255 scope,
256 script_url, 256 script_url,
257 pause_mode_ != DONT_PAUSE, 257 pause_mode_ != DONT_PAUSE,
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 ServiceWorkerFetchEventResult* result, 410 ServiceWorkerFetchEventResult* result,
411 ServiceWorkerResponse* response, 411 ServiceWorkerResponse* response,
412 scoped_ptr<webkit_blob::BlobDataHandle>* blob_data_handle) { 412 scoped_ptr<webkit_blob::BlobDataHandle>* blob_data_handle) {
413 RunOnIOThread( 413 RunOnIOThread(
414 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url)); 414 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url));
415 FetchOnRegisteredWorker(result, response, blob_data_handle); 415 FetchOnRegisteredWorker(result, response, blob_data_handle);
416 } 416 }
417 417
418 void SetUpRegistrationOnIOThread(const std::string& worker_url) { 418 void SetUpRegistrationOnIOThread(const std::string& worker_url) {
419 registration_ = new ServiceWorkerRegistration( 419 registration_ = new ServiceWorkerRegistration(
420 embedded_test_server()->GetURL("/*"), 420 embedded_test_server()->GetURL("/"),
421 embedded_test_server()->GetURL(worker_url), 421 embedded_test_server()->GetURL(worker_url),
422 wrapper()->context()->storage()->NewRegistrationId(), 422 wrapper()->context()->storage()->NewRegistrationId(),
423 wrapper()->context()->AsWeakPtr()); 423 wrapper()->context()->AsWeakPtr());
424 version_ = new ServiceWorkerVersion( 424 version_ = new ServiceWorkerVersion(
425 registration_, 425 registration_,
426 wrapper()->context()->storage()->NewVersionId(), 426 wrapper()->context()->storage()->NewVersionId(),
427 wrapper()->context()->AsWeakPtr()); 427 wrapper()->context()->AsWeakPtr());
428 AssociateRendererProcessToWorker(version_->embedded_worker()); 428 AssociateRendererProcessToWorker(version_->embedded_worker());
429 } 429 }
430 430
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 // Close the only window to be sure we're not re-using its RenderProcessHost. 752 // Close the only window to be sure we're not re-using its RenderProcessHost.
753 shell()->Close(); 753 shell()->Close();
754 EXPECT_EQ(0, CountRenderProcessHosts()); 754 EXPECT_EQ(0, CountRenderProcessHosts());
755 755
756 const std::string kWorkerUrl = "/service_worker/fetch_event.js"; 756 const std::string kWorkerUrl = "/service_worker/fetch_event.js";
757 757
758 // Unregistering nothing should return true. 758 // Unregistering nothing should return true.
759 { 759 {
760 base::RunLoop run_loop; 760 base::RunLoop run_loop;
761 public_context()->UnregisterServiceWorker( 761 public_context()->UnregisterServiceWorker(
762 embedded_test_server()->GetURL("/*"), 762 embedded_test_server()->GetURL("/"),
763 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); 763 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure()));
764 run_loop.Run(); 764 run_loop.Run();
765 } 765 }
766 766
767 // If we use a worker URL that doesn't exist, registration fails. 767 // If we use a worker URL that doesn't exist, registration fails.
768 { 768 {
769 base::RunLoop run_loop; 769 base::RunLoop run_loop;
770 public_context()->RegisterServiceWorker( 770 public_context()->RegisterServiceWorker(
771 embedded_test_server()->GetURL("/*"), 771 embedded_test_server()->GetURL("/"),
772 embedded_test_server()->GetURL("/does/not/exist"), 772 embedded_test_server()->GetURL("/does/not/exist"),
773 base::Bind(&ExpectResultAndRun, false, run_loop.QuitClosure())); 773 base::Bind(&ExpectResultAndRun, false, run_loop.QuitClosure()));
774 run_loop.Run(); 774 run_loop.Run();
775 } 775 }
776 EXPECT_EQ(0, CountRenderProcessHosts()); 776 EXPECT_EQ(0, CountRenderProcessHosts());
777 777
778 // Register returns when the promise would be resolved. 778 // Register returns when the promise would be resolved.
779 { 779 {
780 base::RunLoop run_loop; 780 base::RunLoop run_loop;
781 public_context()->RegisterServiceWorker( 781 public_context()->RegisterServiceWorker(
782 embedded_test_server()->GetURL("/*"), 782 embedded_test_server()->GetURL("/"),
783 embedded_test_server()->GetURL(kWorkerUrl), 783 embedded_test_server()->GetURL(kWorkerUrl),
784 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); 784 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure()));
785 run_loop.Run(); 785 run_loop.Run();
786 } 786 }
787 EXPECT_EQ(1, CountRenderProcessHosts()); 787 EXPECT_EQ(1, CountRenderProcessHosts());
788 788
789 // Registering again should succeed, although the algo still 789 // Registering again should succeed, although the algo still
790 // might not be complete. 790 // might not be complete.
791 { 791 {
792 base::RunLoop run_loop; 792 base::RunLoop run_loop;
793 public_context()->RegisterServiceWorker( 793 public_context()->RegisterServiceWorker(
794 embedded_test_server()->GetURL("/*"), 794 embedded_test_server()->GetURL("/"),
795 embedded_test_server()->GetURL(kWorkerUrl), 795 embedded_test_server()->GetURL(kWorkerUrl),
796 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); 796 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure()));
797 run_loop.Run(); 797 run_loop.Run();
798 } 798 }
799 799
800 // The registration algo might not be far enough along to have 800 // The registration algo might not be far enough along to have
801 // stored the registration data, so it may not be findable 801 // stored the registration data, so it may not be findable
802 // at this point. 802 // at this point.
803 803
804 // Unregistering something should return true. 804 // Unregistering something should return true.
805 { 805 {
806 base::RunLoop run_loop; 806 base::RunLoop run_loop;
807 public_context()->UnregisterServiceWorker( 807 public_context()->UnregisterServiceWorker(
808 embedded_test_server()->GetURL("/*"), 808 embedded_test_server()->GetURL("/"),
809 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure())); 809 base::Bind(&ExpectResultAndRun, true, run_loop.QuitClosure()));
810 run_loop.Run(); 810 run_loop.Run();
811 } 811 }
812 EXPECT_GE(1, CountRenderProcessHosts()) << "Unregistering doesn't stop the " 812 EXPECT_GE(1, CountRenderProcessHosts()) << "Unregistering doesn't stop the "
813 "workers eagerly, so their RPHs " 813 "workers eagerly, so their RPHs "
814 "can still be running."; 814 "can still be running.";
815 815
816 // Should not be able to find it. 816 // Should not be able to find it.
817 { 817 {
818 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; 818 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
819 GURL script_url; 819 GURL script_url;
820 RunOnIOThread( 820 RunOnIOThread(
821 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, 821 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO,
822 this, 822 this,
823 embedded_test_server()->GetURL("/service_worker/empty.html"), 823 embedded_test_server()->GetURL("/service_worker/empty.html"),
824 &status, 824 &status,
825 &script_url)); 825 &script_url));
826 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); 826 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status);
827 } 827 }
828 } 828 }
829 829
830 } // namespace content 830 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698