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

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

Issue 140743012: Start EmbeddedWorker during registration - take 2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clean up existing registration case Created 6 years, 10 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 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 TEST_F(ServiceWorkerDispatcherHostTest, DisabledCausesError) { 71 TEST_F(ServiceWorkerDispatcherHostTest, DisabledCausesError) {
72 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch( 72 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
73 switches::kEnableServiceWorker)); 73 switches::kEnableServiceWorker));
74 74
75 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host = 75 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host =
76 new TestingServiceWorkerDispatcherHost(kRenderProcessId, 76 new TestingServiceWorkerDispatcherHost(kRenderProcessId,
77 context_wrapper_.get()); 77 context_wrapper_.get());
78 78
79 bool handled; 79 bool handled;
80 dispatcher_host->OnMessageReceived( 80 dispatcher_host->OnMessageReceived(
81 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, GURL(), GURL()), 81 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, -1, GURL(), GURL()),
82 &handled); 82 &handled);
83 EXPECT_TRUE(handled); 83 EXPECT_TRUE(handled);
84 84
85 // TODO(alecflett): Pump the message loop when this becomes async. 85 // TODO(alecflett): Pump the message loop when this becomes async.
86 ASSERT_EQ(1UL, dispatcher_host->sent_messages_.size()); 86 ASSERT_EQ(1UL, dispatcher_host->sent_messages_.size());
87 EXPECT_EQ( 87 EXPECT_EQ(
88 static_cast<uint32>(ServiceWorkerMsg_ServiceWorkerRegistrationError::ID), 88 static_cast<uint32>(ServiceWorkerMsg_ServiceWorkerRegistrationError::ID),
89 dispatcher_host->sent_messages_[0]->type()); 89 dispatcher_host->sent_messages_[0]->type());
90 } 90 }
91 91
92 TEST_F(ServiceWorkerDispatcherHostTest, Enabled) { 92 TEST_F(ServiceWorkerDispatcherHostTest, Enabled) {
93 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch( 93 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
94 switches::kEnableServiceWorker)); 94 switches::kEnableServiceWorker));
95 CommandLine::ForCurrentProcess()->AppendSwitch( 95 CommandLine::ForCurrentProcess()->AppendSwitch(
96 switches::kEnableServiceWorker); 96 switches::kEnableServiceWorker);
97 97
98 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host = 98 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host =
99 new TestingServiceWorkerDispatcherHost(kRenderProcessId, 99 new TestingServiceWorkerDispatcherHost(kRenderProcessId,
100 context_wrapper_.get()); 100 context_wrapper_.get());
101 101
102 bool handled; 102 bool handled;
103 dispatcher_host->OnMessageReceived( 103 dispatcher_host->OnMessageReceived(
104 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, GURL(), GURL()), 104 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, -1, GURL(), GURL()),
105 &handled); 105 &handled);
106 EXPECT_TRUE(handled); 106 EXPECT_TRUE(handled);
107 base::RunLoop().RunUntilIdle(); 107 base::RunLoop().RunUntilIdle();
108 108
109 // TODO(alecflett): Pump the message loop when this becomes async. 109 // TODO(alecflett): Pump the message loop when this becomes async.
110 ASSERT_EQ(1UL, dispatcher_host->sent_messages_.size()); 110 ASSERT_EQ(1UL, dispatcher_host->sent_messages_.size());
111 EXPECT_EQ(static_cast<uint32>(ServiceWorkerMsg_ServiceWorkerRegistered::ID), 111 EXPECT_EQ(static_cast<uint32>(ServiceWorkerMsg_ServiceWorkerRegistered::ID),
112 dispatcher_host->sent_messages_[0]->type()); 112 dispatcher_host->sent_messages_[0]->type());
113 } 113 }
114 114
115 TEST_F(ServiceWorkerDispatcherHostTest, EarlyContextDeletion) { 115 TEST_F(ServiceWorkerDispatcherHostTest, EarlyContextDeletion) {
116 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch( 116 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
117 switches::kEnableServiceWorker)); 117 switches::kEnableServiceWorker));
118 CommandLine::ForCurrentProcess()->AppendSwitch( 118 CommandLine::ForCurrentProcess()->AppendSwitch(
119 switches::kEnableServiceWorker); 119 switches::kEnableServiceWorker);
120 120
121 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host = 121 scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host =
122 new TestingServiceWorkerDispatcherHost(kRenderProcessId, 122 new TestingServiceWorkerDispatcherHost(kRenderProcessId,
123 context_wrapper_.get()); 123 context_wrapper_.get());
124 124
125 context_wrapper_->Shutdown(); 125 context_wrapper_->Shutdown();
126 context_wrapper_ = NULL; 126 context_wrapper_ = NULL;
127 127
128 bool handled; 128 bool handled;
129 dispatcher_host->OnMessageReceived( 129 dispatcher_host->OnMessageReceived(
130 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, GURL(), GURL()), 130 ServiceWorkerHostMsg_RegisterServiceWorker(-1, -1, -1, GURL(), GURL()),
131 &handled); 131 &handled);
132 EXPECT_TRUE(handled); 132 EXPECT_TRUE(handled);
133 133
134 // TODO(alecflett): Pump the message loop when this becomes async. 134 // TODO(alecflett): Pump the message loop when this becomes async.
135 ASSERT_EQ(1UL, dispatcher_host->sent_messages_.size()); 135 ASSERT_EQ(1UL, dispatcher_host->sent_messages_.size());
136 EXPECT_EQ( 136 EXPECT_EQ(
137 static_cast<uint32>(ServiceWorkerMsg_ServiceWorkerRegistrationError::ID), 137 static_cast<uint32>(ServiceWorkerMsg_ServiceWorkerRegistrationError::ID),
138 dispatcher_host->sent_messages_[0]->type()); 138 dispatcher_host->sent_messages_[0]->type());
139 } 139 }
140 140
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 ServiceWorkerHostMsg_ProviderCreated(kProviderId), 181 ServiceWorkerHostMsg_ProviderCreated(kProviderId),
182 &handled); 182 &handled);
183 EXPECT_TRUE(handled); 183 EXPECT_TRUE(handled);
184 EXPECT_TRUE(context()->GetProviderHost(kRenderProcessId, kProviderId)); 184 EXPECT_TRUE(context()->GetProviderHost(kRenderProcessId, kProviderId));
185 EXPECT_TRUE(dispatcher_host->HasOneRef()); 185 EXPECT_TRUE(dispatcher_host->HasOneRef());
186 dispatcher_host = NULL; 186 dispatcher_host = NULL;
187 EXPECT_FALSE(context()->GetProviderHost(kRenderProcessId, kProviderId)); 187 EXPECT_FALSE(context()->GetProviderHost(kRenderProcessId, kProviderId));
188 } 188 }
189 189
190 } // namespace content 190 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698