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