Chromium Code Reviews| 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_manager.h" | 5 #include "content/browser/payments/payment_app_manager.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 | 54 |
| 55 class PaymentAppManagerTest : public testing::Test { | 55 class PaymentAppManagerTest : public testing::Test { |
| 56 public: | 56 public: |
| 57 PaymentAppManagerTest() | 57 PaymentAppManagerTest() |
| 58 : thread_bundle_( | 58 : thread_bundle_( |
| 59 new TestBrowserThreadBundle(TestBrowserThreadBundle::IO_MAINLOOP)), | 59 new TestBrowserThreadBundle(TestBrowserThreadBundle::IO_MAINLOOP)), |
| 60 embedded_worker_helper_(new EmbeddedWorkerTestHelper(base::FilePath())), | 60 embedded_worker_helper_(new EmbeddedWorkerTestHelper(base::FilePath())), |
| 61 storage_partition_impl_(new StoragePartitionImpl( | 61 storage_partition_impl_(new StoragePartitionImpl( |
| 62 embedded_worker_helper_->browser_context(), base::FilePath(), | 62 embedded_worker_helper_->browser_context(), base::FilePath(), |
| 63 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, | 63 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, |
| 64 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr)) { | 64 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr)) { |
|
please use gerrit instead
2016/12/14 19:44:00
Initialize sw_registration_id_(0) here to avoid a
zino
2016/12/15 17:56:52
Done.
| |
| 65 | 65 |
| 66 embedded_worker_helper_->context_wrapper()->set_storage_partition( | 66 embedded_worker_helper_->context_wrapper()->set_storage_partition( |
| 67 storage_partition_impl_.get()); | 67 storage_partition_impl_.get()); |
| 68 | 68 |
| 69 payment_app_context_ = | 69 payment_app_context_ = new PaymentAppContextImpl(); |
| 70 new PaymentAppContextImpl(embedded_worker_helper_->context_wrapper()); | 70 payment_app_context_->Init(embedded_worker_helper_->context_wrapper()); |
| 71 | 71 |
| 72 bool called = false; | 72 bool called = false; |
| 73 embedded_worker_helper_->context()->RegisterServiceWorker( | 73 embedded_worker_helper_->context()->RegisterServiceWorker( |
| 74 GURL(kServiceWorkerPattern), GURL(kServiceWorkerScript), NULL, | 74 GURL(kServiceWorkerPattern), GURL(kServiceWorkerScript), NULL, |
| 75 base::Bind(&RegisterServiceWorkerCallback, &called, | 75 base::Bind(&RegisterServiceWorkerCallback, &called, |
| 76 &sw_registration_id_)); | 76 &sw_registration_id_)); |
| 77 base::RunLoop().RunUntilIdle(); | 77 base::RunLoop().RunUntilIdle(); |
| 78 EXPECT_TRUE(called); | 78 EXPECT_TRUE(called); |
|
please use gerrit instead
2016/12/14 19:44:00
Would be nice to have this EXPECT_TRUE(called) als
zino
2016/12/15 17:56:52
Done.
| |
| 79 | 79 |
| 80 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request = | 80 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request = |
| 81 mojo::GetProxy(&service_); | 81 mojo::GetProxy(&service_); |
| 82 payment_app_context_->CreateService(std::move(request)); | 82 payment_app_context_->CreateService(std::move(request)); |
| 83 base::RunLoop().RunUntilIdle(); | 83 base::RunLoop().RunUntilIdle(); |
| 84 | 84 |
| 85 manager_ = payment_app_context_->services_.begin()->first; | 85 manager_ = payment_app_context_->services_.begin()->first; |
| 86 EXPECT_TRUE(manager_); | 86 EXPECT_TRUE(manager_); |
|
please use gerrit instead
2016/12/14 19:44:00
EXPECT_NE(null, manager_) is better, because manag
zino
2016/12/15 23:33:56
Done.
| |
| 87 } | 87 } |
| 88 | 88 |
| 89 ~PaymentAppManagerTest() override { | 89 ~PaymentAppManagerTest() override { |
| 90 payment_app_context_->Shutdown(); | 90 payment_app_context_->Shutdown(); |
| 91 base::RunLoop().RunUntilIdle(); | 91 base::RunLoop().RunUntilIdle(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void SetManifest(const std::string& scope, | 94 void SetManifest(const std::string& scope, |
| 95 payments::mojom::PaymentAppManifestPtr manifest, | 95 payments::mojom::PaymentAppManifestPtr manifest, |
| 96 const PaymentAppManager::SetManifestCallback& callback) { | 96 const PaymentAppManager::SetManifestCallback& callback) { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 125 option->id = "payment-app-id"; | 125 option->id = "payment-app-id"; |
| 126 option->icon = std::string("payment-app-icon"); | 126 option->icon = std::string("payment-app-icon"); |
| 127 option->enabled_methods.push_back("visa"); | 127 option->enabled_methods.push_back("visa"); |
| 128 | 128 |
| 129 payments::mojom::PaymentAppManifestPtr manifest = | 129 payments::mojom::PaymentAppManifestPtr manifest = |
| 130 payments::mojom::PaymentAppManifest::New(); | 130 payments::mojom::PaymentAppManifest::New(); |
| 131 manifest->icon = std::string("payment-app-icon"); | 131 manifest->icon = std::string("payment-app-icon"); |
| 132 manifest->label = "Payment App"; | 132 manifest->label = "Payment App"; |
| 133 manifest->options.push_back(std::move(option)); | 133 manifest->options.push_back(std::move(option)); |
| 134 | 134 |
| 135 payments::mojom::PaymentAppManifestError error; | 135 payments::mojom::PaymentAppManifestError error; |
|
please use gerrit instead
2016/12/14 19:44:00
Initialize it to something that's not NONE to avoi
zino
2016/12/15 17:56:52
Done.
| |
| 136 SetManifest(kServiceWorkerPattern, std::move(manifest), | 136 SetManifest(kServiceWorkerPattern, std::move(manifest), |
| 137 base::Bind(&SetManifestCallback, &error)); | 137 base::Bind(&SetManifestCallback, &error)); |
| 138 | 138 |
| 139 ASSERT_EQ(error, payments::mojom::PaymentAppManifestError::NONE); | 139 ASSERT_EQ(error, payments::mojom::PaymentAppManifestError::NONE); |
| 140 | 140 |
| 141 payments::mojom::PaymentAppManifestPtr read_manifest; | 141 payments::mojom::PaymentAppManifestPtr read_manifest; |
| 142 payments::mojom::PaymentAppManifestError read_error; | 142 payments::mojom::PaymentAppManifestError read_error; |
|
please use gerrit instead
2016/12/14 19:44:00
init to something other than NONE.
zino
2016/12/15 17:56:52
Done.
| |
| 143 GetManifest(kServiceWorkerPattern, | 143 GetManifest(kServiceWorkerPattern, |
| 144 base::Bind(&GetManifestCallback, &read_manifest, &read_error)); | 144 base::Bind(&GetManifestCallback, &read_manifest, &read_error)); |
| 145 | 145 |
| 146 ASSERT_EQ(read_error, payments::mojom::PaymentAppManifestError::NONE); | 146 ASSERT_EQ(read_error, payments::mojom::PaymentAppManifestError::NONE); |
| 147 EXPECT_EQ(read_manifest->icon, std::string("payment-app-icon")); | 147 EXPECT_EQ(read_manifest->icon, std::string("payment-app-icon")); |
| 148 EXPECT_EQ(read_manifest->label, "Payment App"); | 148 EXPECT_EQ(read_manifest->label, "Payment App"); |
| 149 ASSERT_EQ(read_manifest->options.size(), 1U); | 149 ASSERT_EQ(read_manifest->options.size(), 1U); |
| 150 EXPECT_EQ(read_manifest->options[0]->icon, std::string("payment-app-icon")); | 150 EXPECT_EQ(read_manifest->options[0]->icon, std::string("payment-app-icon")); |
| 151 EXPECT_EQ(read_manifest->options[0]->label, "Visa ****"); | 151 EXPECT_EQ(read_manifest->options[0]->label, "Visa ****"); |
| 152 EXPECT_EQ(read_manifest->options[0]->id, "payment-app-id"); | 152 EXPECT_EQ(read_manifest->options[0]->id, "payment-app-id"); |
| 153 ASSERT_EQ(read_manifest->options[0]->enabled_methods.size(), 1U); | 153 ASSERT_EQ(read_manifest->options[0]->enabled_methods.size(), 1U); |
| 154 EXPECT_EQ(read_manifest->options[0]->enabled_methods[0], "visa"); | 154 EXPECT_EQ(read_manifest->options[0]->enabled_methods[0], "visa"); |
| 155 } | 155 } |
| 156 | 156 |
| 157 TEST_F(PaymentAppManagerTest, GetManifestWithoutAssociatedServiceWorker) { | 157 TEST_F(PaymentAppManagerTest, GetManifestWithoutAssociatedServiceWorker) { |
|
please use gerrit instead
2016/12/14 19:44:00
Need a symmetric test case for SetManifestWithoutA
zino
2016/12/15 17:56:52
The name was confusing.
Rename the test to GetMani
| |
| 158 payments::mojom::PaymentAppManifestPtr read_manifest; | 158 payments::mojom::PaymentAppManifestPtr read_manifest; |
| 159 payments::mojom::PaymentAppManifestError read_error; | 159 payments::mojom::PaymentAppManifestError read_error; |
|
please use gerrit instead
2016/12/14 19:44:00
init to something other than MANIFEST_STORAGE_OPER
zino
2016/12/15 17:56:52
Done.
| |
| 160 GetManifest(kServiceWorkerPattern, | 160 GetManifest(kServiceWorkerPattern, |
| 161 base::Bind(&GetManifestCallback, &read_manifest, &read_error)); | 161 base::Bind(&GetManifestCallback, &read_manifest, &read_error)); |
| 162 | 162 |
| 163 EXPECT_EQ(read_error, payments::mojom::PaymentAppManifestError:: | 163 EXPECT_EQ(read_error, payments::mojom::PaymentAppManifestError:: |
| 164 MANIFEST_STORAGE_OPERATION_FAILED); | 164 MANIFEST_STORAGE_OPERATION_FAILED); |
| 165 } | 165 } |
| 166 | 166 |
| 167 } // namespace content | 167 } // namespace content |
| OLD | NEW |