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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 virtual void SetUp() OVERRIDE { | 46 virtual void SetUp() OVERRIDE { |
47 helper_.reset(new EmbeddedWorkerTestHelper(kRenderProcessId)); | 47 helper_.reset(new EmbeddedWorkerTestHelper(kRenderProcessId)); |
48 | 48 |
49 registration_ = new ServiceWorkerRegistration( | 49 registration_ = new ServiceWorkerRegistration( |
50 GURL("http://www.example.com/"), | 50 GURL("http://www.example.com/"), |
51 GURL("http://www.example.com/service_worker.js"), | 51 GURL("http://www.example.com/service_worker.js"), |
52 1L, | 52 1L, |
53 helper_->context()->AsWeakPtr()); | 53 helper_->context()->AsWeakPtr()); |
54 version_ = new ServiceWorkerVersion( | 54 version_ = new ServiceWorkerVersion( |
55 registration_, 1L, helper_->context()->AsWeakPtr()); | 55 registration_.get(), 1L, helper_->context()->AsWeakPtr()); |
56 | 56 |
57 // Simulate adding one process to the worker. | 57 // Simulate adding one process to the worker. |
58 int embedded_worker_id = version_->embedded_worker()->embedded_worker_id(); | 58 int embedded_worker_id = version_->embedded_worker()->embedded_worker_id(); |
59 helper_->SimulateAddProcessToWorker(embedded_worker_id, kRenderProcessId); | 59 helper_->SimulateAddProcessToWorker(embedded_worker_id, kRenderProcessId); |
60 } | 60 } |
61 | 61 |
62 virtual void TearDown() OVERRIDE { | 62 virtual void TearDown() OVERRIDE { |
63 registration_ = NULL; | 63 registration_ = NULL; |
64 version_ = NULL; | 64 version_ = NULL; |
65 helper_.reset(); | 65 helper_.reset(); |
66 } | 66 } |
67 | 67 |
68 IPC::TestSink* ipc_sink() { return helper_->ipc_sink(); } | 68 IPC::TestSink* ipc_sink() { return helper_->ipc_sink(); } |
69 | 69 |
70 TestBrowserThreadBundle browser_thread_bundle_; | 70 TestBrowserThreadBundle browser_thread_bundle_; |
71 scoped_ptr<EmbeddedWorkerTestHelper> helper_; | 71 scoped_ptr<EmbeddedWorkerTestHelper> helper_; |
72 scoped_refptr<ServiceWorkerRegistration> registration_; | 72 scoped_refptr<ServiceWorkerRegistration> registration_; |
73 scoped_refptr<ServiceWorkerVersion> version_; | 73 scoped_refptr<ServiceWorkerVersion> version_; |
74 | 74 |
75 private: | 75 private: |
76 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerHandleTest); | 76 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerHandleTest); |
77 }; | 77 }; |
78 | 78 |
79 TEST_F(ServiceWorkerHandleTest, OnVersionStateChanged) { | 79 TEST_F(ServiceWorkerHandleTest, OnVersionStateChanged) { |
80 scoped_ptr<ServiceWorkerHandle> handle = | 80 scoped_ptr<ServiceWorkerHandle> handle = |
81 ServiceWorkerHandle::Create(helper_->context()->AsWeakPtr(), | 81 ServiceWorkerHandle::Create(helper_->context()->AsWeakPtr(), |
82 helper_.get(), | 82 helper_.get(), |
83 1 /* thread_id */, | 83 1 /* thread_id */, |
84 33 /* provider_id */, | 84 33 /* provider_id */, |
85 version_); | 85 version_.get()); |
86 | 86 |
87 // Start the worker, and then... | 87 // Start the worker, and then... |
88 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; | 88 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; |
89 version_->StartWorker(CreateReceiverOnCurrentThread(&status)); | 89 version_->StartWorker(CreateReceiverOnCurrentThread(&status)); |
90 base::RunLoop().RunUntilIdle(); | 90 base::RunLoop().RunUntilIdle(); |
91 EXPECT_EQ(SERVICE_WORKER_OK, status); | 91 EXPECT_EQ(SERVICE_WORKER_OK, status); |
92 | 92 |
93 // ...dispatch install event. | 93 // ...dispatch install event. |
94 status = SERVICE_WORKER_ERROR_FAILED; | 94 status = SERVICE_WORKER_ERROR_FAILED; |
95 version_->SetStatus(ServiceWorkerVersion::INSTALLING); | 95 version_->SetStatus(ServiceWorkerVersion::INSTALLING); |
(...skipping 15 matching lines...) Expand all Loading... |
111 // 3. SendMessageToWorker (to send InstallEvent), and | 111 // 3. SendMessageToWorker (to send InstallEvent), and |
112 EXPECT_EQ(EmbeddedWorkerContextMsg_MessageToWorker::ID, | 112 EXPECT_EQ(EmbeddedWorkerContextMsg_MessageToWorker::ID, |
113 ipc_sink()->GetMessageAt(2)->type()); | 113 ipc_sink()->GetMessageAt(2)->type()); |
114 // 4. StateChanged (state == Installed). | 114 // 4. StateChanged (state == Installed). |
115 VerifyStateChangedMessage(handle->handle_id(), | 115 VerifyStateChangedMessage(handle->handle_id(), |
116 blink::WebServiceWorkerStateInstalled, | 116 blink::WebServiceWorkerStateInstalled, |
117 ipc_sink()->GetMessageAt(3)); | 117 ipc_sink()->GetMessageAt(3)); |
118 } | 118 } |
119 | 119 |
120 } // namespace content | 120 } // namespace content |
OLD | NEW |