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

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

Issue 2933793002: ServiceWorker: keep dispatcher hosts for unittests in the test helper (Closed)
Patch Set: RegisterMockDispatcherHost -> RegisterDispatcherHost Created 3 years, 6 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
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 base::RunLoop().RunUntilIdle(); 92 base::RunLoop().RunUntilIdle();
93 return navigation_handle_core; 93 return navigation_handle_core;
94 } 94 }
95 95
96 } // namespace 96 } // namespace
97 97
98 static const int kRenderFrameId = 1; 98 static const int kRenderFrameId = 1;
99 99
100 class TestingServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost { 100 class TestingServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost {
101 public: 101 public:
102 TestingServiceWorkerDispatcherHost( 102 TestingServiceWorkerDispatcherHost(int process_id,
103 int process_id, 103 ResourceContext* resource_context,
104 ServiceWorkerContextWrapper* context_wrapper, 104 EmbeddedWorkerTestHelper* helper)
105 ResourceContext* resource_context,
106 EmbeddedWorkerTestHelper* helper)
107 : ServiceWorkerDispatcherHost(process_id, resource_context), 105 : ServiceWorkerDispatcherHost(process_id, resource_context),
108 bad_messages_received_count_(0), 106 bad_messages_received_count_(0),
109 helper_(helper) { 107 helper_(helper) {}
110 Init(context_wrapper);
111 }
112 108
113 bool Send(IPC::Message* message) override { return helper_->Send(message); } 109 bool Send(IPC::Message* message) override { return helper_->Send(message); }
114 110
115 IPC::TestSink* ipc_sink() { return helper_->ipc_sink(); } 111 IPC::TestSink* ipc_sink() { return helper_->ipc_sink(); }
116 112
117 void ShutdownForBadMessage() override { ++bad_messages_received_count_; } 113 void ShutdownForBadMessage() override { ++bad_messages_received_count_; }
118 114
119 int bad_messages_received_count_; 115 int bad_messages_received_count_;
120 116
121 protected: 117 protected:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 155
160 ServiceWorkerContextCore* context() { return helper_->context(); } 156 ServiceWorkerContextCore* context() { return helper_->context(); }
161 ServiceWorkerContextWrapper* context_wrapper() { 157 ServiceWorkerContextWrapper* context_wrapper() {
162 return helper_->context_wrapper(); 158 return helper_->context_wrapper();
163 } 159 }
164 160
165 void Initialize(std::unique_ptr<EmbeddedWorkerTestHelper> helper) { 161 void Initialize(std::unique_ptr<EmbeddedWorkerTestHelper> helper) {
166 helper_.reset(helper.release()); 162 helper_.reset(helper.release());
167 // Replace the default dispatcher host. 163 // Replace the default dispatcher host.
168 int process_id = helper_->mock_render_process_id(); 164 int process_id = helper_->mock_render_process_id();
169 context()->RemoveDispatcherHost(process_id);
170 dispatcher_host_ = new TestingServiceWorkerDispatcherHost( 165 dispatcher_host_ = new TestingServiceWorkerDispatcherHost(
171 process_id, context_wrapper(), &resource_context_, helper_.get()); 166 process_id, &resource_context_, helper_.get());
167 helper_->RegisterDispatcherHost(process_id, nullptr);
168 dispatcher_host_->Init(context_wrapper());
172 } 169 }
173 170
174 void SetUpRegistration(const GURL& scope, const GURL& script_url) { 171 void SetUpRegistration(const GURL& scope, const GURL& script_url) {
175 registration_ = new ServiceWorkerRegistration( 172 registration_ = new ServiceWorkerRegistration(
176 scope, 1L, helper_->context()->AsWeakPtr()); 173 scope, 1L, helper_->context()->AsWeakPtr());
177 version_ = new ServiceWorkerVersion(registration_.get(), script_url, 1L, 174 version_ = new ServiceWorkerVersion(registration_.get(), script_url, 1L,
178 helper_->context()->AsWeakPtr()); 175 helper_->context()->AsWeakPtr());
179 std::vector<ServiceWorkerDatabase::ResourceRecord> records; 176 std::vector<ServiceWorkerDatabase::ResourceRecord> records;
180 records.push_back( 177 records.push_back(
181 ServiceWorkerDatabase::ResourceRecord(10, version_->script_url(), 100)); 178 ServiceWorkerDatabase::ResourceRecord(10, version_->script_url(), 100));
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 dispatcher_host_->OnFilterRemoved(); 733 dispatcher_host_->OnFilterRemoved();
737 734
738 // The dispatcher host should clean up the state from the process. 735 // The dispatcher host should clean up the state from the process.
739 EXPECT_FALSE(context()->GetProviderHost(process_id, provider_id)); 736 EXPECT_FALSE(context()->GetProviderHost(process_id, provider_id));
740 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version_->running_status()); 737 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version_->running_status());
741 738
742 // We should be able to hook up a new dispatcher host although the old object 739 // We should be able to hook up a new dispatcher host although the old object
743 // is not yet destroyed. This is what the browser does when reusing a crashed 740 // is not yet destroyed. This is what the browser does when reusing a crashed
744 // render process. 741 // render process.
745 scoped_refptr<TestingServiceWorkerDispatcherHost> new_dispatcher_host( 742 scoped_refptr<TestingServiceWorkerDispatcherHost> new_dispatcher_host(
746 new TestingServiceWorkerDispatcherHost( 743 new TestingServiceWorkerDispatcherHost(process_id, &resource_context_,
747 process_id, context_wrapper(), &resource_context_, helper_.get())); 744 helper_.get()));
745 new_dispatcher_host->Init(context_wrapper());
748 746
749 // To show the new dispatcher can operate, simulate provider creation. Since 747 // To show the new dispatcher can operate, simulate provider creation. Since
750 // the old dispatcher cleaned up the old provider host, the new one won't 748 // the old dispatcher cleaned up the old provider host, the new one won't
751 // complain. 749 // complain.
752 ServiceWorkerProviderHostInfo host_info(provider_id, MSG_ROUTING_NONE, 750 ServiceWorkerProviderHostInfo host_info(provider_id, MSG_ROUTING_NONE,
753 SERVICE_WORKER_PROVIDER_FOR_WINDOW, 751 SERVICE_WORKER_PROVIDER_FOR_WINDOW,
754 true /* is_parent_frame_secure */); 752 true /* is_parent_frame_secure */);
755 ServiceWorkerRemoteProviderEndpoint remote_endpoint; 753 ServiceWorkerRemoteProviderEndpoint remote_endpoint;
756 remote_endpoint.BindWithProviderHostInfo(&host_info); 754 remote_endpoint.BindWithProviderHostInfo(&host_info);
757 new_dispatcher_host->OnProviderCreated(std::move(host_info)); 755 new_dispatcher_host->OnProviderCreated(std::move(host_info));
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 const int kFetchEventId = 91; // Dummy value 914 const int kFetchEventId = 91; // Dummy value
917 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_FetchEventResponse( 915 dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_FetchEventResponse(
918 version_->embedded_worker()->embedded_worker_id(), kFetchEventId, 916 version_->embedded_worker()->embedded_worker_id(), kFetchEventId,
919 ServiceWorkerResponse(), base::Time::Now())); 917 ServiceWorkerResponse(), base::Time::Now()));
920 918
921 base::RunLoop().RunUntilIdle(); 919 base::RunLoop().RunUntilIdle();
922 EXPECT_EQ(0, dispatcher_host_->bad_messages_received_count_); 920 EXPECT_EQ(0, dispatcher_host_->bad_messages_received_count_);
923 } 921 }
924 922
925 } // namespace content 923 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698