summaryrefslogtreecommitdiffstats
path: root/chrome/browser/visitedlink_unittest.cc
diff options
context:
space:
mode:
authorjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-27 17:13:02 +0000
committerjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-27 17:13:02 +0000
commit6e01dae641ad11e7600dec30de45b506b8d21c0c (patch)
treebc27f693251a8e602fbdf65c50fd4379cd48959c /chrome/browser/visitedlink_unittest.cc
parent25fa78c2ffe3e98231cfb22f4005452da85b201c (diff)
downloadchromium_src-6e01dae641ad11e7600dec30de45b506b8d21c0c.zip
chromium_src-6e01dae641ad11e7600dec30de45b506b8d21c0c.tar.gz
chromium_src-6e01dae641ad11e7600dec30de45b506b8d21c0c.tar.bz2
First step of porting VisitedLinkMaster to POSIX:
* Use POSIX file access APIs rather than HANDLEs. * Add stubs so that VisitedLinkMaster compiles on POSIX. Still to be done: * Bring up Surrounding infrastructure to turn on unit tests. Review URL: http://codereview.chromium.org/18530 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8721 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/visitedlink_unittest.cc')
-rw-r--r--chrome/browser/visitedlink_unittest.cc46
1 files changed, 23 insertions, 23 deletions
diff --git a/chrome/browser/visitedlink_unittest.cc b/chrome/browser/visitedlink_unittest.cc
index 86c2a24..2dac97f 100644
--- a/chrome/browser/visitedlink_unittest.cc
+++ b/chrome/browser/visitedlink_unittest.cc
@@ -9,6 +9,7 @@
#include "base/message_loop.h"
#include "base/file_util.h"
#include "base/path_service.h"
+#include "base/process_util.h"
#include "base/shared_memory.h"
#include "base/string_util.h"
#include "chrome/browser/visitedlink_master.h"
@@ -28,28 +29,28 @@ GURL TestURL(int i) {
return GURL(StringPrintf("%s%d", g_test_prefix, i));
}
-// when testing in single-threaded mode
-VisitedLinkMaster* g_master = NULL;
std::vector<VisitedLinkSlave*> g_slaves;
VisitedLinkMaster::PostNewTableEvent SynchronousBroadcastNewTableEvent;
void SynchronousBroadcastNewTableEvent(base::SharedMemory* table) {
if (table) {
for (std::vector<VisitedLinkSlave>::size_type i = 0;
- i < (int)g_slaves.size(); i++) {
+ i < g_slaves.size(); i++) {
base::SharedMemoryHandle new_handle = NULL;
- table->ShareToProcess(GetCurrentProcess(), &new_handle);
+ table->ShareToProcess(base::GetCurrentProcessHandle(), &new_handle);
g_slaves[i]->Init(new_handle);
}
}
}
+} // namespace
+
class VisitedLinkTest : public testing::Test {
protected:
// Initialize the history system. This should be called before InitVisited().
bool InitHistory() {
history_service_ = new HistoryService;
- return history_service_->Init(history_dir_, NULL);
+ return history_service_->Init(history_dir_.ToWStringHack(), NULL);
}
// Initializes the visited link objects. Pass in the size that you want a
@@ -103,7 +104,7 @@ class VisitedLinkTest : public testing::Test {
// Create a slave database.
VisitedLinkSlave slave;
base::SharedMemoryHandle new_handle = NULL;
- master_->ShareToProcess(GetCurrentProcess(), &new_handle);
+ master_->ShareToProcess(base::GetCurrentProcessHandle(), &new_handle);
bool success = slave.Init(new_handle);
ASSERT_TRUE(success);
g_slaves.push_back(&slave);
@@ -132,12 +133,11 @@ class VisitedLinkTest : public testing::Test {
// testing::Test
virtual void SetUp() {
PathService::Get(base::DIR_TEMP, &history_dir_);
- file_util::AppendToPath(&history_dir_, L"VisitedLinkTest");
+ history_dir_ = history_dir_.Append(FILE_PATH_LITERAL("VisitedLinkTest"));
file_util::Delete(history_dir_, true);
file_util::CreateDirectory(history_dir_);
- visited_file_ = history_dir_;
- file_util::AppendToPath(&visited_file_, L"VisitedLinks");
+ visited_file_ = history_dir_.Append(FILE_PATH_LITERAL("VisitedLinks"));
}
virtual void TearDown() {
@@ -148,15 +148,13 @@ class VisitedLinkTest : public testing::Test {
MessageLoop message_loop_;
// Filenames for the services;
- std::wstring history_dir_;
- std::wstring visited_file_;
+ FilePath history_dir_;
+ FilePath visited_file_;
scoped_ptr<VisitedLinkMaster> master_;
scoped_refptr<HistoryService> history_service_;
};
-} // namespace
-
// This test creates and reads some databases to make sure the data is
// preserved throughout those operations.
TEST_F(VisitedLinkTest, DatabaseIO) {
@@ -178,11 +176,11 @@ TEST_F(VisitedLinkTest, Delete) {
// Add a cluster from 14-17 wrapping around to 0. These will all hash to the
// same value.
- const int kFingerprint0 = kInitialSize * 0 + 14;
- const int kFingerprint1 = kInitialSize * 1 + 14;
- const int kFingerprint2 = kInitialSize * 2 + 14;
- const int kFingerprint3 = kInitialSize * 3 + 14;
- const int kFingerprint4 = kInitialSize * 4 + 14;
+ const VisitedLinkCommon::Fingerprint kFingerprint0 = kInitialSize * 0 + 14;
+ const VisitedLinkCommon::Fingerprint kFingerprint1 = kInitialSize * 1 + 14;
+ const VisitedLinkCommon::Fingerprint kFingerprint2 = kInitialSize * 2 + 14;
+ const VisitedLinkCommon::Fingerprint kFingerprint3 = kInitialSize * 3 + 14;
+ const VisitedLinkCommon::Fingerprint kFingerprint4 = kInitialSize * 4 + 14;
master_->AddFingerprint(kFingerprint0); // @14
master_->AddFingerprint(kFingerprint1); // @15
master_->AddFingerprint(kFingerprint2); // @16
@@ -193,8 +191,9 @@ TEST_F(VisitedLinkTest, Delete) {
// order).
EXPECT_EQ(kFingerprint3, master_->hash_table_[0]);
master_->DeleteFingerprint(kFingerprint3, false);
- EXPECT_EQ(0, master_->hash_table_[1]);
- EXPECT_NE(0, master_->hash_table_[0]);
+ VisitedLinkCommon::Fingerprint zero_fingerprint = 0;
+ EXPECT_EQ(zero_fingerprint, master_->hash_table_[1]);
+ EXPECT_NE(zero_fingerprint, master_->hash_table_[0]);
// Deleting the other four should leave the table empty.
master_->DeleteFingerprint(kFingerprint0, false);
@@ -204,7 +203,8 @@ TEST_F(VisitedLinkTest, Delete) {
EXPECT_EQ(0, master_->used_items_);
for (int i = 0; i < kInitialSize; i++)
- EXPECT_EQ(0, master_->hash_table_[i]) << "Hash table has values in it.";
+ EXPECT_EQ(zero_fingerprint, master_->hash_table_[i]) <<
+ "Hash table has values in it.";
}
// When we delete more than kBigDeleteThreshold we trigger different behavior
@@ -240,7 +240,7 @@ TEST_F(VisitedLinkTest, DeleteAll) {
{
VisitedLinkSlave slave;
base::SharedMemoryHandle new_handle = NULL;
- master_->ShareToProcess(GetCurrentProcess(), &new_handle);
+ master_->ShareToProcess(base::GetCurrentProcessHandle(), &new_handle);
ASSERT_TRUE(slave.Init(new_handle));
g_slaves.push_back(&slave);
@@ -288,7 +288,7 @@ TEST_F(VisitedLinkTest, Resizing) {
// ...and a slave
VisitedLinkSlave slave;
base::SharedMemoryHandle new_handle = NULL;
- master_->ShareToProcess(GetCurrentProcess(), &new_handle);
+ master_->ShareToProcess(base::GetCurrentProcessHandle(), &new_handle);
bool success = slave.Init(new_handle);
ASSERT_TRUE(success);
g_slaves.push_back(&slave);