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 "content/browser/service_worker/service_worker_context_core.h" | 7 #include "content/browser/service_worker/service_worker_context_core.h" |
8 #include "content/browser/service_worker/service_worker_provider_host.h" | 8 #include "content/browser/service_worker/service_worker_provider_host.h" |
9 #include "content/browser/service_worker/service_worker_register_job.h" | 9 #include "content/browser/service_worker/service_worker_register_job.h" |
10 #include "content/browser/service_worker/service_worker_registration.h" | 10 #include "content/browser/service_worker/service_worker_registration.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 // Disassociating one provider_host shouldn't remove all process refs | 107 // Disassociating one provider_host shouldn't remove all process refs |
108 // from the version yet. | 108 // from the version yet. |
109 provider_host1_->SetActiveVersion(NULL); | 109 provider_host1_->SetActiveVersion(NULL); |
110 ASSERT_TRUE(version_->HasProcessToRun()); | 110 ASSERT_TRUE(version_->HasProcessToRun()); |
111 | 111 |
112 // Disassociating the other provider_host will remove all process refs. | 112 // Disassociating the other provider_host will remove all process refs. |
113 provider_host2_->SetActiveVersion(NULL); | 113 provider_host2_->SetActiveVersion(NULL); |
114 ASSERT_FALSE(version_->HasProcessToRun()); | 114 ASSERT_FALSE(version_->HasProcessToRun()); |
115 } | 115 } |
116 | 116 |
117 TEST_F(ServiceWorkerProviderHostTest, SetPendingVersion_ProcessStatus) { | 117 TEST_F(ServiceWorkerProviderHostTest, SetWaitingVersion_ProcessStatus) { |
118 ASSERT_FALSE(version_->HasProcessToRun()); | 118 ASSERT_FALSE(version_->HasProcessToRun()); |
119 | 119 |
120 // Associating version_ to a provider_host's pending version will internally | 120 // Associating version_ to a provider_host's waiting version will internally |
121 // add the provider_host's process ref to the version. | 121 // add the provider_host's process ref to the version. |
122 provider_host1_->SetPendingVersion(version_); | 122 provider_host1_->SetWaitingVersion(version_); |
123 ASSERT_TRUE(version_->HasProcessToRun()); | 123 ASSERT_TRUE(version_->HasProcessToRun()); |
124 | 124 |
125 // Re-associating the same version and provider_host should just work too. | 125 // Re-associating the same version and provider_host should just work too. |
126 provider_host1_->SetPendingVersion(version_); | 126 provider_host1_->SetWaitingVersion(version_); |
127 ASSERT_TRUE(version_->HasProcessToRun()); | 127 ASSERT_TRUE(version_->HasProcessToRun()); |
128 | 128 |
129 // Resetting the provider_host's pending version should remove process refs | 129 // Resetting the provider_host's waiting version should remove process refs |
130 // from the version. | 130 // from the version. |
131 provider_host1_->SetPendingVersion(NULL); | 131 provider_host1_->SetWaitingVersion(NULL); |
132 ASSERT_FALSE(version_->HasProcessToRun()); | 132 ASSERT_FALSE(version_->HasProcessToRun()); |
133 } | 133 } |
134 | 134 |
135 TEST_F(ServiceWorkerProviderHostTest, | 135 TEST_F(ServiceWorkerProviderHostTest, |
136 SetPendingVersion_MultipleHostsForSameProcess) { | 136 SetWaitingVersion_MultipleHostsForSameProcess) { |
137 ASSERT_FALSE(version_->HasProcessToRun()); | 137 ASSERT_FALSE(version_->HasProcessToRun()); |
138 | 138 |
139 // Associating version_ to two providers as active version. | 139 // Associating version_ to two providers as active version. |
140 provider_host1_->SetPendingVersion(version_); | 140 provider_host1_->SetWaitingVersion(version_); |
141 provider_host2_->SetPendingVersion(version_); | 141 provider_host2_->SetWaitingVersion(version_); |
142 ASSERT_TRUE(version_->HasProcessToRun()); | 142 ASSERT_TRUE(version_->HasProcessToRun()); |
143 | 143 |
144 // Disassociating one provider_host shouldn't remove all process refs | 144 // Disassociating one provider_host shouldn't remove all process refs |
145 // from the version yet. | 145 // from the version yet. |
146 provider_host1_->SetPendingVersion(NULL); | 146 provider_host1_->SetWaitingVersion(NULL); |
147 ASSERT_TRUE(version_->HasProcessToRun()); | 147 ASSERT_TRUE(version_->HasProcessToRun()); |
148 | 148 |
149 // Disassociating the other provider_host will remove all process refs. | 149 // Disassociating the other provider_host will remove all process refs. |
150 provider_host2_->SetPendingVersion(NULL); | 150 provider_host2_->SetWaitingVersion(NULL); |
151 ASSERT_FALSE(version_->HasProcessToRun()); | 151 ASSERT_FALSE(version_->HasProcessToRun()); |
152 } | 152 } |
153 | 153 |
154 class ServiceWorkerRegisterJobAndProviderHostTest | 154 class ServiceWorkerRegisterJobAndProviderHostTest |
155 : public ServiceWorkerProviderHostTest { | 155 : public ServiceWorkerProviderHostTest { |
156 protected: | 156 protected: |
157 ServiceWorkerRegisterJobAndProviderHostTest() {} | 157 ServiceWorkerRegisterJobAndProviderHostTest() {} |
158 virtual ~ServiceWorkerRegisterJobAndProviderHostTest() {} | 158 virtual ~ServiceWorkerRegisterJobAndProviderHostTest() {} |
159 | 159 |
160 virtual void SetUp() OVERRIDE { | 160 virtual void SetUp() OVERRIDE { |
161 ServiceWorkerProviderHostTest::SetUp(); | 161 ServiceWorkerProviderHostTest::SetUp(); |
162 register_job_.reset(new ServiceWorkerRegisterJob( | 162 register_job_.reset(new ServiceWorkerRegisterJob( |
163 context_->AsWeakPtr(), scope_, script_url_)); | 163 context_->AsWeakPtr(), scope_, script_url_)); |
164 provider_host1_->set_document_url(GURL("http://www.example.com/foo")); | 164 provider_host1_->set_document_url(GURL("http://www.example.com/foo")); |
165 provider_host2_->set_document_url(GURL("http://www.example.com/bar")); | 165 provider_host2_->set_document_url(GURL("http://www.example.com/bar")); |
166 provider_host3_->set_document_url(GURL("http://www.example.ca/foo")); | 166 provider_host3_->set_document_url(GURL("http://www.example.ca/foo")); |
167 } | 167 } |
168 | 168 |
169 virtual void TearDown() OVERRIDE { | 169 virtual void TearDown() OVERRIDE { |
170 ServiceWorkerProviderHostTest::TearDown(); | 170 ServiceWorkerProviderHostTest::TearDown(); |
171 register_job_.reset(); | 171 register_job_.reset(); |
172 } | 172 } |
173 | 173 |
174 scoped_ptr<ServiceWorkerRegisterJob> register_job_; | 174 scoped_ptr<ServiceWorkerRegisterJob> register_job_; |
175 | 175 |
176 private: | 176 private: |
177 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJobAndProviderHostTest); | 177 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegisterJobAndProviderHostTest); |
178 }; | 178 }; |
179 | 179 |
180 // Test for ServiceWorkerRegisterJob::AssociatePendingVersionToDocuments. | 180 // Test for ServiceWorkerRegisterJob::AssociateWaitingVersionToDocuments. |
181 TEST_F(ServiceWorkerRegisterJobAndProviderHostTest, | 181 TEST_F(ServiceWorkerRegisterJobAndProviderHostTest, |
182 AssociatePendingVersionToDocuments) { | 182 AssociateWaitingVersionToDocuments) { |
183 register_job_->AssociatePendingVersionToDocuments(version_.get()); | 183 register_job_->AssociateWaitingVersionToDocuments(version_.get()); |
184 EXPECT_EQ(version_.get(), provider_host1_->pending_version()); | 184 EXPECT_EQ(version_.get(), provider_host1_->waiting_version()); |
185 EXPECT_EQ(version_.get(), provider_host2_->pending_version()); | 185 EXPECT_EQ(version_.get(), provider_host2_->waiting_version()); |
186 EXPECT_EQ(NULL, provider_host3_->pending_version()); | 186 EXPECT_EQ(NULL, provider_host3_->waiting_version()); |
187 | 187 |
188 register_job_->AssociatePendingVersionToDocuments(NULL); | 188 register_job_->AssociateWaitingVersionToDocuments(NULL); |
189 EXPECT_EQ(NULL, provider_host1_->pending_version()); | 189 EXPECT_EQ(NULL, provider_host1_->waiting_version()); |
190 EXPECT_EQ(NULL, provider_host2_->pending_version()); | 190 EXPECT_EQ(NULL, provider_host2_->waiting_version()); |
191 EXPECT_EQ(NULL, provider_host3_->pending_version()); | 191 EXPECT_EQ(NULL, provider_host3_->waiting_version()); |
192 } | 192 } |
193 | 193 |
194 } // namespace content | 194 } // namespace content |
OLD | NEW |