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" |
11 #include "content/browser/service_worker/service_worker_register_job.h" | 11 #include "content/browser/service_worker/service_worker_register_job.h" |
12 #include "content/browser/service_worker/service_worker_registration.h" | 12 #include "content/browser/service_worker/service_worker_registration.h" |
13 #include "content/browser/service_worker/service_worker_version.h" | 13 #include "content/browser/service_worker/service_worker_version.h" |
14 #include "content/public/test/test_browser_thread_bundle.h" | 14 #include "content/public/test/test_browser_thread_bundle.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
19 static const int kRenderProcessId = 33; // Dummy process ID for testing. | 19 static const int kRenderProcessId = 33; // Dummy process ID for testing. |
20 | 20 |
21 class ServiceWorkerProviderHostTest : public testing::Test { | 21 class ServiceWorkerProviderHostTest : public testing::Test { |
22 protected: | 22 protected: |
23 ServiceWorkerProviderHostTest() | 23 ServiceWorkerProviderHostTest() |
24 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} | 24 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} |
25 ~ServiceWorkerProviderHostTest() override {} | 25 ~ServiceWorkerProviderHostTest() override {} |
26 | 26 |
27 void SetUp() override { | 27 void SetUp() override { |
28 helper_.reset(new EmbeddedWorkerTestHelper(kRenderProcessId)); | 28 helper_.reset( |
| 29 new EmbeddedWorkerTestHelper(base::FilePath(), kRenderProcessId)); |
29 context_ = helper_->context(); | 30 context_ = helper_->context(); |
30 script_url_ = GURL("http://www.example.com/service_worker.js"); | 31 script_url_ = GURL("http://www.example.com/service_worker.js"); |
31 registration1_ = new ServiceWorkerRegistration( | 32 registration1_ = new ServiceWorkerRegistration( |
32 GURL("http://www.example.com/"), 1L, context_->AsWeakPtr()); | 33 GURL("http://www.example.com/"), 1L, context_->AsWeakPtr()); |
33 registration2_ = new ServiceWorkerRegistration( | 34 registration2_ = new ServiceWorkerRegistration( |
34 GURL("http://www.example.com/example"), 2L, context_->AsWeakPtr()); | 35 GURL("http://www.example.com/example"), 2L, context_->AsWeakPtr()); |
35 | 36 |
36 // Prepare provider hosts (for the same process). | 37 // Prepare provider hosts (for the same process). |
37 scoped_ptr<ServiceWorkerProviderHost> host1(new ServiceWorkerProviderHost( | 38 scoped_ptr<ServiceWorkerProviderHost> host1(new ServiceWorkerProviderHost( |
38 kRenderProcessId, MSG_ROUTING_NONE, 1 /* provider_id */, | 39 kRenderProcessId, MSG_ROUTING_NONE, 1 /* provider_id */, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 ASSERT_EQ(provider_host1_->MatchRegistration(), registration2_); | 120 ASSERT_EQ(provider_host1_->MatchRegistration(), registration2_); |
120 provider_host1_->RemoveMatchingRegistration(registration2_.get()); | 121 provider_host1_->RemoveMatchingRegistration(registration2_.get()); |
121 ASSERT_EQ(provider_host1_->MatchRegistration(), registration1_); | 122 ASSERT_EQ(provider_host1_->MatchRegistration(), registration1_); |
122 | 123 |
123 // Should return nullptr after removing all matching registrations. | 124 // Should return nullptr after removing all matching registrations. |
124 provider_host1_->RemoveMatchingRegistration(registration1_.get()); | 125 provider_host1_->RemoveMatchingRegistration(registration1_.get()); |
125 ASSERT_EQ(provider_host1_->MatchRegistration(), nullptr); | 126 ASSERT_EQ(provider_host1_->MatchRegistration(), nullptr); |
126 } | 127 } |
127 | 128 |
128 } // namespace content | 129 } // namespace content |
OLD | NEW |