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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/run_loop.h" | |
8 #include "components/payments/content/payment_app.mojom.h" | 9 #include "components/payments/content/payment_app.mojom.h" |
9 #include "content/browser/payments/payment_app_content_unittest_base.h" | 10 #include "content/browser/payments/payment_app_content_unittest_base.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "url/gurl.h" | 12 #include "url/gurl.h" |
12 | 13 |
13 using payments::mojom::PaymentAppManifestError; | 14 using payments::mojom::PaymentAppManifestError; |
14 using payments::mojom::PaymentAppManifestPtr; | 15 using payments::mojom::PaymentAppManifestPtr; |
16 using payments::mojom::PaymentHandlerStatus; | |
17 using payments::mojom::PaymentInstrument; | |
18 using payments::mojom::PaymentInstrumentPtr; | |
please use gerrit instead
2017/04/12 19:11:31
Please prepend the top namespace with :: and move
zino
2017/04/15 05:18:09
Done.
| |
15 | 19 |
16 namespace content { | 20 namespace content { |
17 namespace { | 21 namespace { |
18 | 22 |
19 const char kServiceWorkerPattern[] = "https://example.com/a"; | 23 const char kServiceWorkerPattern[] = "https://example.com/a"; |
20 const char kServiceWorkerScript[] = "https://example.com/a/script.js"; | 24 const char kServiceWorkerScript[] = "https://example.com/a/script.js"; |
21 | 25 |
22 void SetManifestCallback(bool* called, | 26 void SetManifestCallback(bool* called, |
23 PaymentAppManifestError* out_error, | 27 PaymentAppManifestError* out_error, |
24 PaymentAppManifestError error) { | 28 PaymentAppManifestError error) { |
25 *called = true; | 29 *called = true; |
26 *out_error = error; | 30 *out_error = error; |
27 } | 31 } |
28 | 32 |
29 void GetManifestCallback(bool* called, | 33 void GetManifestCallback(bool* called, |
30 PaymentAppManifestPtr* out_manifest, | 34 PaymentAppManifestPtr* out_manifest, |
31 PaymentAppManifestError* out_error, | 35 PaymentAppManifestError* out_error, |
32 PaymentAppManifestPtr manifest, | 36 PaymentAppManifestPtr manifest, |
33 PaymentAppManifestError error) { | 37 PaymentAppManifestError error) { |
34 *called = true; | 38 *called = true; |
35 *out_manifest = std::move(manifest); | 39 *out_manifest = std::move(manifest); |
36 *out_error = error; | 40 *out_error = error; |
37 } | 41 } |
38 | 42 |
43 void SetPaymentInstrumentCallback(PaymentHandlerStatus* out_status, | |
44 PaymentHandlerStatus status) { | |
45 *out_status = status; | |
46 } | |
47 | |
48 void GetPaymentInstrumentCallback(PaymentInstrumentPtr* out_instrument, | |
49 PaymentHandlerStatus* out_status, | |
50 PaymentInstrumentPtr instrument, | |
51 PaymentHandlerStatus status) { | |
52 *out_instrument = std::move(instrument); | |
53 *out_status = status; | |
54 } | |
55 | |
39 } // namespace | 56 } // namespace |
40 | 57 |
41 class PaymentManagerTest : public PaymentAppContentUnitTestBase { | 58 class PaymentManagerTest : public PaymentAppContentUnitTestBase { |
42 public: | 59 public: |
43 PaymentManagerTest() { | 60 PaymentManagerTest() { |
44 manager_ = CreatePaymentManager(GURL(kServiceWorkerPattern), | 61 manager_ = CreatePaymentManager(GURL(kServiceWorkerPattern), |
45 GURL(kServiceWorkerScript)); | 62 GURL(kServiceWorkerScript)); |
46 EXPECT_NE(nullptr, manager_); | 63 EXPECT_NE(nullptr, manager_); |
47 } | 64 } |
48 | 65 |
49 PaymentManager* payment_manager() const { return manager_; } | 66 PaymentManager* payment_manager() const { return manager_; } |
50 | 67 |
68 void SetPaymentInstrument(const std::string& instrumentKey, | |
69 PaymentInstrumentPtr instrument, | |
70 PaymentHandlerStatus* out_status) { | |
71 manager_->SetPaymentInstrument( | |
72 instrumentKey, std::move(instrument), | |
73 base::Bind(&SetPaymentInstrumentCallback, out_status)); | |
74 base::RunLoop().RunUntilIdle(); | |
75 } | |
76 | |
77 void GetPaymentInstrument(const std::string& instrumentKey, | |
78 PaymentInstrumentPtr* out_instrument, | |
79 PaymentHandlerStatus* out_status) { | |
80 manager_->GetPaymentInstrument( | |
81 instrumentKey, | |
82 base::Bind(&GetPaymentInstrumentCallback, out_instrument, out_status)); | |
83 base::RunLoop().RunUntilIdle(); | |
84 } | |
85 | |
51 private: | 86 private: |
52 // Owned by payment_app_context_. | 87 // Owned by payment_app_context_. |
53 PaymentManager* manager_; | 88 PaymentManager* manager_; |
54 | 89 |
55 DISALLOW_COPY_AND_ASSIGN(PaymentManagerTest); | 90 DISALLOW_COPY_AND_ASSIGN(PaymentManagerTest); |
56 }; | 91 }; |
57 | 92 |
58 TEST_F(PaymentManagerTest, SetAndGetManifest) { | 93 TEST_F(PaymentManagerTest, SetAndGetManifest) { |
59 bool called = false; | 94 bool called = false; |
60 PaymentAppManifestError error = | 95 PaymentAppManifestError error = |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 PaymentAppManifestPtr read_manifest; | 149 PaymentAppManifestPtr read_manifest; |
115 PaymentAppManifestError read_error = PaymentAppManifestError::NONE; | 150 PaymentAppManifestError read_error = PaymentAppManifestError::NONE; |
116 GetManifest(payment_manager(), base::Bind(&GetManifestCallback, &called, | 151 GetManifest(payment_manager(), base::Bind(&GetManifestCallback, &called, |
117 &read_manifest, &read_error)); | 152 &read_manifest, &read_error)); |
118 ASSERT_TRUE(called); | 153 ASSERT_TRUE(called); |
119 | 154 |
120 EXPECT_EQ(PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED, | 155 EXPECT_EQ(PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED, |
121 read_error); | 156 read_error); |
122 } | 157 } |
123 | 158 |
159 TEST_F(PaymentManagerTest, SetAndGetPaymentInstrument) { | |
160 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; | |
161 PaymentInstrumentPtr write_details = PaymentInstrument::New(); | |
162 write_details->name = "Visa ending ****4756", | |
163 write_details->enabled_methods.push_back("visa"); | |
164 write_details->stringified_capabilities = "{}"; | |
165 ASSERT_EQ(PaymentHandlerStatus::NOT_FOUND, write_status); | |
166 SetPaymentInstrument("test_key", std::move(write_details), &write_status); | |
167 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); | |
168 | |
169 PaymentHandlerStatus read_status = PaymentHandlerStatus::NOT_FOUND; | |
170 PaymentInstrumentPtr read_details; | |
171 ASSERT_EQ(PaymentHandlerStatus::NOT_FOUND, read_status); | |
172 GetPaymentInstrument("test_key", &read_details, &read_status); | |
173 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, read_status); | |
174 EXPECT_EQ("Visa ending ****4756", read_details->name); | |
175 ASSERT_EQ(1U, read_details->enabled_methods.size()); | |
176 EXPECT_EQ("visa", read_details->enabled_methods[0]); | |
177 EXPECT_EQ("{}", read_details->stringified_capabilities); | |
178 } | |
179 | |
180 TEST_F(PaymentManagerTest, GetUnstoredPaymentInstrument) { | |
181 PaymentHandlerStatus read_status = PaymentHandlerStatus::SUCCESS; | |
182 PaymentInstrumentPtr read_details; | |
183 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, read_status); | |
184 GetPaymentInstrument("test_key", &read_details, &read_status); | |
185 ASSERT_EQ(PaymentHandlerStatus::NOT_FOUND, read_status); | |
186 } | |
187 | |
124 } // namespace content | 188 } // namespace content |
OLD | NEW |