diff options
author | gavinp@chromium.org <gavinp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-27 21:07:34 +0000 |
---|---|---|
committer | gavinp@chromium.org <gavinp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-27 21:07:34 +0000 |
commit | 4806e850ba4d2fbc633ff2efebef757fbd050a8f (patch) | |
tree | a61c619473cafefeeadf6a205fb218b36346e950 | |
parent | 5880ca980938d780d77d627c4329981a3778ef7c (diff) | |
download | chromium_src-4806e850ba4d2fbc633ff2efebef757fbd050a8f.zip chromium_src-4806e850ba4d2fbc633ff2efebef757fbd050a8f.tar.gz chromium_src-4806e850ba4d2fbc633ff2efebef757fbd050a8f.tar.bz2 |
Add a browsertest for <link rel=prefetch>
Previously we used a pyauto test for prefetch, but I realised a
browser test would work too; here it is.
BUG=none
Review URL: http://codereview.chromium.org/8963029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115846 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/prerender/prefetch_browsertest.cc | 76 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 1 | ||||
-rw-r--r-- | chrome/test/data/prerender/prefetch_target.lnk | 1 | ||||
-rw-r--r-- | chrome/test/data/prerender/simple_prefetch.html | 20 |
4 files changed, 98 insertions, 0 deletions
diff --git a/chrome/browser/prerender/prefetch_browsertest.cc b/chrome/browser/prerender/prefetch_browsertest.cc new file mode 100644 index 0000000..9499342 --- /dev/null +++ b/chrome/browser/prerender/prefetch_browsertest.cc @@ -0,0 +1,76 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/command_line.h" +#include "base/utf_string_conversions.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "chrome/test/base/ui_test_utils.h" + +namespace { + +const char kPrefetchPage[] = "files/prerender/simple_prefetch.html"; + +class PrefetchBrowserTestBase : public InProcessBrowserTest { + public: + explicit PrefetchBrowserTestBase(bool do_prefetching) + : InProcessBrowserTest(), do_prefetching_(do_prefetching) { + EnableDOMAutomation(); + } + + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { + if (do_prefetching_) { + command_line->AppendSwitchASCII( + switches::kPrerenderMode, + switches::kPrerenderModeSwitchValuePrefetchOnly); + } else { + command_line->AppendSwitchASCII( + switches::kPrerenderMode, + switches::kPrerenderModeSwitchValueDisabled); + } + } + + private: + bool do_prefetching_; +}; + +class PrefetchBrowserTest : public PrefetchBrowserTestBase { + public: + PrefetchBrowserTest() + : PrefetchBrowserTestBase(true) {} +}; + +class PrefetchBrowserTestNoPrefetching : public PrefetchBrowserTestBase { + public: + PrefetchBrowserTestNoPrefetching() + : PrefetchBrowserTestBase(false) {} +}; + +IN_PROC_BROWSER_TEST_F(PrefetchBrowserTest, PrefetchOn) { + ASSERT_TRUE(test_server()->Start()); + GURL url = test_server()->GetURL(kPrefetchPage); + + const string16 expected_title = ASCIIToUTF16("link onload"); + ui_test_utils::TitleWatcher title_watcher(browser()->GetSelectedTabContents(), + expected_title); + ui_test_utils::NavigateToURL(browser(), url); + + EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); +} + +IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestNoPrefetching, PrefetchOff) { + ASSERT_TRUE(test_server()->Start()); + GURL url = test_server()->GetURL(kPrefetchPage); + + const string16 expected_title = ASCIIToUTF16("link onerror"); + ui_test_utils::TitleWatcher title_watcher(browser()->GetSelectedTabContents(), + expected_title); + ui_test_utils::NavigateToURL(browser(), url); + + EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); +} + +} // namespace + diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index d0e1a6d..a377b50 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -2627,6 +2627,7 @@ 'browser/policy/enterprise_metrics_browsertest.cc', 'browser/policy/enterprise_metrics_enrollment_browsertest.cc', 'browser/popup_blocker_browsertest.cc', + 'browser/prerender/prefetch_browsertest.cc', 'browser/prerender/prerender_browsertest.cc', 'browser/printing/print_dialog_cloud_uitest.cc', 'browser/printing/print_preview_tab_controller_browsertest.cc', diff --git a/chrome/test/data/prerender/prefetch_target.lnk b/chrome/test/data/prerender/prefetch_target.lnk new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/chrome/test/data/prerender/prefetch_target.lnk @@ -0,0 +1 @@ + diff --git a/chrome/test/data/prerender/simple_prefetch.html b/chrome/test/data/prerender/simple_prefetch.html new file mode 100644 index 0000000..0484c27 --- /dev/null +++ b/chrome/test/data/prerender/simple_prefetch.html @@ -0,0 +1,20 @@ +<html> +<head> +<title>Simple Prefetch Page</title> +<script> +function linkOnload() { + document.title = 'link onload'; +} + +function linkOnerror() { + document.title = 'link onerror'; +} +</script> +<link rel="prefetch" + href="prefetch_target.lnk" + onload="linkOnload()" + onerror="linkOnerror()"/> +</head> +<body> +</body> +</html> |