Chromium Code Reviews| Index: content/browser/payments/payment_app_context_impl_unittest.cc |
| diff --git a/content/browser/payments/payment_app_context_impl_unittest.cc b/content/browser/payments/payment_app_context_impl_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..23f43be893edcf6e81482f82e6dd03fb471a27fa |
| --- /dev/null |
| +++ b/content/browser/payments/payment_app_context_impl_unittest.cc |
| @@ -0,0 +1,101 @@ |
| +// Copyright 2016 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 "base/run_loop.h" |
| +#include "content/browser/payments/payment_app_content_unittest_base.h" |
| + |
| +namespace content { |
| +namespace { |
| + |
| +void SetManifestCallback(bool* called, |
| + payments::mojom::PaymentAppManifestError* out_error, |
|
please use gerrit instead
2016/12/16 21:41:21
#include "components/payments/payment_app.mojom.h"
zino
2016/12/17 17:11:54
Done.
|
| + payments::mojom::PaymentAppManifestError error) { |
| + *called = true; |
| + *out_error = error; |
| +} |
| + |
| +void GetAllManifestsCallback(bool* called, |
| + PaymentAppContext::Manifests* out_manifests, |
|
please use gerrit instead
2016/12/16 21:41:21
#include "content/public/browser/payment_app_conte
zino
2016/12/17 17:11:54
Done.
|
| + PaymentAppContext::Manifests manifests) { |
| + *called = true; |
| + *out_manifests = std::move(manifests); |
|
please use gerrit instead
2016/12/16 21:41:21
#include <utility>
zino
2016/12/17 17:11:54
Done.
|
| +} |
| + |
| +} // namespace |
| + |
| +class PaymentAppContextTest : public PaymentAppContentUnitTestBase { |
| + public: |
| + PaymentAppContextTest() {} |
| + ~PaymentAppContextTest() override {} |
| + |
| + void GetAllManifests(PaymentAppContext::GetAllManifestsCallback callback) { |
| + GetPaymentAppContext()->GetAllManifests(callback); |
| + base::RunLoop().RunUntilIdle(); |
| + } |
| + |
| + void CreatePaymentApp(const GURL& scope_url, const GURL& sw_script_url) { |
|
please use gerrit instead
2016/12/16 21:41:21
#include "url/gurl.h"
zino
2016/12/17 17:11:54
Done.
|
| + PaymentAppManager* manager = |
|
please use gerrit instead
2016/12/16 21:41:21
class PaymentAppManager;
(forward declare on top
zino
2016/12/17 17:11:54
Done.
|
| + CreatePaymentAppManager(scope_url, sw_script_url); |
| + |
| + payments::mojom::PaymentAppOptionPtr option = |
| + payments::mojom::PaymentAppOption::New(); |
| + option->label = "Visa ****"; |
| + option->id = "payment-app-id"; |
| + option->icon = std::string("payment-app-icon"); |
|
please use gerrit instead
2016/12/16 21:41:21
I doubt you need to do std::string(), but if you d
zino
2016/12/17 17:11:54
There is no way to set const char*.
The option->ic
|
| + option->enabled_methods.push_back("visa"); |
| + |
| + payments::mojom::PaymentAppManifestPtr manifest = |
| + payments::mojom::PaymentAppManifest::New(); |
| + manifest->icon = std::string("payment-app-icon"); |
| + manifest->label = scope_url.spec(); |
| + manifest->options.push_back(std::move(option)); |
| + |
| + payments::mojom::PaymentAppManifestError error = payments::mojom:: |
| + PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; |
| + bool called = false; |
| + SetManifest(manager, scope_url.spec(), std::move(manifest), |
| + base::Bind(&SetManifestCallback, &called, &error)); |
| + ASSERT_TRUE(called); |
| + |
| + ASSERT_EQ(error, payments::mojom::PaymentAppManifestError::NONE); |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(PaymentAppContextTest); |
|
please use gerrit instead
2016/12/16 21:41:21
#include "base/macros.h"
zino
2016/12/17 17:11:54
Done.
|
| +}; |
| + |
| +TEST_F(PaymentAppContextTest, Test) { |
|
please use gerrit instead
2016/12/16 21:41:21
#include "testing/gtest/include/gtest/gtest.h"
zino
2016/12/17 17:11:54
Done.
|
| + static const struct { |
| + const char* scopeUrl; |
| + const char* scriptUrl; |
| + } kPaymentAppInfo[] = { |
| + {"https://example.com/a", "https://example.com/a/script.js"}, |
| + {"https://example.com/b", "https://example.com/b/script.js"}, |
| + {"https://example.com/c", "https://example.com/c/script.js"}}; |
| + |
| + for (size_t i = 0; i < arraysize(kPaymentAppInfo); i++) |
|
please use gerrit instead
2016/12/16 21:41:21
#include <cstddef>
please use gerrit instead
2016/12/16 21:41:22
Need {} for the for-loop.
zino
2016/12/17 17:11:54
Done.
zino
2016/12/17 17:11:54
Done.
|
| + CreatePaymentApp(GURL(kPaymentAppInfo[i].scopeUrl), |
| + GURL(kPaymentAppInfo[i].scriptUrl)); |
| + |
| + PaymentAppContext::Manifests manifests; |
| + bool called = false; |
| + GetAllManifests(base::Bind(&GetAllManifestsCallback, &called, &manifests)); |
| + ASSERT_TRUE(called); |
| + |
| + ASSERT_EQ(manifests.size(), 3U); |
| + size_t i = 0; |
| + for (const auto& manifest : manifests) { |
| + EXPECT_EQ(manifest.second->icon, std::string("payment-app-icon")); |
| + EXPECT_EQ(manifest.second->label, kPaymentAppInfo[i++].scopeUrl); |
| + ASSERT_EQ(manifest.second->options.size(), 1U); |
| + EXPECT_EQ(manifest.second->options[0]->icon, |
| + std::string("payment-app-icon")); |
| + EXPECT_EQ(manifest.second->options[0]->label, "Visa ****"); |
| + EXPECT_EQ(manifest.second->options[0]->id, "payment-app-id"); |
| + ASSERT_EQ(manifest.second->options[0]->enabled_methods.size(), 1U); |
| + EXPECT_EQ(manifest.second->options[0]->enabled_methods[0], "visa"); |
| + } |
| +} |
| + |
| +} // namespace content |