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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: components/payments/content/payment_manifest_section_table_unittest.cc
diff --git a/components/payments/content/payment_manifest_section_table_unittest.cc b/components/payments/content/payment_manifest_section_table_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ce5c696a3828d57b88b6d5dff1f93bc37d78d479
--- /dev/null
+++ b/components/payments/content/payment_manifest_section_table_unittest.cc
@@ -0,0 +1,245 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/payments/content/payment_manifest_section_table.h"
+
+#include "base/files/scoped_temp_dir.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace payments {
+namespace {
+
+const size_t kFingerPrintLength = 32;
+
+class PaymentManifestSectionTableTest : public testing::Test {
+ public:
+ PaymentManifestSectionTableTest() {}
+ ~PaymentManifestSectionTableTest() override {}
+
+ protected:
+ void SetUp() override {
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ file_ = temp_dir_.GetPath().AppendASCII("TestWebDatabase");
+
+ table_.reset(new PaymentManifestSectionTable);
+ db_.reset(new WebDatabase);
+ db_->AddTable(table_.get());
+ ASSERT_EQ(sql::INIT_OK, db_->Init(file_));
+ }
+
+ void TearDown() override {}
+
+ base::FilePath file_;
+ base::ScopedTempDir temp_dir_;
+ std::unique_ptr<PaymentManifestSectionTable> table_;
+ std::unique_ptr<WebDatabase> db_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PaymentManifestSectionTableTest);
+};
+
+TEST_F(PaymentManifestSectionTableTest, GetManifestWithoutSection) {
+ PaymentManifestSectionTable* manifest_section_table =
+ PaymentManifestSectionTable::FromWebDatabase(db_.get());
+ std::string bobpay_method_name = "https://bobpay.com";
+ std::vector<mojom::PaymentManifestSectionPtr> retrieved_manifest =
+ manifest_section_table->GetPaymentManifestSections(bobpay_method_name);
+ ASSERT_TRUE(retrieved_manifest.empty());
+}
+
+TEST_F(PaymentManifestSectionTableTest, AddAndGetManifestWithSingleSection) {
+ std::vector<mojom::PaymentManifestSectionPtr> manifest;
+
+ // Adds a section to the manifest.
+ mojom::PaymentManifestSectionPtr section =
+ mojom::PaymentManifestSection::New();
+ section->package_name = "com.bobpay";
+ section->version = static_cast<int64_t>(1);
+ // Adds two finger prints.
+ 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.
+ std::vector<uint8_t> finger_print;
+ for (size_t j = 0; j < kFingerPrintLength; j++) {
+ finger_print.push_back(i * kFingerPrintLength + j);
+ }
+ section->sha256_cert_fingerprints.push_back(finger_print);
+ }
+ manifest.push_back(std::move(section));
+
+ // Adds the manifest to the table.
+ PaymentManifestSectionTable* manifest_section_table =
+ PaymentManifestSectionTable::FromWebDatabase(db_.get());
+ std::string bobpay_method_name = "https://bobpay.com";
+ ASSERT_TRUE(manifest_section_table->AddPaymentManifestSections(
+ bobpay_method_name, manifest));
+
+ // Gets and verifys the manifest.
+ std::vector<mojom::PaymentManifestSectionPtr> retrieved_manifest =
+ manifest_section_table->GetPaymentManifestSections(bobpay_method_name);
+ ASSERT_EQ(retrieved_manifest.size(), 1U);
+ ASSERT_EQ(retrieved_manifest[0]->package_name, "com.bobpay");
+ ASSERT_EQ(retrieved_manifest[0]->version, 1);
+ ASSERT_EQ(retrieved_manifest[0]->sha256_cert_fingerprints.size(), 2U);
+ // Verify the two finger prints.
+ for (size_t i = 0; i < 2; i++) {
+ ASSERT_EQ(retrieved_manifest[0]->sha256_cert_fingerprints[i].size(),
+ kFingerPrintLength);
+ for (size_t j = 0; j < kFingerPrintLength; j++) {
+ ASSERT_EQ(retrieved_manifest[0]->sha256_cert_fingerprints[i][j],
+ i * kFingerPrintLength + j);
+ }
+ }
+}
+
+TEST_F(PaymentManifestSectionTableTest, AddAndGetManifestWithMultipleSections) {
+ std::vector<mojom::PaymentManifestSectionPtr> manifest;
+
+ // Adds section one to the manifest.
+ mojom::PaymentManifestSectionPtr section_1 =
+ mojom::PaymentManifestSection::New();
+ section_1->package_name = "com.bobpay";
+ section_1->version = static_cast<int64_t>(1);
+ // Adds two finger prints.
+ 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.
+ std::vector<uint8_t> finger_print;
+ for (size_t j = 0; j < kFingerPrintLength; j++) {
+ finger_print.push_back(i * kFingerPrintLength + j);
+ }
+ section_1->sha256_cert_fingerprints.push_back(finger_print);
+ }
+ manifest.push_back(std::move(section_1));
+
+ // Adds section two to the manifest.
+ mojom::PaymentManifestSectionPtr section_2 =
+ mojom::PaymentManifestSection::New();
+ section_2->package_name = "com.alicepay";
+ section_2->version = static_cast<int64_t>(2);
+ // Adds two finger prints.
+ 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.
+ std::vector<uint8_t> finger_print;
+ for (size_t j = 0; j < kFingerPrintLength; j++) {
+ finger_print.push_back(2 * i * kFingerPrintLength + j);
+ }
+ section_2->sha256_cert_fingerprints.push_back(finger_print);
+ }
+ manifest.push_back(std::move(section_2));
+
+ // Adds the manifest to the table.
+ PaymentManifestSectionTable* manifest_section_table =
+ PaymentManifestSectionTable::FromWebDatabase(db_.get());
+ std::string bobpay_method_name = "https://bobpay.com";
+ ASSERT_TRUE(manifest_section_table->AddPaymentManifestSections(
+ bobpay_method_name, manifest));
+
+ // Retrieves the manifest.
+ std::vector<mojom::PaymentManifestSectionPtr> retrieved_manifest =
+ manifest_section_table->GetPaymentManifestSections(bobpay_method_name);
+ ASSERT_EQ(retrieved_manifest.size(), 2U);
+
+ // Verifys section one.
+ ASSERT_EQ(retrieved_manifest[0]->package_name, "com.bobpay");
+ ASSERT_EQ(retrieved_manifest[0]->version, 1);
+ ASSERT_EQ(retrieved_manifest[0]->sha256_cert_fingerprints.size(), 2U);
+ 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.
+ ASSERT_EQ(retrieved_manifest[0]->sha256_cert_fingerprints[i].size(),
+ kFingerPrintLength);
+ for (size_t j = 0; j < kFingerPrintLength; j++) {
+ ASSERT_EQ(retrieved_manifest[0]->sha256_cert_fingerprints[i][j],
+ i * kFingerPrintLength + j);
+ }
+ }
+
+ // Verifys section two.
+ ASSERT_EQ(retrieved_manifest[1]->package_name, "com.alicepay");
+ ASSERT_EQ(retrieved_manifest[1]->version, 2);
+ ASSERT_EQ(retrieved_manifest[1]->sha256_cert_fingerprints.size(), 2U);
+ 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.
+ ASSERT_EQ(retrieved_manifest[1]->sha256_cert_fingerprints[i].size(),
+ kFingerPrintLength);
+ for (size_t j = 0; j < kFingerPrintLength; j++) {
+ ASSERT_EQ(retrieved_manifest[1]->sha256_cert_fingerprints[i][j],
+ 2 * i * kFingerPrintLength + j);
+ }
+ }
+}
+
+TEST_F(PaymentManifestSectionTableTest, AddAndGetMultipleManifests) {
+ PaymentManifestSectionTable* manifest_section_table =
+ PaymentManifestSectionTable::FromWebDatabase(db_.get());
+
+ // Adds bobpay manifest to the table.
+ std::vector<mojom::PaymentManifestSectionPtr> manifest_1;
+ mojom::PaymentManifestSectionPtr section_1 =
+ mojom::PaymentManifestSection::New();
+ section_1->package_name = "com.bobpay";
+ section_1->version = static_cast<int64_t>(1);
+ // Adds two finger prints.
+ 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.
+ std::vector<uint8_t> finger_print;
+ for (size_t j = 0; j < kFingerPrintLength; j++) {
+ finger_print.push_back(i * kFingerPrintLength + j);
+ }
+ section_1->sha256_cert_fingerprints.push_back(finger_print);
+ }
+ manifest_1.push_back(std::move(section_1));
+
+ std::string bobpay_method_name = "https://bobpay.com";
+ ASSERT_TRUE(manifest_section_table->AddPaymentManifestSections(
+ bobpay_method_name, manifest_1));
+
+ // Adds alicepay manifest to the table.
+ std::vector<mojom::PaymentManifestSectionPtr> manifest_2;
+ mojom::PaymentManifestSectionPtr section_2 =
+ mojom::PaymentManifestSection::New();
+ section_2->package_name = "com.alicepay";
+ section_2->version = static_cast<int64_t>(2);
+ // Adds two finger prints.
+ 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.
+ std::vector<uint8_t> finger_print;
+ for (size_t j = 0; j < kFingerPrintLength; j++) {
+ finger_print.push_back(2 * i * kFingerPrintLength + j);
+ }
+ section_2->sha256_cert_fingerprints.push_back(finger_print);
+ }
+ manifest_2.push_back(std::move(section_2));
+
+ std::string alicepay_method_name = "https://alicepay.com";
+ ASSERT_TRUE(manifest_section_table->AddPaymentManifestSections(
+ alicepay_method_name, manifest_2));
+
+ // Verifys bobpay manifest.
+ std::vector<mojom::PaymentManifestSectionPtr> bobpay_manifest =
+ manifest_section_table->GetPaymentManifestSections(bobpay_method_name);
+ ASSERT_EQ(bobpay_manifest.size(), 1U);
+
+ ASSERT_EQ(bobpay_manifest[0]->package_name, "com.bobpay");
+ ASSERT_EQ(bobpay_manifest[0]->version, 1);
+ ASSERT_EQ(bobpay_manifest[0]->sha256_cert_fingerprints.size(), 2U);
+ 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.
+ ASSERT_EQ(bobpay_manifest[0]->sha256_cert_fingerprints[i].size(),
+ kFingerPrintLength);
+ for (size_t j = 0; j < kFingerPrintLength; j++) {
+ ASSERT_EQ(bobpay_manifest[0]->sha256_cert_fingerprints[i][j],
+ i * kFingerPrintLength + j);
+ }
+ }
+
+ // Verifys alicepay manifest.
+ std::vector<mojom::PaymentManifestSectionPtr> alicepay_manifest =
+ manifest_section_table->GetPaymentManifestSections(alicepay_method_name);
+ ASSERT_EQ(alicepay_manifest.size(), 1U);
+
+ ASSERT_EQ(alicepay_manifest[0]->package_name, "com.alicepay");
+ ASSERT_EQ(alicepay_manifest[0]->version, 2);
+ ASSERT_EQ(alicepay_manifest[0]->sha256_cert_fingerprints.size(), 2U);
+ 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.
+ ASSERT_EQ(alicepay_manifest[0]->sha256_cert_fingerprints[i].size(),
+ kFingerPrintLength);
+ for (size_t j = 0; j < kFingerPrintLength; j++) {
+ ASSERT_EQ(alicepay_manifest[0]->sha256_cert_fingerprints[i][j],
+ 2 * i * kFingerPrintLength + j);
+ }
+ }
+}
+}
+} // payments

Powered by Google App Engine
This is Rietveld 408576698