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 6f03f02ea28ae86671539f889b4e709f24f88636..3714bec87fdb044da11385ae726e8f74e966b218 100644 |
--- a/content/browser/payments/payment_app_manager_unittest.cc |
+++ b/content/browser/payments/payment_app_manager_unittest.cc |
@@ -2,24 +2,7 @@ |
// 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 "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 "testing/gtest/include/gtest/gtest.h" |
+#include "content/browser/payments/payment_app_content_unittest_base.h" |
namespace content { |
namespace { |
@@ -27,16 +10,6 @@ namespace { |
const char kServiceWorkerPattern[] = "https://example.com/a"; |
const char kServiceWorkerScript[] = "https://example.com/a/script.js"; |
-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(payments::mojom::PaymentAppManifestError* out_error, |
payments::mojom::PaymentAppManifestError error) { |
*out_error = error; |
@@ -52,66 +25,17 @@ void GetManifestCallback(payments::mojom::PaymentAppManifestPtr* out_manifest, |
} // 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, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, |
- nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr)) { |
- 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_->CreateService(std::move(request)); |
- base::RunLoop().RunUntilIdle(); |
- |
- manager_ = payment_app_context_->services_.begin()->first; |
+ PaymentAppManagerTest() { |
+ manager_ = CreatePaymentAppManager(GURL(kServiceWorkerPattern), |
+ GURL(kServiceWorkerScript)); |
EXPECT_TRUE(manager_); |
} |
- ~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* GetPaymentAppManager() 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_; |
DISALLOW_COPY_AND_ASSIGN(PaymentAppManagerTest); |
@@ -132,14 +56,15 @@ TEST_F(PaymentAppManagerTest, SetAndGetManifest) { |
manifest->options.push_back(std::move(option)); |
payments::mojom::PaymentAppManifestError error; |
- SetManifest(kServiceWorkerPattern, std::move(manifest), |
- base::Bind(&SetManifestCallback, &error)); |
+ DCHECK(GetPaymentAppManager()); |
+ SetManifest(GetPaymentAppManager(), kServiceWorkerPattern, |
+ std::move(manifest), base::Bind(&SetManifestCallback, &error)); |
ASSERT_EQ(error, payments::mojom::PaymentAppManifestError::NONE); |
payments::mojom::PaymentAppManifestPtr read_manifest; |
payments::mojom::PaymentAppManifestError read_error; |
- GetManifest(kServiceWorkerPattern, |
+ GetManifest(GetPaymentAppManager(), kServiceWorkerPattern, |
base::Bind(&GetManifestCallback, &read_manifest, &read_error)); |
ASSERT_EQ(read_error, payments::mojom::PaymentAppManifestError::NONE); |
@@ -156,7 +81,7 @@ TEST_F(PaymentAppManagerTest, SetAndGetManifest) { |
TEST_F(PaymentAppManagerTest, GetManifestWithoutAssociatedServiceWorker) { |
payments::mojom::PaymentAppManifestPtr read_manifest; |
payments::mojom::PaymentAppManifestError read_error; |
- GetManifest(kServiceWorkerPattern, |
+ GetManifest(GetPaymentAppManager(), kServiceWorkerPattern, |
base::Bind(&GetManifestCallback, &read_manifest, &read_error)); |
EXPECT_EQ(read_error, payments::mojom::PaymentAppManifestError:: |