Chromium Code Reviews| Index: content/browser/payments/payment_app_manager_unittest.cc |
| diff --git a/content/browser/payments/payment_app_manager_unittest.cc b/content/browser/payments/payment_app_manager_unittest.cc |
| index e67b57c80a860c9470dc173a90fdee89f162a38a..535df384b13b855923516950f9acc87a8a1f6bee 100644 |
| --- a/content/browser/payments/payment_app_manager_unittest.cc |
| +++ b/content/browser/payments/payment_app_manager_unittest.cc |
| @@ -26,6 +26,8 @@ namespace { |
| const char kServiceWorkerPattern[] = "https://example.com/a"; |
| const char kServiceWorkerScript[] = "https://example.com/a/script.js"; |
| +const char kUnregisteredServiceWorkerPattern[] = |
| + "https://example.com/unregistered"; |
| void RegisterServiceWorkerCallback(bool* called, |
| int64_t* store_registration_id, |
| @@ -37,19 +39,40 @@ void RegisterServiceWorkerCallback(bool* called, |
| *store_registration_id = registration_id; |
| } |
| -void SetManifestCallback(payments::mojom::PaymentAppManifestError* out_error, |
| +void SetManifestCallback(bool* called, |
| + payments::mojom::PaymentAppManifestError* out_error, |
| payments::mojom::PaymentAppManifestError error) { |
| + *called = true; |
| *out_error = error; |
| } |
| -void GetManifestCallback(payments::mojom::PaymentAppManifestPtr* out_manifest, |
| +void GetManifestCallback(bool* called, |
| + payments::mojom::PaymentAppManifestPtr* out_manifest, |
| payments::mojom::PaymentAppManifestError* out_error, |
| payments::mojom::PaymentAppManifestPtr manifest, |
| payments::mojom::PaymentAppManifestError error) { |
| + *called = true; |
| *out_manifest = std::move(manifest); |
| *out_error = error; |
| } |
| +payments::mojom::PaymentAppManifestPtr CreatePaymentAppManifestForTest() { |
| + payments::mojom::PaymentAppOptionPtr option = |
| + payments::mojom::PaymentAppOption::New(); |
| + option->label = "Visa ****"; |
| + option->id = "payment-app-id"; |
| + option->icon = std::string("payment-app-icon"); |
| + option->enabled_methods.push_back("visa"); |
| + |
| + payments::mojom::PaymentAppManifestPtr manifest = |
| + payments::mojom::PaymentAppManifest::New(); |
| + manifest->icon = std::string("payment-app-icon"); |
| + manifest->label = "Payment App"; |
| + manifest->options.push_back(std::move(option)); |
| + |
| + return manifest; |
| +} |
| + |
| } // namespace |
| class PaymentAppManagerTest : public testing::Test { |
| @@ -58,16 +81,29 @@ class PaymentAppManagerTest : public testing::Test { |
| : thread_bundle_( |
| new TestBrowserThreadBundle(TestBrowserThreadBundle::IO_MAINLOOP)), |
| embedded_worker_helper_(new EmbeddedWorkerTestHelper(base::FilePath())), |
| - storage_partition_impl_(new StoragePartitionImpl( |
| - embedded_worker_helper_->browser_context(), base::FilePath(), |
| - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, |
| - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr)) { |
| - |
| + storage_partition_impl_( |
| + new StoragePartitionImpl(embedded_worker_helper_->browser_context(), |
| + base::FilePath(), |
| + nullptr, |
| + nullptr, |
| + nullptr, |
| + nullptr, |
| + nullptr, |
| + nullptr, |
| + nullptr, |
| + nullptr, |
| + nullptr, |
| + nullptr, |
| + nullptr, |
| + nullptr, |
| + nullptr, |
| + nullptr)), |
|
please use gerrit instead
2016/12/15 19:24:31
Oh boy! Is this clang-format?
zino
2016/12/15 23:33:57
Yes :(
But, fortuneately the problem was solved af
please use gerrit instead
2016/12/16 14:25:56
Much better.
|
| + sw_registration_id_(0) { |
| embedded_worker_helper_->context_wrapper()->set_storage_partition( |
| storage_partition_impl_.get()); |
| - payment_app_context_ = |
| - new PaymentAppContextImpl(embedded_worker_helper_->context_wrapper()); |
| + payment_app_context_ = new PaymentAppContextImpl(); |
| + payment_app_context_->Init(embedded_worker_helper_->context_wrapper()); |
| bool called = false; |
| embedded_worker_helper_->context()->RegisterServiceWorker( |
| @@ -79,11 +115,11 @@ class PaymentAppManagerTest : public testing::Test { |
| mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request = |
| mojo::GetProxy(&service_); |
| - payment_app_context_->CreateService(std::move(request)); |
| + payment_app_context_->CreatePaymentAppManager(std::move(request)); |
| base::RunLoop().RunUntilIdle(); |
| - manager_ = payment_app_context_->services_.begin()->first; |
| - EXPECT_TRUE(manager_); |
| + manager_ = payment_app_context_->payment_app_managers_.begin()->first; |
| + EXPECT_NE(nullptr, manager_); |
| } |
| ~PaymentAppManagerTest() override { |
| @@ -119,30 +155,23 @@ class PaymentAppManagerTest : public testing::Test { |
| }; |
| TEST_F(PaymentAppManagerTest, SetAndGetManifest) { |
| - payments::mojom::PaymentAppOptionPtr option = |
| - payments::mojom::PaymentAppOption::New(); |
| - option->label = "Visa ****"; |
| - option->id = "payment-app-id"; |
| - option->icon = std::string("payment-app-icon"); |
| - option->enabled_methods.push_back("visa"); |
| - |
| - payments::mojom::PaymentAppManifestPtr manifest = |
| - payments::mojom::PaymentAppManifest::New(); |
| - manifest->icon = std::string("payment-app-icon"); |
| - manifest->label = "Payment App"; |
| - manifest->options.push_back(std::move(option)); |
| - |
| - payments::mojom::PaymentAppManifestError error; |
| - SetManifest(kServiceWorkerPattern, std::move(manifest), |
| - base::Bind(&SetManifestCallback, &error)); |
| + bool called = false; |
| + payments::mojom::PaymentAppManifestError error = payments::mojom:: |
| + PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; |
| + SetManifest(kServiceWorkerPattern, CreatePaymentAppManifestForTest(), |
| + base::Bind(&SetManifestCallback, &called, &error)); |
| + ASSERT_TRUE(called); |
| ASSERT_EQ(error, payments::mojom::PaymentAppManifestError::NONE); |
| + called = false; |
| payments::mojom::PaymentAppManifestPtr read_manifest; |
| - payments::mojom::PaymentAppManifestError read_error; |
| - GetManifest(kServiceWorkerPattern, |
| - base::Bind(&GetManifestCallback, &read_manifest, &read_error)); |
| + payments::mojom::PaymentAppManifestError read_error = payments::mojom:: |
| + PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; |
| + GetManifest(kServiceWorkerPattern, base::Bind(&GetManifestCallback, &called, |
| + &read_manifest, &read_error)); |
| + ASSERT_TRUE(called); |
| ASSERT_EQ(read_error, payments::mojom::PaymentAppManifestError::NONE); |
| EXPECT_EQ(read_manifest->icon, std::string("payment-app-icon")); |
| EXPECT_EQ(read_manifest->label, "Payment App"); |
| @@ -154,12 +183,41 @@ TEST_F(PaymentAppManagerTest, SetAndGetManifest) { |
| EXPECT_EQ(read_manifest->options[0]->enabled_methods[0], "visa"); |
| } |
| +TEST_F(PaymentAppManagerTest, SetManifestWithoutAssociatedServiceWorker) { |
| + bool called = false; |
| + payments::mojom::PaymentAppManifestError error = |
| + payments::mojom::PaymentAppManifestError::NONE; |
| + SetManifest(kUnregisteredServiceWorkerPattern, |
| + CreatePaymentAppManifestForTest(), |
| + base::Bind(&SetManifestCallback, &called, &error)); |
| + |
| + ASSERT_TRUE(called); |
| + EXPECT_EQ(error, payments::mojom::PaymentAppManifestError::NO_ACTIVE_WORKER); |
| +} |
| + |
| TEST_F(PaymentAppManagerTest, GetManifestWithoutAssociatedServiceWorker) { |
| + bool called = false; |
| + payments::mojom::PaymentAppManifestPtr read_manifest; |
| + payments::mojom::PaymentAppManifestError read_error = |
| + payments::mojom::PaymentAppManifestError::NONE; |
| + GetManifest( |
| + kUnregisteredServiceWorkerPattern, |
| + base::Bind(&GetManifestCallback, &called, &read_manifest, &read_error)); |
| + |
| + ASSERT_TRUE(called); |
| + EXPECT_EQ(read_error, |
| + payments::mojom::PaymentAppManifestError::NO_ACTIVE_WORKER); |
| +} |
| + |
| +TEST_F(PaymentAppManagerTest, GetManifestWithNoSavedManifest) { |
| + bool called = false; |
| payments::mojom::PaymentAppManifestPtr read_manifest; |
| - payments::mojom::PaymentAppManifestError read_error; |
| - GetManifest(kServiceWorkerPattern, |
| - base::Bind(&GetManifestCallback, &read_manifest, &read_error)); |
| + payments::mojom::PaymentAppManifestError read_error = |
| + payments::mojom::PaymentAppManifestError::NONE; |
| + GetManifest(kServiceWorkerPattern, base::Bind(&GetManifestCallback, &called, |
| + &read_manifest, &read_error)); |
| + ASSERT_TRUE(called); |
| EXPECT_EQ(read_error, payments::mojom::PaymentAppManifestError:: |
| MANIFEST_STORAGE_OPERATION_FAILED); |
| } |