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

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: rebase and rename for the new manifest format 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..32c189e36ea79c0c373fa84aa4d4ce280e5b316f
--- /dev/null
+++ b/components/payments/android/web_app_manifest_section_table_unittest.cc
@@ -0,0 +1,152 @@
+// 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 {
+
+const size_t kFingerPrintLength = 32;
+
+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_;
Scott Hess - ex-Googler 2017/04/11 17:24:06 Put this above |table_|, since |table_| might refe
gogerald1 2017/04/11 19:01:04 we first create |table_| and then add it to |db_|,
Scott Hess - ex-Googler 2017/04/11 19:31:45 The bit I'm worried about is that table_.db_ maint
gogerald1 2017/04/11 21:53:30 Acknowledged. should be fine here since db_->Init(
+
+ 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);
Scott Hess - ex-Googler 2017/04/11 17:24:06 I think 1l or 1L will also be the right 1. Though
gogerald1 2017/04/11 19:01:04 Use "int64_t" would be more specific and understan
Scott Hess - ex-Googler 2017/04/11 19:31:45 How would it be so? Is it important to know in th
gogerald1 2017/04/11 21:53:30 The reason I was thinking is that: manifest->min_v
+ // Adds two finger prints.
+ for (size_t i = 0; i < 2U; i++) {
+ std::vector<uint8_t> fingerprint;
+ for (size_t j = 0; j < kFingerPrintLength; j++) {
+ fingerprint.push_back(i * kFingerPrintLength + j);
+ }
+ manifest->fingerprints.push_back(fingerprint);
+ }
Scott Hess - ex-Googler 2017/04/11 17:24:06 I see what you're doing, here, but it might also b
gogerald1 2017/04/11 19:01:04 Done.
+
+ // 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 =
+ 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 finger prints.
+ for (size_t i = 0; i < 2U; i++) {
+ ASSERT_EQ(retrieved_manifest->fingerprints[i].size(), kFingerPrintLength);
+ for (size_t j = 0; j < kFingerPrintLength; j++) {
+ ASSERT_EQ(retrieved_manifest->fingerprints[i][j],
+ i * kFingerPrintLength + j);
+ }
+ }
+}
+
+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.
+ for (size_t i = 0; i < 2U; i++) {
+ std::vector<uint8_t> fingerprint;
+ for (size_t j = 0; j < kFingerPrintLength; j++) {
+ fingerprint.push_back(i * kFingerPrintLength + j);
+ }
+ manifest_1->fingerprints.push_back(fingerprint);
+ }
+ 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.
+ for (size_t i = 0; i < 2U; i++) {
+ std::vector<uint8_t> fingerprint;
+ for (size_t j = 0; j < kFingerPrintLength; j++) {
+ fingerprint.push_back(2 * i * kFingerPrintLength + j);
+ }
+ manifest_2->fingerprints.push_back(fingerprint);
+ }
+ ASSERT_TRUE(
+ web_app_manifest_section_table->AddWebAppManifest(manifest_2.get()));
+
+ // Verifys bobpay manifest.
+ mojom::WebAppManifestSectionPtr bobpay_manifest =
+ 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);
+ for (size_t i = 0; i < 2U; i++) {
+ ASSERT_EQ(bobpay_manifest->fingerprints[i].size(), kFingerPrintLength);
+ for (size_t j = 0; j < kFingerPrintLength; j++) {
+ ASSERT_EQ(bobpay_manifest->fingerprints[i][j],
+ i * kFingerPrintLength + j);
+ }
+ }
+
+ // Verifys alicepay manifest.
+ mojom::WebAppManifestSectionPtr alicepay_manifest =
+ 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);
+ for (size_t i = 0; i < 2U; i++) {
+ ASSERT_EQ(alicepay_manifest->fingerprints[i].size(), kFingerPrintLength);
+ for (size_t j = 0; j < kFingerPrintLength; j++) {
+ ASSERT_EQ(alicepay_manifest->fingerprints[i][j],
+ 2 * i * kFingerPrintLength + j);
+ }
+ }
+}
+}
+} // payments

Powered by Google App Engine
This is Rietveld 408576698