This source file includes following definitions.
- MakeFakeHost
- RunTest
- TEST
- TEST
- TEST
- TEST
#include "chrome/browser/history/visit_tracker.h"
#include "base/basictypes.h"
#include "testing/gtest/include/gtest/gtest.h"
using history::VisitTracker;
namespace {
struct VisitToTest {
int host;
int32 page_id;
const char* url;
const history::VisitID visit_id;
const char* referrer;
history::VisitID referring_visit_id;
};
void* MakeFakeHost(int id) {
void* host = 0;
memcpy(&host, &id, sizeof(int));
return host;
}
void RunTest(VisitTracker* tracker, VisitToTest* test, int test_count) {
for (int i = 0; i < test_count; i++) {
void* host = MakeFakeHost(test[i].host);
history::VisitID ref_visit = tracker->GetLastVisit(
host, test[i].page_id, GURL(test[i].referrer));
EXPECT_EQ(test[i].referring_visit_id, ref_visit);
tracker->AddVisit(host, test[i].page_id, GURL(test[i].url),
test[i].visit_id);
}
}
}
TEST(VisitTracker, SimpleTransitions) {
VisitToTest test_simple[] = {
{1, 1, "http://www.google.com/", 1, "", 0},
{1, 2, "http://images.google.com/", 2, "http://www.google.com/", 1},
{1, 3, "http://video.google.com/", 3, "http://www.google.com/", 1},
};
VisitTracker tracker;
RunTest(&tracker, test_simple, arraysize(test_simple));
}
TEST(VisitTracker, Frames) {
VisitToTest test_frames[] = {
{1, 1, "http://foo.com/", 1, "", 0},
{1, 1, "http://foo.com/ad.html", 2, "http://foo.com/", 1},
{1, 1, "http://foo.com/ad2.html", 3, "http://foo.com/", 1},
{1, 2, "http://bar.com/", 4, "http://foo.com/ad.html", 2},
{1, 3, "http://fud.com/", 5, "http://foo.com/ad2.html", 3},
{1, 4, "http://www.google.com/", 6, "http://foo.com/", 1},
};
VisitTracker tracker;
RunTest(&tracker, test_frames, arraysize(test_frames));
}
TEST(VisitTracker, MultiProcess) {
VisitToTest test_processes[] = {
{1, 1, "http://foo.com/", 1, "", 0},
{2, 1, "http://foo.com/", 2, "", 0},
{1, 1, "http://foo.com/ad.html", 3, "http://foo.com/", 1},
{2, 1, "http://foo.com/ad.html", 4, "http://foo.com/", 2},
{1, 2, "http://bar.com/", 5, "http://foo.com/ad.html", 3},
{2, 2, "http://bar.com/", 6, "http://foo.com/ad.html", 4},
{1, 3, "http://www.google.com/", 7, "http://foo.com/", 1},
{2, 3, "http://www.google.com/", 8, "http://foo.com/", 2},
};
VisitTracker tracker;
RunTest(&tracker, test_processes, arraysize(test_processes));
}
TEST(VisitTracker, ProcessRemove) {
VisitToTest part1[] = {
{1, 1, "http://www.google.com/", 1, "", 0},
{1, 2, "http://images.google.com/", 2, "http://www.google.com/", 1},
};
VisitTracker tracker;
RunTest(&tracker, part1, arraysize(part1));
tracker.NotifyRenderProcessHostDestruction(MakeFakeHost(1));
VisitToTest part2[] = {
{1, 1, "http://images.google.com/", 2, "http://www.google.com/", 0},
};
RunTest(&tracker, part2, arraysize(part2));
}