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 3ad55132cb4281a9d16ca4ab4566b1171ab95f2f..c680ed69082b230f08d63b509d2d1ed915e7ef79 100644 |
--- a/content/browser/payments/payment_app_manager_unittest.cc |
+++ b/content/browser/payments/payment_app_manager_unittest.cc |
@@ -2,24 +2,13 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "content/browser/payments/payment_app_manager.h" |
- |
-#include <memory> |
#include <utility> |
-#include <vector> |
-#include "base/bind.h" |
-#include "base/bind_helpers.h" |
-#include "base/run_loop.h" |
+#include "base/macros.h" |
#include "components/payments/payment_app.mojom.h" |
-#include "content/browser/service_worker/embedded_worker_test_helper.h" |
-#include "content/browser/service_worker/service_worker_context_wrapper.h" |
-#include "content/browser/storage_partition_impl.h" |
-#include "content/public/browser/browser_thread.h" |
-#include "content/public/test/test_browser_context.h" |
-#include "content/public/test/test_browser_thread_bundle.h" |
-#include "mojo/public/cpp/bindings/interface_ptr.h" |
+#include "content/browser/payments/payment_app_content_unittest_base.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#include "url/gurl.h" |
namespace content { |
namespace { |
@@ -29,16 +18,6 @@ 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, |
- ServiceWorkerStatusCode status, |
- const std::string& status_message, |
- int64_t registration_id) { |
- EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status); |
- *called = true; |
- *store_registration_id = registration_id; |
-} |
- |
void SetManifestCallback(bool* called, |
payments::mojom::PaymentAppManifestError* out_error, |
payments::mojom::PaymentAppManifestError error) { |
@@ -75,65 +54,17 @@ payments::mojom::PaymentAppManifestPtr CreatePaymentAppManifestForTest() { |
} // namespace |
-class PaymentAppManagerTest : public testing::Test { |
+class PaymentAppManagerTest : public PaymentAppContentUnitTestBase { |
public: |
- PaymentAppManagerTest() |
- : 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)), |
- sw_registration_id_(0) { |
- embedded_worker_helper_->context_wrapper()->set_storage_partition( |
- storage_partition_impl_.get()); |
- |
- payment_app_context_ = new PaymentAppContextImpl(); |
- payment_app_context_->Init(embedded_worker_helper_->context_wrapper()); |
- |
- bool called = false; |
- embedded_worker_helper_->context()->RegisterServiceWorker( |
- GURL(kServiceWorkerPattern), GURL(kServiceWorkerScript), NULL, |
- base::Bind(&RegisterServiceWorkerCallback, &called, |
- &sw_registration_id_)); |
- base::RunLoop().RunUntilIdle(); |
- EXPECT_TRUE(called); |
- |
- mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request = |
- mojo::GetProxy(&service_); |
- payment_app_context_->CreatePaymentAppManager(std::move(request)); |
- base::RunLoop().RunUntilIdle(); |
- |
- manager_ = payment_app_context_->payment_app_managers_.begin()->first; |
- EXPECT_NE(nullptr, manager_); |
+ PaymentAppManagerTest() { |
+ manager_ = CreatePaymentAppManager(GURL(kServiceWorkerPattern), |
+ GURL(kServiceWorkerScript)); |
+ EXPECT_NE(manager_, nullptr); |
} |
- ~PaymentAppManagerTest() override { |
- payment_app_context_->Shutdown(); |
- base::RunLoop().RunUntilIdle(); |
- } |
- |
- void SetManifest(const std::string& scope, |
- payments::mojom::PaymentAppManifestPtr manifest, |
- const PaymentAppManager::SetManifestCallback& callback) { |
- manager_->SetManifest(scope, std::move(manifest), callback); |
- base::RunLoop().RunUntilIdle(); |
- } |
- |
- void GetManifest(const std::string& scope, |
- const PaymentAppManager::GetManifestCallback& callback) { |
- manager_->GetManifest(scope, callback); |
- base::RunLoop().RunUntilIdle(); |
- } |
+ PaymentAppManager* payment_app_manager() const { return manager_; } |
private: |
- std::unique_ptr<TestBrowserThreadBundle> thread_bundle_; |
- std::unique_ptr<EmbeddedWorkerTestHelper> embedded_worker_helper_; |
- std::unique_ptr<StoragePartitionImpl> storage_partition_impl_; |
- int64_t sw_registration_id_; |
- scoped_refptr<PaymentAppContextImpl> payment_app_context_; |
- payments::mojom::PaymentAppManagerPtr service_; |
- |
// Owned by payment_app_context_. |
PaymentAppManager* manager_; |
@@ -144,25 +75,27 @@ TEST_F(PaymentAppManagerTest, SetAndGetManifest) { |
bool called = false; |
payments::mojom::PaymentAppManifestError error = payments::mojom:: |
PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; |
- SetManifest(kServiceWorkerPattern, CreatePaymentAppManifestForTest(), |
+ SetManifest(payment_app_manager(), 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 = payments::mojom:: |
PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; |
- GetManifest(kServiceWorkerPattern, base::Bind(&GetManifestCallback, &called, |
- &read_manifest, &read_error)); |
- |
+ GetManifest( |
+ payment_app_manager(), 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->icon.value(), "payment-app-icon"); |
EXPECT_EQ(read_manifest->name, "Payment App"); |
ASSERT_EQ(read_manifest->options.size(), 1U); |
- EXPECT_EQ(read_manifest->options[0]->icon, std::string("payment-app-icon")); |
+ EXPECT_EQ(read_manifest->options[0]->icon.value(), "payment-app-icon"); |
EXPECT_EQ(read_manifest->options[0]->name, "Visa ****"); |
EXPECT_EQ(read_manifest->options[0]->id, "payment-app-id"); |
ASSERT_EQ(read_manifest->options[0]->enabled_methods.size(), 1U); |
@@ -173,11 +106,11 @@ TEST_F(PaymentAppManagerTest, SetManifestWithoutAssociatedServiceWorker) { |
bool called = false; |
payments::mojom::PaymentAppManifestError error = |
payments::mojom::PaymentAppManifestError::NONE; |
- SetManifest(kUnregisteredServiceWorkerPattern, |
+ SetManifest(payment_app_manager(), kUnregisteredServiceWorkerPattern, |
CreatePaymentAppManifestForTest(), |
base::Bind(&SetManifestCallback, &called, &error)); |
- |
ASSERT_TRUE(called); |
+ |
EXPECT_EQ(error, payments::mojom::PaymentAppManifestError::NO_ACTIVE_WORKER); |
} |
@@ -187,10 +120,10 @@ TEST_F(PaymentAppManagerTest, GetManifestWithoutAssociatedServiceWorker) { |
payments::mojom::PaymentAppManifestError read_error = |
payments::mojom::PaymentAppManifestError::NONE; |
GetManifest( |
- kUnregisteredServiceWorkerPattern, |
+ payment_app_manager(), kUnregisteredServiceWorkerPattern, |
base::Bind(&GetManifestCallback, &called, &read_manifest, &read_error)); |
- |
ASSERT_TRUE(called); |
+ |
EXPECT_EQ(read_error, |
payments::mojom::PaymentAppManifestError::NO_ACTIVE_WORKER); |
} |
@@ -200,10 +133,11 @@ TEST_F(PaymentAppManagerTest, GetManifestWithNoSavedManifest) { |
payments::mojom::PaymentAppManifestPtr read_manifest; |
payments::mojom::PaymentAppManifestError read_error = |
payments::mojom::PaymentAppManifestError::NONE; |
- GetManifest(kServiceWorkerPattern, base::Bind(&GetManifestCallback, &called, |
- &read_manifest, &read_error)); |
- |
+ GetManifest( |
+ payment_app_manager(), kServiceWorkerPattern, |
+ base::Bind(&GetManifestCallback, &called, &read_manifest, &read_error)); |
ASSERT_TRUE(called); |
+ |
EXPECT_EQ(read_error, payments::mojom::PaymentAppManifestError:: |
MANIFEST_STORAGE_OPERATION_FAILED); |
} |