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/browser/service_worker/service_worker_dispatcher_host.h" | 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "content/browser/browser_thread_impl.h" | 10 #include "content/browser/browser_thread_impl.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 110 |
111 TEST_F(ServiceWorkerDispatcherHostTest, Register_SameOrigin) { | 111 TEST_F(ServiceWorkerDispatcherHostTest, Register_SameOrigin) { |
112 const int64 kProviderId = 99; // Dummy value | 112 const int64 kProviderId = 99; // Dummy value |
113 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( | 113 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
114 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); | 114 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
115 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 115 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
116 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); | 116 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); |
117 context()->AddProviderHost(host.Pass()); | 117 context()->AddProviderHost(host.Pass()); |
118 | 118 |
119 Register(kProviderId, | 119 Register(kProviderId, |
120 GURL("https://www.example.com/*"), | 120 GURL("https://www.example.com/"), |
121 GURL("https://www.example.com/bar"), | 121 GURL("https://www.example.com/bar"), |
122 ServiceWorkerMsg_ServiceWorkerRegistered::ID); | 122 ServiceWorkerMsg_ServiceWorkerRegistered::ID); |
123 } | 123 } |
124 | 124 |
125 TEST_F(ServiceWorkerDispatcherHostTest, Register_CrossOrigin) { | 125 TEST_F(ServiceWorkerDispatcherHostTest, Register_CrossOrigin) { |
126 const int64 kProviderId = 99; // Dummy value | 126 const int64 kProviderId = 99; // Dummy value |
127 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( | 127 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
128 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); | 128 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
129 host->SetDocumentUrl(GURL("https://www.example.com/foo")); | 129 host->SetDocumentUrl(GURL("https://www.example.com/foo")); |
130 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); | 130 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); |
131 context()->AddProviderHost(host.Pass()); | 131 context()->AddProviderHost(host.Pass()); |
132 | 132 |
133 // Script has a different host | 133 // Script has a different host |
134 SendRegister(kProviderId, | 134 SendRegister(kProviderId, |
135 GURL("https://www.example.com/*"), | 135 GURL("https://www.example.com/"), |
136 GURL("https://foo.example.com/bar")); | 136 GURL("https://foo.example.com/bar")); |
137 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 137 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
138 | 138 |
139 // Scope has a different host | 139 // Scope has a different host |
140 SendRegister(kProviderId, | 140 SendRegister(kProviderId, |
141 GURL("https://foo.example.com/*"), | 141 GURL("https://foo.example.com/"), |
142 GURL("https://www.example.com/bar")); | 142 GURL("https://www.example.com/bar")); |
143 EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_); | 143 EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_); |
144 | 144 |
145 // Script has a different port | 145 // Script has a different port |
146 SendRegister(kProviderId, | 146 SendRegister(kProviderId, |
147 GURL("https://www.example.com/*"), | 147 GURL("https://www.example.com/"), |
148 GURL("https://www.example.com:8080/bar")); | 148 GURL("https://www.example.com:8080/bar")); |
149 EXPECT_EQ(3, dispatcher_host_->bad_messages_received_count_); | 149 EXPECT_EQ(3, dispatcher_host_->bad_messages_received_count_); |
150 | 150 |
151 // Scope has a different transport | 151 // Scope has a different transport |
152 SendRegister(kProviderId, | 152 SendRegister(kProviderId, |
153 GURL("wss://www.example.com/*"), | 153 GURL("wss://www.example.com/"), |
154 GURL("https://www.example.com/bar")); | 154 GURL("https://www.example.com/bar")); |
155 EXPECT_EQ(4, dispatcher_host_->bad_messages_received_count_); | 155 EXPECT_EQ(4, dispatcher_host_->bad_messages_received_count_); |
156 | 156 |
157 // Script and scope have different hosts | 157 // Script and scope have different hosts |
158 SendRegister(kProviderId, | 158 SendRegister(kProviderId, |
159 GURL("https://foo.example.com/*"), | 159 GURL("https://foo.example.com/"), |
160 GURL("https://foo.example.com/bar")); | 160 GURL("https://foo.example.com/bar")); |
161 EXPECT_EQ(5, dispatcher_host_->bad_messages_received_count_); | 161 EXPECT_EQ(5, dispatcher_host_->bad_messages_received_count_); |
162 | 162 |
163 // Script and scope URLs are invalid | 163 // Script and scope URLs are invalid |
164 SendRegister(kProviderId, | 164 SendRegister(kProviderId, |
165 GURL(), | 165 GURL(), |
166 GURL("h@ttps://@")); | 166 GURL("h@ttps://@")); |
167 EXPECT_EQ(6, dispatcher_host_->bad_messages_received_count_); | 167 EXPECT_EQ(6, dispatcher_host_->bad_messages_received_count_); |
168 } | 168 } |
169 | 169 |
170 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_SameOrigin) { | 170 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_SameOrigin) { |
171 const int64 kProviderId = 99; // Dummy value | 171 const int64 kProviderId = 99; // Dummy value |
172 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( | 172 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
173 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); | 173 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
174 host->SetDocumentUrl(GURL("http://www.example.com/foo")); | 174 host->SetDocumentUrl(GURL("http://www.example.com/foo")); |
175 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); | 175 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); |
176 context()->AddProviderHost(host.Pass()); | 176 context()->AddProviderHost(host.Pass()); |
177 | 177 |
178 Unregister(kProviderId, | 178 Unregister(kProviderId, |
179 GURL("http://www.example.com/*"), | 179 GURL("http://www.example.com/"), |
180 ServiceWorkerMsg_ServiceWorkerUnregistered::ID); | 180 ServiceWorkerMsg_ServiceWorkerUnregistered::ID); |
181 } | 181 } |
182 | 182 |
183 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_CrossOrigin) { | 183 TEST_F(ServiceWorkerDispatcherHostTest, Unregister_CrossOrigin) { |
184 const int64 kProviderId = 99; // Dummy value | 184 const int64 kProviderId = 99; // Dummy value |
185 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( | 185 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
186 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); | 186 kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); |
187 host->SetDocumentUrl(GURL("http://www.example.com/foo")); | 187 host->SetDocumentUrl(GURL("http://www.example.com/foo")); |
188 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); | 188 base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); |
189 context()->AddProviderHost(host.Pass()); | 189 context()->AddProviderHost(host.Pass()); |
190 | 190 |
191 SendUnregister(kProviderId, GURL("http://foo.example.com/*")); | 191 SendUnregister(kProviderId, GURL("http://foo.example.com/")); |
192 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); | 192 EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); |
193 } | 193 } |
194 | 194 |
195 TEST_F(ServiceWorkerDispatcherHostTest, EarlyContextDeletion) { | 195 TEST_F(ServiceWorkerDispatcherHostTest, EarlyContextDeletion) { |
196 helper_->ShutdownContext(); | 196 helper_->ShutdownContext(); |
197 | 197 |
198 // Let the shutdown reach the simulated IO thread. | 198 // Let the shutdown reach the simulated IO thread. |
199 base::RunLoop().RunUntilIdle(); | 199 base::RunLoop().RunUntilIdle(); |
200 | 200 |
201 Register(-1, | 201 Register(-1, |
(...skipping 27 matching lines...) Expand all Loading... |
229 // process to get deleted as well. | 229 // process to get deleted as well. |
230 dispatcher_host_->OnMessageReceived( | 230 dispatcher_host_->OnMessageReceived( |
231 ServiceWorkerHostMsg_ProviderCreated(kProviderId)); | 231 ServiceWorkerHostMsg_ProviderCreated(kProviderId)); |
232 EXPECT_TRUE(context()->GetProviderHost(kRenderProcessId, kProviderId)); | 232 EXPECT_TRUE(context()->GetProviderHost(kRenderProcessId, kProviderId)); |
233 EXPECT_TRUE(dispatcher_host_->HasOneRef()); | 233 EXPECT_TRUE(dispatcher_host_->HasOneRef()); |
234 dispatcher_host_ = NULL; | 234 dispatcher_host_ = NULL; |
235 EXPECT_FALSE(context()->GetProviderHost(kRenderProcessId, kProviderId)); | 235 EXPECT_FALSE(context()->GetProviderHost(kRenderProcessId, kProviderId)); |
236 } | 236 } |
237 | 237 |
238 } // namespace content | 238 } // namespace content |
OLD | NEW |