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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "content/browser/service_worker/embedded_worker_registry.h" | 7 #include "content/browser/service_worker/embedded_worker_registry.h" |
8 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 8 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
9 #include "content/browser/service_worker/service_worker_context_core.h" | 9 #include "content/browser/service_worker/service_worker_context_core.h" |
10 #include "content/browser/service_worker/service_worker_handle.h" | 10 #include "content/browser/service_worker/service_worker_handle.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 } | 37 } |
38 | 38 |
39 } // namespace | 39 } // namespace |
40 | 40 |
41 class ServiceWorkerHandleTest : public testing::Test { | 41 class ServiceWorkerHandleTest : public testing::Test { |
42 public: | 42 public: |
43 ServiceWorkerHandleTest() | 43 ServiceWorkerHandleTest() |
44 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} | 44 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} |
45 | 45 |
46 virtual void SetUp() OVERRIDE { | 46 virtual void SetUp() OVERRIDE { |
47 context_.reset(new ServiceWorkerContextCore(base::FilePath(), NULL, NULL)); | 47 helper_.reset(new EmbeddedWorkerTestHelper(kRenderProcessId)); |
48 helper_.reset(new EmbeddedWorkerTestHelper(context_.get(), | |
49 kRenderProcessId)); | |
50 | 48 |
51 registration_ = new ServiceWorkerRegistration( | 49 registration_ = new ServiceWorkerRegistration( |
52 GURL("http://www.example.com/*"), | 50 GURL("http://www.example.com/*"), |
53 GURL("http://www.example.com/service_worker.js"), | 51 GURL("http://www.example.com/service_worker.js"), |
54 1L, context_->AsWeakPtr()); | 52 1L, |
| 53 helper_->context()->AsWeakPtr()); |
55 version_ = new ServiceWorkerVersion( | 54 version_ = new ServiceWorkerVersion( |
56 registration_, | 55 registration_, 1L, helper_->context()->AsWeakPtr()); |
57 1L, context_->AsWeakPtr()); | |
58 | 56 |
59 // Simulate adding one process to the worker. | 57 // Simulate adding one process to the worker. |
60 int embedded_worker_id = version_->embedded_worker()->embedded_worker_id(); | 58 int embedded_worker_id = version_->embedded_worker()->embedded_worker_id(); |
61 helper_->SimulateAddProcessToWorker(embedded_worker_id, kRenderProcessId); | 59 helper_->SimulateAddProcessToWorker(embedded_worker_id, kRenderProcessId); |
62 } | 60 } |
63 | 61 |
64 virtual void TearDown() OVERRIDE { | 62 virtual void TearDown() OVERRIDE { |
65 registration_ = NULL; | 63 registration_ = NULL; |
66 version_ = NULL; | 64 version_ = NULL; |
67 helper_.reset(); | 65 helper_.reset(); |
68 context_.reset(); | |
69 } | 66 } |
70 | 67 |
71 IPC::TestSink* ipc_sink() { return helper_->ipc_sink(); } | 68 IPC::TestSink* ipc_sink() { return helper_->ipc_sink(); } |
72 | 69 |
73 TestBrowserThreadBundle browser_thread_bundle_; | 70 TestBrowserThreadBundle browser_thread_bundle_; |
74 scoped_ptr<ServiceWorkerContextCore> context_; | |
75 scoped_ptr<EmbeddedWorkerTestHelper> helper_; | 71 scoped_ptr<EmbeddedWorkerTestHelper> helper_; |
76 scoped_refptr<ServiceWorkerRegistration> registration_; | 72 scoped_refptr<ServiceWorkerRegistration> registration_; |
77 scoped_refptr<ServiceWorkerVersion> version_; | 73 scoped_refptr<ServiceWorkerVersion> version_; |
78 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerHandleTest); | 74 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerHandleTest); |
79 }; | 75 }; |
80 | 76 |
81 TEST_F(ServiceWorkerHandleTest, OnVersionStateChanged) { | 77 TEST_F(ServiceWorkerHandleTest, OnVersionStateChanged) { |
82 scoped_ptr<ServiceWorkerHandle> handle = ServiceWorkerHandle::Create( | 78 scoped_ptr<ServiceWorkerHandle> handle = |
83 context_->AsWeakPtr(), helper_.get(), 1 /* thread_id */, version_); | 79 ServiceWorkerHandle::Create(helper_->context()->AsWeakPtr(), |
| 80 helper_.get(), |
| 81 1 /* thread_id */, |
| 82 version_); |
84 | 83 |
85 // Start the worker, and then... | 84 // Start the worker, and then... |
86 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | 85 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
87 version_->StartWorker(CreateReceiverOnCurrentThread(&status)); | 86 version_->StartWorker(CreateReceiverOnCurrentThread(&status)); |
88 base::RunLoop().RunUntilIdle(); | 87 base::RunLoop().RunUntilIdle(); |
89 EXPECT_EQ(SERVICE_WORKER_OK, status); | 88 EXPECT_EQ(SERVICE_WORKER_OK, status); |
90 | 89 |
91 // ...dispatch install event. | 90 // ...dispatch install event. |
92 status = SERVICE_WORKER_ERROR_FAILED; | 91 status = SERVICE_WORKER_ERROR_FAILED; |
93 version_->DispatchInstallEvent(-1, CreateReceiverOnCurrentThread(&status)); | 92 version_->DispatchInstallEvent(-1, CreateReceiverOnCurrentThread(&status)); |
(...skipping 12 matching lines...) Expand all Loading... |
106 // 3. SendMessageToWorker (to send InstallEvent), and | 105 // 3. SendMessageToWorker (to send InstallEvent), and |
107 EXPECT_EQ(EmbeddedWorkerContextMsg_MessageToWorker::ID, | 106 EXPECT_EQ(EmbeddedWorkerContextMsg_MessageToWorker::ID, |
108 ipc_sink()->GetMessageAt(2)->type()); | 107 ipc_sink()->GetMessageAt(2)->type()); |
109 // 4. StateChanged (state == Installed). | 108 // 4. StateChanged (state == Installed). |
110 VerifyStateChangedMessage(handle->handle_id(), | 109 VerifyStateChangedMessage(handle->handle_id(), |
111 blink::WebServiceWorkerStateInstalled, | 110 blink::WebServiceWorkerStateInstalled, |
112 ipc_sink()->GetMessageAt(3)); | 111 ipc_sink()->GetMessageAt(3)); |
113 } | 112 } |
114 | 113 |
115 } // namespace content | 114 } // namespace content |
OLD | NEW |