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 "content/browser/service_worker/service_worker_request_handler.h" | 5 #include "content/browser/service_worker/service_worker_request_handler.h" |
6 | 6 |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "content/browser/fileapi/mock_url_request_delegate.h" | 8 #include "content/browser/fileapi/mock_url_request_delegate.h" |
9 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 9 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
10 #include "content/browser/service_worker/service_worker_context_core.h" | 10 #include "content/browser/service_worker/service_worker_context_core.h" |
11 #include "content/browser/service_worker/service_worker_provider_host.h" | 11 #include "content/browser/service_worker/service_worker_provider_host.h" |
12 #include "content/browser/service_worker/service_worker_registration.h" | 12 #include "content/browser/service_worker/service_worker_registration.h" |
13 #include "content/browser/service_worker/service_worker_utils.h" | 13 #include "content/browser/service_worker/service_worker_utils.h" |
14 #include "content/common/resource_request_body.h" | 14 #include "content/common/resource_request_body.h" |
15 #include "content/public/common/request_context_frame_type.h" | 15 #include "content/public/common/request_context_frame_type.h" |
16 #include "content/public/common/request_context_type.h" | 16 #include "content/public/common/request_context_type.h" |
17 #include "content/public/common/resource_type.h" | 17 #include "content/public/common/resource_type.h" |
18 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
19 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
20 #include "storage/browser/blob/blob_storage_context.h" | 20 #include "storage/browser/blob/blob_storage_context.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 namespace content { | 23 namespace content { |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 int kMockRenderProcessId = 1224; | 27 int kMockRenderProcessId = 1224; |
| 28 int kMockRenderFrameId = 1; |
28 int kMockProviderId = 1; | 29 int kMockProviderId = 1; |
29 | 30 |
30 void EmptyCallback() { | 31 void EmptyCallback() { |
31 } | 32 } |
32 | 33 |
33 } | 34 } |
34 | 35 |
35 class ServiceWorkerRequestHandlerTest : public testing::Test { | 36 class ServiceWorkerRequestHandlerTest : public testing::Test { |
36 public: | 37 public: |
37 ServiceWorkerRequestHandlerTest() | 38 ServiceWorkerRequestHandlerTest() |
38 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} | 39 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} |
39 | 40 |
40 void SetUp() override { | 41 void SetUp() override { |
41 helper_.reset( | 42 helper_.reset( |
42 new EmbeddedWorkerTestHelper(base::FilePath(), kMockRenderProcessId)); | 43 new EmbeddedWorkerTestHelper(base::FilePath(), kMockRenderProcessId)); |
43 | 44 |
44 // A new unstored registration/version. | 45 // A new unstored registration/version. |
45 registration_ = new ServiceWorkerRegistration( | 46 registration_ = new ServiceWorkerRegistration( |
46 GURL("http://host/scope/"), 1L, context()->AsWeakPtr()); | 47 GURL("http://host/scope/"), 1L, context()->AsWeakPtr()); |
47 version_ = new ServiceWorkerVersion(registration_.get(), | 48 version_ = new ServiceWorkerVersion(registration_.get(), |
48 GURL("http://host/script.js"), | 49 GURL("http://host/script.js"), |
49 1L, | 50 1L, |
50 context()->AsWeakPtr()); | 51 context()->AsWeakPtr()); |
51 | 52 |
52 // An empty host. | 53 // An empty host. |
53 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( | 54 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
54 kMockRenderProcessId, MSG_ROUTING_NONE, kMockProviderId, | 55 kMockRenderProcessId, kMockRenderFrameId, MSG_ROUTING_NONE, |
55 SERVICE_WORKER_PROVIDER_FOR_WINDOW, context()->AsWeakPtr(), nullptr)); | 56 kMockProviderId, context()->AsWeakPtr(), nullptr)); |
56 host->SetDocumentUrl(GURL("http://host/scope/")); | 57 host->SetDocumentUrl(GURL("http://host/scope/")); |
57 provider_host_ = host->AsWeakPtr(); | 58 provider_host_ = host->AsWeakPtr(); |
58 context()->AddProviderHost(host.Pass()); | 59 context()->AddProviderHost(host.Pass()); |
59 | 60 |
60 context()->storage()->LazyInitialize(base::Bind(&EmptyCallback)); | 61 context()->storage()->LazyInitialize(base::Bind(&EmptyCallback)); |
61 base::RunLoop().RunUntilIdle(); | 62 base::RunLoop().RunUntilIdle(); |
62 | 63 |
63 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); | 64 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); |
64 registration_->SetActiveVersion(version_); | 65 registration_->SetActiveVersion(version_); |
65 context()->storage()->StoreRegistration( | 66 context()->storage()->StoreRegistration( |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 provider_host_->SetDocumentUrl(GURL("")); | 154 provider_host_->SetDocumentUrl(GURL("")); |
154 EXPECT_FALSE(InitializeHandlerCheck( | 155 EXPECT_FALSE(InitializeHandlerCheck( |
155 "http://host/scope/doc", "GET", true, RESOURCE_TYPE_IMAGE)); | 156 "http://host/scope/doc", "GET", true, RESOURCE_TYPE_IMAGE)); |
156 EXPECT_STREQ("", provider_host_->document_url().spec().c_str()); | 157 EXPECT_STREQ("", provider_host_->document_url().spec().c_str()); |
157 EXPECT_FALSE(InitializeHandlerCheck( | 158 EXPECT_FALSE(InitializeHandlerCheck( |
158 "https://host/scope/doc", "GET", true, RESOURCE_TYPE_IMAGE)); | 159 "https://host/scope/doc", "GET", true, RESOURCE_TYPE_IMAGE)); |
159 EXPECT_STREQ("", provider_host_->document_url().spec().c_str()); | 160 EXPECT_STREQ("", provider_host_->document_url().spec().c_str()); |
160 } | 161 } |
161 | 162 |
162 } // namespace content | 163 } // namespace content |
OLD | NEW |