| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/memory/weak_ptr.h" | 6 #include "base/memory/weak_ptr.h" |
| 7 #include "base/thread_task_runner_handle.h" | 7 #include "base/thread_task_runner_handle.h" |
| 8 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 8 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| 9 #include "content/browser/service_worker/service_worker_context_core.h" | 9 #include "content/browser/service_worker/service_worker_context_core.h" |
| 10 #include "content/browser/service_worker/service_worker_provider_host.h" | 10 #include "content/browser/service_worker/service_worker_provider_host.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 context_ = helper_->context(); | 30 context_ = helper_->context(); |
| 31 script_url_ = GURL("http://www.example.com/service_worker.js"); | 31 script_url_ = GURL("http://www.example.com/service_worker.js"); |
| 32 registration1_ = new ServiceWorkerRegistration( | 32 registration1_ = new ServiceWorkerRegistration( |
| 33 GURL("http://www.example.com/"), 1L, context_->AsWeakPtr()); | 33 GURL("http://www.example.com/"), 1L, context_->AsWeakPtr()); |
| 34 registration2_ = new ServiceWorkerRegistration( | 34 registration2_ = new ServiceWorkerRegistration( |
| 35 GURL("http://www.example.com/example"), 2L, context_->AsWeakPtr()); | 35 GURL("http://www.example.com/example"), 2L, context_->AsWeakPtr()); |
| 36 | 36 |
| 37 // Prepare provider hosts (for the same process). | 37 // Prepare provider hosts (for the same process). |
| 38 scoped_ptr<ServiceWorkerProviderHost> host1(new ServiceWorkerProviderHost( | 38 scoped_ptr<ServiceWorkerProviderHost> host1(new ServiceWorkerProviderHost( |
| 39 kRenderProcessId, MSG_ROUTING_NONE, 1 /* provider_id */, | 39 kRenderProcessId, MSG_ROUTING_NONE, 1 /* provider_id */, |
| 40 SERVICE_WORKER_PROVIDER_FOR_CONTROLLEE, | 40 SERVICE_WORKER_PROVIDER_FOR_WINDOW, context_->AsWeakPtr(), NULL)); |
| 41 context_->AsWeakPtr(), NULL)); | |
| 42 host1->SetDocumentUrl(GURL("http://www.example.com/example1.html")); | 41 host1->SetDocumentUrl(GURL("http://www.example.com/example1.html")); |
| 43 scoped_ptr<ServiceWorkerProviderHost> host2(new ServiceWorkerProviderHost( | 42 scoped_ptr<ServiceWorkerProviderHost> host2(new ServiceWorkerProviderHost( |
| 44 kRenderProcessId, MSG_ROUTING_NONE, 2 /* provider_id */, | 43 kRenderProcessId, MSG_ROUTING_NONE, 2 /* provider_id */, |
| 45 SERVICE_WORKER_PROVIDER_FOR_CONTROLLEE, | 44 SERVICE_WORKER_PROVIDER_FOR_WINDOW, context_->AsWeakPtr(), NULL)); |
| 46 context_->AsWeakPtr(), NULL)); | |
| 47 host2->SetDocumentUrl(GURL("http://www.example.com/example2.html")); | 45 host2->SetDocumentUrl(GURL("http://www.example.com/example2.html")); |
| 48 provider_host1_ = host1->AsWeakPtr(); | 46 provider_host1_ = host1->AsWeakPtr(); |
| 49 provider_host2_ = host2->AsWeakPtr(); | 47 provider_host2_ = host2->AsWeakPtr(); |
| 50 context_->AddProviderHost(make_scoped_ptr(host1.release())); | 48 context_->AddProviderHost(make_scoped_ptr(host1.release())); |
| 51 context_->AddProviderHost(make_scoped_ptr(host2.release())); | 49 context_->AddProviderHost(make_scoped_ptr(host2.release())); |
| 52 } | 50 } |
| 53 | 51 |
| 54 void TearDown() override { | 52 void TearDown() override { |
| 55 registration1_ = 0; | 53 registration1_ = 0; |
| 56 registration2_ = 0; | 54 registration2_ = 0; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 ASSERT_EQ(provider_host1_->MatchRegistration(), registration2_); | 118 ASSERT_EQ(provider_host1_->MatchRegistration(), registration2_); |
| 121 provider_host1_->RemoveMatchingRegistration(registration2_.get()); | 119 provider_host1_->RemoveMatchingRegistration(registration2_.get()); |
| 122 ASSERT_EQ(provider_host1_->MatchRegistration(), registration1_); | 120 ASSERT_EQ(provider_host1_->MatchRegistration(), registration1_); |
| 123 | 121 |
| 124 // Should return nullptr after removing all matching registrations. | 122 // Should return nullptr after removing all matching registrations. |
| 125 provider_host1_->RemoveMatchingRegistration(registration1_.get()); | 123 provider_host1_->RemoveMatchingRegistration(registration1_.get()); |
| 126 ASSERT_EQ(provider_host1_->MatchRegistration(), nullptr); | 124 ASSERT_EQ(provider_host1_->MatchRegistration(), nullptr); |
| 127 } | 125 } |
| 128 | 126 |
| 129 } // namespace content | 127 } // namespace content |
| OLD | NEW |