Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(743)

Unified Diff: content/browser/payments/payment_app_context_impl_unittest.cc

Issue 2556433002: PaymentApp: Implement GetAllManifests() in PaymentAppContext. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..773564ccc0c59c14598dc32a7ec24ee3fc1326b1
--- /dev/null
+++ b/content/browser/payments/payment_app_context_impl_unittest.cc
@@ -0,0 +1,88 @@
+// 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(payments::mojom::PaymentAppManifestError* out_error,
+ payments::mojom::PaymentAppManifestError error) {
+ *out_error = error;
+}
+
+void GetAllManifestsCallback(PaymentAppContext::Manifests* out_manifests,
+ PaymentAppContext::Manifests manifests) {
+ *out_manifests = std::move(manifests);
+}
+
+} // namespace
+
+class PaymentAppContextTest : public PaymentAppContentUnitTestBase {
+ public:
+ PaymentAppContextTest() {}
please use gerrit instead 2016/12/12 20:17:39 Need a destructor as well.
zino 2016/12/16 19:45:41 Done.
+
+ void GetAllManifests(PaymentAppContext::GetAllManifestsCallback callback) {
+ GetPaymentAppContext()->GetAllManifests(callback);
+ base::RunLoop().RunUntilIdle();
+ }
+
+ void CreatePaymentApp(const GURL& scope_url, const GURL& sw_script_url) {
+ PaymentAppManager* manager =
+ 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");
+ 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;
+ SetManifest(manager, scope_url.spec(), std::move(manifest),
+ base::Bind(&SetManifestCallback, &error));
+ ASSERT_EQ(error, payments::mojom::PaymentAppManifestError::NONE);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PaymentAppContextTest);
+};
+
+TEST_F(PaymentAppContextTest, Test) {
+ const char* kPaymentAppInfo[][2] = {
+ {"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"},
+ };
please use gerrit instead 2016/12/12 20:17:39 The standard way to create test data list is: sta
zino 2016/12/16 19:45:40 Done.
+
+ for (int i = 0; i < 3; i++) {
+ CreatePaymentApp(GURL(kPaymentAppInfo[i][0]), GURL(kPaymentAppInfo[i][1]));
+ }
+
+ PaymentAppContext::Manifests manifests;
+ GetAllManifests(base::Bind(&GetAllManifestsCallback, &manifests));
+
+ ASSERT_EQ(manifests.size(), 3U);
+ int i = 0;
+ for (auto& manifest : manifests) {
please use gerrit instead 2016/12/12 20:17:39 const auto&
zino 2016/12/16 19:45:41 Done.
+ EXPECT_EQ(manifest.second->icon, std::string("payment-app-icon"));
please use gerrit instead 2016/12/12 20:17:39 Is std::string() wrapper necessary? I see that you
zino 2016/12/16 19:45:40 The type is base::Optional<std::string>. https://c
+ EXPECT_EQ(manifest.second->label, kPaymentAppInfo[i++][0]);
+ 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

Powered by Google App Engine
This is Rietveld 408576698