Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/android/web_app_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 // Note that the fingerprint is calculated with SHA-256, so the length is 32. | |
| 14 const std::vector<uint8_t> kFingerprintOne = { | |
| 15 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, | |
| 16 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, | |
| 17 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20}; | |
| 18 const std::vector<uint8_t> kFingerprintTwo = { | |
| 19 0x20, 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, 0x17, 0x16, | |
| 20 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, | |
| 21 0x0a, 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01}; | |
| 22 | |
| 23 class WebAppManifestSectionTableTest : public testing::Test { | |
| 24 public: | |
| 25 WebAppManifestSectionTableTest() {} | |
| 26 ~WebAppManifestSectionTableTest() override {} | |
| 27 | |
| 28 protected: | |
| 29 void SetUp() override { | |
| 30 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
| 31 file_ = temp_dir_.GetPath().AppendASCII("TestWebDatabase"); | |
| 32 | |
| 33 table_.reset(new WebAppManifestSectionTable); | |
| 34 db_.reset(new WebDatabase); | |
| 35 db_->AddTable(table_.get()); | |
| 36 ASSERT_EQ(sql::INIT_OK, db_->Init(file_)); | |
| 37 } | |
| 38 | |
| 39 void TearDown() override {} | |
| 40 | |
| 41 base::FilePath file_; | |
| 42 base::ScopedTempDir temp_dir_; | |
| 43 std::unique_ptr<WebAppManifestSectionTable> table_; | |
| 44 std::unique_ptr<WebDatabase> db_; | |
| 45 | |
| 46 private: | |
| 47 DISALLOW_COPY_AND_ASSIGN(WebAppManifestSectionTableTest); | |
| 48 }; | |
| 49 | |
| 50 TEST_F(WebAppManifestSectionTableTest, GetNonExistManifest) { | |
| 51 WebAppManifestSectionTable* web_app_manifest_section_table = | |
| 52 WebAppManifestSectionTable::FromWebDatabase(db_.get()); | |
| 53 mojom::WebAppManifestSectionPtr retrieved_manifest = | |
| 54 web_app_manifest_section_table->GetWebAppManifest("https://bobpay.com"); | |
| 55 ASSERT_TRUE(retrieved_manifest.get() == nullptr); | |
| 56 } | |
| 57 | |
| 58 TEST_F(WebAppManifestSectionTableTest, AddAndGetManifest) { | |
| 59 // create a bobpay web app manifest. | |
| 60 mojom::WebAppManifestSectionPtr manifest = | |
| 61 mojom::WebAppManifestSection::New(); | |
| 62 manifest->id = "com.bobpay"; | |
| 63 manifest->min_version = static_cast<int64_t>(1); | |
| 64 manifest->fingerprints.push_back(kFingerprintOne); | |
| 65 manifest->fingerprints.push_back(kFingerprintTwo); | |
| 66 | |
| 67 // Adds the manifest to the table. | |
| 68 WebAppManifestSectionTable* web_app_manifest_section_table = | |
| 69 WebAppManifestSectionTable::FromWebDatabase(db_.get()); | |
| 70 ASSERT_TRUE( | |
| 71 web_app_manifest_section_table->AddWebAppManifest(manifest.get())); | |
| 72 | |
| 73 // Gets and verifys the manifest. | |
| 74 mojom::WebAppManifestSectionPtr retrieved_manifest = std::move( | |
| 75 web_app_manifest_section_table->GetWebAppManifest("com.bobpay")); | |
| 76 ASSERT_EQ(retrieved_manifest->id, "com.bobpay"); | |
| 77 ASSERT_EQ(retrieved_manifest->min_version, 1); | |
| 78 ASSERT_EQ(retrieved_manifest->fingerprints.size(), 2U); | |
| 79 | |
| 80 // Verify the two fingerprints. | |
| 81 ASSERT_EQ(retrieved_manifest->fingerprints[0].size(), kFingerprintOne.size()); | |
| 82 for (size_t i = 0; i < kFingerprintOne.size(); i++) { | |
| 83 ASSERT_EQ(retrieved_manifest->fingerprints[0][i], kFingerprintOne[i]); | |
| 84 } | |
| 85 ASSERT_EQ(retrieved_manifest->fingerprints[1].size(), kFingerprintTwo.size()); | |
| 86 for (size_t i = 0; i < kFingerprintTwo.size(); i++) { | |
| 87 ASSERT_EQ(retrieved_manifest->fingerprints[1][i], kFingerprintTwo[i]); | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 TEST_F(WebAppManifestSectionTableTest, AddAndGetMultipleManifests) { | |
| 92 WebAppManifestSectionTable* web_app_manifest_section_table = | |
| 93 WebAppManifestSectionTable::FromWebDatabase(db_.get()); | |
| 94 | |
| 95 // Adds bobpay manifest to the table. | |
| 96 mojom::WebAppManifestSectionPtr manifest_1 = | |
| 97 mojom::WebAppManifestSection::New(); | |
| 98 manifest_1->id = "com.bobpay"; | |
| 99 manifest_1->min_version = static_cast<int64_t>(1); | |
| 100 // Adds two finger prints. | |
| 101 manifest_1->fingerprints.push_back(kFingerprintOne); | |
| 102 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
| |
| 103 ASSERT_TRUE( | |
| 104 web_app_manifest_section_table->AddWebAppManifest(manifest_1.get())); | |
| 105 | |
| 106 // Adds alicepay manifest to the table. | |
| 107 mojom::WebAppManifestSectionPtr manifest_2 = | |
| 108 mojom::WebAppManifestSection::New(); | |
| 109 manifest_2->id = "com.alicepay"; | |
| 110 manifest_2->min_version = static_cast<int64_t>(2); | |
| 111 // Adds two finger prints. | |
| 112 manifest_2->fingerprints.push_back(kFingerprintTwo); | |
| 113 manifest_2->fingerprints.push_back(kFingerprintOne); | |
| 114 ASSERT_TRUE( | |
| 115 web_app_manifest_section_table->AddWebAppManifest(manifest_2.get())); | |
| 116 | |
| 117 // Verifys bobpay manifest. | |
| 118 mojom::WebAppManifestSectionPtr bobpay_manifest = std::move( | |
| 119 web_app_manifest_section_table->GetWebAppManifest("com.bobpay")); | |
| 120 ASSERT_EQ(bobpay_manifest->id, "com.bobpay"); | |
| 121 ASSERT_EQ(bobpay_manifest->min_version, 1); | |
| 122 ASSERT_EQ(bobpay_manifest->fingerprints.size(), 2U); | |
| 123 ASSERT_EQ(bobpay_manifest->fingerprints[0].size(), kFingerprintOne.size()); | |
| 124 for (size_t i = 0; i < kFingerprintOne.size(); i++) { | |
| 125 ASSERT_EQ(bobpay_manifest->fingerprints[0][i], kFingerprintOne[i]); | |
| 126 } | |
|
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.
| |
| 127 ASSERT_EQ(bobpay_manifest->fingerprints[1].size(), kFingerprintTwo.size()); | |
| 128 for (size_t i = 0; i < kFingerprintTwo.size(); i++) { | |
| 129 ASSERT_EQ(bobpay_manifest->fingerprints[1][i], kFingerprintTwo[i]); | |
| 130 } | |
| 131 | |
| 132 // Verifys alicepay manifest. | |
| 133 mojom::WebAppManifestSectionPtr alicepay_manifest = std::move( | |
| 134 web_app_manifest_section_table->GetWebAppManifest("com.alicepay")); | |
| 135 ASSERT_EQ(alicepay_manifest->id, "com.alicepay"); | |
| 136 ASSERT_EQ(alicepay_manifest->min_version, 2); | |
| 137 ASSERT_EQ(alicepay_manifest->fingerprints.size(), 2U); | |
| 138 ASSERT_EQ(alicepay_manifest->fingerprints[0].size(), kFingerprintTwo.size()); | |
| 139 for (size_t i = 0; i < kFingerprintTwo.size(); i++) { | |
| 140 ASSERT_EQ(alicepay_manifest->fingerprints[0][i], kFingerprintTwo[i]); | |
| 141 } | |
| 142 ASSERT_EQ(alicepay_manifest->fingerprints[1].size(), kFingerprintOne.size()); | |
| 143 for (size_t i = 0; i < kFingerprintOne.size(); i++) { | |
| 144 ASSERT_EQ(alicepay_manifest->fingerprints[1][i], kFingerprintOne[i]); | |
| 145 } | |
| 146 } | |
| 147 } | |
| 148 } // payments | |
| OLD | NEW |