1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "chrome/test/base/ui_test_utils.h"
12 #include "content/public/test/browser_test_utils.h"
16 const char kPrefetchPage
[] = "files/prerender/simple_prefetch.html";
18 class PrefetchBrowserTestBase
: public InProcessBrowserTest
{
20 explicit PrefetchBrowserTestBase(bool do_prefetching
)
21 : do_prefetching_(do_prefetching
) {}
23 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
24 if (do_prefetching_
) {
25 command_line
->AppendSwitchASCII(
26 switches::kForceFieldTrials
,
27 "Prefetch/ExperimentYes/");
29 command_line
->AppendSwitchASCII(
30 switches::kForceFieldTrials
,
31 "Prefetch/ExperimentNo/");
39 class PrefetchBrowserTest
: public PrefetchBrowserTestBase
{
42 : PrefetchBrowserTestBase(true) {}
45 class PrefetchBrowserTestNoPrefetching
: public PrefetchBrowserTestBase
{
47 PrefetchBrowserTestNoPrefetching()
48 : PrefetchBrowserTestBase(false) {}
51 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTest
, PrefetchOn
) {
52 ASSERT_TRUE(test_server()->Start());
53 GURL url
= test_server()->GetURL(kPrefetchPage
);
55 const base::string16 expected_title
= base::ASCIIToUTF16("link onload");
56 content::TitleWatcher
title_watcher(
57 browser()->tab_strip_model()->GetActiveWebContents(),
59 ui_test_utils::NavigateToURL(browser(), url
);
61 EXPECT_EQ(expected_title
, title_watcher
.WaitAndGetTitle());
64 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestNoPrefetching
, PrefetchOff
) {
65 ASSERT_TRUE(test_server()->Start());
66 GURL url
= test_server()->GetURL(kPrefetchPage
);
68 const base::string16 expected_title
= base::ASCIIToUTF16("link onerror");
69 content::TitleWatcher
title_watcher(
70 browser()->tab_strip_model()->GetActiveWebContents(),
72 ui_test_utils::NavigateToURL(browser(), url
);
74 EXPECT_EQ(expected_title
, title_watcher
.WaitAndGetTitle());