OLD | NEW |
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 "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "content/browser/browser_thread_impl.h" | 10 #include "content/browser/browser_thread_impl.h" |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 615 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
616 EXPECT_EQ(STORAGE_RECOVERED, notifications_[1].type); | 616 EXPECT_EQ(STORAGE_RECOVERED, notifications_[1].type); |
617 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); | 617 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); |
618 EXPECT_EQ(pattern, notifications_[2].pattern); | 618 EXPECT_EQ(pattern, notifications_[2].pattern); |
619 EXPECT_EQ(registration_id, notifications_[2].registration_id); | 619 EXPECT_EQ(registration_id, notifications_[2].registration_id); |
620 } | 620 } |
621 | 621 |
622 TEST_F(ServiceWorkerContextTest, ProviderHostIterator) { | 622 TEST_F(ServiceWorkerContextTest, ProviderHostIterator) { |
623 const int kRenderProcessId1 = 1; | 623 const int kRenderProcessId1 = 1; |
624 const int kRenderProcessId2 = 2; | 624 const int kRenderProcessId2 = 2; |
| 625 int kMockRenderFrameId1 = 1; |
| 626 int kMockRenderFrameId2 = 2; |
| 627 int kMockRenderFrameId3 = 3; |
625 const GURL kOrigin1 = GURL("http://www.example.com/"); | 628 const GURL kOrigin1 = GURL("http://www.example.com/"); |
626 const GURL kOrigin2 = GURL("https://www.example.com/"); | 629 const GURL kOrigin2 = GURL("https://www.example.com/"); |
627 int provider_id = 1; | 630 int provider_id = 1; |
628 | 631 |
629 // Host1 (provider_id=1): process_id=1, origin1. | 632 // Host1 (provider_id=1): process_id=1, origin1. |
630 ServiceWorkerProviderHost* host1(new ServiceWorkerProviderHost( | 633 ServiceWorkerProviderHost* host1(new ServiceWorkerProviderHost( |
631 kRenderProcessId1, MSG_ROUTING_NONE, provider_id++, | 634 kRenderProcessId1, kMockRenderFrameId1, MSG_ROUTING_NONE, provider_id++, |
632 SERVICE_WORKER_PROVIDER_FOR_WINDOW, context()->AsWeakPtr(), nullptr)); | 635 context()->AsWeakPtr(), nullptr)); |
633 host1->SetDocumentUrl(kOrigin1); | 636 host1->SetDocumentUrl(kOrigin1); |
634 | 637 |
635 // Host2 (provider_id=2): process_id=2, origin2. | 638 // Host2 (provider_id=2): process_id=2, origin2. |
636 ServiceWorkerProviderHost* host2(new ServiceWorkerProviderHost( | 639 ServiceWorkerProviderHost* host2(new ServiceWorkerProviderHost( |
637 kRenderProcessId2, MSG_ROUTING_NONE, provider_id++, | 640 kRenderProcessId2, kMockRenderFrameId2, MSG_ROUTING_NONE, provider_id++, |
638 SERVICE_WORKER_PROVIDER_FOR_WINDOW, context()->AsWeakPtr(), nullptr)); | 641 context()->AsWeakPtr(), nullptr)); |
639 host2->SetDocumentUrl(kOrigin2); | 642 host2->SetDocumentUrl(kOrigin2); |
640 | 643 |
641 // Host3 (provider_id=3): process_id=2, origin1. | 644 // Host3 (provider_id=3): process_id=2, origin1. |
642 ServiceWorkerProviderHost* host3(new ServiceWorkerProviderHost( | 645 ServiceWorkerProviderHost* host3(new ServiceWorkerProviderHost( |
643 kRenderProcessId2, MSG_ROUTING_NONE, provider_id++, | 646 kRenderProcessId2, kMockRenderFrameId3, MSG_ROUTING_NONE, provider_id++, |
644 SERVICE_WORKER_PROVIDER_FOR_WINDOW, context()->AsWeakPtr(), nullptr)); | 647 context()->AsWeakPtr(), nullptr)); |
645 host3->SetDocumentUrl(kOrigin1); | 648 host3->SetDocumentUrl(kOrigin1); |
646 | 649 |
647 // Host4 (provider_id=4): process_id=2, origin2, for ServiceWorker. | 650 // Host4 (provider_id=4): process_id=2, origin2, for ServiceWorker. |
648 ServiceWorkerProviderHost* host4(new ServiceWorkerProviderHost( | 651 ServiceWorkerProviderHost* host4(new ServiceWorkerProviderHost( |
649 kRenderProcessId2, MSG_ROUTING_NONE, provider_id++, | 652 kRenderProcessId2, MSG_ROUTING_NONE, MSG_ROUTING_NONE, provider_id++, |
650 SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, context()->AsWeakPtr(), nullptr)); | 653 context()->AsWeakPtr(), nullptr)); |
651 host4->SetDocumentUrl(kOrigin2); | 654 host4->SetDocumentUrl(kOrigin2); |
652 | 655 |
653 context()->AddProviderHost(make_scoped_ptr(host1)); | 656 context()->AddProviderHost(make_scoped_ptr(host1)); |
654 context()->AddProviderHost(make_scoped_ptr(host2)); | 657 context()->AddProviderHost(make_scoped_ptr(host2)); |
655 context()->AddProviderHost(make_scoped_ptr(host3)); | 658 context()->AddProviderHost(make_scoped_ptr(host3)); |
656 context()->AddProviderHost(make_scoped_ptr(host4)); | 659 context()->AddProviderHost(make_scoped_ptr(host4)); |
657 | 660 |
658 // Iterate over all provider hosts. | 661 // Iterate over all provider hosts. |
659 std::set<ServiceWorkerProviderHost*> results; | 662 std::set<ServiceWorkerProviderHost*> results; |
660 for (auto it = context()->GetProviderHostIterator(); !it->IsAtEnd(); | 663 for (auto it = context()->GetProviderHostIterator(); !it->IsAtEnd(); |
(...skipping 26 matching lines...) Expand all Loading... |
687 EXPECT_EQ(1u, results.size()); | 690 EXPECT_EQ(1u, results.size()); |
688 EXPECT_TRUE(ContainsKey(results, host2)); | 691 EXPECT_TRUE(ContainsKey(results, host2)); |
689 | 692 |
690 context()->RemoveProviderHost(kRenderProcessId1, 1); | 693 context()->RemoveProviderHost(kRenderProcessId1, 1); |
691 context()->RemoveProviderHost(kRenderProcessId2, 2); | 694 context()->RemoveProviderHost(kRenderProcessId2, 2); |
692 context()->RemoveProviderHost(kRenderProcessId2, 3); | 695 context()->RemoveProviderHost(kRenderProcessId2, 3); |
693 context()->RemoveProviderHost(kRenderProcessId2, 4); | 696 context()->RemoveProviderHost(kRenderProcessId2, 4); |
694 } | 697 } |
695 | 698 |
696 } // namespace content | 699 } // namespace content |
OLD | NEW |