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

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

Issue 238043002: Teach EmbeddedWorkerInstance to create a process when it needs one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Handle 2 places where context_ could be NULL. Created 6 years, 7 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
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/service_worker/embedded_worker_instance.h" 9 #include "content/browser/service_worker/embedded_worker_instance.h"
10 #include "content/browser/service_worker/embedded_worker_registry.h" 10 #include "content/browser/service_worker/embedded_worker_registry.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 worker_ = wrapper()->context()->embedded_worker_registry()->CreateWorker(); 157 worker_ = wrapper()->context()->embedded_worker_registry()->CreateWorker();
158 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker_->status()); 158 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker_->status());
159 worker_->AddListener(this); 159 worker_->AddListener(this);
160 160
161 AssociateRendererProcessToWorker(worker_.get()); 161 AssociateRendererProcessToWorker(worker_.get());
162 162
163 const int64 service_worker_version_id = 33L; 163 const int64 service_worker_version_id = 33L;
164 const GURL scope = embedded_test_server()->GetURL("/*"); 164 const GURL scope = embedded_test_server()->GetURL("/*");
165 const GURL script_url = embedded_test_server()->GetURL( 165 const GURL script_url = embedded_test_server()->GetURL(
166 "/service_worker/worker.js"); 166 "/service_worker/worker.js");
167 ServiceWorkerStatusCode status = worker_->Start( 167 std::vector<int> processes;
168 service_worker_version_id, scope, script_url); 168 processes.push_back(
169 169 shell()->web_contents()->GetRenderProcessHost()->GetID());
170 worker_->Start(
171 service_worker_version_id,
172 scope,
173 script_url,
174 processes,
175 base::Bind(&EmbeddedWorkerBrowserTest::StartOnIOThread2, this));
176 }
177 void StartOnIOThread2(ServiceWorkerStatusCode status) {
170 last_worker_status_ = worker_->status(); 178 last_worker_status_ = worker_->status();
171 EXPECT_EQ(SERVICE_WORKER_OK, status); 179 EXPECT_EQ(SERVICE_WORKER_OK, status);
172 EXPECT_EQ(EmbeddedWorkerInstance::STARTING, last_worker_status_); 180 EXPECT_EQ(EmbeddedWorkerInstance::STARTING, last_worker_status_);
173 181
174 if (status != SERVICE_WORKER_OK && !done_closure_.is_null()) 182 if (status != SERVICE_WORKER_OK && !done_closure_.is_null())
175 done_closure_.Run(); 183 done_closure_.Run();
176 } 184 }
177 185
178 void StopOnIOThread() { 186 void StopOnIOThread() {
179 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 187 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 run_loop.QuitClosure())); 597 run_loop.QuitClosure()));
590 run_loop.Run(); 598 run_loop.Run();
591 } 599 }
592 600
593 // Register returns when the promise would be resolved. 601 // Register returns when the promise would be resolved.
594 { 602 {
595 base::RunLoop run_loop; 603 base::RunLoop run_loop;
596 public_context()->RegisterServiceWorker( 604 public_context()->RegisterServiceWorker(
597 embedded_test_server()->GetURL("/*"), 605 embedded_test_server()->GetURL("/*"),
598 embedded_test_server()->GetURL(kWorkerUrl), 606 embedded_test_server()->GetURL(kWorkerUrl),
599 RenderProcessID(),
600 base::Bind(&ServiceWorkerBlackBoxBrowserTest::ExpectResultAndRun, 607 base::Bind(&ServiceWorkerBlackBoxBrowserTest::ExpectResultAndRun,
601 true, 608 true,
602 run_loop.QuitClosure())); 609 run_loop.QuitClosure()));
603 run_loop.Run(); 610 run_loop.Run();
604 } 611 }
605 612
606 // Registering again should succeed, although the algo still 613 // Registering again should succeed, although the algo still
607 // might not be complete. 614 // might not be complete.
608 { 615 {
609 base::RunLoop run_loop; 616 base::RunLoop run_loop;
610 public_context()->RegisterServiceWorker( 617 public_context()->RegisterServiceWorker(
611 embedded_test_server()->GetURL("/*"), 618 embedded_test_server()->GetURL("/*"),
612 embedded_test_server()->GetURL(kWorkerUrl), 619 embedded_test_server()->GetURL(kWorkerUrl),
613 RenderProcessID(),
614 base::Bind(&ServiceWorkerBlackBoxBrowserTest::ExpectResultAndRun, 620 base::Bind(&ServiceWorkerBlackBoxBrowserTest::ExpectResultAndRun,
615 true, 621 true,
616 run_loop.QuitClosure())); 622 run_loop.QuitClosure()));
617 run_loop.Run(); 623 run_loop.Run();
618 } 624 }
619 625
620 // The registration algo might not be far enough along to have 626 // The registration algo might not be far enough along to have
621 // stored the registration data, so it may not be findable 627 // stored the registration data, so it may not be findable
622 // at this point. 628 // at this point.
623 629
(...skipping 17 matching lines...) Expand all
641 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, 647 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO,
642 this, 648 this,
643 embedded_test_server()->GetURL("/service_worker/empty.html"), 649 embedded_test_server()->GetURL("/service_worker/empty.html"),
644 &status, 650 &status,
645 &script_url)); 651 &script_url));
646 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); 652 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status);
647 } 653 }
648 } 654 }
649 655
650 } // namespace content 656 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698