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" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 public: | 43 public: |
44 PaymentAppProviderTest() {} | 44 PaymentAppProviderTest() {} |
45 ~PaymentAppProviderTest() override {} | 45 ~PaymentAppProviderTest() override {} |
46 | 46 |
47 void GetAllManifests(PaymentAppProvider::GetAllManifestsCallback callback) { | 47 void GetAllManifests(PaymentAppProvider::GetAllManifestsCallback callback) { |
48 PaymentAppProviderImpl::GetInstance()->GetAllManifests(browser_context(), | 48 PaymentAppProviderImpl::GetInstance()->GetAllManifests(browser_context(), |
49 callback); | 49 callback); |
50 base::RunLoop().RunUntilIdle(); | 50 base::RunLoop().RunUntilIdle(); |
51 } | 51 } |
52 | 52 |
53 void InvokePaymentApp(int64_t registration_id, | |
54 payments::mojom::PaymentAppRequestDataPtr data) { | |
55 PaymentAppProviderImpl::GetInstance()->InvokePaymentApp( | |
56 browser_context(), registration_id, std::move(data)); | |
57 base::RunLoop().RunUntilIdle(); | |
58 } | |
59 | |
53 void CreatePaymentApp(const GURL& scope_url, const GURL& sw_script_url) { | 60 void CreatePaymentApp(const GURL& scope_url, const GURL& sw_script_url) { |
54 PaymentAppManager* manager = | 61 PaymentAppManager* manager = |
55 CreatePaymentAppManager(scope_url, sw_script_url); | 62 CreatePaymentAppManager(scope_url, sw_script_url); |
56 | 63 |
57 PaymentAppManifestError error = | 64 PaymentAppManifestError error = |
58 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; | 65 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; |
59 bool called = false; | 66 bool called = false; |
60 SetManifest(manager, CreatePaymentAppManifestForTest(scope_url.spec()), | 67 SetManifest(manager, CreatePaymentAppManifestForTest(scope_url.spec()), |
61 base::Bind(&SetManifestCallback, &called, &error)); | 68 base::Bind(&SetManifestCallback, &called, &error)); |
62 ASSERT_TRUE(called); | 69 ASSERT_TRUE(called); |
63 | 70 |
64 ASSERT_EQ(PaymentAppManifestError::NONE, error); | 71 ASSERT_EQ(PaymentAppManifestError::NONE, error); |
72 base::RunLoop().RunUntilIdle(); | |
please use gerrit instead
2017/01/12 19:04:00
Which call in here is asynchronous?
zino
2017/01/13 16:41:11
It's unnecessary. It's my mistake.
Done.
| |
65 } | 73 } |
66 | 74 |
67 private: | 75 private: |
68 DISALLOW_COPY_AND_ASSIGN(PaymentAppProviderTest); | 76 DISALLOW_COPY_AND_ASSIGN(PaymentAppProviderTest); |
69 }; | 77 }; |
70 | 78 |
71 TEST_F(PaymentAppProviderTest, Test) { | 79 TEST_F(PaymentAppProviderTest, GetAllManifestsTest) { |
72 static const struct { | 80 static const struct { |
73 const char* scopeUrl; | 81 const char* scopeUrl; |
74 const char* scriptUrl; | 82 const char* scriptUrl; |
75 } kPaymentAppInfo[] = { | 83 } kPaymentAppInfo[] = { |
76 {"https://example.com/a", "https://example.com/a/script.js"}, | 84 {"https://example.com/a", "https://example.com/a/script.js"}, |
77 {"https://example.com/b", "https://example.com/b/script.js"}, | 85 {"https://example.com/b", "https://example.com/b/script.js"}, |
78 {"https://example.com/c", "https://example.com/c/script.js"}}; | 86 {"https://example.com/c", "https://example.com/c/script.js"}}; |
79 | 87 |
80 for (size_t i = 0; i < arraysize(kPaymentAppInfo); i++) { | 88 for (size_t i = 0; i < arraysize(kPaymentAppInfo); i++) { |
81 CreatePaymentApp(GURL(kPaymentAppInfo[i].scopeUrl), | 89 CreatePaymentApp(GURL(kPaymentAppInfo[i].scopeUrl), |
(...skipping 12 matching lines...) Expand all Loading... | |
94 EXPECT_EQ(kPaymentAppInfo[i++].scopeUrl, manifest.second->name); | 102 EXPECT_EQ(kPaymentAppInfo[i++].scopeUrl, manifest.second->name); |
95 ASSERT_EQ(1U, manifest.second->options.size()); | 103 ASSERT_EQ(1U, manifest.second->options.size()); |
96 EXPECT_EQ("payment-app-icon", manifest.second->options[0]->icon.value()); | 104 EXPECT_EQ("payment-app-icon", manifest.second->options[0]->icon.value()); |
97 EXPECT_EQ("Visa ****", manifest.second->options[0]->name); | 105 EXPECT_EQ("Visa ****", manifest.second->options[0]->name); |
98 EXPECT_EQ("payment-app-id", manifest.second->options[0]->id); | 106 EXPECT_EQ("payment-app-id", manifest.second->options[0]->id); |
99 ASSERT_EQ(1U, manifest.second->options[0]->enabled_methods.size()); | 107 ASSERT_EQ(1U, manifest.second->options[0]->enabled_methods.size()); |
100 EXPECT_EQ("visa", manifest.second->options[0]->enabled_methods[0]); | 108 EXPECT_EQ("visa", manifest.second->options[0]->enabled_methods[0]); |
101 } | 109 } |
102 } | 110 } |
103 | 111 |
112 TEST_F(PaymentAppProviderTest, InvokePaymentAppTest) { | |
113 static const struct { | |
114 const char* scopeUrl; | |
115 const char* scriptUrl; | |
116 } kPaymentAppInfo[] = { | |
117 {"https://example.com/a", "https://example.com/a/script.js"}, | |
118 {"https://example.com/b", "https://example.com/b/script.js"}, | |
119 {"https://example.com/c", "https://example.com/c/script.js"}}; | |
120 | |
121 for (size_t i = 0; i < arraysize(kPaymentAppInfo); i++) { | |
122 CreatePaymentApp(GURL(kPaymentAppInfo[i].scopeUrl), | |
123 GURL(kPaymentAppInfo[i].scriptUrl)); | |
124 } | |
125 | |
126 PaymentAppProvider::Manifests manifests; | |
127 bool called = false; | |
128 GetAllManifests(base::Bind(&GetAllManifestsCallback, &called, &manifests)); | |
129 ASSERT_TRUE(called); | |
130 ASSERT_EQ(3U, manifests.size()); | |
131 | |
132 payments::mojom::PaymentAppRequestDataPtr data = | |
133 payments::mojom::PaymentAppRequestData::New(); | |
134 data->methodData.push_back(payments::mojom::PaymentMethodData::New()); | |
135 data->total = payments::mojom::PaymentItem::New(); | |
136 data->total->amount = payments::mojom::PaymentCurrencyAmount::New(); | |
137 | |
138 init_payment_app_invoked(); | |
139 EXPECT_FALSE(payment_app_invoked()); | |
140 InvokePaymentApp(manifests[1].first, std::move(data)); | |
141 | |
142 ASSERT_TRUE(payment_app_invoked()); | |
143 EXPECT_EQ(manifests[1].first, last_sw_registration_id()); | |
144 EXPECT_EQ(GURL(kPaymentAppInfo[1].scopeUrl), last_sw_scope_url()); | |
145 } | |
146 | |
104 } // namespace content | 147 } // namespace content |
OLD | NEW |