summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--chrome/chrome.sln44
-rw-r--r--chrome/test/url_fetch_test/url_fetch_test.cc123
-rw-r--r--chrome/test/url_fetch_test/url_fetch_test.vcproj216
3 files changed, 383 insertions, 0 deletions
diff --git a/chrome/chrome.sln b/chrome/chrome.sln
index f5a9607..c1002d1 100644
--- a/chrome/chrome.sln
+++ b/chrome/chrome.sln
@@ -1693,6 +1693,41 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_support_base", "..\bas
Release.AspNetCompiler.Debug = "False"
EndProjectSection
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "url_fetch_test", "test\url_fetch_test\url_fetch_test.vcproj", "{7EFD0C91-198E-4043-9E71-4A4C7879B929}"
+ ProjectSection(WebsiteProperties) = preProject
+ Debug.AspNetCompiler.Debug = "True"
+ Release.AspNetCompiler.Debug = "False"
+ EndProjectSection
+ ProjectSection(ProjectDependencies) = postProject
+ {0D04AEC1-6B68-492C-BCCF-808DFD69ABC6} = {0D04AEC1-6B68-492C-BCCF-808DFD69ABC6}
+ {1556EF78-C7E6-43C8-951F-F6B43AC0DD12} = {1556EF78-C7E6-43C8-951F-F6B43AC0DD12}
+ {1832A374-8A74-4F9E-B536-69A699B3E165} = {1832A374-8A74-4F9E-B536-69A699B3E165}
+ {21E22961-22BF-4493-BD3A-868F93DA5179} = {21E22961-22BF-4493-BD3A-868F93DA5179}
+ {2A70CBF0-847E-4E3A-B926-542A656DC7FE} = {2A70CBF0-847E-4E3A-B926-542A656DC7FE}
+ {326E9795-E760-410A-B69A-3F79DB3F5243} = {326E9795-E760-410A-B69A-3F79DB3F5243}
+ {5BF908A7-68FB-4A4B-99E3-8C749F1FE4EA} = {5BF908A7-68FB-4A4B-99E3-8C749F1FE4EA}
+ {7100F41F-868D-4E99-80A2-AF8E6574749D} = {7100F41F-868D-4E99-80A2-AF8E6574749D}
+ {7B219FAA-E360-43C8-B341-804A94EEFFAC} = {7B219FAA-E360-43C8-B341-804A94EEFFAC}
+ {8423AF0D-4B88-4EBF-94E1-E4D00D00E21C} = {8423AF0D-4B88-4EBF-94E1-E4D00D00E21C}
+ {899F1280-3441-4D1F-BA04-CCD6208D9146} = {899F1280-3441-4D1F-BA04-CCD6208D9146}
+ {8C27D792-2648-4F5E-9ED0-374276327308} = {8C27D792-2648-4F5E-9ED0-374276327308}
+ {A28310B8-7BD0-4CDF-A7D8-59CAB42AA1C4} = {A28310B8-7BD0-4CDF-A7D8-59CAB42AA1C4}
+ {A493331B-3180-49FE-8D0E-D121645E63AD} = {A493331B-3180-49FE-8D0E-D121645E63AD}
+ {A508ADD3-CECE-4E0F-8448-2F5E454DF551} = {A508ADD3-CECE-4E0F-8448-2F5E454DF551}
+ {BE6D5659-A8D5-4890-A42C-090DD10EF62C} = {BE6D5659-A8D5-4890-A42C-090DD10EF62C}
+ {BFE8E2A7-3B3B-43B0-A994-3058B852DB8B} = {BFE8E2A7-3B3B-43B0-A994-3058B852DB8B}
+ {C564F145-9172-42C3-BFCB-6014CA97DBCD} = {C564F145-9172-42C3-BFCB-6014CA97DBCD}
+ {CAE2D1E6-3F19-492F-A35C-68AA7ACAD6D3} = {CAE2D1E6-3F19-492F-A35C-68AA7ACAD6D3}
+ {CD9CA56E-4E94-444C-87D4-58CA1E6F300D} = {CD9CA56E-4E94-444C-87D4-58CA1E6F300D}
+ {E750512D-FC7C-4C98-BF04-0A0DAF882055} = {E750512D-FC7C-4C98-BF04-0A0DAF882055}
+ {E7B11CF0-FE40-4A69-AE20-1B882F4D7585} = {E7B11CF0-FE40-4A69-AE20-1B882F4D7585}
+ {EC8B7909-62AF-470D-A75D-E1D89C837142} = {EC8B7909-62AF-470D-A75D-E1D89C837142}
+ {EF5E94AB-B646-4E5B-A058-52EF07B8351C} = {EF5E94AB-B646-4E5B-A058-52EF07B8351C}
+ {F54ABC59-5C00-414A-A9BA-BAF26D1699F0} = {F54ABC59-5C00-414A-A9BA-BAF26D1699F0}
+ {F9810DE8-CBC3-4605-A7B1-ECA2D5292FD7} = {F9810DE8-CBC3-4605-A7B1-ECA2D5292FD7}
+ {FA537565-7B03-4FFC-AF15-F7A979B72E22} = {FA537565-7B03-4FFC-AF15-F7A979B72E22}
+ EndProjectSection
+EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_worker", "test\worker\test_worker.vcproj", "{3E03D462-780D-4C4D-B22E-5E095E6CF110}"
ProjectSection(ProjectDependencies) = postProject
{1832A374-8A74-4F9E-B536-69A699B3E165} = {1832A374-8A74-4F9E-B536-69A699B3E165}
@@ -2284,6 +2319,14 @@ Global
{7EA8C4AB-F9C6-4FA1-8B0A-74F5650430B2}.Release|Mixed Platforms.Build.0 = Release|Win32
{7EA8C4AB-F9C6-4FA1-8B0A-74F5650430B2}.Release|Win32.ActiveCfg = Release|Win32
{7EA8C4AB-F9C6-4FA1-8B0A-74F5650430B2}.Release|Win32.Build.0 = Release|Win32
+ {7EFD0C91-198E-4043-9E71-4A4C7879B929}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
+ {7EFD0C91-198E-4043-9E71-4A4C7879B929}.Debug|Mixed Platforms.Build.0 = Debug|Win32
+ {7EFD0C91-198E-4043-9E71-4A4C7879B929}.Debug|Win32.ActiveCfg = Debug|Win32
+ {7EFD0C91-198E-4043-9E71-4A4C7879B929}.Debug|Win32.Build.0 = Debug|Win32
+ {7EFD0C91-198E-4043-9E71-4A4C7879B929}.Release|Mixed Platforms.ActiveCfg = Release|Win32
+ {7EFD0C91-198E-4043-9E71-4A4C7879B929}.Release|Mixed Platforms.Build.0 = Release|Win32
+ {7EFD0C91-198E-4043-9E71-4A4C7879B929}.Release|Win32.ActiveCfg = Release|Win32
+ {7EFD0C91-198E-4043-9E71-4A4C7879B929}.Release|Win32.Build.0 = Release|Win32
{7F0A70F6-BE3F-4C19-B435-956AB8F30BA4}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{7F0A70F6-BE3F-4C19-B435-956AB8F30BA4}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{7F0A70F6-BE3F-4C19-B435-956AB8F30BA4}.Debug|Win32.ActiveCfg = Debug|Win32
@@ -3115,6 +3158,7 @@ Global
{7D1EC571-687B-5D48-E259-C5BA78E717D0} = {846901FD-A619-4BD5-A303-38174730CDD6}
{7D456640-3619-4D23-A56D-E0084400CCBF} = {2325D8C4-8EF5-42AC-8900-492225750DE4}
{7EA8C4AB-F9C6-4FA1-8B0A-74F5650430B2} = {2325D8C4-8EF5-42AC-8900-492225750DE4}
+ {7EFD0C91-198E-4043-9E71-4A4C7879B929} = {1174D37F-6ABB-45DA-81B3-C631281273B7}
{7F0A70F6-BE3F-4C19-B435-956AB8F30BA4} = {1174D37F-6ABB-45DA-81B3-C631281273B7}
{80E37CB5-059D-4F4B-AEF6-08265468D368} = {2325D8C4-8EF5-42AC-8900-492225750DE4}
{82F5BFE5-FDCE-47D4-8B38-BEEBED561681} = {2325D8C4-8EF5-42AC-8900-492225750DE4}
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>