| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/sha2.h" | 6 #include "base/sha2.h" |
| 7 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 7 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
| 8 #include "googleurl/src/gurl.h" | 8 #include "googleurl/src/gurl.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // Tests that we generate the required host/path combinations for testing | 30 // Tests that we generate the required host/path combinations for testing |
| 31 // according to the Safe Browsing spec. | 31 // according to the Safe Browsing spec. |
| 32 // See section 6.2 in | 32 // See section 6.2 in |
| 33 // http://code.google.com/p/google-safe-browsing/wiki/Protocolv2Spec. | 33 // http://code.google.com/p/google-safe-browsing/wiki/Protocolv2Spec. |
| 34 TEST(SafeBrowsingUtilTest, UrlParsing) { | 34 TEST(SafeBrowsingUtilTest, UrlParsing) { |
| 35 std::vector<std::string> hosts, paths; | 35 std::vector<std::string> hosts, paths; |
| 36 | 36 |
| 37 GURL url("http://a.b.c/1/2.html?param=1"); | 37 GURL url("http://a.b.c/1/2.html?param=1"); |
| 38 safe_browsing_util::GenerateHostsToCheck(url, &hosts); | 38 safe_browsing_util::GenerateHostsToCheck(url, &hosts); |
| 39 safe_browsing_util::GeneratePathsToCheck(url, &paths); | 39 safe_browsing_util::GeneratePathsToCheck(url, &paths); |
| 40 EXPECT_EQ(hosts.size(), 2); | 40 EXPECT_EQ(hosts.size(), static_cast<size_t>(2)); |
| 41 EXPECT_EQ(paths.size(), 4); | 41 EXPECT_EQ(paths.size(), static_cast<size_t>(4)); |
| 42 EXPECT_EQ(hosts[0], "b.c"); | 42 EXPECT_EQ(hosts[0], "b.c"); |
| 43 EXPECT_EQ(hosts[1], "a.b.c"); | 43 EXPECT_EQ(hosts[1], "a.b.c"); |
| 44 | 44 |
| 45 EXPECT_TRUE(VectorContains(paths, "/1/2.html?param=1")); | 45 EXPECT_TRUE(VectorContains(paths, "/1/2.html?param=1")); |
| 46 EXPECT_TRUE(VectorContains(paths, "/1/2.html")); | 46 EXPECT_TRUE(VectorContains(paths, "/1/2.html")); |
| 47 EXPECT_TRUE(VectorContains(paths, "/1/")); | 47 EXPECT_TRUE(VectorContains(paths, "/1/")); |
| 48 EXPECT_TRUE(VectorContains(paths, "/")); | 48 EXPECT_TRUE(VectorContains(paths, "/")); |
| 49 | 49 |
| 50 url = GURL("http://a.b.c.d.e.f.g/1.html"); | 50 url = GURL("http://a.b.c.d.e.f.g/1.html"); |
| 51 safe_browsing_util::GenerateHostsToCheck(url, &hosts); | 51 safe_browsing_util::GenerateHostsToCheck(url, &hosts); |
| 52 safe_browsing_util::GeneratePathsToCheck(url, &paths); | 52 safe_browsing_util::GeneratePathsToCheck(url, &paths); |
| 53 EXPECT_EQ(hosts.size(), 5); | 53 EXPECT_EQ(hosts.size(), static_cast<size_t>(5)); |
| 54 EXPECT_EQ(paths.size(), 2); | 54 EXPECT_EQ(paths.size(), static_cast<size_t>(2)); |
| 55 EXPECT_EQ(hosts[0], "f.g"); | 55 EXPECT_EQ(hosts[0], "f.g"); |
| 56 EXPECT_EQ(hosts[1], "e.f.g"); | 56 EXPECT_EQ(hosts[1], "e.f.g"); |
| 57 EXPECT_EQ(hosts[2], "d.e.f.g"); | 57 EXPECT_EQ(hosts[2], "d.e.f.g"); |
| 58 EXPECT_EQ(hosts[3], "c.d.e.f.g"); | 58 EXPECT_EQ(hosts[3], "c.d.e.f.g"); |
| 59 EXPECT_EQ(hosts[4], "a.b.c.d.e.f.g"); | 59 EXPECT_EQ(hosts[4], "a.b.c.d.e.f.g"); |
| 60 EXPECT_TRUE(VectorContains(paths, "/1.html")); | 60 EXPECT_TRUE(VectorContains(paths, "/1.html")); |
| 61 EXPECT_TRUE(VectorContains(paths, "/")); | 61 EXPECT_TRUE(VectorContains(paths, "/")); |
| 62 | 62 |
| 63 url = GURL("http://a.b/saw-cgi/eBayISAPI.dll/"); | 63 url = GURL("http://a.b/saw-cgi/eBayISAPI.dll/"); |
| 64 safe_browsing_util::GeneratePathsToCheck(url, &paths); | 64 safe_browsing_util::GeneratePathsToCheck(url, &paths); |
| 65 EXPECT_EQ(paths.size(), 3); | 65 EXPECT_EQ(paths.size(), static_cast<size_t>(3)); |
| 66 EXPECT_TRUE(VectorContains(paths, "/saw-cgi/eBayISAPI.dll/")); | 66 EXPECT_TRUE(VectorContains(paths, "/saw-cgi/eBayISAPI.dll/")); |
| 67 EXPECT_TRUE(VectorContains(paths, "/saw-cgi/")); | 67 EXPECT_TRUE(VectorContains(paths, "/saw-cgi/")); |
| 68 EXPECT_TRUE(VectorContains(paths, "/")); | 68 EXPECT_TRUE(VectorContains(paths, "/")); |
| 69 } | 69 } |
| 70 | 70 |
| 71 | 71 |
| 72 TEST(SafeBrowsingUtilTest, FullHashCompare) { | 72 TEST(SafeBrowsingUtilTest, FullHashCompare) { |
| 73 GURL url("http://www.evil.com/phish.html"); | 73 GURL url("http://www.evil.com/phish.html"); |
| 74 SBFullHashResult full_hash; | 74 SBFullHashResult full_hash; |
| 75 base::SHA256HashString(url.host() + url.path(), | 75 base::SHA256HashString(url.host() + url.path(), |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 // Now add the prefix. | 286 // Now add the prefix. |
| 287 entry = SBEntry::Create(SBEntry::ADD_PREFIX, 1); | 287 entry = SBEntry::Create(SBEntry::ADD_PREFIX, 1); |
| 288 entry->SetPrefixAt(0, 0x01000000); | 288 entry->SetPrefixAt(0, 0x01000000); |
| 289 entry->set_list_id(1); | 289 entry->set_list_id(1); |
| 290 entry->set_chunk_id(1); | 290 entry->set_chunk_id(1); |
| 291 info.AddPrefixes(entry); | 291 info.AddPrefixes(entry); |
| 292 entry->Destroy(); | 292 entry->Destroy(); |
| 293 | 293 |
| 294 EXPECT_FALSE(info.Contains(full_hashes, &list_id, &prefix_hits)); | 294 EXPECT_FALSE(info.Contains(full_hashes, &list_id, &prefix_hits)); |
| 295 } | 295 } |
| OLD | NEW |