Commit fdf6ef12 authored by Rouslan Solomakhin's avatar Rouslan Solomakhin Committed by Commit Bot

[Web Payment][Chrome OS] Test support for PaymentAppService.

Before this patch, the test environment for an ARC PaymentAppService
unit test was being setup inside of the only PaymentAppService unit
test, which prevented sharing this environment among multiple unit test
files.

This patch separates the ARC PaymentAppService test environment into its
own test support file.

After this patch, it's possible to share the setup code for ARC
PaymentAppService test environment among multiple unit test files;

Bug: 1061503
Change-Id: If8271d7d277823dc53630bcdc4f6097bc9a6a2b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2248749
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarYusuke Sato <yusukes@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797746}
parent ed5303f1
...@@ -309,6 +309,8 @@ static_library("notification_test_support") { ...@@ -309,6 +309,8 @@ static_library("notification_test_support") {
static_library("arc_test_support") { static_library("arc_test_support") {
testonly = true testonly = true
sources = [ sources = [
"test/arc_payment_app_bridge_test_support.cc",
"test/arc_payment_app_bridge_test_support.h",
"test/fake_accessibility_helper_instance.cc", "test/fake_accessibility_helper_instance.cc",
"test/fake_accessibility_helper_instance.h", "test/fake_accessibility_helper_instance.h",
"test/fake_app_instance.cc", "test/fake_app_instance.cc",
......
specific_include_rules = { include_rules = {
"test_browser_context.h": [ "+content/public/test",
"+content/public/test/test_browser_context.h",
]
} }
per-file fake_*_instance.*=* per-file fake_*_instance.*=*
per-file payment_app_service_test_support.cc=file://components/arc/pay/OWNERS
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/arc/test/arc_payment_app_bridge_test_support.h"
#include "components/arc/session/arc_bridge_service.h"
namespace arc {
ArcPaymentAppBridgeTestSupport::MockPaymentAppInstance::
MockPaymentAppInstance() = default;
ArcPaymentAppBridgeTestSupport::MockPaymentAppInstance::
~MockPaymentAppInstance() = default;
ArcPaymentAppBridgeTestSupport::ScopedSetInstance::ScopedSetInstance(
ArcServiceManager* manager,
mojom::PaymentAppInstance* instance)
: manager_(manager), instance_(instance) {
manager_->arc_bridge_service()->payment_app()->SetInstance(instance_);
}
ArcPaymentAppBridgeTestSupport::ScopedSetInstance::~ScopedSetInstance() {
manager_->arc_bridge_service()->payment_app()->CloseInstance(instance_);
}
ArcPaymentAppBridgeTestSupport::ArcPaymentAppBridgeTestSupport() = default;
ArcPaymentAppBridgeTestSupport::~ArcPaymentAppBridgeTestSupport() = default;
std::unique_ptr<ArcPaymentAppBridgeTestSupport::ScopedSetInstance>
ArcPaymentAppBridgeTestSupport::CreateScopedSetInstance() {
return std::make_unique<ScopedSetInstance>(manager(), instance());
}
} // namespace arc
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_ARC_TEST_ARC_PAYMENT_APP_BRIDGE_TEST_SUPPORT_H_
#define COMPONENTS_ARC_TEST_ARC_PAYMENT_APP_BRIDGE_TEST_SUPPORT_H_
#include <memory>
#include <string>
#include "components/arc/arc_service_manager.h"
#include "components/arc/mojom/payment_app.mojom.h"
#include "components/arc/pay/arc_payment_app_bridge.h"
#include "components/arc/test/test_browser_context.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace content {
class BrowserContext;
} // namespace content
namespace arc {
// Common support utility for tests of payment_app.mojom interface.
class ArcPaymentAppBridgeTestSupport {
public:
// The mock payment_app.mojom interface.
class MockPaymentAppInstance : public mojom::PaymentAppInstance {
public:
MockPaymentAppInstance();
~MockPaymentAppInstance() override;
MockPaymentAppInstance(const MockPaymentAppInstance& other) = delete;
MockPaymentAppInstance& operator=(const MockPaymentAppInstance& other) =
delete;
MOCK_METHOD2(
IsPaymentImplemented,
void(const std::string& package_name,
ArcPaymentAppBridge::IsPaymentImplementedCallback callback));
MOCK_METHOD2(IsReadyToPay,
void(mojom::PaymentParametersPtr,
ArcPaymentAppBridge::IsReadyToPayCallback));
MOCK_METHOD2(InvokePaymentApp,
void(mojom::PaymentParametersPtr,
ArcPaymentAppBridge::InvokePaymentAppCallback));
};
// Sets up the payment_app.mojom connection in the constructor and disconnects
// in the destructor.
class ScopedSetInstance {
public:
ScopedSetInstance(ArcServiceManager* manager,
mojom::PaymentAppInstance* instance);
~ScopedSetInstance();
ScopedSetInstance(const ScopedSetInstance& other) = delete;
ScopedSetInstance& operator=(const ScopedSetInstance& other) = delete;
private:
ArcServiceManager* manager_;
mojom::PaymentAppInstance* instance_;
};
ArcPaymentAppBridgeTestSupport();
~ArcPaymentAppBridgeTestSupport();
ArcPaymentAppBridgeTestSupport(const ArcPaymentAppBridgeTestSupport& other) =
delete;
ArcPaymentAppBridgeTestSupport& operator=(
const ArcPaymentAppBridgeTestSupport& other) = delete;
// Creates a ScopedSetInstance to be placed on the stack, so that
// payment_app.mojom connection is available in the test and is cleaned up
// when the returned value goes out of scope.
std::unique_ptr<ScopedSetInstance> CreateScopedSetInstance();
// The ARC service manager.
ArcServiceManager* manager() { return ArcServiceManager::Get(); }
// The mock payment_app.mojom connection.
MockPaymentAppInstance* instance() { return &instance_; }
// The browser context that should be used in the test.
content::BrowserContext* context() { return &context_; }
private:
// Required for the TestBrowserContext and ArcServiceManager.
content::BrowserTaskEnvironment task_environment_;
// Used for retrieving an instance of ArcPaymentAppBridge owned by a
// BrowserContext.
TestBrowserContext context_;
// The unit test must create an instance of ArcServiceManager for
// ArcServiceManager::Get() to work correctly.
ArcServiceManager manager_;
MockPaymentAppInstance instance_;
};
} // namespace arc
#endif // COMPONENTS_ARC_TEST_ARC_PAYMENT_APP_BRIDGE_TEST_SUPPORT_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment