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

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

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

Powered by Google App Engine
This is Rietveld 408576698