summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-27 18:46:33 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-27 18:46:33 +0000
commitfb9846b4550d2bc633824fcceb0d8ef89674ffc5 (patch)
tree830e3730989cb60a292571464d324f9c903765ee
parent43ceffd67ecabba9c9368b16e840f5bf37afac6b (diff)
downloadchromium_src-fb9846b4550d2bc633824fcceb0d8ef89674ffc5.zip
chromium_src-fb9846b4550d2bc633824fcceb0d8ef89674ffc5.tar.gz
chromium_src-fb9846b4550d2bc633824fcceb0d8ef89674ffc5.tar.bz2
Make AutomationProxyTest.NavigateToURLWithTimeout* tests not-flaky.
I used a mock url request job which is guaranteed to finish after the timeout the test uses. TEST=none http://crbug.com/16462 Review URL: http://codereview.chromium.org/155941 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21668 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/automation/automation_provider.cc2
-rw-r--r--chrome/browser/automation/url_request_mock_http_job.cc40
-rw-r--r--chrome/browser/automation/url_request_mock_http_job.h5
-rw-r--r--chrome/browser/automation/url_request_slow_http_job.cc58
-rw-r--r--chrome/browser/automation/url_request_slow_http_job.h41
-rw-r--r--chrome/chrome.gyp2
-rw-r--r--chrome/test/automation/automation_proxy_uitest.cc18
7 files changed, 148 insertions, 18 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 1ce2c87..2f74d23 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -24,6 +24,7 @@
#include "chrome/browser/automation/url_request_failed_dns_job.h"
#include "chrome/browser/automation/url_request_mock_http_job.h"
#include "chrome/browser/automation/url_request_slow_download_job.h"
+#include "chrome/browser/automation/url_request_slow_http_job.h"
#include "chrome/browser/blocked_popup_container.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_window.h"
@@ -2120,6 +2121,7 @@ class SetFilteredInetTask : public Task {
std::wstring root_http;
PathService::Get(chrome::DIR_TEST_DATA, &root_http);
URLRequestMockHTTPJob::AddUITestUrls(root_http);
+ URLRequestSlowHTTPJob::AddUITestUrls(root_http);
} else {
// Revert to the default handlers.
URLRequestFilter::GetInstance()->ClearHandlers();
diff --git a/chrome/browser/automation/url_request_mock_http_job.cc b/chrome/browser/automation/url_request_mock_http_job.cc
index 4bb191a..4d212a5 100644
--- a/chrome/browser/automation/url_request_mock_http_job.cc
+++ b/chrome/browser/automation/url_request_mock_http_job.cc
@@ -19,22 +19,8 @@ std::wstring URLRequestMockHTTPJob::base_path_ = L"";
/* static */
URLRequestJob* URLRequestMockHTTPJob::Factory(URLRequest* request,
const std::string& scheme) {
- std::wstring file_url(L"file:///");
- file_url += base_path_;
- const std::string& url = request->url().spec();
- // Fix up the url to be the file url we're loading from disk.
- std::string host_prefix("http://");
- host_prefix.append(kMockHostname);
- size_t host_prefix_len = host_prefix.length();
- if (url.compare(0, host_prefix_len, host_prefix.data(),
- host_prefix_len) == 0) {
- file_url += UTF8ToWide(url.substr(host_prefix_len));
- }
-
- // Convert the file:/// URL to a path on disk.
- FilePath file_path;
- net::FileURLToFilePath(GURL(WideToUTF8(file_url)), &file_path);
- return new URLRequestMockHTTPJob(request, file_path);
+ return new URLRequestMockHTTPJob(request,
+ GetOnDiskPath(base_path_, request, scheme));
}
/* static */
@@ -56,6 +42,28 @@ GURL URLRequestMockHTTPJob::GetMockUrl(const std::wstring& path) {
return GURL(url);
}
+/* static */
+FilePath URLRequestMockHTTPJob::GetOnDiskPath(const std::wstring& base_path,
+ URLRequest* request,
+ const std::string& scheme) {
+ std::wstring file_url(L"file:///");
+ file_url += base_path;
+ const std::string& url = request->url().spec();
+ // Fix up the url to be the file url we're loading from disk.
+ std::string host_prefix("http://");
+ host_prefix.append(kMockHostname);
+ size_t host_prefix_len = host_prefix.length();
+ if (url.compare(0, host_prefix_len, host_prefix.data(),
+ host_prefix_len) == 0) {
+ file_url += UTF8ToWide(url.substr(host_prefix_len));
+ }
+
+ // Convert the file:/// URL to a path on disk.
+ FilePath file_path;
+ net::FileURLToFilePath(GURL(WideToUTF8(file_url)), &file_path);
+ return file_path;
+}
+
URLRequestMockHTTPJob::URLRequestMockHTTPJob(URLRequest* request,
const FilePath& file_path)
: URLRequestFileJob(request, file_path) { }
diff --git a/chrome/browser/automation/url_request_mock_http_job.h b/chrome/browser/automation/url_request_mock_http_job.h
index a417c09..2a7de09 100644
--- a/chrome/browser/automation/url_request_mock_http_job.h
+++ b/chrome/browser/automation/url_request_mock_http_job.h
@@ -28,6 +28,11 @@ class URLRequestMockHTTPJob : public URLRequestFileJob {
// Given the path to a file relative to base_path_, construct a mock URL.
static GURL GetMockUrl(const std::wstring& path);
+ protected:
+ static FilePath GetOnDiskPath(const std::wstring& base_path,
+ URLRequest* request,
+ const std::string& scheme);
+
private:
void GetResponseInfoConst(net::HttpResponseInfo* info) const;
diff --git a/chrome/browser/automation/url_request_slow_http_job.cc b/chrome/browser/automation/url_request_slow_http_job.cc
new file mode 100644
index 0000000..30d9dfa
--- /dev/null
+++ b/chrome/browser/automation/url_request_slow_http_job.cc
@@ -0,0 +1,58 @@
+// 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 "chrome/browser/automation/url_request_slow_http_job.h"
+
+#include "base/platform_thread.h"
+#include "base/string_util.h"
+#include "base/time.h"
+#include "net/url_request/url_request_filter.h"
+
+static const char kMockHostname[] = "mock.slow.http";
+
+std::wstring URLRequestSlowHTTPJob::base_path_ = L"";
+
+// static
+const int URLRequestSlowHTTPJob::kDelayMs = 1000;
+
+using base::TimeDelta;
+
+/* static */
+URLRequestJob* URLRequestSlowHTTPJob::Factory(URLRequest* request,
+ const std::string& scheme) {
+ return new URLRequestSlowHTTPJob(request,
+ GetOnDiskPath(base_path_, request, scheme));
+}
+
+/* static */
+void URLRequestSlowHTTPJob::AddUITestUrls(const std::wstring& base_path) {
+ base_path_ = base_path;
+
+ // Add kMockHostname to URLRequestFilter.
+ URLRequestFilter* filter = URLRequestFilter::GetInstance();
+ filter->AddHostnameHandler("http", kMockHostname,
+ URLRequestSlowHTTPJob::Factory);
+}
+
+/* static */
+GURL URLRequestSlowHTTPJob::GetMockUrl(const std::wstring& path) {
+ std::string url = "http://";
+ url.append(kMockHostname);
+ url.append("/");
+ url.append(WideToUTF8(path));
+ return GURL(url);
+}
+
+URLRequestSlowHTTPJob::URLRequestSlowHTTPJob(URLRequest* request,
+ const FilePath& file_path)
+ : URLRequestMockHTTPJob(request, file_path) { }
+
+void URLRequestSlowHTTPJob::Start() {
+ delay_timer_.Start(TimeDelta::FromMilliseconds(kDelayMs), this,
+ &URLRequestSlowHTTPJob::RealStart);
+}
+
+void URLRequestSlowHTTPJob::RealStart() {
+ URLRequestMockHTTPJob::Start();
+}
diff --git a/chrome/browser/automation/url_request_slow_http_job.h b/chrome/browser/automation/url_request_slow_http_job.h
new file mode 100644
index 0000000..6048287
--- /dev/null
+++ b/chrome/browser/automation/url_request_slow_http_job.h
@@ -0,0 +1,41 @@
+// 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.
+//
+// A URLRequestMockHTTPJob class that inserts a time delay in processing.
+
+#ifndef CHROME_BROWSER_AUTOMATION_URL_REQUEST_SLOW_HTTP_JOB_H_
+#define CHROME_BROWSER_AUTOMATION_URL_REQUEST_SLOW_HTTP_JOB_H_
+
+#include <string>
+
+#include "base/timer.h"
+#include "chrome/browser/automation/url_request_mock_http_job.h"
+
+class URLRequestSlowHTTPJob : public URLRequestMockHTTPJob {
+ public:
+ URLRequestSlowHTTPJob(URLRequest* request, const FilePath& file_path);
+
+ static const int kDelayMs;
+
+ static URLRequest::ProtocolFactory Factory;
+
+ // For UI tests: adds the testing URLs to the URLRequestFilter.
+ static void AddUITestUrls(const std::wstring& base_path);
+
+ // Given the path to a file relative to base_path_, construct a mock URL.
+ static GURL GetMockUrl(const std::wstring& path);
+
+ virtual void Start();
+
+ private:
+ void RealStart();
+
+ base::OneShotTimer<URLRequestSlowHTTPJob> delay_timer_;
+
+ // This is the file path leading to the root of the directory to use as the
+ // root of the http server.
+ static std::wstring base_path_;
+};
+
+# endif // CHROME_BROWSER_AUTOMATION_URL_REQUEST_SLOW_HTTP_JOB_H_
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index f404291..6d5e032 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -644,6 +644,8 @@
'browser/automation/url_request_mock_http_job.h',
'browser/automation/url_request_slow_download_job.cc',
'browser/automation/url_request_slow_download_job.h',
+ 'browser/automation/url_request_slow_http_job.cc',
+ 'browser/automation/url_request_slow_http_job.h',
'browser/back_forward_menu_model.cc',
'browser/back_forward_menu_model.h',
'browser/back_forward_menu_model_views.cc',
diff --git a/chrome/test/automation/automation_proxy_uitest.cc b/chrome/test/automation/automation_proxy_uitest.cc
index 5739ca5..943d90c 100644
--- a/chrome/test/automation/automation_proxy_uitest.cc
+++ b/chrome/test/automation/automation_proxy_uitest.cc
@@ -12,6 +12,7 @@
#include "base/string_util.h"
#include "build/build_config.h"
#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/browser/automation/url_request_slow_http_job.h"
#include "chrome/browser/view_ids.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
@@ -287,6 +288,14 @@ TEST_F(AutomationProxyTest, NavigateToURLWithTimeout1) {
std::wstring title;
ASSERT_TRUE(tab->GetTabTitle(&title));
ASSERT_STREQ(L"Title Of Awesomeness", title.c_str());
+
+ // Use timeout high enough to allow the browser to create a url request job.
+ const int kLowTimeoutMs = 250;
+ ASSERT_GE(URLRequestSlowHTTPJob::kDelayMs, kLowTimeoutMs);
+ tab->NavigateToURLWithTimeout(
+ URLRequestSlowHTTPJob::GetMockUrl(filename.ToWStringHack()),
+ kLowTimeoutMs, &is_timeout);
+ ASSERT_TRUE(is_timeout);
}
TEST_F(AutomationProxyTest, NavigateToURLWithTimeout2) {
@@ -299,8 +308,13 @@ TEST_F(AutomationProxyTest, NavigateToURLWithTimeout2) {
filename1 = filename1.AppendASCII("title1.html");
bool is_timeout;
- tab->NavigateToURLWithTimeout(net::FilePathToFileURL(filename1),
- 1, &is_timeout);
+
+ // Use timeout high enough to allow the browser to create a url request job.
+ const int kLowTimeoutMs = 250;
+ ASSERT_GE(URLRequestSlowHTTPJob::kDelayMs, kLowTimeoutMs);
+ tab->NavigateToURLWithTimeout(
+ URLRequestSlowHTTPJob::GetMockUrl(filename1.ToWStringHack()),
+ kLowTimeoutMs, &is_timeout);
ASSERT_TRUE(is_timeout);
FilePath filename2(test_data_directory_);