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

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

Issue 321613002: ServiceWorker browser test fix (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/browser/fileapi/chrome_blob_storage_context.h" 9 #include "content/browser/fileapi/chrome_blob_storage_context.h"
10 #include "content/browser/service_worker/embedded_worker_instance.h" 10 #include "content/browser/service_worker/embedded_worker_instance.h"
(...skipping 21 matching lines...) Expand all
32 #include "webkit/common/blob/blob_data.h" 32 #include "webkit/common/blob/blob_data.h"
33 33
34 namespace content { 34 namespace content {
35 35
36 namespace { 36 namespace {
37 37
38 struct FetchResult { 38 struct FetchResult {
39 ServiceWorkerStatusCode status; 39 ServiceWorkerStatusCode status;
40 ServiceWorkerFetchEventResult result; 40 ServiceWorkerFetchEventResult result;
41 ServiceWorkerResponse response; 41 ServiceWorkerResponse response;
42 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle;
42 }; 43 };
43 44
44 void RunAndQuit(const base::Closure& closure, 45 void RunAndQuit(const base::Closure& closure,
45 const base::Closure& quit, 46 const base::Closure& quit,
46 base::MessageLoopProxy* original_message_loop) { 47 base::MessageLoopProxy* original_message_loop) {
47 closure.Run(); 48 closure.Run();
48 original_message_loop->PostTask(FROM_HERE, quit); 49 original_message_loop->PostTask(FROM_HERE, quit);
49 } 50 }
50 51
51 void RunOnIOThread(const base::Closure& closure) { 52 void RunOnIOThread(const base::Closure& closure) {
(...skipping 17 matching lines...) Expand all
69 FROM_HERE, 70 FROM_HERE,
70 base::Bind(closure, quit_on_original_thread)); 71 base::Bind(closure, quit_on_original_thread));
71 run_loop.Run(); 72 run_loop.Run();
72 } 73 }
73 74
74 // Contrary to the style guide, the output parameter of this function comes 75 // Contrary to the style guide, the output parameter of this function comes
75 // before input parameters so Bind can be used on it to create a FetchCallback 76 // before input parameters so Bind can be used on it to create a FetchCallback
76 // to pass to DispatchFetchEvent. 77 // to pass to DispatchFetchEvent.
77 void ReceiveFetchResult(BrowserThread::ID run_quit_thread, 78 void ReceiveFetchResult(BrowserThread::ID run_quit_thread,
78 const base::Closure& quit, 79 const base::Closure& quit,
80 ChromeBlobStorageContext* blob_context,
79 FetchResult* out_result, 81 FetchResult* out_result,
80 ServiceWorkerStatusCode actual_status, 82 ServiceWorkerStatusCode actual_status,
81 ServiceWorkerFetchEventResult actual_result, 83 ServiceWorkerFetchEventResult actual_result,
82 const ServiceWorkerResponse& actual_response) { 84 const ServiceWorkerResponse& actual_response) {
83 out_result->status = actual_status; 85 out_result->status = actual_status;
84 out_result->result = actual_result; 86 out_result->result = actual_result;
85 out_result->response = actual_response; 87 out_result->response = actual_response;
88 if (!actual_response.blob_uuid.empty()) {
89 out_result->blob_data_handle =
90 blob_context->context()->GetBlobDataFromUUID(
91 actual_response.blob_uuid);
92 }
86 if (!quit.is_null()) 93 if (!quit.is_null())
87 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit); 94 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit);
88 } 95 }
89 96
90 ServiceWorkerVersion::FetchCallback CreateResponseReceiver( 97 ServiceWorkerVersion::FetchCallback CreateResponseReceiver(
91 BrowserThread::ID run_quit_thread, 98 BrowserThread::ID run_quit_thread,
92 const base::Closure& quit, 99 const base::Closure& quit,
100 ChromeBlobStorageContext* blob_context,
93 FetchResult* result) { 101 FetchResult* result) {
94 return base::Bind(&ReceiveFetchResult, run_quit_thread, quit, result); 102 return base::Bind(&ReceiveFetchResult, run_quit_thread, quit,
103 blob_context, result);
95 } 104 }
96 105
97 void ReadResponseBody(std::string* body, 106 void ReadResponseBody(std::string* body,
98 scoped_refptr<ChromeBlobStorageContext> context, 107 scoped_refptr<ChromeBlobStorageContext> context,
99 std::string blob_uuid) { 108 std::string blob_uuid) {
100 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle = 109 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle =
101 context->context()->GetBlobDataFromUUID(blob_uuid); 110 context->context()->GetBlobDataFromUUID(blob_uuid);
102 ASSERT_EQ(1U, blob_data_handle->data()->items().size()); 111 ASSERT_EQ(1U, blob_data_handle->data()->items().size());
103 *body = std::string(blob_data_handle->data()->items()[0].bytes(), 112 *body = std::string(blob_data_handle->data()->items()[0].bytes(),
104 blob_data_handle->data()->items()[0].length()); 113 blob_data_handle->data()->items()[0].length());
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 BrowserThread::IO, 304 BrowserThread::IO,
296 FROM_HERE, 305 FROM_HERE,
297 base::Bind( 306 base::Bind(
298 &self::ActivateOnIOThread, this, run_loop.QuitClosure(), &status)); 307 &self::ActivateOnIOThread, this, run_loop.QuitClosure(), &status));
299 run_loop.Run(); 308 run_loop.Run();
300 ASSERT_EQ(expected_status, status); 309 ASSERT_EQ(expected_status, status);
301 } 310 }
302 311
303 void FetchOnRegisteredWorker(ServiceWorkerFetchEventResult* result, 312 void FetchOnRegisteredWorker(ServiceWorkerFetchEventResult* result,
304 ServiceWorkerResponse* response) { 313 ServiceWorkerResponse* response) {
314 blob_context_ = ChromeBlobStorageContext::GetFor(
315 shell()->web_contents()->GetBrowserContext());
305 FetchResult fetch_result; 316 FetchResult fetch_result;
michaeln 2014/06/06 22:59:24 ooops, this isn't right yet
306 fetch_result.status = SERVICE_WORKER_ERROR_FAILED; 317 fetch_result.status = SERVICE_WORKER_ERROR_FAILED;
307 base::RunLoop fetch_run_loop; 318 base::RunLoop fetch_run_loop;
308 BrowserThread::PostTask(BrowserThread::IO, 319 BrowserThread::PostTask(BrowserThread::IO,
309 FROM_HERE, 320 FROM_HERE,
310 base::Bind(&self::FetchOnIOThread, 321 base::Bind(&self::FetchOnIOThread,
311 this, 322 this,
312 fetch_run_loop.QuitClosure(), 323 fetch_run_loop.QuitClosure(),
313 &fetch_result)); 324 &fetch_result));
314 fetch_run_loop.Run(); 325 fetch_run_loop.Run();
315 *result = fetch_result.result; 326 *result = fetch_result.result;
316 *response = fetch_result.response; 327 *response = fetch_result.response;
317 ASSERT_EQ(SERVICE_WORKER_OK, fetch_result.status); 328 ASSERT_EQ(SERVICE_WORKER_OK, fetch_result.status);
318 } 329 }
319 330
320 void FetchTestHelper(const std::string& worker_url, 331 void FetchTestHelper(const std::string& worker_url,
321 ServiceWorkerFetchEventResult* result, 332 ServiceWorkerFetchEventResult* result,
322 ServiceWorkerResponse* response) { 333 ServiceWorkerResponse* response) {
323 RunOnIOThread( 334 RunOnIOThread(
324 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url)); 335 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url));
325
326 FetchOnRegisteredWorker(result, response); 336 FetchOnRegisteredWorker(result, response);
327 } 337 }
328 338
329 void SetUpRegistrationOnIOThread(const std::string& worker_url) { 339 void SetUpRegistrationOnIOThread(const std::string& worker_url) {
330 registration_ = new ServiceWorkerRegistration( 340 registration_ = new ServiceWorkerRegistration(
331 embedded_test_server()->GetURL("/*"), 341 embedded_test_server()->GetURL("/*"),
332 embedded_test_server()->GetURL(worker_url), 342 embedded_test_server()->GetURL(worker_url),
333 wrapper()->context()->storage()->NewRegistrationId(), 343 wrapper()->context()->storage()->NewRegistrationId(),
334 wrapper()->context()->AsWeakPtr()); 344 wrapper()->context()->AsWeakPtr());
335 version_ = new ServiceWorkerVersion( 345 version_ = new ServiceWorkerVersion(
(...skipping 25 matching lines...) Expand all
361 } 371 }
362 372
363 void FetchOnIOThread(const base::Closure& done, FetchResult* result) { 373 void FetchOnIOThread(const base::Closure& done, FetchResult* result) {
364 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 374 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
365 ServiceWorkerFetchRequest request( 375 ServiceWorkerFetchRequest request(
366 embedded_test_server()->GetURL("/service_worker/empty.html"), 376 embedded_test_server()->GetURL("/service_worker/empty.html"),
367 "GET", 377 "GET",
368 std::map<std::string, std::string>()); 378 std::map<std::string, std::string>());
369 version_->SetStatus(ServiceWorkerVersion::ACTIVE); 379 version_->SetStatus(ServiceWorkerVersion::ACTIVE);
370 version_->DispatchFetchEvent( 380 version_->DispatchFetchEvent(
371 request, CreateResponseReceiver(BrowserThread::UI, done, result)); 381 request, CreateResponseReceiver(BrowserThread::UI, done,
382 blob_context_, result));
372 } 383 }
373 384
374 void StopOnIOThread(const base::Closure& done, 385 void StopOnIOThread(const base::Closure& done,
375 ServiceWorkerStatusCode* result) { 386 ServiceWorkerStatusCode* result) {
376 ASSERT_TRUE(version_); 387 ASSERT_TRUE(version_);
377 version_->StopWorker(CreateReceiver(BrowserThread::UI, done, result)); 388 version_->StopWorker(CreateReceiver(BrowserThread::UI, done, result));
378 } 389 }
379 390
380 void SyncEventOnIOThread(const base::Closure& done, 391 void SyncEventOnIOThread(const base::Closure& done,
381 ServiceWorkerStatusCode* result) { 392 ServiceWorkerStatusCode* result) {
382 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 393 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
383 version_->SetStatus(ServiceWorkerVersion::ACTIVE); 394 version_->SetStatus(ServiceWorkerVersion::ACTIVE);
384 version_->DispatchSyncEvent( 395 version_->DispatchSyncEvent(
385 CreateReceiver(BrowserThread::UI, done, result)); 396 CreateReceiver(BrowserThread::UI, done, result));
386 } 397 }
387 398
388 protected: 399 protected:
389 scoped_refptr<ServiceWorkerRegistration> registration_; 400 scoped_refptr<ServiceWorkerRegistration> registration_;
390 scoped_refptr<ServiceWorkerVersion> version_; 401 scoped_refptr<ServiceWorkerVersion> version_;
402 scoped_refptr<ChromeBlobStorageContext> blob_context_;
391 }; 403 };
392 404
393 IN_PROC_BROWSER_TEST_F(EmbeddedWorkerBrowserTest, StartAndStop) { 405 IN_PROC_BROWSER_TEST_F(EmbeddedWorkerBrowserTest, StartAndStop) {
394 // Start a worker and wait until OnStarted() is called. 406 // Start a worker and wait until OnStarted() is called.
395 base::RunLoop start_run_loop; 407 base::RunLoop start_run_loop;
396 done_closure_ = start_run_loop.QuitClosure(); 408 done_closure_ = start_run_loop.QuitClosure();
397 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 409 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
398 base::Bind(&self::StartOnIOThread, this)); 410 base::Bind(&self::StartOnIOThread, this));
399 start_run_loop.Run(); 411 start_run_loop.Run();
400 412
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, 691 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO,
680 this, 692 this,
681 embedded_test_server()->GetURL("/service_worker/empty.html"), 693 embedded_test_server()->GetURL("/service_worker/empty.html"),
682 &status, 694 &status,
683 &script_url)); 695 &script_url));
684 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); 696 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status);
685 } 697 }
686 } 698 }
687 699
688 } // namespace content 700 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698