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

Side by Side 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: simplify 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 unified diff | Download patch
OLDNEW
(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 class WebAppManifestSectionTableTest : public testing::Test {
14 public:
15 WebAppManifestSectionTableTest() {}
16 ~WebAppManifestSectionTableTest() override {}
17
18 protected:
19 void SetUp() override {
20 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
21 file_ = temp_dir_.GetPath().AppendASCII("TestWebDatabase");
22
23 table_.reset(new WebAppManifestSectionTable);
24 db_.reset(new WebDatabase);
25 db_->AddTable(table_.get());
26 ASSERT_EQ(sql::INIT_OK, db_->Init(file_));
27 }
28
29 void TearDown() override {}
30
31 std::unique_ptr<std::vector<uint8_t>> GenerateFingerprint(uint8_t seed) {
Scott Hess - ex-Googler 2017/04/11 23:37:10 plain std::vector<> should work fine for this. No
gogerald1 2017/04/12 13:55:17 Done.
32 auto fingerprint = base::MakeUnique<std::vector<uint8_t>>();
33 // Note that the fingerprint is calculated with SHA-256, so the length is
34 // 32.
35 for (size_t i = 0; i < 32U; i++) {
36 fingerprint->push_back((seed + i) % 256U);
37 }
38 return fingerprint;
39 }
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 std::unique_ptr<std::vector<uint8_t>> fingerprint_one =
60 std::move(GenerateFingerprint(1));
Scott Hess - ex-Googler 2017/04/11 23:37:10 Then these can just be std::vector<>, too. I thin
gogerald1 2017/04/12 13:55:18 Done.
61 std::unique_ptr<std::vector<uint8_t>> fingerprint_two =
62 std::move(GenerateFingerprint(32));
63
64 // create a bobpay web app manifest.
65 mojom::WebAppManifestSectionPtr manifest =
66 mojom::WebAppManifestSection::New();
67 manifest->id = "com.bobpay";
68 manifest->min_version = static_cast<int64_t>(1);
69 manifest->fingerprints.push_back(*fingerprint_one);
70 manifest->fingerprints.push_back(*fingerprint_two);
71
72 // Adds the manifest to the table.
73 WebAppManifestSectionTable* web_app_manifest_section_table =
74 WebAppManifestSectionTable::FromWebDatabase(db_.get());
75 ASSERT_TRUE(
76 web_app_manifest_section_table->AddWebAppManifest(manifest.get()));
77
78 // Gets and verifys the manifest.
79 mojom::WebAppManifestSectionPtr retrieved_manifest = std::move(
80 web_app_manifest_section_table->GetWebAppManifest("com.bobpay"));
81 ASSERT_EQ(retrieved_manifest->id, "com.bobpay");
82 ASSERT_EQ(retrieved_manifest->min_version, 1);
83 ASSERT_EQ(retrieved_manifest->fingerprints.size(), 2U);
84
85 // Verify the two fingerprints.
86 ASSERT_TRUE(retrieved_manifest->fingerprints[0] == *fingerprint_one);
87 ASSERT_TRUE(retrieved_manifest->fingerprints[1] == *fingerprint_two);
88 }
89
90 TEST_F(WebAppManifestSectionTableTest, AddAndGetMultipleManifests) {
91 std::unique_ptr<std::vector<uint8_t>> fingerprint_one =
92 std::move(GenerateFingerprint(1));
93 std::unique_ptr<std::vector<uint8_t>> fingerprint_two =
94 std::move(GenerateFingerprint(32));
95 std::unique_ptr<std::vector<uint8_t>> fingerprint_three =
96 std::move(GenerateFingerprint(2));
97 std::unique_ptr<std::vector<uint8_t>> fingerprint_four =
98 std::move(GenerateFingerprint(30));
99
100 WebAppManifestSectionTable* web_app_manifest_section_table =
101 WebAppManifestSectionTable::FromWebDatabase(db_.get());
102
103 // Adds bobpay manifest to the table.
104 mojom::WebAppManifestSectionPtr manifest_1 =
105 mojom::WebAppManifestSection::New();
106 manifest_1->id = "com.bobpay";
107 manifest_1->min_version = static_cast<int64_t>(1);
108 // Adds two finger prints.
109 manifest_1->fingerprints.push_back(*fingerprint_one);
110 manifest_1->fingerprints.push_back(*fingerprint_two);
111 ASSERT_TRUE(
112 web_app_manifest_section_table->AddWebAppManifest(manifest_1.get()));
113
114 // Adds alicepay manifest to the table.
115 mojom::WebAppManifestSectionPtr manifest_2 =
116 mojom::WebAppManifestSection::New();
117 manifest_2->id = "com.alicepay";
118 manifest_2->min_version = static_cast<int64_t>(2);
119 // Adds two finger prints.
120 manifest_2->fingerprints.push_back(*fingerprint_three);
121 manifest_2->fingerprints.push_back(*fingerprint_four);
122 ASSERT_TRUE(
123 web_app_manifest_section_table->AddWebAppManifest(manifest_2.get()));
124
125 // Verifys bobpay manifest.
126 mojom::WebAppManifestSectionPtr bobpay_manifest = std::move(
127 web_app_manifest_section_table->GetWebAppManifest("com.bobpay"));
128 ASSERT_EQ(bobpay_manifest->id, "com.bobpay");
129 ASSERT_EQ(bobpay_manifest->min_version, 1);
130 ASSERT_EQ(bobpay_manifest->fingerprints.size(), 2U);
131 ASSERT_TRUE(bobpay_manifest->fingerprints[0] == *fingerprint_one);
132 ASSERT_TRUE(bobpay_manifest->fingerprints[1] == *fingerprint_two);
133
134 // Verifys alicepay manifest.
135 mojom::WebAppManifestSectionPtr alicepay_manifest = std::move(
136 web_app_manifest_section_table->GetWebAppManifest("com.alicepay"));
137 ASSERT_EQ(alicepay_manifest->id, "com.alicepay");
138 ASSERT_EQ(alicepay_manifest->min_version, 2);
139 ASSERT_EQ(alicepay_manifest->fingerprints.size(), 2U);
140 ASSERT_TRUE(alicepay_manifest->fingerprints[0] == *fingerprint_three);
141 ASSERT_TRUE(alicepay_manifest->fingerprints[1] == *fingerprint_four);
142 }
143 }
144 } // payments
OLDNEW
« no previous file with comments | « components/payments/android/web_app_manifest_section_table.cc ('k') | components/webdata_services/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698