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

Side by Side Diff: components/payments/content/payment_manifest_section_table_unittest.cc

Issue 2801513002: [Payments] Add web app manifest section table in SQLite web database (Closed)
Patch Set: address comments Created 3 years, 8 months 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 2017 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 "components/payments/content/payment_manifest_section_table.h"
6
7 #include "base/files/scoped_temp_dir.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace payments {
11 namespace {
12
13 const size_t kFingerPrintLength = 32;
14
15 class PaymentManifestSectionTableTest : public testing::Test {
16 public:
17 PaymentManifestSectionTableTest() {}
18 ~PaymentManifestSectionTableTest() override {}
19
20 protected:
21 void SetUp() override {
22 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
23 file_ = temp_dir_.GetPath().AppendASCII("TestWebDatabase");
24
25 table_.reset(new PaymentManifestSectionTable);
26 db_.reset(new WebDatabase);
27 db_->AddTable(table_.get());
28 ASSERT_EQ(sql::INIT_OK, db_->Init(file_));
29 }
30
31 void TearDown() override {}
32
33 base::FilePath file_;
34 base::ScopedTempDir temp_dir_;
35 std::unique_ptr<PaymentManifestSectionTable> table_;
36 std::unique_ptr<WebDatabase> db_;
37
38 private:
39 DISALLOW_COPY_AND_ASSIGN(PaymentManifestSectionTableTest);
40 };
41
42 TEST_F(PaymentManifestSectionTableTest, GetManifestWithoutSection) {
43 PaymentManifestSectionTable* manifest_section_table =
44 PaymentManifestSectionTable::FromWebDatabase(db_.get());
45 std::string bobpay_method_name = "https://bobpay.com";
46 std::vector<mojom::PaymentManifestSectionPtr> retrieved_manifest =
47 manifest_section_table->GetPaymentManifestSections(bobpay_method_name);
48 ASSERT_TRUE(retrieved_manifest.empty());
49 }
50
51 TEST_F(PaymentManifestSectionTableTest, AddAndGetManifestWithSingleSection) {
52 std::vector<mojom::PaymentManifestSectionPtr> manifest;
53
54 // Adds a section to the manifest.
55 mojom::PaymentManifestSectionPtr section =
56 mojom::PaymentManifestSection::New();
57 section->package_name = "com.bobpay";
58 section->version = static_cast<int64_t>(1);
59 // Adds two finger prints.
60 for (size_t i = 0; i < 2; i++) {
please use gerrit instead 2017/04/06 14:35:29 Use "2U" instead of "2" to avoid compiler complain
gogerald1 2017/04/06 16:42:10 Done.
61 std::vector<uint8_t> finger_print;
62 for (size_t j = 0; j < kFingerPrintLength; j++) {
63 finger_print.push_back(i * kFingerPrintLength + j);
64 }
65 section->sha256_cert_fingerprints.push_back(finger_print);
66 }
67 manifest.push_back(std::move(section));
68
69 // Adds the manifest to the table.
70 PaymentManifestSectionTable* manifest_section_table =
71 PaymentManifestSectionTable::FromWebDatabase(db_.get());
72 std::string bobpay_method_name = "https://bobpay.com";
73 ASSERT_TRUE(manifest_section_table->AddPaymentManifestSections(
74 bobpay_method_name, manifest));
75
76 // Gets and verifys the manifest.
77 std::vector<mojom::PaymentManifestSectionPtr> retrieved_manifest =
78 manifest_section_table->GetPaymentManifestSections(bobpay_method_name);
79 ASSERT_EQ(retrieved_manifest.size(), 1U);
80 ASSERT_EQ(retrieved_manifest[0]->package_name, "com.bobpay");
81 ASSERT_EQ(retrieved_manifest[0]->version, 1);
82 ASSERT_EQ(retrieved_manifest[0]->sha256_cert_fingerprints.size(), 2U);
83 // Verify the two finger prints.
84 for (size_t i = 0; i < 2; i++) {
85 ASSERT_EQ(retrieved_manifest[0]->sha256_cert_fingerprints[i].size(),
86 kFingerPrintLength);
87 for (size_t j = 0; j < kFingerPrintLength; j++) {
88 ASSERT_EQ(retrieved_manifest[0]->sha256_cert_fingerprints[i][j],
89 i * kFingerPrintLength + j);
90 }
91 }
92 }
93
94 TEST_F(PaymentManifestSectionTableTest, AddAndGetManifestWithMultipleSections) {
95 std::vector<mojom::PaymentManifestSectionPtr> manifest;
96
97 // Adds section one to the manifest.
98 mojom::PaymentManifestSectionPtr section_1 =
99 mojom::PaymentManifestSection::New();
100 section_1->package_name = "com.bobpay";
101 section_1->version = static_cast<int64_t>(1);
102 // Adds two finger prints.
103 for (size_t i = 0; i < 2; i++) {
please use gerrit instead 2017/04/06 14:35:29 2U
gogerald1 2017/04/06 16:42:10 Done.
104 std::vector<uint8_t> finger_print;
105 for (size_t j = 0; j < kFingerPrintLength; j++) {
106 finger_print.push_back(i * kFingerPrintLength + j);
107 }
108 section_1->sha256_cert_fingerprints.push_back(finger_print);
109 }
110 manifest.push_back(std::move(section_1));
111
112 // Adds section two to the manifest.
113 mojom::PaymentManifestSectionPtr section_2 =
114 mojom::PaymentManifestSection::New();
115 section_2->package_name = "com.alicepay";
116 section_2->version = static_cast<int64_t>(2);
117 // Adds two finger prints.
118 for (size_t i = 0; i < 2; i++) {
please use gerrit instead 2017/04/06 14:35:29 2U
gogerald1 2017/04/06 16:42:09 Done.
119 std::vector<uint8_t> finger_print;
120 for (size_t j = 0; j < kFingerPrintLength; j++) {
121 finger_print.push_back(2 * i * kFingerPrintLength + j);
122 }
123 section_2->sha256_cert_fingerprints.push_back(finger_print);
124 }
125 manifest.push_back(std::move(section_2));
126
127 // Adds the manifest to the table.
128 PaymentManifestSectionTable* manifest_section_table =
129 PaymentManifestSectionTable::FromWebDatabase(db_.get());
130 std::string bobpay_method_name = "https://bobpay.com";
131 ASSERT_TRUE(manifest_section_table->AddPaymentManifestSections(
132 bobpay_method_name, manifest));
133
134 // Retrieves the manifest.
135 std::vector<mojom::PaymentManifestSectionPtr> retrieved_manifest =
136 manifest_section_table->GetPaymentManifestSections(bobpay_method_name);
137 ASSERT_EQ(retrieved_manifest.size(), 2U);
138
139 // Verifys section one.
140 ASSERT_EQ(retrieved_manifest[0]->package_name, "com.bobpay");
141 ASSERT_EQ(retrieved_manifest[0]->version, 1);
142 ASSERT_EQ(retrieved_manifest[0]->sha256_cert_fingerprints.size(), 2U);
143 for (size_t i = 0; i < 2; i++) {
please use gerrit instead 2017/04/06 14:35:29 2U
gogerald1 2017/04/06 16:42:10 Done.
144 ASSERT_EQ(retrieved_manifest[0]->sha256_cert_fingerprints[i].size(),
145 kFingerPrintLength);
146 for (size_t j = 0; j < kFingerPrintLength; j++) {
147 ASSERT_EQ(retrieved_manifest[0]->sha256_cert_fingerprints[i][j],
148 i * kFingerPrintLength + j);
149 }
150 }
151
152 // Verifys section two.
153 ASSERT_EQ(retrieved_manifest[1]->package_name, "com.alicepay");
154 ASSERT_EQ(retrieved_manifest[1]->version, 2);
155 ASSERT_EQ(retrieved_manifest[1]->sha256_cert_fingerprints.size(), 2U);
156 for (size_t i = 0; i < 2; i++) {
please use gerrit instead 2017/04/06 14:35:29 2U
gogerald1 2017/04/06 16:42:10 Done.
157 ASSERT_EQ(retrieved_manifest[1]->sha256_cert_fingerprints[i].size(),
158 kFingerPrintLength);
159 for (size_t j = 0; j < kFingerPrintLength; j++) {
160 ASSERT_EQ(retrieved_manifest[1]->sha256_cert_fingerprints[i][j],
161 2 * i * kFingerPrintLength + j);
162 }
163 }
164 }
165
166 TEST_F(PaymentManifestSectionTableTest, AddAndGetMultipleManifests) {
167 PaymentManifestSectionTable* manifest_section_table =
168 PaymentManifestSectionTable::FromWebDatabase(db_.get());
169
170 // Adds bobpay manifest to the table.
171 std::vector<mojom::PaymentManifestSectionPtr> manifest_1;
172 mojom::PaymentManifestSectionPtr section_1 =
173 mojom::PaymentManifestSection::New();
174 section_1->package_name = "com.bobpay";
175 section_1->version = static_cast<int64_t>(1);
176 // Adds two finger prints.
177 for (size_t i = 0; i < 2; i++) {
please use gerrit instead 2017/04/06 14:35:29 2U
gogerald1 2017/04/06 16:42:10 Done.
178 std::vector<uint8_t> finger_print;
179 for (size_t j = 0; j < kFingerPrintLength; j++) {
180 finger_print.push_back(i * kFingerPrintLength + j);
181 }
182 section_1->sha256_cert_fingerprints.push_back(finger_print);
183 }
184 manifest_1.push_back(std::move(section_1));
185
186 std::string bobpay_method_name = "https://bobpay.com";
187 ASSERT_TRUE(manifest_section_table->AddPaymentManifestSections(
188 bobpay_method_name, manifest_1));
189
190 // Adds alicepay manifest to the table.
191 std::vector<mojom::PaymentManifestSectionPtr> manifest_2;
192 mojom::PaymentManifestSectionPtr section_2 =
193 mojom::PaymentManifestSection::New();
194 section_2->package_name = "com.alicepay";
195 section_2->version = static_cast<int64_t>(2);
196 // Adds two finger prints.
197 for (size_t i = 0; i < 2; i++) {
please use gerrit instead 2017/04/06 14:35:29 2U
gogerald1 2017/04/06 16:42:09 Done.
198 std::vector<uint8_t> finger_print;
199 for (size_t j = 0; j < kFingerPrintLength; j++) {
200 finger_print.push_back(2 * i * kFingerPrintLength + j);
201 }
202 section_2->sha256_cert_fingerprints.push_back(finger_print);
203 }
204 manifest_2.push_back(std::move(section_2));
205
206 std::string alicepay_method_name = "https://alicepay.com";
207 ASSERT_TRUE(manifest_section_table->AddPaymentManifestSections(
208 alicepay_method_name, manifest_2));
209
210 // Verifys bobpay manifest.
211 std::vector<mojom::PaymentManifestSectionPtr> bobpay_manifest =
212 manifest_section_table->GetPaymentManifestSections(bobpay_method_name);
213 ASSERT_EQ(bobpay_manifest.size(), 1U);
214
215 ASSERT_EQ(bobpay_manifest[0]->package_name, "com.bobpay");
216 ASSERT_EQ(bobpay_manifest[0]->version, 1);
217 ASSERT_EQ(bobpay_manifest[0]->sha256_cert_fingerprints.size(), 2U);
218 for (size_t i = 0; i < 2; i++) {
please use gerrit instead 2017/04/06 14:35:29 2U
gogerald1 2017/04/06 16:42:09 Done.
219 ASSERT_EQ(bobpay_manifest[0]->sha256_cert_fingerprints[i].size(),
220 kFingerPrintLength);
221 for (size_t j = 0; j < kFingerPrintLength; j++) {
222 ASSERT_EQ(bobpay_manifest[0]->sha256_cert_fingerprints[i][j],
223 i * kFingerPrintLength + j);
224 }
225 }
226
227 // Verifys alicepay manifest.
228 std::vector<mojom::PaymentManifestSectionPtr> alicepay_manifest =
229 manifest_section_table->GetPaymentManifestSections(alicepay_method_name);
230 ASSERT_EQ(alicepay_manifest.size(), 1U);
231
232 ASSERT_EQ(alicepay_manifest[0]->package_name, "com.alicepay");
233 ASSERT_EQ(alicepay_manifest[0]->version, 2);
234 ASSERT_EQ(alicepay_manifest[0]->sha256_cert_fingerprints.size(), 2U);
235 for (size_t i = 0; i < 2; i++) {
please use gerrit instead 2017/04/06 14:35:29 2U
gogerald1 2017/04/06 16:42:10 Done.
236 ASSERT_EQ(alicepay_manifest[0]->sha256_cert_fingerprints[i].size(),
237 kFingerPrintLength);
238 for (size_t j = 0; j < kFingerPrintLength; j++) {
239 ASSERT_EQ(alicepay_manifest[0]->sha256_cert_fingerprints[i][j],
240 2 * i * kFingerPrintLength + j);
241 }
242 }
243 }
244 }
245 } // payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698