| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/payments/payment_app_content_unittest_base.h" | 5 #include "content/browser/payments/payment_app_content_unittest_base.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 *called = true; | 40 *called = true; |
| 41 } | 41 } |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 class PaymentAppContentUnitTestBase::PaymentAppForWorkerTestHelper | 45 class PaymentAppContentUnitTestBase::PaymentAppForWorkerTestHelper |
| 46 : public EmbeddedWorkerTestHelper { | 46 : public EmbeddedWorkerTestHelper { |
| 47 public: | 47 public: |
| 48 PaymentAppForWorkerTestHelper() | 48 PaymentAppForWorkerTestHelper() |
| 49 : EmbeddedWorkerTestHelper(base::FilePath()), | 49 : EmbeddedWorkerTestHelper(base::FilePath()), |
| 50 was_dispatched_(false), | |
| 51 last_sw_registration_id_(kInvalidServiceWorkerRegistrationId) {} | 50 last_sw_registration_id_(kInvalidServiceWorkerRegistrationId) {} |
| 52 ~PaymentAppForWorkerTestHelper() override {} | 51 ~PaymentAppForWorkerTestHelper() override {} |
| 53 | 52 |
| 54 void OnStartWorker( | 53 void OnStartWorker( |
| 55 int embedded_worker_id, | 54 int embedded_worker_id, |
| 56 int64_t service_worker_version_id, | 55 int64_t service_worker_version_id, |
| 57 const GURL& scope, | 56 const GURL& scope, |
| 58 const GURL& script_url, | 57 const GURL& script_url, |
| 59 bool pause_after_download, | 58 bool pause_after_download, |
| 60 mojom::ServiceWorkerEventDispatcherRequest request) override { | 59 mojom::ServiceWorkerEventDispatcherRequest request) override { |
| 61 ServiceWorkerVersion* version = | 60 ServiceWorkerVersion* version = |
| 62 context()->GetLiveVersion(service_worker_version_id); | 61 context()->GetLiveVersion(service_worker_version_id); |
| 63 last_sw_registration_id_ = version->registration_id(); | 62 last_sw_registration_id_ = version->registration_id(); |
| 64 last_sw_scope_ = scope; | 63 last_sw_scope_ = scope; |
| 65 EmbeddedWorkerTestHelper::OnStartWorker( | 64 EmbeddedWorkerTestHelper::OnStartWorker( |
| 66 embedded_worker_id, service_worker_version_id, scope, script_url, | 65 embedded_worker_id, service_worker_version_id, scope, script_url, |
| 67 pause_after_download, std::move(request)); | 66 pause_after_download, std::move(request)); |
| 68 } | 67 } |
| 69 | 68 |
| 70 void OnPaymentRequestEvent( | 69 void OnPaymentRequestEvent( |
| 71 payments::mojom::PaymentAppRequestPtr app_request, | 70 payments::mojom::PaymentAppRequestPtr app_request, |
| 71 payments::mojom::PaymentAppResponseCallbackPtr response_callback, |
| 72 const mojom::ServiceWorkerEventDispatcher:: | 72 const mojom::ServiceWorkerEventDispatcher:: |
| 73 DispatchPaymentRequestEventCallback& callback) override { | 73 DispatchPaymentRequestEventCallback& callback) override { |
| 74 ASSERT_FALSE(was_dispatched_); | 74 EmbeddedWorkerTestHelper::OnPaymentRequestEvent( |
| 75 EmbeddedWorkerTestHelper::OnPaymentRequestEvent(std::move(app_request), | 75 std::move(app_request), std::move(response_callback), callback); |
| 76 callback); | |
| 77 was_dispatched_ = true; | |
| 78 } | 76 } |
| 79 | 77 |
| 80 bool was_dispatched_; | |
| 81 int64_t last_sw_registration_id_; | 78 int64_t last_sw_registration_id_; |
| 82 GURL last_sw_scope_; | 79 GURL last_sw_scope_; |
| 83 | 80 |
| 84 private: | 81 private: |
| 85 DISALLOW_COPY_AND_ASSIGN(PaymentAppForWorkerTestHelper); | 82 DISALLOW_COPY_AND_ASSIGN(PaymentAppForWorkerTestHelper); |
| 86 }; | 83 }; |
| 87 | 84 |
| 88 PaymentAppContentUnitTestBase::PaymentAppContentUnitTestBase() | 85 PaymentAppContentUnitTestBase::PaymentAppContentUnitTestBase() |
| 89 : thread_bundle_( | 86 : thread_bundle_( |
| 90 new TestBrowserThreadBundle(TestBrowserThreadBundle::IO_MAINLOOP)), | 87 new TestBrowserThreadBundle(TestBrowserThreadBundle::IO_MAINLOOP)), |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 void PaymentAppContentUnitTestBase::UnregisterServiceWorker( | 186 void PaymentAppContentUnitTestBase::UnregisterServiceWorker( |
| 190 const GURL& scope_url) { | 187 const GURL& scope_url) { |
| 191 // Unregister service worker. | 188 // Unregister service worker. |
| 192 bool called = false; | 189 bool called = false; |
| 193 worker_helper_->context()->UnregisterServiceWorker( | 190 worker_helper_->context()->UnregisterServiceWorker( |
| 194 scope_url, base::Bind(&UnregisterServiceWorkerCallback, &called)); | 191 scope_url, base::Bind(&UnregisterServiceWorkerCallback, &called)); |
| 195 base::RunLoop().RunUntilIdle(); | 192 base::RunLoop().RunUntilIdle(); |
| 196 EXPECT_TRUE(called); | 193 EXPECT_TRUE(called); |
| 197 } | 194 } |
| 198 | 195 |
| 199 void PaymentAppContentUnitTestBase::ResetPaymentAppInvoked() const { | |
| 200 worker_helper_->was_dispatched_ = false; | |
| 201 } | |
| 202 | |
| 203 bool PaymentAppContentUnitTestBase::payment_app_invoked() const { | |
| 204 return worker_helper_->was_dispatched_; | |
| 205 } | |
| 206 | |
| 207 int64_t PaymentAppContentUnitTestBase::last_sw_registration_id() const { | 196 int64_t PaymentAppContentUnitTestBase::last_sw_registration_id() const { |
| 208 return worker_helper_->last_sw_registration_id_; | 197 return worker_helper_->last_sw_registration_id_; |
| 209 } | 198 } |
| 210 | 199 |
| 211 const GURL& PaymentAppContentUnitTestBase::last_sw_scope_url() const { | 200 const GURL& PaymentAppContentUnitTestBase::last_sw_scope_url() const { |
| 212 return worker_helper_->last_sw_scope_; | 201 return worker_helper_->last_sw_scope_; |
| 213 } | 202 } |
| 214 | 203 |
| 215 StoragePartitionImpl* PaymentAppContentUnitTestBase::storage_partition() { | 204 StoragePartitionImpl* PaymentAppContentUnitTestBase::storage_partition() { |
| 216 return static_cast<StoragePartitionImpl*>( | 205 return static_cast<StoragePartitionImpl*>( |
| 217 BrowserContext::GetDefaultStoragePartition(browser_context())); | 206 BrowserContext::GetDefaultStoragePartition(browser_context())); |
| 218 } | 207 } |
| 219 | 208 |
| 220 PaymentAppContextImpl* PaymentAppContentUnitTestBase::payment_app_context() { | 209 PaymentAppContextImpl* PaymentAppContentUnitTestBase::payment_app_context() { |
| 221 return storage_partition()->GetPaymentAppContext(); | 210 return storage_partition()->GetPaymentAppContext(); |
| 222 } | 211 } |
| 223 | 212 |
| 224 } // namespace content | 213 } // namespace content |
| OLD | NEW |