Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: content/browser/service_worker/service_worker_handle_unittest.cc

Issue 2251633002: Use tri-state enum for the existence of Fetch Handler in ServiceWorkerVersion. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_has_fetch_handler(true);
97 version_->SetStatus(ServiceWorkerVersion::INSTALLING);
96 98
97 // Make the registration findable via storage functions. 99 // Make the registration findable via storage functions.
98 helper_->context()->storage()->LazyInitialize(base::Bind(&base::DoNothing)); 100 helper_->context()->storage()->LazyInitialize(base::Bind(&base::DoNothing));
99 base::RunLoop().RunUntilIdle(); 101 base::RunLoop().RunUntilIdle();
100 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; 102 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
101 helper_->context()->storage()->StoreRegistration( 103 helper_->context()->storage()->StoreRegistration(
102 registration_.get(), 104 registration_.get(),
103 version_.get(), 105 version_.get(),
104 CreateReceiverOnCurrentThread(&status)); 106 CreateReceiverOnCurrentThread(&status));
105 base::RunLoop().RunUntilIdle(); 107 base::RunLoop().RunUntilIdle();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 ServiceWorkerHandle::Create(helper_->context()->AsWeakPtr(), 145 ServiceWorkerHandle::Create(helper_->context()->AsWeakPtr(),
144 provider_host_->AsWeakPtr(), version_.get()); 146 provider_host_->AsWeakPtr(), version_.get());
145 147
146 // Start the worker, and then... 148 // Start the worker, and then...
147 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; 149 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
148 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, 150 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN,
149 CreateReceiverOnCurrentThread(&status)); 151 CreateReceiverOnCurrentThread(&status));
150 base::RunLoop().RunUntilIdle(); 152 base::RunLoop().RunUntilIdle();
151 EXPECT_EQ(SERVICE_WORKER_OK, status); 153 EXPECT_EQ(SERVICE_WORKER_OK, status);
152 154
153 // ...update state to installing... 155 // ...update state to installed.
154 version_->SetStatus(ServiceWorkerVersion::INSTALLING);
155
156 // ...and update state to installed.
157 version_->SetStatus(ServiceWorkerVersion::INSTALLED); 156 version_->SetStatus(ServiceWorkerVersion::INSTALLED);
158 157
159 ASSERT_EQ(3UL, ipc_sink()->message_count()); 158 ASSERT_EQ(2UL, ipc_sink()->message_count());
160 ASSERT_EQ(0L, dispatcher_host_->bad_message_received_count_); 159 ASSERT_EQ(0L, dispatcher_host_->bad_message_received_count_);
161 160
162 // We should be sending 1. StartWorker, 161 // We should be sending 1. StartWorker,
163 EXPECT_EQ(EmbeddedWorkerMsg_StartWorker::ID, 162 EXPECT_EQ(EmbeddedWorkerMsg_StartWorker::ID,
164 ipc_sink()->GetMessageAt(0)->type()); 163 ipc_sink()->GetMessageAt(0)->type());
165 // 2. StateChanged (state == Installing), 164 // 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(), 165 VerifyStateChangedMessage(handle->handle_id(),
171 blink::WebServiceWorkerStateInstalled, 166 blink::WebServiceWorkerStateInstalled,
172 ipc_sink()->GetMessageAt(2)); 167 ipc_sink()->GetMessageAt(1));
173 } 168 }
174 169
175 } // namespace content 170 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698