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" |
11 #include "content/browser/service_worker/embedded_worker_registry.h" | 11 #include "content/browser/service_worker/embedded_worker_registry.h" |
12 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 12 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
13 #include "content/browser/service_worker/service_worker_context_core.h" | 13 #include "content/browser/service_worker/service_worker_context_core.h" |
14 #include "content/browser/service_worker/service_worker_context_observer.h" | 14 #include "content/browser/service_worker/service_worker_context_observer.h" |
15 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 15 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
16 #include "content/browser/service_worker/service_worker_provider_host.h" | |
16 #include "content/browser/service_worker/service_worker_registration.h" | 17 #include "content/browser/service_worker/service_worker_registration.h" |
17 #include "content/browser/service_worker/service_worker_storage.h" | 18 #include "content/browser/service_worker/service_worker_storage.h" |
18 #include "content/common/service_worker/embedded_worker_messages.h" | 19 #include "content/common/service_worker/embedded_worker_messages.h" |
19 #include "content/common/service_worker/service_worker_messages.h" | 20 #include "content/common/service_worker/service_worker_messages.h" |
20 #include "content/public/test/test_browser_thread_bundle.h" | 21 #include "content/public/test/test_browser_thread_bundle.h" |
21 #include "content/public/test/test_utils.h" | 22 #include "content/public/test/test_utils.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 | 24 |
24 namespace content { | 25 namespace content { |
25 | 26 |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
599 ASSERT_EQ(3u, notifications_.size()); | 600 ASSERT_EQ(3u, notifications_.size()); |
600 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 601 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
601 EXPECT_EQ(pattern, notifications_[0].pattern); | 602 EXPECT_EQ(pattern, notifications_[0].pattern); |
602 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 603 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
603 EXPECT_EQ(STORAGE_RECOVERED, notifications_[1].type); | 604 EXPECT_EQ(STORAGE_RECOVERED, notifications_[1].type); |
604 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); | 605 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); |
605 EXPECT_EQ(pattern, notifications_[2].pattern); | 606 EXPECT_EQ(pattern, notifications_[2].pattern); |
606 EXPECT_EQ(registration_id, notifications_[2].registration_id); | 607 EXPECT_EQ(registration_id, notifications_[2].registration_id); |
607 } | 608 } |
608 | 609 |
610 TEST_F(ServiceWorkerContextTest, ProviderHostIterator) { | |
611 const int kRenderProcessId1 = 1; | |
612 const int kRenderProcessId2 = 2; | |
613 const GURL kOrigin1 = GURL("http://www.example.com/"); | |
614 const GURL kOrigin2 = GURL("https://www.example.com/"); | |
615 int provider_id = 1; | |
616 | |
617 // Host1 (provider_id=1): process_id=1, origin1. | |
618 ServiceWorkerProviderHost* host1(new ServiceWorkerProviderHost( | |
619 kRenderProcessId1, MSG_ROUTING_NONE, provider_id++, | |
620 SERVICE_WORKER_PROVIDER_FOR_CONTROLLEE, context()->AsWeakPtr(), nullptr)); | |
621 host1->SetDocumentUrl(kOrigin1); | |
622 | |
623 // Host2 (provider_id=2): process_id=2, origin2. | |
624 ServiceWorkerProviderHost* host2(new ServiceWorkerProviderHost( | |
625 kRenderProcessId2, MSG_ROUTING_NONE, provider_id++, | |
626 SERVICE_WORKER_PROVIDER_FOR_CONTROLLEE, context()->AsWeakPtr(), nullptr)); | |
627 host2->SetDocumentUrl(kOrigin2); | |
628 | |
629 // Host3 (provider_id=3): process_id=2, origin1. | |
630 ServiceWorkerProviderHost* host3(new ServiceWorkerProviderHost( | |
631 kRenderProcessId2, MSG_ROUTING_NONE, provider_id++, | |
632 SERVICE_WORKER_PROVIDER_FOR_CONTROLLEE, context()->AsWeakPtr(), nullptr)); | |
633 host3->SetDocumentUrl(kOrigin1); | |
634 | |
635 // Host4 (provider_id=4): process_id=2, origin2, for ServiceWorker. | |
636 ServiceWorkerProviderHost* host4(new ServiceWorkerProviderHost( | |
637 kRenderProcessId2, MSG_ROUTING_NONE, provider_id++, | |
638 SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, context()->AsWeakPtr(), nullptr)); | |
639 host3->SetDocumentUrl(kOrigin1); | |
nhiroki
2015/03/20 09:08:05
According to the comment, this should be
host3 ->
kinuko
2015/03/20 09:19:12
:O fixed.
| |
640 | |
641 context()->AddProviderHost(make_scoped_ptr(host1)); | |
642 context()->AddProviderHost(make_scoped_ptr(host2)); | |
643 context()->AddProviderHost(make_scoped_ptr(host3)); | |
644 context()->AddProviderHost(make_scoped_ptr(host4)); | |
645 | |
646 // Iterate over all provider hosts. | |
647 std::set<ServiceWorkerProviderHost*> results; | |
648 for (auto it = context()->GetProviderHostIterator(); !it->IsAtEnd(); | |
649 it->Advance()) { | |
650 results.insert(it->GetProviderHost()); | |
651 } | |
652 EXPECT_EQ(4u, results.size()); | |
653 EXPECT_TRUE(ContainsKey(results, host1)); | |
654 EXPECT_TRUE(ContainsKey(results, host2)); | |
655 EXPECT_TRUE(ContainsKey(results, host3)); | |
656 EXPECT_TRUE(ContainsKey(results, host4)); | |
657 | |
658 // Iterate over the client provider hosts that belong to kOrigin1. | |
659 results.clear(); | |
660 for (auto it = context()->GetClientProviderHostIterator(kOrigin1); | |
661 !it->IsAtEnd(); it->Advance()) { | |
662 results.insert(it->GetProviderHost()); | |
663 } | |
664 EXPECT_EQ(2u, results.size()); | |
665 EXPECT_TRUE(ContainsKey(results, host1)); | |
666 EXPECT_TRUE(ContainsKey(results, host3)); | |
667 | |
668 // Iterate over the provider hosts that belong to kOrigin2. | |
669 // (This should not include host4 as it's not for controllee.) | |
670 results.clear(); | |
671 for (auto it = context()->GetClientProviderHostIterator(kOrigin2); | |
672 !it->IsAtEnd(); it->Advance()) { | |
673 results.insert(it->GetProviderHost()); | |
674 } | |
675 EXPECT_EQ(1u, results.size()); | |
676 EXPECT_TRUE(ContainsKey(results, host2)); | |
677 | |
678 context()->RemoveProviderHost(kRenderProcessId1, 1); | |
679 context()->RemoveProviderHost(kRenderProcessId2, 2); | |
680 context()->RemoveProviderHost(kRenderProcessId2, 3); | |
681 context()->RemoveProviderHost(kRenderProcessId2, 4); | |
682 } | |
683 | |
609 } // namespace content | 684 } // namespace content |
OLD | NEW |