OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/password_manager/core/browser/affiliation_database.h" | 5 #include "components/password_manager/core/browser/affiliation_database.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "sql/test/scoped_error_ignorer.h" | 12 #include "sql/test/scoped_error_expecter.h" |
13 #include "sql/test/test_helpers.h" | 13 #include "sql/test/test_helpers.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "third_party/sqlite/sqlite3.h" | 16 #include "third_party/sqlite/sqlite3.h" |
17 | 17 |
18 namespace password_manager { | 18 namespace password_manager { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 const char kTestFacetURI1[] = "https://alpha.example.com"; | 22 const char kTestFacetURI1[] = "https://alpha.example.com"; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 }; | 105 }; |
106 | 106 |
107 TEST_F(AffiliationDatabaseTest, Store) { | 107 TEST_F(AffiliationDatabaseTest, Store) { |
108 LOG(ERROR) << "During this test, SQL errors (number 19) will be logged to " | 108 LOG(ERROR) << "During this test, SQL errors (number 19) will be logged to " |
109 "the console. This is expected."; | 109 "the console. This is expected."; |
110 | 110 |
111 ASSERT_NO_FATAL_FAILURE(StoreInitialTestData()); | 111 ASSERT_NO_FATAL_FAILURE(StoreInitialTestData()); |
112 | 112 |
113 // Verify that duplicate equivalence classes are not allowed to be stored. | 113 // Verify that duplicate equivalence classes are not allowed to be stored. |
114 { | 114 { |
115 sql::ScopedErrorIgnorer error_ignorer; | 115 sql::test::ScopedErrorExpecter expecter; |
116 error_ignorer.IgnoreError(SQLITE_CONSTRAINT); | 116 expecter.ExpectError(SQLITE_CONSTRAINT); |
117 AffiliatedFacetsWithUpdateTime duplicate = TestEquivalenceClass1(); | 117 AffiliatedFacetsWithUpdateTime duplicate = TestEquivalenceClass1(); |
118 EXPECT_FALSE(db().Store(duplicate)); | 118 EXPECT_FALSE(db().Store(duplicate)); |
119 EXPECT_TRUE(error_ignorer.CheckIgnoredErrors()); | 119 EXPECT_TRUE(expecter.SawExpectedErrors()); |
120 } | 120 } |
121 | 121 |
122 // Verify that intersecting equivalence classes are not allowed to be stored. | 122 // Verify that intersecting equivalence classes are not allowed to be stored. |
123 { | 123 { |
124 sql::ScopedErrorIgnorer error_ignorer; | 124 sql::test::ScopedErrorExpecter expecter; |
125 error_ignorer.IgnoreError(SQLITE_CONSTRAINT); | 125 expecter.ExpectError(SQLITE_CONSTRAINT); |
126 AffiliatedFacetsWithUpdateTime intersecting; | 126 AffiliatedFacetsWithUpdateTime intersecting; |
127 intersecting.facets.push_back(FacetURI::FromCanonicalSpec(kTestFacetURI3)); | 127 intersecting.facets.push_back(FacetURI::FromCanonicalSpec(kTestFacetURI3)); |
128 intersecting.facets.push_back(FacetURI::FromCanonicalSpec(kTestFacetURI4)); | 128 intersecting.facets.push_back(FacetURI::FromCanonicalSpec(kTestFacetURI4)); |
129 EXPECT_FALSE(db().Store(intersecting)); | 129 EXPECT_FALSE(db().Store(intersecting)); |
130 EXPECT_TRUE(error_ignorer.CheckIgnoredErrors()); | 130 EXPECT_TRUE(expecter.SawExpectedErrors()); |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 TEST_F(AffiliationDatabaseTest, GetAllAffiliations) { | 134 TEST_F(AffiliationDatabaseTest, GetAllAffiliations) { |
135 std::vector<AffiliatedFacetsWithUpdateTime> affiliations; | 135 std::vector<AffiliatedFacetsWithUpdateTime> affiliations; |
136 | 136 |
137 // Empty database should not return any equivalence classes. | 137 // Empty database should not return any equivalence classes. |
138 db().GetAllAffiliations(&affiliations); | 138 db().GetAllAffiliations(&affiliations); |
139 EXPECT_EQ(0u, affiliations.size()); | 139 EXPECT_EQ(0u, affiliations.size()); |
140 | 140 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 // Verify that all files get deleted. | 300 // Verify that all files get deleted. |
301 TEST_F(AffiliationDatabaseTest, Delete) { | 301 TEST_F(AffiliationDatabaseTest, Delete) { |
302 ASSERT_NO_FATAL_FAILURE(StoreInitialTestData()); | 302 ASSERT_NO_FATAL_FAILURE(StoreInitialTestData()); |
303 CloseDatabase(); | 303 CloseDatabase(); |
304 | 304 |
305 AffiliationDatabase::Delete(db_path()); | 305 AffiliationDatabase::Delete(db_path()); |
306 EXPECT_TRUE(base::IsDirectoryEmpty(db_path().DirName())); | 306 EXPECT_TRUE(base::IsDirectoryEmpty(db_path().DirName())); |
307 } | 307 } |
308 | 308 |
309 } // namespace password_manager | 309 } // namespace password_manager |
OLD | NEW |