OLD | NEW |
| (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 using payments::mojom::PaymentAppManifestError; | |
19 using payments::mojom::PaymentAppManifestPtr; | |
20 | |
21 namespace content { | |
22 | |
23 class PaymentAppManager; | |
24 | |
25 namespace { | |
26 | |
27 void SetManifestCallback(bool* called, | |
28 PaymentAppManifestError* out_error, | |
29 PaymentAppManifestError error) { | |
30 *called = true; | |
31 *out_error = error; | |
32 } | |
33 | |
34 void GetAllManifestsCallback(bool* called, | |
35 PaymentAppContext::Manifests* out_manifests, | |
36 PaymentAppContext::Manifests manifests) { | |
37 *called = true; | |
38 *out_manifests = std::move(manifests); | |
39 } | |
40 | |
41 } // namespace | |
42 | |
43 class PaymentAppContextTest : public PaymentAppContentUnitTestBase { | |
44 public: | |
45 PaymentAppContextTest() {} | |
46 ~PaymentAppContextTest() override {} | |
47 | |
48 void GetAllManifests(PaymentAppContext::GetAllManifestsCallback callback) { | |
49 payment_app_context()->GetAllManifests(callback); | |
50 base::RunLoop().RunUntilIdle(); | |
51 } | |
52 | |
53 void CreatePaymentApp(const GURL& scope_url, const GURL& sw_script_url) { | |
54 PaymentAppManager* manager = | |
55 CreatePaymentAppManager(scope_url, sw_script_url); | |
56 | |
57 PaymentAppManifestError error = | |
58 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; | |
59 bool called = false; | |
60 SetManifest(manager, CreatePaymentAppManifestForTest(scope_url.spec()), | |
61 base::Bind(&SetManifestCallback, &called, &error)); | |
62 ASSERT_TRUE(called); | |
63 | |
64 ASSERT_EQ(PaymentAppManifestError::NONE, error); | |
65 } | |
66 | |
67 private: | |
68 DISALLOW_COPY_AND_ASSIGN(PaymentAppContextTest); | |
69 }; | |
70 | |
71 TEST_F(PaymentAppContextTest, Test) { | |
72 static const struct { | |
73 const char* scopeUrl; | |
74 const char* scriptUrl; | |
75 } kPaymentAppInfo[] = { | |
76 {"https://example.com/a", "https://example.com/a/script.js"}, | |
77 {"https://example.com/b", "https://example.com/b/script.js"}, | |
78 {"https://example.com/c", "https://example.com/c/script.js"}}; | |
79 | |
80 for (size_t i = 0; i < arraysize(kPaymentAppInfo); i++) { | |
81 CreatePaymentApp(GURL(kPaymentAppInfo[i].scopeUrl), | |
82 GURL(kPaymentAppInfo[i].scriptUrl)); | |
83 } | |
84 | |
85 PaymentAppContext::Manifests manifests; | |
86 bool called = false; | |
87 GetAllManifests(base::Bind(&GetAllManifestsCallback, &called, &manifests)); | |
88 ASSERT_TRUE(called); | |
89 | |
90 ASSERT_EQ(3U, manifests.size()); | |
91 size_t i = 0; | |
92 for (const auto& manifest : manifests) { | |
93 EXPECT_EQ("payment-app-icon", manifest.second->icon.value()); | |
94 EXPECT_EQ(kPaymentAppInfo[i++].scopeUrl, manifest.second->name); | |
95 ASSERT_EQ(1U, manifest.second->options.size()); | |
96 EXPECT_EQ("payment-app-icon", manifest.second->options[0]->icon.value()); | |
97 EXPECT_EQ("Visa ****", manifest.second->options[0]->name); | |
98 EXPECT_EQ("payment-app-id", manifest.second->options[0]->id); | |
99 ASSERT_EQ(1U, manifest.second->options[0]->enabled_methods.size()); | |
100 EXPECT_EQ("visa", manifest.second->options[0]->enabled_methods[0]); | |
101 } | |
102 } | |
103 | |
104 } // namespace content | |
OLD | NEW |