summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net/predictor_unittest.cc
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-01 09:46:32 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-01 09:46:32 +0000
commitb435b6279959d1b6b4db7e474162536be731a6c5 (patch)
tree517c0c474d3638f89c4abee71c19522dbb5d94f2 /chrome/browser/net/predictor_unittest.cc
parent48b9f99b5c3a3d992897ee5bed61a4e07765dcfa (diff)
downloadchromium_src-b435b6279959d1b6b4db7e474162536be731a6c5.zip
chromium_src-b435b6279959d1b6b4db7e474162536be731a6c5.tar.gz
chromium_src-b435b6279959d1b6b4db7e474162536be731a6c5.tar.bz2
Fix a crash when viewing about:dns.
BUG=116345 Review URL: http://codereview.chromium.org/9555017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124394 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net/predictor_unittest.cc')
-rw-r--r--chrome/browser/net/predictor_unittest.cc77
1 files changed, 77 insertions, 0 deletions
diff --git a/chrome/browser/net/predictor_unittest.cc b/chrome/browser/net/predictor_unittest.cc
index ebdd1b38..92974de 100644
--- a/chrome/browser/net/predictor_unittest.cc
+++ b/chrome/browser/net/predictor_unittest.cc
@@ -376,6 +376,83 @@ TEST_F(PredictorTest, ReferrerSerializationSingleReferrerTest) {
predictor.Shutdown();
}
+// Check that GetHtmlReferrerLists() doesn't crash when given duplicated
+// domains for referring URL, and that it sorts the results in the
+// correct order.
+TEST_F(PredictorTest, GetHtmlReferrerLists) {
+ Predictor predictor(true);
+ predictor.SetHostResolver(host_resolver_.get());
+ const double kUseRate = 23.4;
+ scoped_ptr<ListValue> referral_list(NewEmptySerializationList());
+
+ AddToSerializedList(
+ GURL("http://d.google.com/x1"),
+ GURL("http://foo.com/"),
+ kUseRate, referral_list.get());
+
+ // Duplicated hostname (d.google.com). This should not cause any crashes
+ // (i.e. crbug.com/116345)
+ AddToSerializedList(
+ GURL("http://d.google.com/x2"),
+ GURL("http://foo.com/"),
+ kUseRate, referral_list.get());
+
+ AddToSerializedList(
+ GURL("http://a.yahoo.com/y"),
+ GURL("http://foo1.com/"),
+ kUseRate, referral_list.get());
+
+ AddToSerializedList(
+ GURL("http://b.google.com/x3"),
+ GURL("http://foo2.com/"),
+ kUseRate, referral_list.get());
+
+ AddToSerializedList(
+ GURL("http://d.yahoo.com/x5"),
+ GURL("http://i.like.turtles/"),
+ kUseRate, referral_list.get());
+
+ AddToSerializedList(
+ GURL("http://c.yahoo.com/x4"),
+ GURL("http://foo3.com/"),
+ kUseRate, referral_list.get());
+
+ predictor.DeserializeReferrers(*referral_list.get());
+
+ std::string html;
+ predictor.GetHtmlReferrerLists(&html);
+
+ // The lexicographic sorting of hostnames would be:
+ // a.yahoo.com
+ // b.google.com
+ // c.yahoo.com
+ // d.google.com
+ // d.yahoo.com
+ //
+ // However we expect to sort them by domain in the output:
+ // b.google.com
+ // d.google.com
+ // a.yahoo.com
+ // c.yahoo.com
+ // d.yahoo.com
+
+ size_t pos[] = {
+ html.find("<td rowspan=1>http://b.google.com/x3"),
+ html.find("<td rowspan=1>http://d.google.com/x1"),
+ html.find("<td rowspan=1>http://d.google.com/x2"),
+ html.find("<td rowspan=1>http://a.yahoo.com/y"),
+ html.find("<td rowspan=1>http://c.yahoo.com/x4"),
+ html.find("<td rowspan=1>http://d.yahoo.com/x5"),
+ };
+
+ // Make sure things appeared in the expected order.
+ for (size_t i = 1; i < arraysize(pos); ++i) {
+ EXPECT_LT(pos[i - 1], pos[i]) << "Mismatch for pos[" << i << "]";
+ }
+
+ predictor.Shutdown();
+}
+
// Verify that two floats are within 1% of each other in value.
#define EXPECT_SIMILAR(a, b) do { \
double espilon_ratio = 1.01; \