| 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 "base/files/scoped_temp_dir.h" | 5 #include "base/files/scoped_temp_dir.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "content/browser/browser_thread_impl.h" | 8 #include "content/browser/browser_thread_impl.h" |
| 9 #include "content/browser/fileapi/mock_url_request_delegate.h" | 9 #include "content/browser/fileapi/mock_url_request_delegate.h" |
| 10 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 10 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 void EmptyCallback() {} | 33 void EmptyCallback() {} |
| 34 | 34 |
| 35 } | 35 } |
| 36 | 36 |
| 37 class ServiceWorkerControlleeRequestHandlerTest : public testing::Test { | 37 class ServiceWorkerControlleeRequestHandlerTest : public testing::Test { |
| 38 public: | 38 public: |
| 39 ServiceWorkerControlleeRequestHandlerTest() | 39 ServiceWorkerControlleeRequestHandlerTest() |
| 40 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} | 40 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} |
| 41 | 41 |
| 42 virtual void SetUp() OVERRIDE { | 42 virtual void SetUp() override { |
| 43 helper_.reset(new EmbeddedWorkerTestHelper(kMockRenderProcessId)); | 43 helper_.reset(new EmbeddedWorkerTestHelper(kMockRenderProcessId)); |
| 44 | 44 |
| 45 // A new unstored registration/version. | 45 // A new unstored registration/version. |
| 46 scope_ = GURL("http://host/scope/"); | 46 scope_ = GURL("http://host/scope/"); |
| 47 script_url_ = GURL("http://host/script.js"); | 47 script_url_ = GURL("http://host/script.js"); |
| 48 registration_ = new ServiceWorkerRegistration( | 48 registration_ = new ServiceWorkerRegistration( |
| 49 scope_, 1L, context()->AsWeakPtr()); | 49 scope_, 1L, context()->AsWeakPtr()); |
| 50 version_ = new ServiceWorkerVersion( | 50 version_ = new ServiceWorkerVersion( |
| 51 registration_.get(), script_url_, 1L, context()->AsWeakPtr()); | 51 registration_.get(), script_url_, 1L, context()->AsWeakPtr()); |
| 52 | 52 |
| 53 // An empty host. | 53 // An empty host. |
| 54 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( | 54 scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( |
| 55 kMockRenderProcessId, kMockProviderId, | 55 kMockRenderProcessId, kMockProviderId, |
| 56 context()->AsWeakPtr(), NULL)); | 56 context()->AsWeakPtr(), NULL)); |
| 57 provider_host_ = host->AsWeakPtr(); | 57 provider_host_ = host->AsWeakPtr(); |
| 58 context()->AddProviderHost(host.Pass()); | 58 context()->AddProviderHost(host.Pass()); |
| 59 | 59 |
| 60 context()->storage()->LazyInitialize(base::Bind(&EmptyCallback)); | 60 context()->storage()->LazyInitialize(base::Bind(&EmptyCallback)); |
| 61 base::RunLoop().RunUntilIdle(); | 61 base::RunLoop().RunUntilIdle(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 virtual void TearDown() OVERRIDE { | 64 virtual void TearDown() override { |
| 65 version_ = NULL; | 65 version_ = NULL; |
| 66 registration_ = NULL; | 66 registration_ = NULL; |
| 67 helper_.reset(); | 67 helper_.reset(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 ServiceWorkerContextCore* context() const { return helper_->context(); } | 70 ServiceWorkerContextCore* context() const { return helper_->context(); } |
| 71 | 71 |
| 72 protected: | 72 protected: |
| 73 TestBrowserThreadBundle browser_thread_bundle_; | 73 TestBrowserThreadBundle browser_thread_bundle_; |
| 74 scoped_ptr<EmbeddedWorkerTestHelper> helper_; | 74 scoped_ptr<EmbeddedWorkerTestHelper> helper_; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 // Shouldn't crash if the ProviderHost is deleted prior to completion of | 174 // Shouldn't crash if the ProviderHost is deleted prior to completion of |
| 175 // the database lookup. | 175 // the database lookup. |
| 176 context()->RemoveProviderHost(kMockRenderProcessId, kMockProviderId); | 176 context()->RemoveProviderHost(kMockRenderProcessId, kMockProviderId); |
| 177 EXPECT_FALSE(provider_host_.get()); | 177 EXPECT_FALSE(provider_host_.get()); |
| 178 base::RunLoop().RunUntilIdle(); | 178 base::RunLoop().RunUntilIdle(); |
| 179 EXPECT_TRUE(sw_job->ShouldFallbackToNetwork()); | 179 EXPECT_TRUE(sw_job->ShouldFallbackToNetwork()); |
| 180 EXPECT_FALSE(sw_job->ShouldForwardToServiceWorker()); | 180 EXPECT_FALSE(sw_job->ShouldForwardToServiceWorker()); |
| 181 } | 181 } |
| 182 | 182 |
| 183 } // namespace content | 183 } // namespace content |
| OLD | NEW |