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

Unified Diff: content/browser/service_worker/service_worker_dispatcher_host_unittest.cc

Issue 1146913004: Service Worker: Add ServiceWorkerContainer.getRegistrations() method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update tools/metrics/histograms/histograms.xml. Created 5 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_dispatcher_host_unittest.cc
diff --git a/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc b/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc
index 1fdb416ed20aa29411144b17ac4534c58ed21658..e2f2f7f602237e0447fe51b93dd838680db12403 100644
--- a/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc
+++ b/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc
@@ -129,6 +129,19 @@ class ServiceWorkerDispatcherHostTest : public testing::Test {
dispatcher_host_->ipc_sink()->ClearMessages();
}
+ void SendGetRegistrations(int64 provider_id) {
+ dispatcher_host_->OnMessageReceived(
+ ServiceWorkerHostMsg_GetRegistrations(-1, -1, provider_id));
+ base::RunLoop().RunUntilIdle();
+ }
+
+ void GetRegistrations(int64 provider_id, uint32 expected_message) {
+ SendGetRegistrations(provider_id);
+ EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching(
+ expected_message));
+ dispatcher_host_->ipc_sink()->ClearMessages();
+ }
+
ServiceWorkerProviderHost* CreateServiceWorkerProviderHost(int provider_id) {
return new ServiceWorkerProviderHost(
kRenderProcessId, kRenderFrameId, provider_id,
@@ -177,6 +190,8 @@ TEST_F(ServiceWorkerDispatcherHostTest,
GetRegistration(kProviderId,
GURL("https://www.example.com/"),
ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID);
+ GetRegistrations(kProviderId,
+ ServiceWorkerMsg_ServiceWorkerGetRegistrationsError::ID);
SetBrowserClientForTesting(old_browser_client);
}
@@ -494,6 +509,37 @@ TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_EarlyContextDeletion) {
ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID);
}
+TEST_F(ServiceWorkerDispatcherHostTest, GetRegistrations_SecureOrigin) {
+ const int64 kProviderId = 99; // Dummy value
+ scoped_ptr<ServiceWorkerProviderHost> host(
+ CreateServiceWorkerProviderHost(kProviderId));
+ host->SetDocumentUrl(GURL("https://www.example.com/foo"));
+ context()->AddProviderHost(host.Pass());
+
+ GetRegistrations(kProviderId, ServiceWorkerMsg_DidGetRegistrations::ID);
+}
+
+TEST_F(ServiceWorkerDispatcherHostTest,
+ GetRegistrations_NonSecureOriginShouldFail) {
+ const int64 kProviderId = 99; // Dummy value
+ scoped_ptr<ServiceWorkerProviderHost> host(
+ CreateServiceWorkerProviderHost(kProviderId));
+ host->SetDocumentUrl(GURL("http://www.example.com/foo"));
+ context()->AddProviderHost(host.Pass());
+
+ SendGetRegistrations(kProviderId);
+ EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
+}
+
+TEST_F(ServiceWorkerDispatcherHostTest, GetRegistrations_EarlyContextDeletion) {
+ helper_->ShutdownContext();
+
+ // Let the shutdown reach the simulated IO thread.
+ base::RunLoop().RunUntilIdle();
+
+ GetRegistrations(-1, ServiceWorkerMsg_ServiceWorkerGetRegistrationsError::ID);
+}
+
TEST_F(ServiceWorkerDispatcherHostTest, CleanupOnRendererCrash) {
// Add a provider and worker.
const int64 kProviderId = 99; // Dummy value

Powered by Google App Engine
This is Rietveld 408576698