| 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_provider_host.h" | 5 #include "content/browser/service_worker/service_worker_provider_host.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 11 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| 12 #include "content/browser/service_worker/service_worker_context_core.h" | 12 #include "content/browser/service_worker/service_worker_context_core.h" |
| 13 #include "content/browser/service_worker/service_worker_register_job.h" | 13 #include "content/browser/service_worker/service_worker_register_job.h" |
| 14 #include "content/browser/service_worker/service_worker_registration.h" | 14 #include "content/browser/service_worker/service_worker_registration.h" |
| 15 #include "content/browser/service_worker/service_worker_test_utils.h" | 15 #include "content/browser/service_worker/service_worker_test_utils.h" |
| 16 #include "content/browser/service_worker/service_worker_version.h" | 16 #include "content/browser/service_worker/service_worker_version.h" |
| 17 #include "content/common/url_schemes.h" | 17 #include "content/common/url_schemes.h" |
| 18 #include "content/public/common/origin_util.h" | 18 #include "content/public/common/origin_util.h" |
| 19 #include "content/public/test/test_browser_thread_bundle.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
| 20 #include "content/public/test/test_utils.h" |
| 20 #include "content/test/test_content_browser_client.h" | 21 #include "content/test/test_content_browser_client.h" |
| 21 #include "content/test/test_content_client.h" | 22 #include "content/test/test_content_client.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 24 |
| 24 namespace content { | 25 namespace content { |
| 25 | 26 |
| 26 const char kServiceWorkerScheme[] = "i-can-use-service-worker"; | 27 const char kServiceWorkerScheme[] = "i-can-use-service-worker"; |
| 27 | 28 |
| 28 class ServiceWorkerTestContentClient : public TestContentClient { | 29 class ServiceWorkerTestContentClient : public TestContentClient { |
| 29 public: | 30 public: |
| 30 void AddAdditionalSchemes(Schemes* schemes) override { | 31 void AddAdditionalSchemes(Schemes* schemes) override { |
| 31 schemes->service_worker_schemes.push_back(kServiceWorkerScheme); | 32 schemes->service_worker_schemes.push_back(kServiceWorkerScheme); |
| 32 } | 33 } |
| 33 }; | 34 }; |
| 34 | 35 |
| 35 class ServiceWorkerProviderHostTest : public testing::Test { | 36 class ServiceWorkerProviderHostTest : public testing::Test { |
| 36 protected: | 37 protected: |
| 37 ServiceWorkerProviderHostTest() | 38 ServiceWorkerProviderHostTest() |
| 38 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) { | 39 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) { |
| 39 SetContentClient(&test_content_client_); | 40 SetContentClient(&test_content_client_); |
| 40 } | 41 } |
| 41 ~ServiceWorkerProviderHostTest() override {} | 42 ~ServiceWorkerProviderHostTest() override {} |
| 42 | 43 |
| 43 void SetUp() override { | 44 void SetUp() override { |
| 44 old_content_browser_client_ = | 45 old_content_browser_client_ = |
| 45 SetBrowserClientForTesting(&test_content_browser_client_); | 46 SetBrowserClientForTesting(&test_content_browser_client_); |
| 46 RefreshSecuritySchemesForTesting(); | 47 ResetSchemesAndOriginsWhitelist(); |
| 47 | 48 |
| 48 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); | 49 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); |
| 49 context_ = helper_->context(); | 50 context_ = helper_->context(); |
| 50 script_url_ = GURL("https://www.example.com/service_worker.js"); | 51 script_url_ = GURL("https://www.example.com/service_worker.js"); |
| 51 registration1_ = new ServiceWorkerRegistration( | 52 registration1_ = new ServiceWorkerRegistration( |
| 52 GURL("https://www.example.com/"), 1L, context_->AsWeakPtr()); | 53 GURL("https://www.example.com/"), 1L, context_->AsWeakPtr()); |
| 53 registration2_ = new ServiceWorkerRegistration( | 54 registration2_ = new ServiceWorkerRegistration( |
| 54 GURL("https://www.example.com/example"), 2L, context_->AsWeakPtr()); | 55 GURL("https://www.example.com/example"), 2L, context_->AsWeakPtr()); |
| 55 registration3_ = new ServiceWorkerRegistration( | 56 registration3_ = new ServiceWorkerRegistration( |
| 56 GURL("https://other.example.com/"), 3L, context_->AsWeakPtr()); | 57 GURL("https://other.example.com/"), 3L, context_->AsWeakPtr()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 75 context_->AddProviderHost(base::WrapUnique(host1.release())); | 76 context_->AddProviderHost(base::WrapUnique(host1.release())); |
| 76 context_->AddProviderHost(base::WrapUnique(host2.release())); | 77 context_->AddProviderHost(base::WrapUnique(host2.release())); |
| 77 } | 78 } |
| 78 | 79 |
| 79 void TearDown() override { | 80 void TearDown() override { |
| 80 registration1_ = 0; | 81 registration1_ = 0; |
| 81 registration2_ = 0; | 82 registration2_ = 0; |
| 82 helper_.reset(); | 83 helper_.reset(); |
| 83 SetBrowserClientForTesting(old_content_browser_client_); | 84 SetBrowserClientForTesting(old_content_browser_client_); |
| 84 // Reset cached security schemes so we don't affect other tests. | 85 // Reset cached security schemes so we don't affect other tests. |
| 85 RefreshSecuritySchemesForTesting(); | 86 ResetSchemesAndOriginsWhitelist(); |
| 86 } | 87 } |
| 87 | 88 |
| 88 bool PatternHasProcessToRun(const GURL& pattern) const { | 89 bool PatternHasProcessToRun(const GURL& pattern) const { |
| 89 return context_->process_manager()->PatternHasProcessToRun(pattern); | 90 return context_->process_manager()->PatternHasProcessToRun(pattern); |
| 90 } | 91 } |
| 91 | 92 |
| 92 TestBrowserThreadBundle thread_bundle_; | 93 TestBrowserThreadBundle thread_bundle_; |
| 93 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; | 94 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; |
| 94 ServiceWorkerContextCore* context_; | 95 ServiceWorkerContextCore* context_; |
| 95 scoped_refptr<ServiceWorkerRegistration> registration1_; | 96 scoped_refptr<ServiceWorkerRegistration> registration1_; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 EXPECT_FALSE(IsOriginSecure(url)); | 198 EXPECT_FALSE(IsOriginSecure(url)); |
| 198 EXPECT_TRUE(OriginCanAccessServiceWorkers(url)); | 199 EXPECT_TRUE(OriginCanAccessServiceWorkers(url)); |
| 199 EXPECT_TRUE(provider_host1_->IsContextSecureForServiceWorker()); | 200 EXPECT_TRUE(provider_host1_->IsContextSecureForServiceWorker()); |
| 200 | 201 |
| 201 // Exceptional service worker scheme with insecure parent frame. | 202 // Exceptional service worker scheme with insecure parent frame. |
| 202 provider_host1_->parent_frame_security_level_ = FrameSecurityLevel::INSECURE; | 203 provider_host1_->parent_frame_security_level_ = FrameSecurityLevel::INSECURE; |
| 203 EXPECT_FALSE(provider_host1_->IsContextSecureForServiceWorker()); | 204 EXPECT_FALSE(provider_host1_->IsContextSecureForServiceWorker()); |
| 204 } | 205 } |
| 205 | 206 |
| 206 } // namespace content | 207 } // namespace content |
| OLD | NEW |