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 <tuple> | 5 #include <tuple> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "content/browser/service_worker/embedded_worker_registry.h" | 10 #include "content/browser/service_worker/embedded_worker_registry.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 helper_->context()->AsWeakPtr()); | 86 helper_->context()->AsWeakPtr()); |
87 version_ = new ServiceWorkerVersion( | 87 version_ = new ServiceWorkerVersion( |
88 registration_.get(), | 88 registration_.get(), |
89 GURL("http://www.example.com/service_worker.js"), | 89 GURL("http://www.example.com/service_worker.js"), |
90 1L, | 90 1L, |
91 helper_->context()->AsWeakPtr()); | 91 helper_->context()->AsWeakPtr()); |
92 std::vector<ServiceWorkerDatabase::ResourceRecord> records; | 92 std::vector<ServiceWorkerDatabase::ResourceRecord> records; |
93 records.push_back( | 93 records.push_back( |
94 ServiceWorkerDatabase::ResourceRecord(10, version_->script_url(), 100)); | 94 ServiceWorkerDatabase::ResourceRecord(10, version_->script_url(), 100)); |
95 version_->script_cache_map()->SetResources(records); | 95 version_->script_cache_map()->SetResources(records); |
| 96 version_->set_fetch_handler_existence( |
| 97 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); |
| 98 version_->SetStatus(ServiceWorkerVersion::INSTALLING); |
96 | 99 |
97 // Make the registration findable via storage functions. | 100 // Make the registration findable via storage functions. |
98 helper_->context()->storage()->LazyInitialize(base::Bind(&base::DoNothing)); | 101 helper_->context()->storage()->LazyInitialize(base::Bind(&base::DoNothing)); |
99 base::RunLoop().RunUntilIdle(); | 102 base::RunLoop().RunUntilIdle(); |
100 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | 103 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
101 helper_->context()->storage()->StoreRegistration( | 104 helper_->context()->storage()->StoreRegistration( |
102 registration_.get(), | 105 registration_.get(), |
103 version_.get(), | 106 version_.get(), |
104 CreateReceiverOnCurrentThread(&status)); | 107 CreateReceiverOnCurrentThread(&status)); |
105 base::RunLoop().RunUntilIdle(); | 108 base::RunLoop().RunUntilIdle(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 ServiceWorkerHandle::Create(helper_->context()->AsWeakPtr(), | 146 ServiceWorkerHandle::Create(helper_->context()->AsWeakPtr(), |
144 provider_host_->AsWeakPtr(), version_.get()); | 147 provider_host_->AsWeakPtr(), version_.get()); |
145 | 148 |
146 // Start the worker, and then... | 149 // Start the worker, and then... |
147 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | 150 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
148 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, | 151 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, |
149 CreateReceiverOnCurrentThread(&status)); | 152 CreateReceiverOnCurrentThread(&status)); |
150 base::RunLoop().RunUntilIdle(); | 153 base::RunLoop().RunUntilIdle(); |
151 EXPECT_EQ(SERVICE_WORKER_OK, status); | 154 EXPECT_EQ(SERVICE_WORKER_OK, status); |
152 | 155 |
153 // ...update state to installing... | 156 // ...update state to installed. |
154 version_->SetStatus(ServiceWorkerVersion::INSTALLING); | |
155 | |
156 // ...and update state to installed. | |
157 version_->SetStatus(ServiceWorkerVersion::INSTALLED); | 157 version_->SetStatus(ServiceWorkerVersion::INSTALLED); |
158 | 158 |
159 ASSERT_EQ(3UL, ipc_sink()->message_count()); | 159 ASSERT_EQ(2UL, ipc_sink()->message_count()); |
160 ASSERT_EQ(0L, dispatcher_host_->bad_message_received_count_); | 160 ASSERT_EQ(0L, dispatcher_host_->bad_message_received_count_); |
161 | 161 |
162 // We should be sending 1. StartWorker, | 162 // We should be sending 1. StartWorker, |
163 EXPECT_EQ(EmbeddedWorkerMsg_StartWorker::ID, | 163 EXPECT_EQ(EmbeddedWorkerMsg_StartWorker::ID, |
164 ipc_sink()->GetMessageAt(0)->type()); | 164 ipc_sink()->GetMessageAt(0)->type()); |
165 // 2. StateChanged (state == Installing), | 165 // 2. StateChanged (state == Installed). |
166 VerifyStateChangedMessage(handle->handle_id(), | |
167 blink::WebServiceWorkerStateInstalling, | |
168 ipc_sink()->GetMessageAt(1)); | |
169 // 3. StateChanged (state == Installed). | |
170 VerifyStateChangedMessage(handle->handle_id(), | 166 VerifyStateChangedMessage(handle->handle_id(), |
171 blink::WebServiceWorkerStateInstalled, | 167 blink::WebServiceWorkerStateInstalled, |
172 ipc_sink()->GetMessageAt(2)); | 168 ipc_sink()->GetMessageAt(1)); |
173 } | 169 } |
174 | 170 |
175 } // namespace content | 171 } // namespace content |
OLD | NEW |