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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_database_unittest.cc

Issue 105293002: Move more file_util functions to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Unit tests for the SafeBrowsing storage system. 5 // Unit tests for the SafeBrowsing storage system.
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 1618 matching lines...) Expand 10 before | Expand all | Expand 10 after
1629 InsertAddChunkHostPrefixUrl(&chunk, 1, "www.evil.com/", 1629 InsertAddChunkHostPrefixUrl(&chunk, 1, "www.evil.com/",
1630 "www.evil.com/malware.html"); 1630 "www.evil.com/malware.html");
1631 chunks.clear(); 1631 chunks.clear();
1632 chunks.push_back(chunk); 1632 chunks.push_back(chunk);
1633 database_->InsertChunks(safe_browsing_util::kMalwareList, chunks); 1633 database_->InsertChunks(safe_browsing_util::kMalwareList, chunks);
1634 database_->UpdateFinished(true); 1634 database_->UpdateFinished(true);
1635 1635
1636 // Get an older time to reset the lastmod time for detecting whether 1636 // Get an older time to reset the lastmod time for detecting whether
1637 // the file has been updated. 1637 // the file has been updated.
1638 base::PlatformFileInfo before_info, after_info; 1638 base::PlatformFileInfo before_info, after_info;
1639 ASSERT_TRUE(file_util::GetFileInfo(filename, &before_info)); 1639 ASSERT_TRUE(base::GetFileInfo(filename, &before_info));
1640 const base::Time old_last_modified = 1640 const base::Time old_last_modified =
1641 before_info.last_modified - base::TimeDelta::FromSeconds(10); 1641 before_info.last_modified - base::TimeDelta::FromSeconds(10);
1642 1642
1643 // Inserting another chunk updates the database file. The sleep is 1643 // Inserting another chunk updates the database file. The sleep is
1644 // needed because otherwise the entire test can finish w/in the 1644 // needed because otherwise the entire test can finish w/in the
1645 // resolution of the lastmod time. 1645 // resolution of the lastmod time.
1646 ASSERT_TRUE(file_util::SetLastModifiedTime(filename, old_last_modified)); 1646 ASSERT_TRUE(file_util::SetLastModifiedTime(filename, old_last_modified));
1647 ASSERT_TRUE(file_util::GetFileInfo(filename, &before_info)); 1647 ASSERT_TRUE(base::GetFileInfo(filename, &before_info));
1648 EXPECT_TRUE(database_->UpdateStarted(&lists)); 1648 EXPECT_TRUE(database_->UpdateStarted(&lists));
1649 chunk.hosts.clear(); 1649 chunk.hosts.clear();
1650 InsertAddChunkHostPrefixUrl(&chunk, 2, "www.foo.com/", 1650 InsertAddChunkHostPrefixUrl(&chunk, 2, "www.foo.com/",
1651 "www.foo.com/malware.html"); 1651 "www.foo.com/malware.html");
1652 chunks.clear(); 1652 chunks.clear();
1653 chunks.push_back(chunk); 1653 chunks.push_back(chunk);
1654 database_->InsertChunks(safe_browsing_util::kMalwareList, chunks); 1654 database_->InsertChunks(safe_browsing_util::kMalwareList, chunks);
1655 database_->UpdateFinished(true); 1655 database_->UpdateFinished(true);
1656 ASSERT_TRUE(file_util::GetFileInfo(filename, &after_info)); 1656 ASSERT_TRUE(base::GetFileInfo(filename, &after_info));
1657 EXPECT_LT(before_info.last_modified, after_info.last_modified); 1657 EXPECT_LT(before_info.last_modified, after_info.last_modified);
1658 1658
1659 // Deleting a chunk updates the database file. 1659 // Deleting a chunk updates the database file.
1660 ASSERT_TRUE(file_util::SetLastModifiedTime(filename, old_last_modified)); 1660 ASSERT_TRUE(file_util::SetLastModifiedTime(filename, old_last_modified));
1661 ASSERT_TRUE(file_util::GetFileInfo(filename, &before_info)); 1661 ASSERT_TRUE(base::GetFileInfo(filename, &before_info));
1662 EXPECT_TRUE(database_->UpdateStarted(&lists)); 1662 EXPECT_TRUE(database_->UpdateStarted(&lists));
1663 AddDelChunk(safe_browsing_util::kMalwareList, chunk.chunk_number); 1663 AddDelChunk(safe_browsing_util::kMalwareList, chunk.chunk_number);
1664 database_->UpdateFinished(true); 1664 database_->UpdateFinished(true);
1665 ASSERT_TRUE(file_util::GetFileInfo(filename, &after_info)); 1665 ASSERT_TRUE(base::GetFileInfo(filename, &after_info));
1666 EXPECT_LT(before_info.last_modified, after_info.last_modified); 1666 EXPECT_LT(before_info.last_modified, after_info.last_modified);
1667 1667
1668 // Simply calling |UpdateStarted()| then |UpdateFinished()| does not 1668 // Simply calling |UpdateStarted()| then |UpdateFinished()| does not
1669 // update the database file. 1669 // update the database file.
1670 ASSERT_TRUE(file_util::SetLastModifiedTime(filename, old_last_modified)); 1670 ASSERT_TRUE(file_util::SetLastModifiedTime(filename, old_last_modified));
1671 ASSERT_TRUE(file_util::GetFileInfo(filename, &before_info)); 1671 ASSERT_TRUE(base::GetFileInfo(filename, &before_info));
1672 EXPECT_TRUE(database_->UpdateStarted(&lists)); 1672 EXPECT_TRUE(database_->UpdateStarted(&lists));
1673 database_->UpdateFinished(true); 1673 database_->UpdateFinished(true);
1674 ASSERT_TRUE(file_util::GetFileInfo(filename, &after_info)); 1674 ASSERT_TRUE(base::GetFileInfo(filename, &after_info));
1675 EXPECT_EQ(before_info.last_modified, after_info.last_modified); 1675 EXPECT_EQ(before_info.last_modified, after_info.last_modified);
1676 } 1676 }
1677 1677
1678 // Test that a filter file is written out during update and read back 1678 // Test that a filter file is written out during update and read back
1679 // in during setup. 1679 // in during setup.
1680 TEST_F(SafeBrowsingDatabaseTest, FilterFile) { 1680 TEST_F(SafeBrowsingDatabaseTest, FilterFile) {
1681 // Create a database with trivial example data and write it out. 1681 // Create a database with trivial example data and write it out.
1682 { 1682 {
1683 SBChunkList chunks; 1683 SBChunkList chunks;
1684 SBChunk chunk; 1684 SBChunk chunk;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1825 EXPECT_FALSE(database_->ContainsMalwareIP("192.1.124.0")); 1825 EXPECT_FALSE(database_->ContainsMalwareIP("192.1.124.0"));
1826 1826
1827 EXPECT_FALSE(database_->ContainsMalwareIP("192.1.127.255")); 1827 EXPECT_FALSE(database_->ContainsMalwareIP("192.1.127.255"));
1828 EXPECT_TRUE(database_->ContainsMalwareIP("192.1.128.0")); 1828 EXPECT_TRUE(database_->ContainsMalwareIP("192.1.128.0"));
1829 EXPECT_TRUE(database_->ContainsMalwareIP("::ffff:192.1.128.1")); 1829 EXPECT_TRUE(database_->ContainsMalwareIP("::ffff:192.1.128.1"));
1830 EXPECT_TRUE(database_->ContainsMalwareIP("192.1.128.255")); 1830 EXPECT_TRUE(database_->ContainsMalwareIP("192.1.128.255"));
1831 EXPECT_TRUE(database_->ContainsMalwareIP("192.1.255.0")); 1831 EXPECT_TRUE(database_->ContainsMalwareIP("192.1.255.0"));
1832 EXPECT_TRUE(database_->ContainsMalwareIP("192.1.255.255")); 1832 EXPECT_TRUE(database_->ContainsMalwareIP("192.1.255.255"));
1833 EXPECT_FALSE(database_->ContainsMalwareIP("192.2.0.0")); 1833 EXPECT_FALSE(database_->ContainsMalwareIP("192.2.0.0"));
1834 } 1834 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_database.cc ('k') | chrome/browser/ui/pdf/pdf_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698