OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/service_worker/service_worker_dispatcher_host.h" | 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "content/browser/browser_thread_impl.h" | 10 #include "content/browser/browser_thread_impl.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 TEST_F(ServiceWorkerDispatcherHostTest, DisabledCausesError) { | 82 TEST_F(ServiceWorkerDispatcherHostTest, DisabledCausesError) { |
83 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch( | 83 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch( |
84 switches::kEnableServiceWorker)); | 84 switches::kEnableServiceWorker)); |
85 | 85 |
86 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host = | 86 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host = |
87 new TestingServiceWorkerDispatcherHost( | 87 new TestingServiceWorkerDispatcherHost( |
88 kRenderProcessId, context_wrapper_.get(), helper_.get()); | 88 kRenderProcessId, context_wrapper_.get(), helper_.get()); |
89 | 89 |
90 bool handled; | 90 bool handled; |
91 dispatcher_host->OnMessageReceived( | 91 dispatcher_host->OnMessageReceived( |
92 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, GURL(), GURL()), | 92 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, -1, GURL(), GURL()), |
93 &handled); | 93 &handled); |
94 EXPECT_TRUE(handled); | 94 EXPECT_TRUE(handled); |
95 | 95 |
96 // TODO(alecflett): Pump the message loop when this becomes async. | 96 // TODO(alecflett): Pump the message loop when this becomes async. |
97 ASSERT_EQ(1UL, dispatcher_host->ipc_sink()->message_count()); | 97 ASSERT_EQ(1UL, dispatcher_host->ipc_sink()->message_count()); |
98 EXPECT_TRUE(dispatcher_host->ipc_sink()->GetUniqueMessageMatching( | 98 EXPECT_TRUE(dispatcher_host->ipc_sink()->GetUniqueMessageMatching( |
99 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID)); | 99 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID)); |
100 } | 100 } |
101 | 101 |
102 // Disable this since now we cache command-line switch in | 102 // Disable this since now we cache command-line switch in |
103 // ServiceWorkerUtils::IsFeatureEnabled() and this could be flaky depending | 103 // ServiceWorkerUtils::IsFeatureEnabled() and this could be flaky depending |
104 // on testing order. (crbug.com/352581) | 104 // on testing order. (crbug.com/352581) |
105 // TODO(kinuko): Just remove DisabledCausesError test above and enable | 105 // TODO(kinuko): Just remove DisabledCausesError test above and enable |
106 // this test when we remove the --enable-service-worker flag. | 106 // this test when we remove the --enable-service-worker flag. |
107 TEST_F(ServiceWorkerDispatcherHostTest, DISABLED_Enabled) { | 107 TEST_F(ServiceWorkerDispatcherHostTest, DISABLED_Enabled) { |
108 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch( | 108 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch( |
109 switches::kEnableServiceWorker)); | 109 switches::kEnableServiceWorker)); |
110 CommandLine::ForCurrentProcess()->AppendSwitch( | 110 CommandLine::ForCurrentProcess()->AppendSwitch( |
111 switches::kEnableServiceWorker); | 111 switches::kEnableServiceWorker); |
112 | 112 |
113 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host = | 113 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host = |
114 new TestingServiceWorkerDispatcherHost( | 114 new TestingServiceWorkerDispatcherHost( |
115 kRenderProcessId, context_wrapper_.get(), helper_.get()); | 115 kRenderProcessId, context_wrapper_.get(), helper_.get()); |
116 | 116 |
117 bool handled; | 117 bool handled; |
118 dispatcher_host->OnMessageReceived( | 118 dispatcher_host->OnMessageReceived( |
119 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, GURL(), GURL()), | 119 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, -1, GURL(), GURL()), |
120 &handled); | 120 &handled); |
121 EXPECT_TRUE(handled); | 121 EXPECT_TRUE(handled); |
122 base::RunLoop().RunUntilIdle(); | 122 base::RunLoop().RunUntilIdle(); |
123 | 123 |
124 // TODO(alecflett): Pump the message loop when this becomes async. | 124 // TODO(alecflett): Pump the message loop when this becomes async. |
125 ASSERT_EQ(2UL, dispatcher_host->ipc_sink()->message_count()); | 125 ASSERT_EQ(2UL, dispatcher_host->ipc_sink()->message_count()); |
126 EXPECT_TRUE(dispatcher_host->ipc_sink()->GetUniqueMessageMatching( | 126 EXPECT_TRUE(dispatcher_host->ipc_sink()->GetUniqueMessageMatching( |
127 EmbeddedWorkerMsg_StartWorker::ID)); | 127 EmbeddedWorkerMsg_StartWorker::ID)); |
128 EXPECT_TRUE(dispatcher_host->ipc_sink()->GetUniqueMessageMatching( | 128 EXPECT_TRUE(dispatcher_host->ipc_sink()->GetUniqueMessageMatching( |
129 ServiceWorkerMsg_ServiceWorkerRegistered::ID)); | 129 ServiceWorkerMsg_ServiceWorkerRegistered::ID)); |
130 } | 130 } |
131 | 131 |
132 TEST_F(ServiceWorkerDispatcherHostTest, EarlyContextDeletion) { | 132 TEST_F(ServiceWorkerDispatcherHostTest, EarlyContextDeletion) { |
133 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch( | 133 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch( |
134 switches::kEnableServiceWorker)); | 134 switches::kEnableServiceWorker)); |
135 CommandLine::ForCurrentProcess()->AppendSwitch( | 135 CommandLine::ForCurrentProcess()->AppendSwitch( |
136 switches::kEnableServiceWorker); | 136 switches::kEnableServiceWorker); |
137 | 137 |
138 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host = | 138 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host = |
139 new TestingServiceWorkerDispatcherHost( | 139 new TestingServiceWorkerDispatcherHost( |
140 kRenderProcessId, context_wrapper_.get(), helper_.get()); | 140 kRenderProcessId, context_wrapper_.get(), helper_.get()); |
141 | 141 |
142 context_wrapper_->Shutdown(); | 142 context_wrapper_->Shutdown(); |
143 context_wrapper_ = NULL; | 143 context_wrapper_ = NULL; |
144 | 144 |
145 bool handled; | 145 bool handled; |
146 dispatcher_host->OnMessageReceived( | 146 dispatcher_host->OnMessageReceived( |
147 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, GURL(), GURL()), | 147 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, -1, GURL(), GURL()), |
148 &handled); | 148 &handled); |
149 EXPECT_TRUE(handled); | 149 EXPECT_TRUE(handled); |
150 | 150 |
151 // TODO(alecflett): Pump the message loop when this becomes async. | 151 // TODO(alecflett): Pump the message loop when this becomes async. |
152 ASSERT_EQ(1UL, dispatcher_host->ipc_sink()->message_count()); | 152 ASSERT_EQ(1UL, dispatcher_host->ipc_sink()->message_count()); |
153 EXPECT_TRUE(dispatcher_host->ipc_sink()->GetUniqueMessageMatching( | 153 EXPECT_TRUE(dispatcher_host->ipc_sink()->GetUniqueMessageMatching( |
154 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID)); | 154 ServiceWorkerMsg_ServiceWorkerRegistrationError::ID)); |
155 } | 155 } |
156 | 156 |
157 TEST_F(ServiceWorkerDispatcherHostTest, ProviderCreatedAndDestroyed) { | 157 TEST_F(ServiceWorkerDispatcherHostTest, ProviderCreatedAndDestroyed) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 ServiceWorkerHostMsg_ProviderCreated(kProviderId), | 197 ServiceWorkerHostMsg_ProviderCreated(kProviderId), |
198 &handled); | 198 &handled); |
199 EXPECT_TRUE(handled); | 199 EXPECT_TRUE(handled); |
200 EXPECT_TRUE(context()->GetProviderHost(kRenderProcessId, kProviderId)); | 200 EXPECT_TRUE(context()->GetProviderHost(kRenderProcessId, kProviderId)); |
201 EXPECT_TRUE(dispatcher_host->HasOneRef()); | 201 EXPECT_TRUE(dispatcher_host->HasOneRef()); |
202 dispatcher_host = NULL; | 202 dispatcher_host = NULL; |
203 EXPECT_FALSE(context()->GetProviderHost(kRenderProcessId, kProviderId)); | 203 EXPECT_FALSE(context()->GetProviderHost(kRenderProcessId, kProviderId)); |
204 } | 204 } |
205 | 205 |
206 } // namespace content | 206 } // namespace content |
OLD | NEW |