15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2011 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/prerender/prerender_util.h"
68bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
78bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "base/metrics/histogram.h"
88bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "base/metrics/histogram_samples.h"
98bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "base/metrics/statistics_recorder.h"
108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "net/http/http_response_headers.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "url/gurl.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace prerender {
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class PrerenderUtilTest : public testing::Test {
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PrerenderUtilTest() {
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Ensure that extracting a urlencoded URL in the url= query string component
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// works.
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(PrerenderUtilTest, ExtractURLInQueryStringTest) {
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL result;
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(MaybeGetQueryStringBasedAliasURL(
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GURL("http://www.google.com/url?sa=t&source=web&cd=1&ved=0CBcQFjAA&url=http%3A%2F%2Fwww.abercrombie.com%2Fwebapp%2Fwcs%2Fstores%2Fservlet%2FStoreLocator%3FcatalogId%3D%26storeId%3D10051%26langId%3D-1&rct=j&q=allinurl%3A%26&ei=KLyUTYGSEdTWiAKUmLCdCQ&usg=AFQjCNF8nJ2MpBFfr1ijO39_f22bcKyccw&sig2=2ymyGpO0unJwU1d4kdCUjQ"),
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      &result));
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_EQ(GURL("http://www.abercrombie.com/webapp/wcs/stores/servlet/StoreLocator?catalogId=&storeId=10051&langId=-1").spec(), result.spec());
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(MaybeGetQueryStringBasedAliasURL(
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GURL("http://www.google.com/url?sadf=test&blah=blahblahblah"), &result));
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(MaybeGetQueryStringBasedAliasURL(
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GURL("http://www.google.com/?url=INVALIDurlsAREsoMUCHfun.com"), &result));
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(MaybeGetQueryStringBasedAliasURL(
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GURL("http://www.google.com/?url=http://validURLSareGREAT.com"),
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      &result));
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_EQ(GURL("http://validURLSareGREAT.com").spec(), result.spec());
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Ensure that extracting an experiment in the lpe= query string component
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// works.
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(PrerenderUtilTest, ExtractExperimentInQueryStringTest) {
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(GetQueryStringBasedExperiment(
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GURL("http://www.google.com/url?sa=t&source=web&cd=1&ved=0CBcQFjAA&url=http%3A%2F%2Fwww.abercrombie.com%2Fwebapp%2Fwcs%2Fstores%2Fservlet%2FStoreLocator%3FcatalogId%3D%26storeId%3D10051%26langId%3D-1&rct=j&q=allinurl%3A%26&ei=KLyUTYGSEdTWiAKUmLCdCQ&usg=AFQjCNF8nJ2MpBFfr1ijO39_f22bcKyccw&sig2=2ymyGpO0unJwU1d4kdCUjQ&lpe=4&asdf=test")), 4);
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(GetQueryStringBasedExperiment(
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GURL("http://www.google.com/test.php?a=b")), kNoExperiment);
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(GetQueryStringBasedExperiment(
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GURL("http://www.google.com/test.php?lpe=5")), 5);
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(GetQueryStringBasedExperiment(
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GURL("http://www.google.com/test.php?lpe=50")), kNoExperiment);
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(GetQueryStringBasedExperiment(
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GURL("http://www.google.com/test.php?lpe=0")), kNoExperiment);
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(GetQueryStringBasedExperiment(
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GURL("http://www.google.com/test.php?lpe=10")), kNoExperiment);
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Ensure that we detect Google search result URLs correctly.
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(PrerenderUtilTest, DetectGoogleSearchREsultURLTest) {
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/#asdf")));
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/")));
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/?a=b")));
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(IsGoogleSearchResultURL(
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GURL("http://www.google.com/search?q=hi")));
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/search")));
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.com/webhp")));
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(IsGoogleSearchResultURL(
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GURL("http://www.google.com/webhp?a=b#123")));
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://www.google.com/imgres")));
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(IsGoogleSearchResultURL(
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GURL("http://www.google.com/imgres?q=hi")));
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(IsGoogleSearchResultURL(
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GURL("http://www.google.com/imgres?q=hi#123")));
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://google.com/search")));
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://WWW.GooGLE.CoM/search")));
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://WWW.GooGLE.CoM/SeArcH")));
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(IsGoogleSearchResultURL(GURL("http://www.google.co.uk/search")));
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://google.co.uk/search")));
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(IsGoogleSearchResultURL(GURL("http://www.chromium.org/search")));
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Ensure that we count PageSpeed headers correctly.
828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)TEST_F(PrerenderUtilTest, CountPageSpeedHeadersTest) {
838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  base::StatisticsRecorder::Initialize();
848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  GURL url("http://google.com");
858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  std::string temp("HTTP/1.1 200 OK\n\n");
868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  std::replace(temp.begin(), temp.end(), '\n', '\0');
878bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  scoped_refptr<net::HttpResponseHeaders> headers(
888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      new net::HttpResponseHeaders(temp));
898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  int num_responses = 0;
918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  int num_mps = 0;
928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  int num_ngx = 0;
938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  int num_pss = 0;
948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  int num_other = 0;
958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  int num_bucket_1  = 0;  // unrecognized format/value bucket
968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  int num_bucket_30 = 0;  // 1.2.24.1 bucket
978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  int num_bucket_33 = 0;  // 1.3.25.2 bucket
988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  scoped_ptr<base::HistogramSamples> server_samples;
1008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  scoped_ptr<base::HistogramSamples> version_samples;
1018bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // No PageSpeed header. The VersionCounts histogram isn't created yet.
1038bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  GatherPagespeedData(ResourceType::MAIN_FRAME, url, headers.get());
1048bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  base::HistogramBase* server_histogram =
1058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      base::StatisticsRecorder::FindHistogram(
1068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)          "Prerender.PagespeedHeader.ServerCounts");
1078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  ASSERT_TRUE(server_histogram != NULL);
1088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  ASSERT_TRUE(NULL == base::StatisticsRecorder::FindHistogram(
1098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      "Prerender.PagespeedHeader.VersionCounts"));
1108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  server_samples = server_histogram->SnapshotSamples();
1128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(++num_responses, server_samples->GetCount(0));
1138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_mps,       server_samples->GetCount(1));
1148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_ngx,       server_samples->GetCount(2));
1158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_pss,       server_samples->GetCount(3));
1168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_other,     server_samples->GetCount(4));
1178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // X-Mod-Pagespeed header in expected format. VersionCounts now exists.
1198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  headers->AddHeader("X-Mod-Pagespeed: 1.2.24.1-2300");
1208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  GatherPagespeedData(ResourceType::MAIN_FRAME, url, headers.get());
1218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  base::HistogramBase* version_histogram =
1228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      base::StatisticsRecorder::FindHistogram(
1238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)          "Prerender.PagespeedHeader.VersionCounts");
1248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  ASSERT_TRUE(version_histogram != NULL);
1258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  server_samples = server_histogram->SnapshotSamples();
1268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  version_samples = version_histogram->SnapshotSamples();
1278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(++num_responses, server_samples->GetCount(0));
1288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(++num_mps,       server_samples->GetCount(1));
1298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_ngx,       server_samples->GetCount(2));
1308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_pss,       server_samples->GetCount(3));
1318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_other,     server_samples->GetCount(4));
1328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_bucket_1,  version_samples->GetCount(1));
1338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(++num_bucket_30, version_samples->GetCount(30));  // +1 for #30
1348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_bucket_33, version_samples->GetCount(33));
1358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  headers->RemoveHeader("X-Mod-Pagespeed");
1368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // X-Mod-Pagespeed header in unexpected format.
1388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  headers->AddHeader("X-Mod-Pagespeed: Powered By PageSpeed!");
1398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  GatherPagespeedData(ResourceType::MAIN_FRAME, url, headers.get());
1408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  server_samples = server_histogram->SnapshotSamples();
1418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  version_samples = version_histogram->SnapshotSamples();
1428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(++num_responses, server_samples->GetCount(0));
1438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(++num_mps,       server_samples->GetCount(1));
1448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_ngx,       server_samples->GetCount(2));
1458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_pss,       server_samples->GetCount(3));
1468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_other,     server_samples->GetCount(4));
1478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(++num_bucket_1,  version_samples->GetCount(1));   // +1 for 'huh?'
1488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_bucket_30, version_samples->GetCount(30));
1498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_bucket_33, version_samples->GetCount(33));
1508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  headers->RemoveHeader("X-Mod-Pagespeed");
1518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // X-Page-Speed header in mod_pagespeed format (so ngx_pagespeed).
1538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  headers->AddHeader("X-Page-Speed: 1.3.25.2-2530");
1548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  GatherPagespeedData(ResourceType::MAIN_FRAME, url, headers.get());
1558bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  server_samples = server_histogram->SnapshotSamples();
1568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  version_samples = version_histogram->SnapshotSamples();
1578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(++num_responses, server_samples->GetCount(0));
1588bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_mps,       server_samples->GetCount(1));
1598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(++num_ngx,       server_samples->GetCount(2));
1608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_pss,       server_samples->GetCount(3));
1618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_other,     server_samples->GetCount(4));
1628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_bucket_1,  version_samples->GetCount(1));
1638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_bucket_30, version_samples->GetCount(30));
1648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(++num_bucket_33, version_samples->GetCount(33));  // +1 for #33
1658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  headers->RemoveHeader("X-Page-Speed");
1668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // X-Page-Speed header in PageSpeed Service format.
1688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  headers->AddHeader("X-Page-Speed: 97_4_bo");
1698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  GatherPagespeedData(ResourceType::MAIN_FRAME, url, headers.get());
1708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  server_samples = server_histogram->SnapshotSamples();
1718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  version_samples = version_histogram->SnapshotSamples();
1728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(++num_responses, server_samples->GetCount(0));
1738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_mps,       server_samples->GetCount(1));    // no change
1748bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_ngx,       server_samples->GetCount(2));
1758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(++num_pss,       server_samples->GetCount(3));    // +1 for PSS
1768bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_other,     server_samples->GetCount(4));
1778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_bucket_1,  version_samples->GetCount(1));
1788bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_bucket_30, version_samples->GetCount(30));
1798bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_bucket_33, version_samples->GetCount(33));
1808bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  headers->RemoveHeader("X-Page-Speed");
1818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // X-Page-Speed header in an unrecognized format (IISpeed in this case).
1838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  headers->AddHeader("X-Page-Speed: 1.0PS1.2-20130615");
1848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  GatherPagespeedData(ResourceType::MAIN_FRAME, url, headers.get());
1858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  server_samples = server_histogram->SnapshotSamples();
1868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  version_samples = version_histogram->SnapshotSamples();
1878bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(++num_responses, server_samples->GetCount(0));
1888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_mps,       server_samples->GetCount(1));    // no change
1898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_pss,       server_samples->GetCount(3));
1908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(++num_other,     server_samples->GetCount(4));    // +1 for 'other'
1918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_bucket_1,  version_samples->GetCount(1));
1928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_bucket_30, version_samples->GetCount(30));
1938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_bucket_33, version_samples->GetCount(33));
1948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Not a main frame => not counted at all.
1968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  GatherPagespeedData(ResourceType::SUB_FRAME, url, headers.get());
1978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  server_samples = server_histogram->SnapshotSamples();
1988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  version_samples = version_histogram->SnapshotSamples();
1998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_responses, server_samples->GetCount(0));
2008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_mps,       server_samples->GetCount(1));
2018bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_ngx,       server_samples->GetCount(2));
2028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_pss,       server_samples->GetCount(3));
2038bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_other,     server_samples->GetCount(4));
2048bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_bucket_1,  version_samples->GetCount(1));
2058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_bucket_30, version_samples->GetCount(30));
2068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_bucket_33, version_samples->GetCount(33));
2078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Not a http/https URL => not counted at all.
2098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  GURL data_url("data:image/png;base64,yadda yadda==");
2108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  GatherPagespeedData(ResourceType::MAIN_FRAME, data_url, headers.get());
2118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  server_samples = server_histogram->SnapshotSamples();
2128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  version_samples = version_histogram->SnapshotSamples();
2138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_responses, server_samples->GetCount(0));
2148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_mps,       server_samples->GetCount(1));
2158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_ngx,       server_samples->GetCount(2));
2168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_pss,       server_samples->GetCount(3));
2178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_other,     server_samples->GetCount(4));
2188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_bucket_1,  version_samples->GetCount(1));
2198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_bucket_30, version_samples->GetCount(30));
2208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(  num_bucket_33, version_samples->GetCount(33));
2218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  headers->RemoveHeader("X-Page-Speed");
2238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
2248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace prerender
226