| 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 26 matching lines...) Expand all Loading... |
| 37 ServiceWorkerStatusCode status) { | 37 ServiceWorkerStatusCode status) { |
| 38 EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status); | 38 EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status); |
| 39 *called = true; | 39 *called = true; |
| 40 } | 40 } |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 PaymentAppContentUnitTestBase::PaymentAppContentUnitTestBase() | 44 PaymentAppContentUnitTestBase::PaymentAppContentUnitTestBase() |
| 45 : thread_bundle_( | 45 : thread_bundle_( |
| 46 new TestBrowserThreadBundle(TestBrowserThreadBundle::IO_MAINLOOP)), | 46 new TestBrowserThreadBundle(TestBrowserThreadBundle::IO_MAINLOOP)), |
| 47 embedded_worker_helper_(new EmbeddedWorkerTestHelper(base::FilePath())), | 47 embedded_worker_helper_(new EmbeddedWorkerTestHelper(base::FilePath())) { |
| 48 storage_partition_impl_( | |
| 49 new StoragePartitionImpl( | |
| 50 embedded_worker_helper_->browser_context(), base::FilePath(), | |
| 51 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, | |
| 52 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr)), | |
| 53 payment_app_context_(new PaymentAppContextImpl()) { | |
| 54 embedded_worker_helper_->context_wrapper()->set_storage_partition( | 48 embedded_worker_helper_->context_wrapper()->set_storage_partition( |
| 55 storage_partition_impl_.get()); | 49 storage_partition()); |
| 56 payment_app_context_->Init(embedded_worker_helper_->context_wrapper()); | 50 payment_app_context()->Init(embedded_worker_helper_->context_wrapper()); |
| 57 base::RunLoop().RunUntilIdle(); | 51 base::RunLoop().RunUntilIdle(); |
| 58 } | 52 } |
| 59 | 53 |
| 60 PaymentAppContentUnitTestBase::~PaymentAppContentUnitTestBase() { | 54 PaymentAppContentUnitTestBase::~PaymentAppContentUnitTestBase() {} |
| 61 payment_app_context_->Shutdown(); | 55 |
| 62 base::RunLoop().RunUntilIdle(); | 56 BrowserContext* PaymentAppContentUnitTestBase::browser_context() { |
| 57 DCHECK(embedded_worker_helper_); |
| 58 return embedded_worker_helper_->browser_context(); |
| 63 } | 59 } |
| 64 | 60 |
| 65 PaymentAppManager* PaymentAppContentUnitTestBase::CreatePaymentAppManager( | 61 PaymentAppManager* PaymentAppContentUnitTestBase::CreatePaymentAppManager( |
| 66 const GURL& scope_url, | 62 const GURL& scope_url, |
| 67 const GURL& sw_script_url) { | 63 const GURL& sw_script_url) { |
| 68 // Register service worker for payment app manager. | 64 // Register service worker for payment app manager. |
| 69 bool called = false; | 65 bool called = false; |
| 70 embedded_worker_helper_->context()->RegisterServiceWorker( | 66 embedded_worker_helper_->context()->RegisterServiceWorker( |
| 71 scope_url, sw_script_url, nullptr, | 67 scope_url, sw_script_url, nullptr, |
| 72 base::Bind(&RegisterServiceWorkerCallback, &called)); | 68 base::Bind(&RegisterServiceWorkerCallback, &called)); |
| 73 base::RunLoop().RunUntilIdle(); | 69 base::RunLoop().RunUntilIdle(); |
| 74 EXPECT_TRUE(called); | 70 EXPECT_TRUE(called); |
| 75 | 71 |
| 76 // This function should eventually return created payment app manager | 72 // This function should eventually return created payment app manager |
| 77 // but there is no way to get last created payment app manager from | 73 // but there is no way to get last created payment app manager from |
| 78 // payment_app_context_->payment_app_managers_ because its type is std::map | 74 // payment_app_context()->payment_app_managers_ because its type is std::map |
| 79 // and can not ensure its order. So, just make a set of existing payment app | 75 // and can not ensure its order. So, just make a set of existing payment app |
| 80 // managers before creating a new manager and then check what is a new thing. | 76 // managers before creating a new manager and then check what is a new thing. |
| 81 std::set<PaymentAppManager*> existing_managers; | 77 std::set<PaymentAppManager*> existing_managers; |
| 82 for (const auto& existing_manager : | 78 for (const auto& existing_manager : |
| 83 payment_app_context_->payment_app_managers_) { | 79 payment_app_context()->payment_app_managers_) { |
| 84 existing_managers.insert(existing_manager.first); | 80 existing_managers.insert(existing_manager.first); |
| 85 } | 81 } |
| 86 | 82 |
| 87 // Create a new payment app manager. | 83 // Create a new payment app manager. |
| 88 payments::mojom::PaymentAppManagerPtr manager; | 84 payments::mojom::PaymentAppManagerPtr manager; |
| 89 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request = | 85 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request = |
| 90 mojo::MakeRequest(&manager); | 86 mojo::MakeRequest(&manager); |
| 91 payment_app_managers_.push_back(std::move(manager)); | 87 payment_app_managers_.push_back(std::move(manager)); |
| 92 payment_app_context_->CreatePaymentAppManager(std::move(request)); | 88 payment_app_context()->CreatePaymentAppManager(std::move(request)); |
| 93 base::RunLoop().RunUntilIdle(); | 89 base::RunLoop().RunUntilIdle(); |
| 94 | 90 |
| 95 // Find a last registered payment app manager. | 91 // Find a last registered payment app manager. |
| 96 for (const auto& candidate_manager : | 92 for (const auto& candidate_manager : |
| 97 payment_app_context_->payment_app_managers_) { | 93 payment_app_context()->payment_app_managers_) { |
| 98 if (!base::ContainsKey(existing_managers, candidate_manager.first)) { | 94 if (!base::ContainsKey(existing_managers, candidate_manager.first)) { |
| 99 candidate_manager.first->Init(scope_url.spec()); | 95 candidate_manager.first->Init(scope_url.spec()); |
| 100 base::RunLoop().RunUntilIdle(); | 96 base::RunLoop().RunUntilIdle(); |
| 101 return candidate_manager.first; | 97 return candidate_manager.first; |
| 102 } | 98 } |
| 103 } | 99 } |
| 104 | 100 |
| 105 NOTREACHED(); | 101 NOTREACHED(); |
| 106 return nullptr; | 102 return nullptr; |
| 107 } | 103 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 void PaymentAppContentUnitTestBase::UnregisterServiceWorker( | 141 void PaymentAppContentUnitTestBase::UnregisterServiceWorker( |
| 146 const GURL& scope_url) { | 142 const GURL& scope_url) { |
| 147 // Unregister service worker. | 143 // Unregister service worker. |
| 148 bool called = false; | 144 bool called = false; |
| 149 embedded_worker_helper_->context()->UnregisterServiceWorker( | 145 embedded_worker_helper_->context()->UnregisterServiceWorker( |
| 150 scope_url, base::Bind(&UnregisterServiceWorkerCallback, &called)); | 146 scope_url, base::Bind(&UnregisterServiceWorkerCallback, &called)); |
| 151 base::RunLoop().RunUntilIdle(); | 147 base::RunLoop().RunUntilIdle(); |
| 152 EXPECT_TRUE(called); | 148 EXPECT_TRUE(called); |
| 153 } | 149 } |
| 154 | 150 |
| 151 StoragePartitionImpl* PaymentAppContentUnitTestBase::storage_partition() { |
| 152 return static_cast<StoragePartitionImpl*>( |
| 153 BrowserContext::GetDefaultStoragePartition(browser_context())); |
| 154 } |
| 155 |
| 156 PaymentAppContextImpl* PaymentAppContentUnitTestBase::payment_app_context() { |
| 157 return storage_partition()->GetPaymentAppContext(); |
| 158 } |
| 159 |
| 155 } // namespace content | 160 } // namespace content |
| OLD | NEW |