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

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

Issue 637183002: Replace FINAL and OVERRIDE with their C++11 counterparts in content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased the patch Created 6 years, 2 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "content/browser/fileapi/chrome_blob_storage_context.h" 10 #include "content/browser/fileapi/chrome_blob_storage_context.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 class WorkerActivatedObserver 138 class WorkerActivatedObserver
139 : public ServiceWorkerContextObserver, 139 : public ServiceWorkerContextObserver,
140 public base::RefCountedThreadSafe<WorkerActivatedObserver> { 140 public base::RefCountedThreadSafe<WorkerActivatedObserver> {
141 public: 141 public:
142 explicit WorkerActivatedObserver(ServiceWorkerContextWrapper* context) 142 explicit WorkerActivatedObserver(ServiceWorkerContextWrapper* context)
143 : context_(context) {} 143 : context_(context) {}
144 void Init() { 144 void Init() {
145 RunOnIOThread(base::Bind(&WorkerActivatedObserver::InitOnIOThread, this)); 145 RunOnIOThread(base::Bind(&WorkerActivatedObserver::InitOnIOThread, this));
146 } 146 }
147 // ServiceWorkerContextObserver overrides. 147 // ServiceWorkerContextObserver overrides.
148 virtual void OnVersionStateChanged(int64 version_id) OVERRIDE { 148 virtual void OnVersionStateChanged(int64 version_id) override {
149 DCHECK_CURRENTLY_ON(BrowserThread::IO); 149 DCHECK_CURRENTLY_ON(BrowserThread::IO);
150 const ServiceWorkerVersion* version = 150 const ServiceWorkerVersion* version =
151 context_->context()->GetLiveVersion(version_id); 151 context_->context()->GetLiveVersion(version_id);
152 if (version->status() == ServiceWorkerVersion::ACTIVATED) { 152 if (version->status() == ServiceWorkerVersion::ACTIVATED) {
153 context_->RemoveObserver(this); 153 context_->RemoveObserver(this);
154 BrowserThread::PostTask(BrowserThread::UI, 154 BrowserThread::PostTask(BrowserThread::UI,
155 FROM_HERE, 155 FROM_HERE,
156 base::Bind(&WorkerActivatedObserver::Quit, this)); 156 base::Bind(&WorkerActivatedObserver::Quit, this));
157 } 157 }
158 } 158 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 // an experiration far in the future. 190 // an experiration far in the future.
191 class LongLivedResourceInterceptor : public net::URLRequestInterceptor { 191 class LongLivedResourceInterceptor : public net::URLRequestInterceptor {
192 public: 192 public:
193 LongLivedResourceInterceptor(const std::string& body) 193 LongLivedResourceInterceptor(const std::string& body)
194 : body_(body) {} 194 : body_(body) {}
195 virtual ~LongLivedResourceInterceptor() {} 195 virtual ~LongLivedResourceInterceptor() {}
196 196
197 // net::URLRequestInterceptor implementation 197 // net::URLRequestInterceptor implementation
198 virtual net::URLRequestJob* MaybeInterceptRequest( 198 virtual net::URLRequestJob* MaybeInterceptRequest(
199 net::URLRequest* request, 199 net::URLRequest* request,
200 net::NetworkDelegate* network_delegate) const OVERRIDE { 200 net::NetworkDelegate* network_delegate) const override {
201 const char kHeaders[] = 201 const char kHeaders[] =
202 "HTTP/1.1 200 OK\0" 202 "HTTP/1.1 200 OK\0"
203 "Content-Type: text/javascript\0" 203 "Content-Type: text/javascript\0"
204 "Expires: Thu, 1 Jan 2100 20:00:00 GMT\0" 204 "Expires: Thu, 1 Jan 2100 20:00:00 GMT\0"
205 "\0"; 205 "\0";
206 std::string headers(kHeaders, arraysize(kHeaders)); 206 std::string headers(kHeaders, arraysize(kHeaders));
207 return new net::URLRequestTestJob( 207 return new net::URLRequestTestJob(
208 request, network_delegate, headers, body_, true); 208 request, network_delegate, headers, body_, true);
209 } 209 }
210 210
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 wrapper->context()->GetLiveVersion(version_id); 255 wrapper->context()->GetLiveVersion(version_id);
256 *num_resources = static_cast<int>(version->script_cache_map()->size()); 256 *num_resources = static_cast<int>(version->script_cache_map()->size());
257 } 257 }
258 258
259 } // namespace 259 } // namespace
260 260
261 class ServiceWorkerBrowserTest : public ContentBrowserTest { 261 class ServiceWorkerBrowserTest : public ContentBrowserTest {
262 protected: 262 protected:
263 typedef ServiceWorkerBrowserTest self; 263 typedef ServiceWorkerBrowserTest self;
264 264
265 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE { 265 virtual void SetUpCommandLine(base::CommandLine* command_line) override {
266 command_line->AppendSwitch( 266 command_line->AppendSwitch(
267 switches::kEnableExperimentalWebPlatformFeatures); 267 switches::kEnableExperimentalWebPlatformFeatures);
268 } 268 }
269 269
270 virtual void SetUpOnMainThread() OVERRIDE { 270 virtual void SetUpOnMainThread() override {
271 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 271 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
272 StoragePartition* partition = BrowserContext::GetDefaultStoragePartition( 272 StoragePartition* partition = BrowserContext::GetDefaultStoragePartition(
273 shell()->web_contents()->GetBrowserContext()); 273 shell()->web_contents()->GetBrowserContext());
274 wrapper_ = static_cast<ServiceWorkerContextWrapper*>( 274 wrapper_ = static_cast<ServiceWorkerContextWrapper*>(
275 partition->GetServiceWorkerContext()); 275 partition->GetServiceWorkerContext());
276 276
277 // Navigate to the page to set up a renderer page (where we can embed 277 // Navigate to the page to set up a renderer page (where we can embed
278 // a worker). 278 // a worker).
279 NavigateToURLBlockUntilNavigationsComplete( 279 NavigateToURLBlockUntilNavigationsComplete(
280 shell(), 280 shell(),
281 embedded_test_server()->GetURL("/service_worker/empty.html"), 1); 281 embedded_test_server()->GetURL("/service_worker/empty.html"), 1);
282 282
283 RunOnIOThread(base::Bind(&self::SetUpOnIOThread, this)); 283 RunOnIOThread(base::Bind(&self::SetUpOnIOThread, this));
284 } 284 }
285 285
286 virtual void TearDownOnMainThread() OVERRIDE { 286 virtual void TearDownOnMainThread() override {
287 RunOnIOThread(base::Bind(&self::TearDownOnIOThread, this)); 287 RunOnIOThread(base::Bind(&self::TearDownOnIOThread, this));
288 wrapper_ = NULL; 288 wrapper_ = NULL;
289 } 289 }
290 290
291 virtual void SetUpOnIOThread() {} 291 virtual void SetUpOnIOThread() {}
292 virtual void TearDownOnIOThread() {} 292 virtual void TearDownOnIOThread() {}
293 293
294 ServiceWorkerContextWrapper* wrapper() { return wrapper_.get(); } 294 ServiceWorkerContextWrapper* wrapper() { return wrapper_.get(); }
295 ServiceWorkerContext* public_context() { return wrapper(); } 295 ServiceWorkerContext* public_context() { return wrapper(); }
296 296
297 void AssociateRendererProcessToPattern(const GURL& pattern) { 297 void AssociateRendererProcessToPattern(const GURL& pattern) {
298 wrapper_->process_manager()->AddProcessReferenceToPattern( 298 wrapper_->process_manager()->AddProcessReferenceToPattern(
299 pattern, shell()->web_contents()->GetRenderProcessHost()->GetID()); 299 pattern, shell()->web_contents()->GetRenderProcessHost()->GetID());
300 } 300 }
301 301
302 private: 302 private:
303 scoped_refptr<ServiceWorkerContextWrapper> wrapper_; 303 scoped_refptr<ServiceWorkerContextWrapper> wrapper_;
304 }; 304 };
305 305
306 class EmbeddedWorkerBrowserTest : public ServiceWorkerBrowserTest, 306 class EmbeddedWorkerBrowserTest : public ServiceWorkerBrowserTest,
307 public EmbeddedWorkerInstance::Listener { 307 public EmbeddedWorkerInstance::Listener {
308 public: 308 public:
309 typedef EmbeddedWorkerBrowserTest self; 309 typedef EmbeddedWorkerBrowserTest self;
310 310
311 EmbeddedWorkerBrowserTest() 311 EmbeddedWorkerBrowserTest()
312 : last_worker_status_(EmbeddedWorkerInstance::STOPPED), 312 : last_worker_status_(EmbeddedWorkerInstance::STOPPED),
313 pause_mode_(DONT_PAUSE) {} 313 pause_mode_(DONT_PAUSE) {}
314 virtual ~EmbeddedWorkerBrowserTest() {} 314 virtual ~EmbeddedWorkerBrowserTest() {}
315 315
316 virtual void TearDownOnIOThread() OVERRIDE { 316 virtual void TearDownOnIOThread() override {
317 if (worker_) { 317 if (worker_) {
318 worker_->RemoveListener(this); 318 worker_->RemoveListener(this);
319 worker_.reset(); 319 worker_.reset();
320 } 320 }
321 } 321 }
322 322
323 void StartOnIOThread() { 323 void StartOnIOThread() {
324 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 324 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
325 worker_ = wrapper()->context()->embedded_worker_registry()->CreateWorker(); 325 worker_ = wrapper()->context()->embedded_worker_registry()->CreateWorker();
326 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker_->status()); 326 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker_->status());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 last_worker_status_ = worker_->status(); 360 last_worker_status_ = worker_->status();
361 EXPECT_EQ(SERVICE_WORKER_OK, status); 361 EXPECT_EQ(SERVICE_WORKER_OK, status);
362 EXPECT_EQ(EmbeddedWorkerInstance::STOPPING, last_worker_status_); 362 EXPECT_EQ(EmbeddedWorkerInstance::STOPPING, last_worker_status_);
363 363
364 if (status != SERVICE_WORKER_OK && !done_closure_.is_null()) 364 if (status != SERVICE_WORKER_OK && !done_closure_.is_null())
365 done_closure_.Run(); 365 done_closure_.Run();
366 } 366 }
367 367
368 protected: 368 protected:
369 // EmbeddedWorkerInstance::Observer overrides: 369 // EmbeddedWorkerInstance::Observer overrides:
370 virtual void OnStarted() OVERRIDE { 370 virtual void OnStarted() override {
371 ASSERT_TRUE(worker_ != NULL); 371 ASSERT_TRUE(worker_ != NULL);
372 ASSERT_FALSE(done_closure_.is_null()); 372 ASSERT_FALSE(done_closure_.is_null());
373 last_worker_status_ = worker_->status(); 373 last_worker_status_ = worker_->status();
374 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, done_closure_); 374 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, done_closure_);
375 } 375 }
376 virtual void OnStopped() OVERRIDE { 376 virtual void OnStopped() override {
377 ASSERT_TRUE(worker_ != NULL); 377 ASSERT_TRUE(worker_ != NULL);
378 ASSERT_FALSE(done_closure_.is_null()); 378 ASSERT_FALSE(done_closure_.is_null());
379 last_worker_status_ = worker_->status(); 379 last_worker_status_ = worker_->status();
380 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, done_closure_); 380 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, done_closure_);
381 } 381 }
382 virtual void OnPausedAfterDownload() OVERRIDE { 382 virtual void OnPausedAfterDownload() override {
383 if (pause_mode_ == PAUSE_THEN_RESUME) 383 if (pause_mode_ == PAUSE_THEN_RESUME)
384 worker_->ResumeAfterDownload(); 384 worker_->ResumeAfterDownload();
385 else if (pause_mode_ == PAUSE_THEN_STOP) 385 else if (pause_mode_ == PAUSE_THEN_STOP)
386 worker_->Stop(); 386 worker_->Stop();
387 else 387 else
388 ASSERT_TRUE(false); 388 ASSERT_TRUE(false);
389 } 389 }
390 virtual void OnReportException(const base::string16& error_message, 390 virtual void OnReportException(const base::string16& error_message,
391 int line_number, 391 int line_number,
392 int column_number, 392 int column_number,
393 const GURL& source_url) OVERRIDE {} 393 const GURL& source_url) override {}
394 virtual void OnReportConsoleMessage(int source_identifier, 394 virtual void OnReportConsoleMessage(int source_identifier,
395 int message_level, 395 int message_level,
396 const base::string16& message, 396 const base::string16& message,
397 int line_number, 397 int line_number,
398 const GURL& source_url) OVERRIDE {} 398 const GURL& source_url) override {}
399 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { 399 virtual bool OnMessageReceived(const IPC::Message& message) override {
400 return false; 400 return false;
401 } 401 }
402 402
403 scoped_ptr<EmbeddedWorkerInstance> worker_; 403 scoped_ptr<EmbeddedWorkerInstance> worker_;
404 EmbeddedWorkerInstance::Status last_worker_status_; 404 EmbeddedWorkerInstance::Status last_worker_status_;
405 405
406 enum { 406 enum {
407 DONT_PAUSE, 407 DONT_PAUSE,
408 PAUSE_THEN_RESUME, 408 PAUSE_THEN_RESUME,
409 PAUSE_THEN_STOP, 409 PAUSE_THEN_STOP,
410 } pause_mode_; 410 } pause_mode_;
411 411
412 // Called by EmbeddedWorkerInstance::Observer overrides so that 412 // Called by EmbeddedWorkerInstance::Observer overrides so that
413 // test code can wait for the worker status notifications. 413 // test code can wait for the worker status notifications.
414 base::Closure done_closure_; 414 base::Closure done_closure_;
415 }; 415 };
416 416
417 class ServiceWorkerVersionBrowserTest : public ServiceWorkerBrowserTest { 417 class ServiceWorkerVersionBrowserTest : public ServiceWorkerBrowserTest {
418 public: 418 public:
419 typedef ServiceWorkerVersionBrowserTest self; 419 typedef ServiceWorkerVersionBrowserTest self;
420 420
421 virtual ~ServiceWorkerVersionBrowserTest() {} 421 virtual ~ServiceWorkerVersionBrowserTest() {}
422 422
423 virtual void TearDownOnIOThread() OVERRIDE { 423 virtual void TearDownOnIOThread() override {
424 registration_ = NULL; 424 registration_ = NULL;
425 version_ = NULL; 425 version_ = NULL;
426 } 426 }
427 427
428 void InstallTestHelper(const std::string& worker_url, 428 void InstallTestHelper(const std::string& worker_url,
429 ServiceWorkerStatusCode expected_status) { 429 ServiceWorkerStatusCode expected_status) {
430 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this, 430 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, this,
431 worker_url)); 431 worker_url));
432 432
433 // Dispatch install on a worker. 433 // Dispatch install on a worker.
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 RunOnIOThread( 946 RunOnIOThread(
947 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, 947 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO,
948 this, 948 this,
949 embedded_test_server()->GetURL("/service_worker/empty.html"), 949 embedded_test_server()->GetURL("/service_worker/empty.html"),
950 &status)); 950 &status));
951 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); 951 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status);
952 } 952 }
953 } 953 }
954 954
955 } // namespace content 955 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/embedded_worker_test_helper.h ('k') | content/browser/service_worker/service_worker_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698