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

Unified Diff: components/payments/android/web_app_manifest_section_table_unittest.cc

Issue 2801513002: [Payments] Add web app manifest section table in SQLite web database (Closed)
Patch Set: address sql 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/android/web_app_manifest_section_table_unittest.cc
diff --git a/components/payments/android/web_app_manifest_section_table_unittest.cc b/components/payments/android/web_app_manifest_section_table_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5a0d045c12e50280185e25a103270e78ef2fa13c
--- /dev/null
+++ b/components/payments/android/web_app_manifest_section_table_unittest.cc
@@ -0,0 +1,148 @@
+// 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/android/web_app_manifest_section_table.h"
+
+#include "base/files/scoped_temp_dir.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace payments {
+namespace {
+
+// Note that the fingerprint is calculated with SHA-256, so the length is 32.
+const std::vector<uint8_t> kFingerprintOne = {
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
+ 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
+ 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20};
+const std::vector<uint8_t> kFingerprintTwo = {
+ 0x20, 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, 0x17, 0x16,
+ 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b,
+ 0x0a, 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01};
+
+class WebAppManifestSectionTableTest : public testing::Test {
+ public:
+ WebAppManifestSectionTableTest() {}
+ ~WebAppManifestSectionTableTest() override {}
+
+ protected:
+ void SetUp() override {
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ file_ = temp_dir_.GetPath().AppendASCII("TestWebDatabase");
+
+ table_.reset(new WebAppManifestSectionTable);
+ 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<WebAppManifestSectionTable> table_;
+ std::unique_ptr<WebDatabase> db_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(WebAppManifestSectionTableTest);
+};
+
+TEST_F(WebAppManifestSectionTableTest, GetNonExistManifest) {
+ WebAppManifestSectionTable* web_app_manifest_section_table =
+ WebAppManifestSectionTable::FromWebDatabase(db_.get());
+ mojom::WebAppManifestSectionPtr retrieved_manifest =
+ web_app_manifest_section_table->GetWebAppManifest("https://bobpay.com");
+ ASSERT_TRUE(retrieved_manifest.get() == nullptr);
+}
+
+TEST_F(WebAppManifestSectionTableTest, AddAndGetManifest) {
+ // create a bobpay web app manifest.
+ mojom::WebAppManifestSectionPtr manifest =
+ mojom::WebAppManifestSection::New();
+ manifest->id = "com.bobpay";
+ manifest->min_version = static_cast<int64_t>(1);
+ manifest->fingerprints.push_back(kFingerprintOne);
+ manifest->fingerprints.push_back(kFingerprintTwo);
+
+ // Adds the manifest to the table.
+ WebAppManifestSectionTable* web_app_manifest_section_table =
+ WebAppManifestSectionTable::FromWebDatabase(db_.get());
+ ASSERT_TRUE(
+ web_app_manifest_section_table->AddWebAppManifest(manifest.get()));
+
+ // Gets and verifys the manifest.
+ mojom::WebAppManifestSectionPtr retrieved_manifest = std::move(
+ web_app_manifest_section_table->GetWebAppManifest("com.bobpay"));
+ ASSERT_EQ(retrieved_manifest->id, "com.bobpay");
+ ASSERT_EQ(retrieved_manifest->min_version, 1);
+ ASSERT_EQ(retrieved_manifest->fingerprints.size(), 2U);
+
+ // Verify the two fingerprints.
+ ASSERT_EQ(retrieved_manifest->fingerprints[0].size(), kFingerprintOne.size());
+ for (size_t i = 0; i < kFingerprintOne.size(); i++) {
+ ASSERT_EQ(retrieved_manifest->fingerprints[0][i], kFingerprintOne[i]);
+ }
+ ASSERT_EQ(retrieved_manifest->fingerprints[1].size(), kFingerprintTwo.size());
+ for (size_t i = 0; i < kFingerprintTwo.size(); i++) {
+ ASSERT_EQ(retrieved_manifest->fingerprints[1][i], kFingerprintTwo[i]);
+ }
+}
+
+TEST_F(WebAppManifestSectionTableTest, AddAndGetMultipleManifests) {
+ WebAppManifestSectionTable* web_app_manifest_section_table =
+ WebAppManifestSectionTable::FromWebDatabase(db_.get());
+
+ // Adds bobpay manifest to the table.
+ mojom::WebAppManifestSectionPtr manifest_1 =
+ mojom::WebAppManifestSection::New();
+ manifest_1->id = "com.bobpay";
+ manifest_1->min_version = static_cast<int64_t>(1);
+ // Adds two finger prints.
+ manifest_1->fingerprints.push_back(kFingerprintOne);
+ manifest_1->fingerprints.push_back(kFingerprintTwo);
Scott Hess - ex-Googler 2017/04/11 19:31:46 Thanks, I like this better. The one problem is th
gogerald1 2017/04/11 21:53:30 Done. Changed to generate fingerprint dynamically
+ ASSERT_TRUE(
+ web_app_manifest_section_table->AddWebAppManifest(manifest_1.get()));
+
+ // Adds alicepay manifest to the table.
+ mojom::WebAppManifestSectionPtr manifest_2 =
+ mojom::WebAppManifestSection::New();
+ manifest_2->id = "com.alicepay";
+ manifest_2->min_version = static_cast<int64_t>(2);
+ // Adds two finger prints.
+ manifest_2->fingerprints.push_back(kFingerprintTwo);
+ manifest_2->fingerprints.push_back(kFingerprintOne);
+ ASSERT_TRUE(
+ web_app_manifest_section_table->AddWebAppManifest(manifest_2.get()));
+
+ // Verifys bobpay manifest.
+ mojom::WebAppManifestSectionPtr bobpay_manifest = std::move(
+ web_app_manifest_section_table->GetWebAppManifest("com.bobpay"));
+ ASSERT_EQ(bobpay_manifest->id, "com.bobpay");
+ ASSERT_EQ(bobpay_manifest->min_version, 1);
+ ASSERT_EQ(bobpay_manifest->fingerprints.size(), 2U);
+ ASSERT_EQ(bobpay_manifest->fingerprints[0].size(), kFingerprintOne.size());
+ for (size_t i = 0; i < kFingerprintOne.size(); i++) {
+ ASSERT_EQ(bobpay_manifest->fingerprints[0][i], kFingerprintOne[i]);
+ }
Scott Hess - ex-Googler 2017/04/11 19:31:46 ASSERT_TRUE(bobpay_manifest->fingerprints[0] == kF
gogerald1 2017/04/11 21:53:30 Done.
+ ASSERT_EQ(bobpay_manifest->fingerprints[1].size(), kFingerprintTwo.size());
+ for (size_t i = 0; i < kFingerprintTwo.size(); i++) {
+ ASSERT_EQ(bobpay_manifest->fingerprints[1][i], kFingerprintTwo[i]);
+ }
+
+ // Verifys alicepay manifest.
+ mojom::WebAppManifestSectionPtr alicepay_manifest = std::move(
+ web_app_manifest_section_table->GetWebAppManifest("com.alicepay"));
+ ASSERT_EQ(alicepay_manifest->id, "com.alicepay");
+ ASSERT_EQ(alicepay_manifest->min_version, 2);
+ ASSERT_EQ(alicepay_manifest->fingerprints.size(), 2U);
+ ASSERT_EQ(alicepay_manifest->fingerprints[0].size(), kFingerprintTwo.size());
+ for (size_t i = 0; i < kFingerprintTwo.size(); i++) {
+ ASSERT_EQ(alicepay_manifest->fingerprints[0][i], kFingerprintTwo[i]);
+ }
+ ASSERT_EQ(alicepay_manifest->fingerprints[1].size(), kFingerprintOne.size());
+ for (size_t i = 0; i < kFingerprintOne.size(); i++) {
+ ASSERT_EQ(alicepay_manifest->fingerprints[1][i], kFingerprintOne[i]);
+ }
+}
+}
+} // payments

Powered by Google App Engine
This is Rietveld 408576698