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