summaryrefslogtreecommitdiffstats
path: root/chrome/common/net/cache_uitest.cc
diff options
context:
space:
mode:
authorinitial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-26 23:55:29 +0000
committerinitial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-26 23:55:29 +0000
commit09911bf300f1a419907a9412154760efd0b7abc3 (patch)
treef131325fb4e2ad12c6d3504ab75b16dd92facfed /chrome/common/net/cache_uitest.cc
parent586acc5fe142f498261f52c66862fa417c3d52d2 (diff)
downloadchromium_src-09911bf300f1a419907a9412154760efd0b7abc3.zip
chromium_src-09911bf300f1a419907a9412154760efd0b7abc3.tar.gz
chromium_src-09911bf300f1a419907a9412154760efd0b7abc3.tar.bz2
Add chrome to the repository.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/net/cache_uitest.cc')
-rw-r--r--chrome/common/net/cache_uitest.cc201
1 files changed, 201 insertions, 0 deletions
diff --git a/chrome/common/net/cache_uitest.cc b/chrome/common/net/cache_uitest.cc
new file mode 100644
index 0000000..36ad388
--- /dev/null
+++ b/chrome/common/net/cache_uitest.cc
@@ -0,0 +1,201 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include <string>
+
+#include "base/string_util.h"
+#include "chrome/test/ui/ui_test.h"
+#include "chrome/test/automation/automation_proxy.h"
+#include "chrome/test/automation/browser_proxy.h"
+#include "chrome/test/automation/tab_proxy.h"
+#include "net/url_request/url_request_unittest.h"
+
+// The CacheTest class extends the UITest class and provides functions to
+// get a new tab and to run the tests on a particular path
+//
+// Typical usage:
+//
+// 1. Provide this class as the TestCase for TEST_F macro
+// 2. Then run the cache test on a specific path using the function
+// RunCacheTest
+//
+// For example:
+//
+// TEST_F(CacheTest, NoCacheMaxAge) {
+// RunCacheTest(L"nocachetime/maxage", false, false);
+// }
+//
+// Note that delays used in running the test is initialized to defaults
+class CacheTest : public UITest {
+ protected:
+
+ // Runs the cache test for the specified path.
+ // Can specify the test to check if a new tab is loaded from the cache
+ // and also if a delayed reload is required. A true value passed to the
+ // third parameter causes a delayed reload of the path in a new tab.
+ // The amount of delay is set by a class constant.
+ void RunCacheTest(const std::wstring &url,
+ bool expect_new_tab_cached,
+ bool expect_delayed_reload);
+
+ private:
+ // Class constants
+ static const int kWaitForCacheUpdateMsec = 2000;
+ static const int kCacheWaitMultiplier = 4; // Used to increase delay
+
+ // Appends a new tab to the test chrome window and loads the specified
+ // URL. The new tab will try to get the URL from the cache before requesting
+ // the server for it.
+ void GetNewTab(AutomationProxy* automationProxy, const GURL& tab_url);
+};
+
+// Runs the cache test for the specified path.
+void CacheTest::RunCacheTest(const std::wstring &url,
+ bool expect_new_tab_cached,
+ bool expect_delayed_reload) {
+ TestServer server(L"chrome/test/data");
+ GURL test_page(server.TestServerPageW(url));
+
+ NavigateToURL(test_page);
+ std::wstring original_time = GetActiveTabTitle();
+
+ Sleep(kWaitForCacheUpdateMsec);
+
+ GetNewTab(automation(), test_page);
+ std::wstring revisit_time = GetActiveTabTitle();
+
+ if (expect_new_tab_cached) {
+ EXPECT_EQ(original_time, revisit_time);
+ }else {
+ EXPECT_NE(original_time, revisit_time);
+ }
+
+ Sleep(kWaitForCacheUpdateMsec);
+
+ // Force reload, overriding the caching behavior
+ NavigateToURL(test_page);
+ std::wstring reload_time = GetActiveTabTitle();
+
+ EXPECT_NE(revisit_time, reload_time);
+
+ if (expect_delayed_reload) {
+ Sleep(kWaitForCacheUpdateMsec * kCacheWaitMultiplier);
+
+ GetNewTab(automation(), test_page);
+ revisit_time = GetActiveTabTitle();
+
+ EXPECT_NE(reload_time, revisit_time);
+ }
+}
+
+// Appends a new tab to the test chrome window and loads the specified URL.
+void CacheTest::GetNewTab(AutomationProxy* automationProxy,
+ const GURL& tab_url) {
+ scoped_ptr<BrowserProxy> window_proxy(automationProxy->GetBrowserWindow(0));
+ ASSERT_TRUE(window_proxy.get());
+ ASSERT_TRUE(window_proxy->AppendTab(tab_url));
+}
+
+// Tests that a cached copy of the page is not used when max-age=0 headers
+// are specified.
+TEST_F(CacheTest, NoCacheMaxAge) {
+ RunCacheTest(L"nocachetime/maxage", false, false);
+}
+
+// Tests that a cached copy of the page is not used when no-cache header
+// is specified.
+TEST_F(CacheTest, NoCache) {
+ RunCacheTest(L"nocachetime", false, false);
+}
+
+// Tests that a cached copy of a page is used when its headers specify
+// that it should be cached for 60 seconds.
+TEST_F(CacheTest, Cache) {
+ RunCacheTest(L"cachetime", true, false);
+}
+
+// Tests that a cached copy of the page is used when expires header
+// specifies that the page has not yet expired.
+TEST_F(CacheTest, Expires) {
+ RunCacheTest(L"cache/expires", true, false);
+}
+
+// Tests that a cached copy of the page is used when proxy-revalidate header
+// is specified and the page has not yet expired.
+TEST_F(CacheTest, ProxyRevalidate) {
+ RunCacheTest(L"cache/proxy-revalidate", true, false);
+}
+
+// Tests that a cached copy of the page is used when private header
+// is specified and the page has not yet expired.
+TEST_F(CacheTest, Private) {
+ RunCacheTest(L"cache/private", true, true);
+}
+
+// Tests that a cached copy of the page is used when public header
+// is specified and the page has not yet expired.
+TEST_F(CacheTest, Public) {
+ RunCacheTest(L"cache/public", true, true);
+}
+
+// Tests that a cached copy of the page is not used when s-maxage header
+// is specified.
+TEST_F(CacheTest, SMaxAge) {
+ RunCacheTest(L"cache/s-maxage", false, false);
+}
+
+// Tests that a cached copy of the page is not used when must-revalidate header
+// is specified.
+TEST_F(CacheTest, MustRevalidate) {
+ RunCacheTest(L"cache/must-revalidate", false, false);
+}
+
+// Tests that a cached copy of the page is not used when must-revalidate header
+// is specified, even though the page has not yet expired.
+TEST_F(CacheTest, MustRevalidateMaxAge) {
+ RunCacheTest(L"cache/must-revalidate/max-age", false, false);
+}
+
+// Tests that a cached copy of the page is not used when no-store header
+// is specified.
+TEST_F(CacheTest, NoStore) {
+ RunCacheTest(L"cache/no-store", false, false);
+}
+
+// Tests that a cached copy of the page is not used when no-store header
+// is specified, even though the page has not yet expired.
+TEST_F(CacheTest, NoStoreMaxAge) {
+ RunCacheTest(L"cache/no-store/max-age", false, false);
+}
+
+// Tests that a cached copy of the page is not transformed when no-transform
+// header is specified.
+TEST_F(CacheTest, NoTransform) {
+ RunCacheTest(L"cache/no-transform", false, false);
+}