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

Side by Side Diff: components/payments/android/web_app_manifest_section_table_unittest.cc

Issue 2838433002: [Payments] Cache payment manifests. (Closed)
Patch Set: fix tests 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/payments/android/web_app_manifest_section_table.h" 5 #include "components/payments/android/web_app_manifest_section_table.h"
6 6
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace payments { 10 namespace payments {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 std::unique_ptr<WebAppManifestSectionTable> table_; 43 std::unique_ptr<WebAppManifestSectionTable> table_;
44 std::unique_ptr<WebDatabase> db_; 44 std::unique_ptr<WebDatabase> db_;
45 45
46 private: 46 private:
47 DISALLOW_COPY_AND_ASSIGN(WebAppManifestSectionTableTest); 47 DISALLOW_COPY_AND_ASSIGN(WebAppManifestSectionTableTest);
48 }; 48 };
49 49
50 TEST_F(WebAppManifestSectionTableTest, GetNonExistManifest) { 50 TEST_F(WebAppManifestSectionTableTest, GetNonExistManifest) {
51 WebAppManifestSectionTable* web_app_manifest_section_table = 51 WebAppManifestSectionTable* web_app_manifest_section_table =
52 WebAppManifestSectionTable::FromWebDatabase(db_.get()); 52 WebAppManifestSectionTable::FromWebDatabase(db_.get());
53 mojom::WebAppManifestSectionPtr retrieved_manifest = 53 std::vector<mojom::WebAppManifestSectionPtr> retrieved_manifest =
54 web_app_manifest_section_table->GetWebAppManifest("https://bobpay.com"); 54 web_app_manifest_section_table->GetWebAppManifest("https://bobpay.com");
55 ASSERT_TRUE(retrieved_manifest.get() == nullptr); 55 ASSERT_TRUE(retrieved_manifest.empty());
56 } 56 }
57 57
58 TEST_F(WebAppManifestSectionTableTest, AddAndGetManifest) { 58 TEST_F(WebAppManifestSectionTableTest, AddAndGetManifest) {
59 std::vector<uint8_t> fingerprint_one = GenerateFingerprint(1); 59 std::vector<uint8_t> fingerprint_one = GenerateFingerprint(1);
60 std::vector<uint8_t> fingerprint_two = GenerateFingerprint(32); 60 std::vector<uint8_t> fingerprint_two = GenerateFingerprint(32);
61 61
62 // create a bobpay web app manifest. 62 // create a bobpay web app manifest.
63 mojom::WebAppManifestSectionPtr manifest = 63 std::vector<mojom::WebAppManifestSectionPtr> manifest;
64 mojom::WebAppManifestSection::New(); 64 mojom::WebAppManifestSectionPtr section = mojom::WebAppManifestSection::New();
65 manifest->id = "com.bobpay"; 65 section->id = "com.bobpay";
66 manifest->min_version = static_cast<int64_t>(1); 66 section->min_version = static_cast<int64_t>(1);
67 manifest->fingerprints.push_back(fingerprint_one); 67 section->fingerprints.push_back(fingerprint_one);
68 manifest->fingerprints.push_back(fingerprint_two); 68 section->fingerprints.push_back(fingerprint_two);
69 manifest.emplace_back(std::move(section));
69 70
70 // Adds the manifest to the table. 71 // Adds the manifest to the table.
71 WebAppManifestSectionTable* web_app_manifest_section_table = 72 WebAppManifestSectionTable* web_app_manifest_section_table =
72 WebAppManifestSectionTable::FromWebDatabase(db_.get()); 73 WebAppManifestSectionTable::FromWebDatabase(db_.get());
73 ASSERT_TRUE( 74 ASSERT_TRUE(web_app_manifest_section_table->AddWebAppManifest(manifest));
74 web_app_manifest_section_table->AddWebAppManifest(manifest.get()));
75 75
76 // Gets and verifys the manifest. 76 // Gets and verifys the manifest.
77 mojom::WebAppManifestSectionPtr retrieved_manifest = 77 std::vector<mojom::WebAppManifestSectionPtr> retrieved_manifest =
78 web_app_manifest_section_table->GetWebAppManifest("com.bobpay"); 78 web_app_manifest_section_table->GetWebAppManifest("com.bobpay");
79 ASSERT_EQ(retrieved_manifest->id, "com.bobpay"); 79 ASSERT_EQ(retrieved_manifest.size(), 1U);
80 ASSERT_EQ(retrieved_manifest->min_version, 1); 80 ASSERT_EQ(retrieved_manifest[0]->id, "com.bobpay");
81 ASSERT_EQ(retrieved_manifest->fingerprints.size(), 2U); 81 ASSERT_EQ(retrieved_manifest[0]->min_version, 1);
82 ASSERT_EQ(retrieved_manifest[0]->fingerprints.size(), 2U);
82 83
83 // Verify the two fingerprints. 84 // Verify the two fingerprints.
84 ASSERT_TRUE(retrieved_manifest->fingerprints[0] == fingerprint_one); 85 ASSERT_TRUE(retrieved_manifest[0]->fingerprints[0] == fingerprint_one);
85 ASSERT_TRUE(retrieved_manifest->fingerprints[1] == fingerprint_two); 86 ASSERT_TRUE(retrieved_manifest[0]->fingerprints[1] == fingerprint_two);
86 } 87 }
87 88
88 TEST_F(WebAppManifestSectionTableTest, AddAndGetMultipleManifests) { 89 TEST_F(WebAppManifestSectionTableTest, AddAndGetMultipleManifests) {
89 std::vector<uint8_t> fingerprint_one = GenerateFingerprint(1); 90 std::vector<uint8_t> fingerprint_one = GenerateFingerprint(1);
90 std::vector<uint8_t> fingerprint_two = GenerateFingerprint(32); 91 std::vector<uint8_t> fingerprint_two = GenerateFingerprint(32);
91 std::vector<uint8_t> fingerprint_three = GenerateFingerprint(2); 92 std::vector<uint8_t> fingerprint_three = GenerateFingerprint(2);
92 std::vector<uint8_t> fingerprint_four = GenerateFingerprint(30); 93 std::vector<uint8_t> fingerprint_four = GenerateFingerprint(30);
93 94
94 WebAppManifestSectionTable* web_app_manifest_section_table = 95 WebAppManifestSectionTable* web_app_manifest_section_table =
95 WebAppManifestSectionTable::FromWebDatabase(db_.get()); 96 WebAppManifestSectionTable::FromWebDatabase(db_.get());
96 97
97 // Adds bobpay manifest to the table. 98 // Adds bobpay manifest to the table.
98 mojom::WebAppManifestSectionPtr manifest_1 = 99 std::vector<mojom::WebAppManifestSectionPtr> manifest_1;
100 mojom::WebAppManifestSectionPtr manifest_1_section =
99 mojom::WebAppManifestSection::New(); 101 mojom::WebAppManifestSection::New();
100 manifest_1->id = "com.bobpay"; 102 manifest_1_section->id = "com.bobpay";
101 manifest_1->min_version = static_cast<int64_t>(1); 103 manifest_1_section->min_version = static_cast<int64_t>(1);
102 // Adds two finger prints. 104 // Adds two finger prints.
103 manifest_1->fingerprints.push_back(fingerprint_one); 105 manifest_1_section->fingerprints.push_back(fingerprint_one);
104 manifest_1->fingerprints.push_back(fingerprint_two); 106 manifest_1_section->fingerprints.push_back(fingerprint_two);
105 ASSERT_TRUE( 107 manifest_1.emplace_back(std::move(manifest_1_section));
106 web_app_manifest_section_table->AddWebAppManifest(manifest_1.get())); 108 ASSERT_TRUE(web_app_manifest_section_table->AddWebAppManifest(manifest_1));
107 109
108 // Adds alicepay manifest to the table. 110 // Adds alicepay manifest to the table.
109 mojom::WebAppManifestSectionPtr manifest_2 = 111 std::vector<mojom::WebAppManifestSectionPtr> manifest_2;
112 mojom::WebAppManifestSectionPtr manifest_2_section =
110 mojom::WebAppManifestSection::New(); 113 mojom::WebAppManifestSection::New();
111 manifest_2->id = "com.alicepay"; 114 manifest_2_section->id = "com.alicepay";
112 manifest_2->min_version = static_cast<int64_t>(2); 115 manifest_2_section->min_version = static_cast<int64_t>(2);
113 // Adds two finger prints. 116 // Adds two finger prints.
114 manifest_2->fingerprints.push_back(fingerprint_three); 117 manifest_2_section->fingerprints.push_back(fingerprint_three);
115 manifest_2->fingerprints.push_back(fingerprint_four); 118 manifest_2_section->fingerprints.push_back(fingerprint_four);
116 ASSERT_TRUE( 119 manifest_2.emplace_back(std::move(manifest_2_section));
117 web_app_manifest_section_table->AddWebAppManifest(manifest_2.get())); 120 ASSERT_TRUE(web_app_manifest_section_table->AddWebAppManifest(manifest_2));
118 121
119 // Verifys bobpay manifest. 122 // Verifys bobpay manifest.
120 mojom::WebAppManifestSectionPtr bobpay_manifest = 123 std::vector<mojom::WebAppManifestSectionPtr> bobpay_manifest =
121 web_app_manifest_section_table->GetWebAppManifest("com.bobpay"); 124 web_app_manifest_section_table->GetWebAppManifest("com.bobpay");
122 ASSERT_EQ(bobpay_manifest->id, "com.bobpay"); 125 ASSERT_EQ(bobpay_manifest.size(), 1U);
123 ASSERT_EQ(bobpay_manifest->min_version, 1); 126 ASSERT_EQ(bobpay_manifest[0]->id, "com.bobpay");
124 ASSERT_EQ(bobpay_manifest->fingerprints.size(), 2U); 127 ASSERT_EQ(bobpay_manifest[0]->min_version, 1);
125 ASSERT_TRUE(bobpay_manifest->fingerprints[0] == fingerprint_one); 128 ASSERT_EQ(bobpay_manifest[0]->fingerprints.size(), 2U);
126 ASSERT_TRUE(bobpay_manifest->fingerprints[1] == fingerprint_two); 129 ASSERT_TRUE(bobpay_manifest[0]->fingerprints[0] == fingerprint_one);
130 ASSERT_TRUE(bobpay_manifest[0]->fingerprints[1] == fingerprint_two);
127 131
128 // Verifys alicepay manifest. 132 // Verifys alicepay manifest.
129 mojom::WebAppManifestSectionPtr alicepay_manifest = 133 std::vector<mojom::WebAppManifestSectionPtr> alicepay_manifest =
130 web_app_manifest_section_table->GetWebAppManifest("com.alicepay"); 134 web_app_manifest_section_table->GetWebAppManifest("com.alicepay");
131 ASSERT_EQ(alicepay_manifest->id, "com.alicepay"); 135 ASSERT_EQ(alicepay_manifest.size(), 1U);
132 ASSERT_EQ(alicepay_manifest->min_version, 2); 136 ASSERT_EQ(alicepay_manifest[0]->id, "com.alicepay");
133 ASSERT_EQ(alicepay_manifest->fingerprints.size(), 2U); 137 ASSERT_EQ(alicepay_manifest[0]->min_version, 2);
134 ASSERT_TRUE(alicepay_manifest->fingerprints[0] == fingerprint_three); 138 ASSERT_EQ(alicepay_manifest[0]->fingerprints.size(), 2U);
135 ASSERT_TRUE(alicepay_manifest->fingerprints[1] == fingerprint_four); 139 ASSERT_TRUE(alicepay_manifest[0]->fingerprints[0] == fingerprint_three);
140 ASSERT_TRUE(alicepay_manifest[0]->fingerprints[1] == fingerprint_four);
136 } 141 }
137 142
138 } // namespace 143 } // namespace
139 144
140 } // namespace payments 145 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698