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 10 matching lines...) Expand all Loading... |
21 #include "content/public/test/test_browser_thread_bundle.h" | 21 #include "content/public/test/test_browser_thread_bundle.h" |
22 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" | 22 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" |
23 #include "mojo/public/cpp/bindings/interface_request.h" | 23 #include "mojo/public/cpp/bindings/interface_request.h" |
24 #include "services/service_manager/public/cpp/bind_source_info.h" | 24 #include "services/service_manager/public/cpp/bind_source_info.h" |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 void RegisterServiceWorkerCallback(bool* called, | 30 void RegisterServiceWorkerCallback(bool* called, |
| 31 int64_t* out_registration_id, |
31 ServiceWorkerStatusCode status, | 32 ServiceWorkerStatusCode status, |
32 const std::string& status_message, | 33 const std::string& status_message, |
33 int64_t registration_id) { | 34 int64_t registration_id) { |
34 EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status); | 35 EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status); |
35 *called = true; | 36 *called = true; |
| 37 *out_registration_id = registration_id; |
36 } | 38 } |
37 | 39 |
38 void UnregisterServiceWorkerCallback(bool* called, | 40 void UnregisterServiceWorkerCallback(bool* called, |
39 ServiceWorkerStatusCode status) { | 41 ServiceWorkerStatusCode status) { |
40 EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status); | 42 EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status); |
41 *called = true; | 43 *called = true; |
42 } | 44 } |
43 | 45 |
| 46 void StopWorkerCallback(bool* called, ServiceWorkerStatusCode status) { |
| 47 EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status); |
| 48 *called = true; |
| 49 } |
| 50 |
44 } // namespace | 51 } // namespace |
45 | 52 |
46 class PaymentAppContentUnitTestBase::PaymentAppForWorkerTestHelper | 53 class PaymentAppContentUnitTestBase::PaymentAppForWorkerTestHelper |
47 : public EmbeddedWorkerTestHelper { | 54 : public EmbeddedWorkerTestHelper { |
48 public: | 55 public: |
49 PaymentAppForWorkerTestHelper() | 56 PaymentAppForWorkerTestHelper() |
50 : EmbeddedWorkerTestHelper(base::FilePath()), | 57 : EmbeddedWorkerTestHelper(base::FilePath()), |
51 last_sw_registration_id_(kInvalidServiceWorkerRegistrationId) {} | 58 last_sw_registration_id_(kInvalidServiceWorkerRegistrationId) {} |
52 ~PaymentAppForWorkerTestHelper() override {} | 59 ~PaymentAppForWorkerTestHelper() override {} |
53 | 60 |
54 void OnStartWorker(int embedded_worker_id, | 61 void OnStartWorker( |
55 int64_t service_worker_version_id, | 62 int embedded_worker_id, |
56 const GURL& scope, | 63 int64_t service_worker_version_id, |
57 const GURL& script_url, | 64 const GURL& scope, |
58 bool pause_after_download, | 65 const GURL& script_url, |
59 mojom::ServiceWorkerEventDispatcherRequest request, | 66 bool pause_after_download, |
60 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo | 67 mojom::ServiceWorkerEventDispatcherRequest request, |
61 instance_host) override { | 68 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host, |
| 69 mojom::ServiceWorkerProviderInfoForStartWorkerPtr provider_info) |
| 70 override { |
62 ServiceWorkerVersion* version = | 71 ServiceWorkerVersion* version = |
63 context()->GetLiveVersion(service_worker_version_id); | 72 context()->GetLiveVersion(service_worker_version_id); |
64 last_sw_registration_id_ = version->registration_id(); | 73 last_sw_registration_id_ = version->registration_id(); |
65 last_sw_scope_ = scope; | 74 last_sw_scope_ = scope; |
66 EmbeddedWorkerTestHelper::OnStartWorker( | 75 EmbeddedWorkerTestHelper::OnStartWorker( |
67 embedded_worker_id, service_worker_version_id, scope, script_url, | 76 embedded_worker_id, service_worker_version_id, scope, script_url, |
68 pause_after_download, std::move(request), std::move(instance_host)); | 77 pause_after_download, std::move(request), std::move(instance_host), |
| 78 std::move(provider_info)); |
69 } | 79 } |
70 | 80 |
71 void OnPaymentRequestEvent( | 81 void OnPaymentRequestEvent( |
72 payments::mojom::PaymentRequestEventDataPtr event_data, | 82 payments::mojom::PaymentRequestEventDataPtr event_data, |
73 payments::mojom::PaymentAppResponseCallbackPtr response_callback, | 83 payments::mojom::PaymentAppResponseCallbackPtr response_callback, |
74 mojom::ServiceWorkerEventDispatcher::DispatchPaymentRequestEventCallback | 84 mojom::ServiceWorkerEventDispatcher::DispatchPaymentRequestEventCallback |
75 callback) override { | 85 callback) override { |
76 EmbeddedWorkerTestHelper::OnPaymentRequestEvent( | 86 EmbeddedWorkerTestHelper::OnPaymentRequestEvent( |
77 std::move(event_data), std::move(response_callback), | 87 std::move(event_data), std::move(response_callback), |
78 std::move(callback)); | 88 std::move(callback)); |
(...skipping 25 matching lines...) Expand all Loading... |
104 BrowserContext* PaymentAppContentUnitTestBase::browser_context() { | 114 BrowserContext* PaymentAppContentUnitTestBase::browser_context() { |
105 DCHECK(worker_helper_); | 115 DCHECK(worker_helper_); |
106 return worker_helper_->browser_context(); | 116 return worker_helper_->browser_context(); |
107 } | 117 } |
108 | 118 |
109 PaymentManager* PaymentAppContentUnitTestBase::CreatePaymentManager( | 119 PaymentManager* PaymentAppContentUnitTestBase::CreatePaymentManager( |
110 const GURL& scope_url, | 120 const GURL& scope_url, |
111 const GURL& sw_script_url) { | 121 const GURL& sw_script_url) { |
112 // Register service worker for payment manager. | 122 // Register service worker for payment manager. |
113 bool called = false; | 123 bool called = false; |
| 124 int64_t registration_id; |
114 worker_helper_->context()->RegisterServiceWorker( | 125 worker_helper_->context()->RegisterServiceWorker( |
115 scope_url, sw_script_url, nullptr, | 126 scope_url, sw_script_url, nullptr, |
116 base::Bind(&RegisterServiceWorkerCallback, &called)); | 127 base::Bind(&RegisterServiceWorkerCallback, &called, ®istration_id)); |
117 base::RunLoop().RunUntilIdle(); | 128 base::RunLoop().RunUntilIdle(); |
118 EXPECT_TRUE(called); | 129 EXPECT_TRUE(called); |
119 | 130 |
| 131 // Ensure the worker used for installation has stopped. |
| 132 called = false; |
| 133 ServiceWorkerRegistration* registration = |
| 134 worker_helper_->context()->GetLiveRegistration(registration_id); |
| 135 EXPECT_TRUE(registration); |
| 136 EXPECT_TRUE(registration->active_version()); |
| 137 EXPECT_FALSE(registration->waiting_version()); |
| 138 EXPECT_FALSE(registration->installing_version()); |
| 139 registration->active_version()->StopWorker( |
| 140 base::Bind(&StopWorkerCallback, &called)); |
| 141 base::RunLoop().RunUntilIdle(); |
| 142 EXPECT_TRUE(called); |
| 143 |
120 // This function should eventually return created payment manager | 144 // This function should eventually return created payment manager |
121 // but there is no way to get last created payment manager from | 145 // but there is no way to get last created payment manager from |
122 // payment_app_context()->payment_managers_ because its type is std::map | 146 // payment_app_context()->payment_managers_ because its type is std::map |
123 // and can not ensure its order. So, just make a set of existing payment app | 147 // and can not ensure its order. So, just make a set of existing payment app |
124 // managers before creating a new manager and then check what is a new thing. | 148 // managers before creating a new manager and then check what is a new thing. |
125 std::set<PaymentManager*> existing_managers; | 149 std::set<PaymentManager*> existing_managers; |
126 for (const auto& existing_manager : | 150 for (const auto& existing_manager : |
127 payment_app_context()->payment_managers_) { | 151 payment_app_context()->payment_managers_) { |
128 existing_managers.insert(existing_manager.first); | 152 existing_managers.insert(existing_manager.first); |
129 } | 153 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 StoragePartitionImpl* PaymentAppContentUnitTestBase::storage_partition() { | 196 StoragePartitionImpl* PaymentAppContentUnitTestBase::storage_partition() { |
173 return static_cast<StoragePartitionImpl*>( | 197 return static_cast<StoragePartitionImpl*>( |
174 BrowserContext::GetDefaultStoragePartition(browser_context())); | 198 BrowserContext::GetDefaultStoragePartition(browser_context())); |
175 } | 199 } |
176 | 200 |
177 PaymentAppContextImpl* PaymentAppContentUnitTestBase::payment_app_context() { | 201 PaymentAppContextImpl* PaymentAppContentUnitTestBase::payment_app_context() { |
178 return storage_partition()->GetPaymentAppContext(); | 202 return storage_partition()->GetPaymentAppContext(); |
179 } | 203 } |
180 | 204 |
181 } // namespace content | 205 } // namespace content |
OLD | NEW |