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

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

Powered by Google App Engine
This is Rietveld 408576698