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

Side by Side Diff: content/browser/payments/payment_app_context_impl_unittest.cc

Issue 2556433002: PaymentApp: Implement GetAllManifests() in PaymentAppContext. (Closed)
Patch Set: addressed comments 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <cstddef>
6 #include <string>
7 #include <utility>
8
9 #include "base/macros.h"
10 #include "base/run_loop.h"
11 #include "components/payments/payment_app.mojom.h"
12 #include "content/browser/payments/payment_app_content_unittest_base.h"
13 #include "content/browser/payments/payment_app_context_impl.h"
14 #include "content/public/browser/payment_app_context.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "url/gurl.h"
17
18 namespace content {
19
20 class PaymentAppManager;
21
22 namespace {
23
24 void SetManifestCallback(bool* called,
25 payments::mojom::PaymentAppManifestError* out_error,
26 payments::mojom::PaymentAppManifestError error) {
27 *called = true;
28 *out_error = error;
29 }
30
31 void GetAllManifestsCallback(bool* called,
32 PaymentAppContext::Manifests* out_manifests,
33 PaymentAppContext::Manifests manifests) {
34 *called = true;
35 *out_manifests = std::move(manifests);
36 }
37
38 } // namespace
39
40 class PaymentAppContextTest : public PaymentAppContentUnitTestBase {
41 public:
42 PaymentAppContextTest() {}
43 ~PaymentAppContextTest() override {}
44
45 void GetAllManifests(PaymentAppContext::GetAllManifestsCallback callback) {
46 payment_app_context()->GetAllManifests(callback);
47 base::RunLoop().RunUntilIdle();
48 }
49
50 void CreatePaymentApp(const GURL& scope_url, const GURL& sw_script_url) {
51 PaymentAppManager* manager =
52 CreatePaymentAppManager(scope_url, sw_script_url);
53
54 payments::mojom::PaymentAppOptionPtr option =
55 payments::mojom::PaymentAppOption::New();
56 option->name = "Visa ****";
57 option->id = "payment-app-id";
58 option->icon = std::string("payment-app-icon");
59 option->enabled_methods.push_back("visa");
60
61 payments::mojom::PaymentAppManifestPtr manifest =
62 payments::mojom::PaymentAppManifest::New();
63 manifest->icon = std::string("payment-app-icon");
64 manifest->name = scope_url.spec();
65 manifest->options.push_back(std::move(option));
66
67 payments::mojom::PaymentAppManifestError error = payments::mojom::
68 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED;
69 bool called = false;
70 SetManifest(manager, scope_url.spec(), std::move(manifest),
71 base::Bind(&SetManifestCallback, &called, &error));
72 ASSERT_TRUE(called);
73
74 ASSERT_EQ(error, payments::mojom::PaymentAppManifestError::NONE);
75 }
76
77 private:
78 DISALLOW_COPY_AND_ASSIGN(PaymentAppContextTest);
79 };
80
81 TEST_F(PaymentAppContextTest, Test) {
82 static const struct {
83 const char* scopeUrl;
84 const char* scriptUrl;
85 } kPaymentAppInfo[] = {
86 {"https://example.com/a", "https://example.com/a/script.js"},
87 {"https://example.com/b", "https://example.com/b/script.js"},
88 {"https://example.com/c", "https://example.com/c/script.js"}};
89
90 for (size_t i = 0; i < arraysize(kPaymentAppInfo); i++) {
91 CreatePaymentApp(GURL(kPaymentAppInfo[i].scopeUrl),
92 GURL(kPaymentAppInfo[i].scriptUrl));
93 }
94
95 PaymentAppContext::Manifests manifests;
96 bool called = false;
97 GetAllManifests(base::Bind(&GetAllManifestsCallback, &called, &manifests));
98 ASSERT_TRUE(called);
99
100 ASSERT_EQ(manifests.size(), 3U);
101 size_t i = 0;
102 for (const auto& manifest : manifests) {
103 EXPECT_EQ(manifest.second->icon.value(), "payment-app-icon");
104 EXPECT_EQ(manifest.second->name, kPaymentAppInfo[i++].scopeUrl);
105 ASSERT_EQ(manifest.second->options.size(), 1U);
106 EXPECT_EQ(manifest.second->options[0]->icon.value(), "payment-app-icon");
107 EXPECT_EQ(manifest.second->options[0]->name, "Visa ****");
108 EXPECT_EQ(manifest.second->options[0]->id, "payment-app-id");
109 ASSERT_EQ(manifest.second->options[0]->enabled_methods.size(), 1U);
110 EXPECT_EQ(manifest.second->options[0]->enabled_methods[0], "visa");
111 }
112 }
113
114 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/payments/payment_app_context_impl.cc ('k') | content/browser/payments/payment_app_database.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698