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

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

Issue 2638313002: Manage ServiceWorkerDispatcherHost in ServiceWorkerContextCore (Closed)
Patch Set: Fix an include guard Created 3 years, 10 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/public/browser/service_worker_context.h" 5 #include "content/public/browser/service_worker_context.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 } 576 }
577 577
578 TEST_F(ServiceWorkerContextTest, ProviderHostIterator) { 578 TEST_F(ServiceWorkerContextTest, ProviderHostIterator) {
579 const int kRenderProcessId1 = 1; 579 const int kRenderProcessId1 = 1;
580 const int kRenderProcessId2 = 2; 580 const int kRenderProcessId2 = 2;
581 const GURL kOrigin1 = GURL("http://www.example.com/"); 581 const GURL kOrigin1 = GURL("http://www.example.com/");
582 const GURL kOrigin2 = GURL("https://www.example.com/"); 582 const GURL kOrigin2 = GURL("https://www.example.com/");
583 int provider_id = 1; 583 int provider_id = 1;
584 584
585 // Host1 (provider_id=1): process_id=1, origin1. 585 // Host1 (provider_id=1): process_id=1, origin1.
586 ServiceWorkerProviderHost* host1(new ServiceWorkerProviderHost( 586 std::unique_ptr<ServiceWorkerProviderHost> host1 =
587 kRenderProcessId1, MSG_ROUTING_NONE, provider_id++, 587 CreateProviderHostForWindow(kRenderProcessId1, provider_id++,
588 SERVICE_WORKER_PROVIDER_FOR_WINDOW, 588 true /* is_parent_frame_secure */,
589 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE, 589 context()->AsWeakPtr());
590 context()->AsWeakPtr(), nullptr));
591 host1->SetDocumentUrl(kOrigin1); 590 host1->SetDocumentUrl(kOrigin1);
592 591
593 // Host2 (provider_id=2): process_id=2, origin2. 592 // Host2 (provider_id=2): process_id=2, origin2.
594 ServiceWorkerProviderHost* host2(new ServiceWorkerProviderHost( 593 std::unique_ptr<ServiceWorkerProviderHost> host2 =
595 kRenderProcessId2, MSG_ROUTING_NONE, provider_id++, 594 CreateProviderHostForWindow(kRenderProcessId2, provider_id++,
596 SERVICE_WORKER_PROVIDER_FOR_WINDOW, 595 true /* is_parent_frame_secure */,
597 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE, 596 context()->AsWeakPtr());
598 context()->AsWeakPtr(), nullptr));
599 host2->SetDocumentUrl(kOrigin2); 597 host2->SetDocumentUrl(kOrigin2);
600 598
601 // Host3 (provider_id=3): process_id=2, origin1. 599 // Host3 (provider_id=3): process_id=2, origin1.
602 ServiceWorkerProviderHost* host3(new ServiceWorkerProviderHost( 600 std::unique_ptr<ServiceWorkerProviderHost> host3 =
603 kRenderProcessId2, MSG_ROUTING_NONE, provider_id++, 601 CreateProviderHostForWindow(kRenderProcessId2, provider_id++,
604 SERVICE_WORKER_PROVIDER_FOR_WINDOW, 602 true /* is_parent_frame_secure */,
605 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE, 603 context()->AsWeakPtr());
606 context()->AsWeakPtr(), nullptr));
607 host3->SetDocumentUrl(kOrigin1); 604 host3->SetDocumentUrl(kOrigin1);
608 605
609 // Host4 (provider_id=4): process_id=2, origin2, for ServiceWorker. 606 // Host4 (provider_id=4): process_id=2, origin2, for ServiceWorker.
610 ServiceWorkerProviderHost* host4(new ServiceWorkerProviderHost( 607 std::unique_ptr<ServiceWorkerProviderHost> host4 =
611 kRenderProcessId2, MSG_ROUTING_NONE, provider_id++, 608 CreateProviderHostForServiceWorkerContext(
612 SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, 609 kRenderProcessId2, provider_id++, true /* is_parent_frame_secure */,
613 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE, 610 context()->AsWeakPtr());
614 context()->AsWeakPtr(), nullptr));
615 host4->SetDocumentUrl(kOrigin2); 611 host4->SetDocumentUrl(kOrigin2);
616 612
617 context()->AddProviderHost(base::WrapUnique(host1)); 613 ServiceWorkerProviderHost* host1_raw = host1.get();
618 context()->AddProviderHost(base::WrapUnique(host2)); 614 ServiceWorkerProviderHost* host2_raw = host2.get();
619 context()->AddProviderHost(base::WrapUnique(host3)); 615 ServiceWorkerProviderHost* host3_raw = host3.get();
620 context()->AddProviderHost(base::WrapUnique(host4)); 616 ServiceWorkerProviderHost* host4_raw = host4.get();
617 context()->AddProviderHost(std::move(host1));
618 context()->AddProviderHost(std::move(host2));
619 context()->AddProviderHost(std::move(host3));
620 context()->AddProviderHost(std::move(host4));
621 621
622 // Iterate over all provider hosts. 622 // Iterate over all provider hosts.
623 std::set<ServiceWorkerProviderHost*> results; 623 std::set<ServiceWorkerProviderHost*> results;
624 for (auto it = context()->GetProviderHostIterator(); !it->IsAtEnd(); 624 for (auto it = context()->GetProviderHostIterator(); !it->IsAtEnd();
625 it->Advance()) { 625 it->Advance()) {
626 results.insert(it->GetProviderHost()); 626 results.insert(it->GetProviderHost());
627 } 627 }
628 EXPECT_EQ(4u, results.size()); 628 EXPECT_EQ(4u, results.size());
629 EXPECT_TRUE(ContainsKey(results, host1)); 629 EXPECT_TRUE(ContainsKey(results, host1_raw));
630 EXPECT_TRUE(ContainsKey(results, host2)); 630 EXPECT_TRUE(ContainsKey(results, host2_raw));
631 EXPECT_TRUE(ContainsKey(results, host3)); 631 EXPECT_TRUE(ContainsKey(results, host3_raw));
632 EXPECT_TRUE(ContainsKey(results, host4)); 632 EXPECT_TRUE(ContainsKey(results, host4_raw));
633 633
634 // Iterate over the client provider hosts that belong to kOrigin1. 634 // Iterate over the client provider hosts that belong to kOrigin1.
635 results.clear(); 635 results.clear();
636 for (auto it = context()->GetClientProviderHostIterator(kOrigin1); 636 for (auto it = context()->GetClientProviderHostIterator(kOrigin1);
637 !it->IsAtEnd(); it->Advance()) { 637 !it->IsAtEnd(); it->Advance()) {
638 results.insert(it->GetProviderHost()); 638 results.insert(it->GetProviderHost());
639 } 639 }
640 EXPECT_EQ(2u, results.size()); 640 EXPECT_EQ(2u, results.size());
641 EXPECT_TRUE(ContainsKey(results, host1)); 641 EXPECT_TRUE(ContainsKey(results, host1_raw));
642 EXPECT_TRUE(ContainsKey(results, host3)); 642 EXPECT_TRUE(ContainsKey(results, host3_raw));
643 643
644 // Iterate over the provider hosts that belong to kOrigin2. 644 // Iterate over the provider hosts that belong to kOrigin2.
645 // (This should not include host4 as it's not for controllee.) 645 // (This should not include host4 as it's not for controllee.)
646 results.clear(); 646 results.clear();
647 for (auto it = context()->GetClientProviderHostIterator(kOrigin2); 647 for (auto it = context()->GetClientProviderHostIterator(kOrigin2);
648 !it->IsAtEnd(); it->Advance()) { 648 !it->IsAtEnd(); it->Advance()) {
649 results.insert(it->GetProviderHost()); 649 results.insert(it->GetProviderHost());
650 } 650 }
651 EXPECT_EQ(1u, results.size()); 651 EXPECT_EQ(1u, results.size());
652 EXPECT_TRUE(ContainsKey(results, host2)); 652 EXPECT_TRUE(ContainsKey(results, host2_raw));
653 653
654 context()->RemoveProviderHost(kRenderProcessId1, 1); 654 context()->RemoveProviderHost(kRenderProcessId1, 1);
655 context()->RemoveProviderHost(kRenderProcessId2, 2); 655 context()->RemoveProviderHost(kRenderProcessId2, 2);
656 context()->RemoveProviderHost(kRenderProcessId2, 3); 656 context()->RemoveProviderHost(kRenderProcessId2, 3);
657 context()->RemoveProviderHost(kRenderProcessId2, 4); 657 context()->RemoveProviderHost(kRenderProcessId2, 4);
658 } 658 }
659 659
660 class ServiceWorkerContextRecoveryTest 660 class ServiceWorkerContextRecoveryTest
661 : public ServiceWorkerContextTest, 661 : public ServiceWorkerContextTest,
662 public testing::WithParamInterface<bool> { 662 public testing::WithParamInterface<bool> {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); 758 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type);
759 EXPECT_EQ(pattern, notifications_[2].pattern); 759 EXPECT_EQ(pattern, notifications_[2].pattern);
760 EXPECT_EQ(registration_id, notifications_[2].registration_id); 760 EXPECT_EQ(registration_id, notifications_[2].registration_id);
761 } 761 }
762 762
763 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest, 763 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest,
764 ServiceWorkerContextRecoveryTest, 764 ServiceWorkerContextRecoveryTest,
765 testing::Bool()); 765 testing::Bool());
766 766
767 } // namespace content 767 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698