summaryrefslogtreecommitdiffstats
path: root/chrome/test/url_fetch_test
diff options
context:
space:
mode:
authorasargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-02 21:00:28 +0000
committerasargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-02 21:00:28 +0000
commit6feeee9ee4ffffb960dee9b4f8860262905b7c2f (patch)
tree999aa96c0450b79772b540582374fc27e36dbd1e /chrome/test/url_fetch_test
parentea8c745aa6a3be27b904060832fdf14bb11193bf (diff)
downloadchromium_src-6feeee9ee4ffffb960dee9b4f8860262905b7c2f.zip
chromium_src-6feeee9ee4ffffb960dee9b4f8860262905b7c2f.tar.gz
chromium_src-6feeee9ee4ffffb960dee9b4f8860262905b7c2f.tar.bz2
Add a ui test that can be used to fetch a url and wait for a cookie to be set.
It can also save a cookie value and javascript value out to a file. Review URL: http://codereview.chromium.org/57021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13032 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/url_fetch_test')
-rw-r--r--chrome/test/url_fetch_test/url_fetch_test.cc123
-rw-r--r--chrome/test/url_fetch_test/url_fetch_test.vcproj216
2 files changed, 339 insertions, 0 deletions
diff --git a/chrome/test/url_fetch_test/url_fetch_test.cc b/chrome/test/url_fetch_test/url_fetch_test.cc
new file mode 100644
index 0000000..bb773a5
--- /dev/null
+++ b/chrome/test/url_fetch_test/url_fetch_test.cc
@@ -0,0 +1,123 @@
+// Copyright (c) 2009 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/file_path.h"
+#include "base/file_util.h"
+#include "base/string_util.h"
+#include "chrome/test/automation/tab_proxy.h"
+#include "chrome/test/ui/ui_test.h"
+
+namespace {
+
+// Provides a UI Test that lets us take the browser to a url, and
+// wait for a cookie value to be set before closing the page.
+class UrlFetchTest : public UITest {
+ public:
+ UrlFetchTest() {
+ show_window_ = true;
+ dom_automation_enabled_ = true;
+ }
+ struct UrlFetchTestResult {
+ std::string cookie_value;
+ std::string javascript_variable;
+ };
+
+ void RunTest(const GURL& url, const char *waitCookieName,
+ const char *waitCookieValue, const wchar_t *varToFetch,
+ UrlFetchTestResult *result) {
+ scoped_ptr<TabProxy> tab(GetActiveTab());
+ tab->NavigateToURL(url);
+
+ if (waitCookieName) {
+ if (waitCookieValue) {
+ bool completed = WaitUntilCookieValue(tab.get(), url, waitCookieName,
+ 3000, UITest::test_timeout_ms(),
+ waitCookieValue);
+ ASSERT_TRUE(completed);
+ } else {
+ result->cookie_value = WaitUntilCookieNonEmpty(
+ tab.get(), url, waitCookieName, 3000, UITest::test_timeout_ms());
+ ASSERT_TRUE(result->cookie_value.length());
+ }
+ }
+ if (varToFetch) {
+ std::wstring script = StringPrintf(
+ L"window.domAutomationController.send(%s);", varToFetch);
+
+ std::wstring value;
+ bool success = tab->ExecuteAndExtractString(L"", script, &value);
+ ASSERT_TRUE(success);
+ result->javascript_variable = WideToUTF8(value);
+ }
+ }
+};
+
+} // namespace
+
+
+bool writeValueToFile(std::string value, std::wstring filePath) {
+ int retval = file_util::WriteFile(
+ FilePath(filePath), value.c_str(), value.length());
+ return retval == value.length();
+}
+
+// To actually do anything useful, this test should have a url
+// passed on the command line, eg.
+//
+// --url=http://foo.bar.com
+//
+// Additional arguments:
+//
+// --wait_cookie_name=<name>
+// Waits for a cookie named <name> to be set before exiting successfully.
+//
+// --wait_cookie_value=<value>
+// In conjunction with --wait_cookie_name, this waits for a specific value
+// to be set. (Incompatible with --wait_cookie_output)
+//
+// --wait_cookie_output=<filepath>
+// In conjunction with --wait_cookie_name, this saves the cookie value to
+// a file at the given path. (Incompatible with --wait_cookie_value)
+//
+// --jsvar=<name>
+// At the end of the test, fetch the named javascript variable from the page.
+//
+// --jsvar_output=<filepath>
+// Write the value of the variable named by '--jsvar' to a file at the given
+// path.
+TEST_F(UrlFetchTest, UrlFetch) {
+ const CommandLine *cmdLine = CommandLine::ForCurrentProcess();
+
+ if (!cmdLine->HasSwitch(L"url")) {
+ return;
+ }
+
+ std::string cookieName =
+ WideToASCII(cmdLine->GetSwitchValue(L"wait_cookie_name"));
+ std::string cookieValue =
+ WideToASCII(cmdLine->GetSwitchValue(L"wait_cookie_value"));
+
+ std::wstring jsvar = cmdLine->GetSwitchValue(L"jsvar");
+
+ UrlFetchTestResult result;
+ RunTest(GURL(cmdLine->GetSwitchValue(L"url")),
+ cookieName.length() > 0 ? cookieName.c_str() : NULL,
+ cookieValue.length() > 0 ? cookieValue.c_str() : NULL,
+ jsvar.length() > 0 ? jsvar.c_str() : NULL,
+ &result);
+
+ // Write out the cookie if requested
+ std::wstring cookieOutputPath =
+ cmdLine->GetSwitchValue(L"wait_cookie_output");
+ if (cookieOutputPath.length() > 0) {
+ ASSERT_TRUE(writeValueToFile(result.cookie_value, cookieOutputPath));
+ }
+
+ // Write out the JS Variable if requested
+ std::wstring jsvarOutputPath = cmdLine->GetSwitchValue(L"jsvar_output");
+ if (jsvarOutputPath.length() > 0) {
+ ASSERT_TRUE(writeValueToFile(result.javascript_variable, jsvarOutputPath));
+ }
+}
diff --git a/chrome/test/url_fetch_test/url_fetch_test.vcproj b/chrome/test/url_fetch_test/url_fetch_test.vcproj
new file mode 100644
index 0000000..a704ff0
--- /dev/null
+++ b/chrome/test/url_fetch_test/url_fetch_test.vcproj
@@ -0,0 +1,216 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="url_fetch_test"
+ ProjectGUID="{7EFD0C91-198E-4043-9E71-4A4C7879B929}"
+ RootNamespace="url_fetch_test"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(SolutionDir)..\build\common.vsprops;$(SolutionDir)..\build\debug.vsprops;..\..\tools\build\win\precompiled_wtl.vsprops;$(SolutionDir)..\third_party\libxml\build\using_libxml.vsprops;$(SolutionDir)..\third_party\libxslt\build\using_libxslt.vsprops;..\..\tools\build\win\unit_test.vsprops;..\..\tools\build\win\ui_test.vsprops;..\..\tools\build\win\test_memory_usage.vsprops;$(SolutionDir)..\skia\using_skia.vsprops;$(SolutionDir)..\third_party\icu38\build\using_icu.vsprops;$(SolutionDir)\tools\build\win\js_engine.vsprops;$(SolutionDir)..\testing\using_gtest.vsprops"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories="&quot;$(OutDir)\obj\generated_resources&quot;"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ ConfigurationType="1"
+ InheritedPropertySheets="$(SolutionDir)..\build\common.vsprops;$(SolutionDir)..\build\release.vsprops;$(SolutionDir)..\third_party\libxml\build\using_libxml.vsprops;$(SolutionDir)..\third_party\libxslt\build\using_libxslt.vsprops;..\..\tools\build\win\unit_test.vsprops;..\..\tools\build\win\ui_test.vsprops;$(SolutionDir)..\skia\using_skia.vsprops;$(SolutionDir)..\third_party\icu38\build\using_icu.vsprops;$(SolutionDir)\tools\build\win\js_engine.vsprops;$(SolutionDir)..\testing\using_gtest.vsprops"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories="&quot;$(OutDir)\obj\generated_resources&quot;"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="winmm.lib"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Common"
+ >
+ <File
+ RelativePath="..\ui\npapi_test_helper.cc"
+ >
+ </File>
+ <File
+ RelativePath="..\ui\npapi_test_helper.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\tools\build\win\precompiled_wtl.cc"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="1"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\..\tools\build\win\precompiled_wtl.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ui\run_all_unittests.cc"
+ >
+ </File>
+ <File
+ RelativePath="..\testing_browser_process.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ui\ui_test.cc"
+ >
+ </File>
+ <File
+ RelativePath="..\ui\ui_test.h"
+ >
+ </File>
+ <File
+ RelativePath="..\ui\ui_test_suite.cc"
+ >
+ </File>
+ <File
+ RelativePath="..\ui\ui_test_suite.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\net\url_request\url_request_test_job.cc"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\net\url_request\url_request_test_job.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="TestUrlFetch"
+ >
+ <File
+ RelativePath="..\url_fetch_test\url_fetch_test.cc"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>