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

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

Issue 296053013: Revert 272142 "Save running SW instance info, including its Site..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 7 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 "content/browser/service_worker/embedded_worker_instance.h" 9 #include "content/browser/service_worker/embedded_worker_instance.h"
10 #include "content/browser/service_worker/embedded_worker_registry.h" 10 #include "content/browser/service_worker/embedded_worker_registry.h"
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 public: 543 public:
544 typedef ServiceWorkerBlackBoxBrowserTest self; 544 typedef ServiceWorkerBlackBoxBrowserTest self;
545 545
546 static void ExpectResultAndRun(bool expected, 546 static void ExpectResultAndRun(bool expected,
547 const base::Closure& continuation, 547 const base::Closure& continuation,
548 bool actual) { 548 bool actual) {
549 EXPECT_EQ(expected, actual); 549 EXPECT_EQ(expected, actual);
550 continuation.Run(); 550 continuation.Run();
551 } 551 }
552 552
553 int RenderProcessID() {
554 return shell()->web_contents()->GetRenderProcessHost()->GetID();
555 }
556
553 void FindRegistrationOnIO(const GURL& document_url, 557 void FindRegistrationOnIO(const GURL& document_url,
554 ServiceWorkerStatusCode* status, 558 ServiceWorkerStatusCode* status,
555 GURL* script_url, 559 GURL* script_url,
556 const base::Closure& continuation) { 560 const base::Closure& continuation) {
557 wrapper()->context()->storage()->FindRegistrationForDocument( 561 wrapper()->context()->storage()->FindRegistrationForDocument(
558 document_url, 562 document_url,
559 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO2, 563 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO2,
560 this, 564 this,
561 status, 565 status,
562 script_url, 566 script_url,
563 continuation)); 567 continuation));
564 } 568 }
565 569
566 void FindRegistrationOnIO2( 570 void FindRegistrationOnIO2(
567 ServiceWorkerStatusCode* out_status, 571 ServiceWorkerStatusCode* out_status,
568 GURL* script_url, 572 GURL* script_url,
569 const base::Closure& continuation, 573 const base::Closure& continuation,
570 ServiceWorkerStatusCode status, 574 ServiceWorkerStatusCode status,
571 const scoped_refptr<ServiceWorkerRegistration>& registration) { 575 const scoped_refptr<ServiceWorkerRegistration>& registration) {
572 *out_status = status; 576 *out_status = status;
573 if (registration) { 577 if (registration) {
574 *script_url = registration->script_url(); 578 *script_url = registration->script_url();
575 } else { 579 } else {
576 EXPECT_NE(SERVICE_WORKER_OK, status); 580 EXPECT_NE(SERVICE_WORKER_OK, status);
577 } 581 }
578 continuation.Run(); 582 continuation.Run();
579 } 583 }
580 }; 584 };
581 585
582 static int CountRenderProcessHosts() {
583 int result = 0;
584 for (RenderProcessHost::iterator iter(RenderProcessHost::AllHostsIterator());
585 !iter.IsAtEnd();
586 iter.Advance()) {
587 result++;
588 }
589 return result;
590 }
591
592 IN_PROC_BROWSER_TEST_F(ServiceWorkerBlackBoxBrowserTest, Registration) { 586 IN_PROC_BROWSER_TEST_F(ServiceWorkerBlackBoxBrowserTest, Registration) {
593 // Close the only window to be sure we're not re-using its RenderProcessHost.
594 shell()->Close();
595 EXPECT_EQ(0, CountRenderProcessHosts());
596
597 const std::string kWorkerUrl = "/service_worker/fetch_event.js"; 587 const std::string kWorkerUrl = "/service_worker/fetch_event.js";
598 588
599 // Unregistering nothing should return true. 589 // Unregistering nothing should return true.
600 { 590 {
601 base::RunLoop run_loop; 591 base::RunLoop run_loop;
602 public_context()->UnregisterServiceWorker( 592 public_context()->UnregisterServiceWorker(
603 embedded_test_server()->GetURL("/*"), 593 embedded_test_server()->GetURL("/*"),
604 base::Bind(&ServiceWorkerBlackBoxBrowserTest::ExpectResultAndRun, 594 base::Bind(&ServiceWorkerBlackBoxBrowserTest::ExpectResultAndRun,
605 true, 595 true,
606 run_loop.QuitClosure())); 596 run_loop.QuitClosure()));
607 run_loop.Run(); 597 run_loop.Run();
608 } 598 }
609 599
610 // If we use a worker URL that doesn't exist, registration fails.
611 {
612 base::RunLoop run_loop;
613 public_context()->RegisterServiceWorker(
614 embedded_test_server()->GetURL("/*"),
615 embedded_test_server()->GetURL("/does/not/exist"),
616 base::Bind(&ServiceWorkerBlackBoxBrowserTest::ExpectResultAndRun,
617 false,
618 run_loop.QuitClosure()));
619 run_loop.Run();
620 }
621 EXPECT_EQ(0, CountRenderProcessHosts());
622
623 // Register returns when the promise would be resolved. 600 // Register returns when the promise would be resolved.
624 { 601 {
625 base::RunLoop run_loop; 602 base::RunLoop run_loop;
626 public_context()->RegisterServiceWorker( 603 public_context()->RegisterServiceWorker(
627 embedded_test_server()->GetURL("/*"), 604 embedded_test_server()->GetURL("/*"),
628 embedded_test_server()->GetURL(kWorkerUrl), 605 embedded_test_server()->GetURL(kWorkerUrl),
629 base::Bind(&ServiceWorkerBlackBoxBrowserTest::ExpectResultAndRun, 606 base::Bind(&ServiceWorkerBlackBoxBrowserTest::ExpectResultAndRun,
630 true, 607 true,
631 run_loop.QuitClosure())); 608 run_loop.QuitClosure()));
632 run_loop.Run(); 609 run_loop.Run();
633 } 610 }
634 EXPECT_EQ(1, CountRenderProcessHosts());
635 611
636 // Registering again should succeed, although the algo still 612 // Registering again should succeed, although the algo still
637 // might not be complete. 613 // might not be complete.
638 { 614 {
639 base::RunLoop run_loop; 615 base::RunLoop run_loop;
640 public_context()->RegisterServiceWorker( 616 public_context()->RegisterServiceWorker(
641 embedded_test_server()->GetURL("/*"), 617 embedded_test_server()->GetURL("/*"),
642 embedded_test_server()->GetURL(kWorkerUrl), 618 embedded_test_server()->GetURL(kWorkerUrl),
643 base::Bind(&ServiceWorkerBlackBoxBrowserTest::ExpectResultAndRun, 619 base::Bind(&ServiceWorkerBlackBoxBrowserTest::ExpectResultAndRun,
644 true, 620 true,
645 run_loop.QuitClosure())); 621 run_loop.QuitClosure()));
646 run_loop.Run(); 622 run_loop.Run();
647 } 623 }
648 624
649 // The registration algo might not be far enough along to have 625 // The registration algo might not be far enough along to have
650 // stored the registration data, so it may not be findable 626 // stored the registration data, so it may not be findable
651 // at this point. 627 // at this point.
652 628
653 // Unregistering something should return true. 629 // Unregistering something should return true.
654 { 630 {
655 base::RunLoop run_loop; 631 base::RunLoop run_loop;
656 public_context()->UnregisterServiceWorker( 632 public_context()->UnregisterServiceWorker(
657 embedded_test_server()->GetURL("/*"), 633 embedded_test_server()->GetURL("/*"),
658 base::Bind(&ServiceWorkerBlackBoxBrowserTest::ExpectResultAndRun, 634 base::Bind(&ServiceWorkerBlackBoxBrowserTest::ExpectResultAndRun,
659 true, 635 true,
660 run_loop.QuitClosure())); 636 run_loop.QuitClosure()));
661 run_loop.Run(); 637 run_loop.Run();
662 } 638 }
663 EXPECT_GE(1, CountRenderProcessHosts()) << "Unregistering doesn't stop the "
664 "workers eagerly, so their RPHs "
665 "can still be running.";
666 639
667 // Should not be able to find it. 640 // Should not be able to find it.
668 { 641 {
669 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; 642 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
670 GURL script_url; 643 GURL script_url;
671 RunOnIOThread( 644 RunOnIOThread(
672 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, 645 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO,
673 this, 646 this,
674 embedded_test_server()->GetURL("/service_worker/empty.html"), 647 embedded_test_server()->GetURL("/service_worker/empty.html"),
675 &status, 648 &status,
676 &script_url)); 649 &script_url));
677 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); 650 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status);
678 } 651 }
679 } 652 }
680 653
681 } // namespace content 654 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698