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 "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/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 *body = std::string(data->items()[0]->bytes(), data->items()[0]->length()); | 164 *body = std::string(data->items()[0]->bytes(), data->items()[0]->length()); |
165 } | 165 } |
166 | 166 |
167 void ExpectResultAndRun(bool expected, | 167 void ExpectResultAndRun(bool expected, |
168 const base::Closure& continuation, | 168 const base::Closure& continuation, |
169 bool actual) { | 169 bool actual) { |
170 EXPECT_EQ(expected, actual); | 170 EXPECT_EQ(expected, actual); |
171 continuation.Run(); | 171 continuation.Run(); |
172 } | 172 } |
173 | 173 |
| 174 SyncRegistrationPtr CreateOneShotSyncRegistration(const std::string& tag) { |
| 175 SyncRegistrationPtr registration = SyncRegistration::New(); |
| 176 registration->tag = tag; |
| 177 return registration.Pass(); |
| 178 } |
| 179 |
174 class WorkerActivatedObserver | 180 class WorkerActivatedObserver |
175 : public ServiceWorkerContextObserver, | 181 : public ServiceWorkerContextObserver, |
176 public base::RefCountedThreadSafe<WorkerActivatedObserver> { | 182 public base::RefCountedThreadSafe<WorkerActivatedObserver> { |
177 public: | 183 public: |
178 explicit WorkerActivatedObserver(ServiceWorkerContextWrapper* context) | 184 explicit WorkerActivatedObserver(ServiceWorkerContextWrapper* context) |
179 : context_(context) {} | 185 : context_(context) {} |
180 void Init() { | 186 void Init() { |
181 RunOnIOThread(base::Bind(&WorkerActivatedObserver::InitOnIOThread, this)); | 187 RunOnIOThread(base::Bind(&WorkerActivatedObserver::InitOnIOThread, this)); |
182 } | 188 } |
183 // ServiceWorkerContextObserver overrides. | 189 // ServiceWorkerContextObserver overrides. |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 ServiceWorkerStatusCode* result) { | 788 ServiceWorkerStatusCode* result) { |
783 ASSERT_TRUE(version_.get()); | 789 ASSERT_TRUE(version_.get()); |
784 version_->StopWorker(CreateReceiver(BrowserThread::UI, done, result)); | 790 version_->StopWorker(CreateReceiver(BrowserThread::UI, done, result)); |
785 } | 791 } |
786 | 792 |
787 void SyncEventOnIOThread(const base::Closure& done, | 793 void SyncEventOnIOThread(const base::Closure& done, |
788 ServiceWorkerStatusCode* result) { | 794 ServiceWorkerStatusCode* result) { |
789 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 795 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
790 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); | 796 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); |
791 version_->DispatchSyncEvent( | 797 version_->DispatchSyncEvent( |
| 798 CreateOneShotSyncRegistration(""), |
792 CreateReceiver(BrowserThread::UI, done, result)); | 799 CreateReceiver(BrowserThread::UI, done, result)); |
793 } | 800 } |
794 | 801 |
795 protected: | 802 protected: |
796 scoped_refptr<ServiceWorkerRegistration> registration_; | 803 scoped_refptr<ServiceWorkerRegistration> registration_; |
797 scoped_refptr<ServiceWorkerVersion> version_; | 804 scoped_refptr<ServiceWorkerVersion> version_; |
798 scoped_refptr<ChromeBlobStorageContext> blob_context_; | 805 scoped_refptr<ChromeBlobStorageContext> blob_context_; |
799 }; | 806 }; |
800 | 807 |
801 IN_PROC_BROWSER_TEST_F(EmbeddedWorkerBrowserTest, StartAndStop) { | 808 IN_PROC_BROWSER_TEST_F(EmbeddedWorkerBrowserTest, StartAndStop) { |
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1517 ASSERT_EQ(SERVICE_WORKER_OK, status); | 1524 ASSERT_EQ(SERVICE_WORKER_OK, status); |
1518 // Stop the worker. | 1525 // Stop the worker. |
1519 StopWorker(SERVICE_WORKER_OK); | 1526 StopWorker(SERVICE_WORKER_OK); |
1520 // Restart the worker. | 1527 // Restart the worker. |
1521 StartWorker(SERVICE_WORKER_OK); | 1528 StartWorker(SERVICE_WORKER_OK); |
1522 // Stop the worker. | 1529 // Stop the worker. |
1523 StopWorker(SERVICE_WORKER_OK); | 1530 StopWorker(SERVICE_WORKER_OK); |
1524 } | 1531 } |
1525 | 1532 |
1526 } // namespace content | 1533 } // namespace content |
OLD | NEW |