| Index: content/browser/service_worker/service_worker_context_unittest.cc
|
| diff --git a/content/browser/service_worker/service_worker_context_unittest.cc b/content/browser/service_worker/service_worker_context_unittest.cc
|
| index fe206bca8701582bf0bb33994b97a1ff8390c64c..2474486c5f859b79a528cfcfc31523f05903817a 100644
|
| --- a/content/browser/service_worker/service_worker_context_unittest.cc
|
| +++ b/content/browser/service_worker/service_worker_context_unittest.cc
|
| @@ -13,6 +13,7 @@
|
| #include "content/browser/service_worker/service_worker_context_core.h"
|
| #include "content/browser/service_worker/service_worker_context_observer.h"
|
| #include "content/browser/service_worker/service_worker_context_wrapper.h"
|
| +#include "content/browser/service_worker/service_worker_provider_host.h"
|
| #include "content/browser/service_worker/service_worker_registration.h"
|
| #include "content/browser/service_worker/service_worker_storage.h"
|
| #include "content/common/service_worker/embedded_worker_messages.h"
|
| @@ -606,4 +607,68 @@ TEST_F(ServiceWorkerContextTest, DeleteAndStartOver) {
|
| EXPECT_EQ(registration_id, notifications_[2].registration_id);
|
| }
|
|
|
| +TEST_F(ServiceWorkerContextTest, ProviderHostIterator) {
|
| + const int kRenderProcessId1 = 1;
|
| + const int kRenderProcessId2 = 2;
|
| + const GURL kOrigin1 = GURL("http://www.example.com/");
|
| + const GURL kOrigin2 = GURL("https://www.example.com/");
|
| + int provider_id = 1;
|
| +
|
| + // Host1 (provider_id=1): process_id=1, origin1.
|
| + ServiceWorkerProviderHost* host1(new ServiceWorkerProviderHost(
|
| + kRenderProcessId1, MSG_ROUTING_NONE, provider_id++,
|
| + SERVICE_WORKER_PROVIDER_FOR_CONTROLLEE, context()->AsWeakPtr(), nullptr));
|
| + host1->SetDocumentUrl(kOrigin1);
|
| +
|
| + // Host2 (provider_id=2): process_id=2, origin2.
|
| + ServiceWorkerProviderHost* host2(new ServiceWorkerProviderHost(
|
| + kRenderProcessId2, MSG_ROUTING_NONE, provider_id++,
|
| + SERVICE_WORKER_PROVIDER_FOR_CONTROLLEE, context()->AsWeakPtr(), nullptr));
|
| + host2->SetDocumentUrl(kOrigin2);
|
| +
|
| + // Host3 (provider_id=3): process_id=2, origin1.
|
| + ServiceWorkerProviderHost* host3(new ServiceWorkerProviderHost(
|
| + kRenderProcessId2, MSG_ROUTING_NONE, provider_id++,
|
| + SERVICE_WORKER_PROVIDER_FOR_CONTROLLEE, context()->AsWeakPtr(), nullptr));
|
| + host3->SetDocumentUrl(kOrigin1);
|
| +
|
| + context()->AddProviderHost(make_scoped_ptr(host1));
|
| + context()->AddProviderHost(make_scoped_ptr(host2));
|
| + context()->AddProviderHost(make_scoped_ptr(host3));
|
| +
|
| + // Iterate over all provider hosts.
|
| + std::set<ServiceWorkerProviderHost*> results;
|
| + for (auto it = context()->GetProviderHostIterator(); !it->IsAtEnd();
|
| + it->Advance()) {
|
| + results.insert(it->GetProviderHost());
|
| + }
|
| + EXPECT_EQ(3u, results.size());
|
| + EXPECT_TRUE(ContainsKey(results, host1));
|
| + EXPECT_TRUE(ContainsKey(results, host2));
|
| + EXPECT_TRUE(ContainsKey(results, host3));
|
| +
|
| + // Iterate over the provider hosts that belong to kOrigin1.
|
| + results.clear();
|
| + for (auto it = context()->GetProviderHostIteratorForOrigin(kOrigin1);
|
| + !it->IsAtEnd(); it->Advance()) {
|
| + results.insert(it->GetProviderHost());
|
| + }
|
| + EXPECT_EQ(2u, results.size());
|
| + EXPECT_TRUE(ContainsKey(results, host1));
|
| + EXPECT_TRUE(ContainsKey(results, host3));
|
| +
|
| + // Iterate over the provider hosts that belong to kOrigin2.
|
| + results.clear();
|
| + for (auto it = context()->GetProviderHostIteratorForOrigin(kOrigin2);
|
| + !it->IsAtEnd(); it->Advance()) {
|
| + results.insert(it->GetProviderHost());
|
| + }
|
| + EXPECT_EQ(1u, results.size());
|
| + EXPECT_TRUE(ContainsKey(results, host2));
|
| +
|
| + context()->RemoveProviderHost(kRenderProcessId1, 1);
|
| + context()->RemoveProviderHost(kRenderProcessId2, 2);
|
| + context()->RemoveProviderHost(kRenderProcessId2, 3);
|
| +}
|
| +
|
| } // namespace content
|
|
|