summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-22 19:49:29 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-22 19:49:29 +0000
commit93389a1ddac1ff5d3cb885eb2ab2a914b4fbe019 (patch)
treeafa311727466e89e38641c65ed2c17cb23009582 /chrome
parenta6a0a45aad69cb69169134a1ef21bc745f2057b9 (diff)
downloadchromium_src-93389a1ddac1ff5d3cb885eb2ab2a914b4fbe019.zip
chromium_src-93389a1ddac1ff5d3cb885eb2ab2a914b4fbe019.tar.gz
chromium_src-93389a1ddac1ff5d3cb885eb2ab2a914b4fbe019.tar.bz2
Makes WebUI pages return a status code of 200 instead of 0.
BUG=none TEST=none Review URL: http://codereview.chromium.org/6675016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79021 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/ui/webui/chrome_url_data_manager_backend.cc20
-rw-r--r--chrome/browser/ui/webui/chrome_url_data_manager_browsertest.cc56
-rw-r--r--chrome/chrome_tests.gypi1
3 files changed, 73 insertions, 4 deletions
diff --git a/chrome/browser/ui/webui/chrome_url_data_manager_backend.cc b/chrome/browser/ui/webui/chrome_url_data_manager_backend.cc
index f9e1de2..abd7927 100644
--- a/chrome/browser/ui/webui/chrome_url_data_manager_backend.cc
+++ b/chrome/browser/ui/webui/chrome_url_data_manager_backend.cc
@@ -22,6 +22,7 @@
#include "grit/platform_locale_settings.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
+#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_file_job.h"
#include "net/url_request/url_request_job.h"
@@ -70,10 +71,13 @@ class URLRequestChromeJob : public net::URLRequestJob {
explicit URLRequestChromeJob(net::URLRequest* request);
// net::URLRequestJob implementation.
- virtual void Start();
- virtual void Kill();
- virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read);
- virtual bool GetMimeType(std::string* mime_type) const;
+ virtual void Start() OVERRIDE;
+ virtual void Kill() OVERRIDE;
+ virtual bool ReadRawData(net::IOBuffer* buf,
+ int buf_size,
+ int *bytes_read) OVERRIDE;
+ virtual bool GetMimeType(std::string* mime_type) const OVERRIDE;
+ virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE;
// Called by ChromeURLDataManager to notify us that the data blob is ready
// for us.
@@ -302,6 +306,14 @@ bool URLRequestChromeJob::GetMimeType(std::string* mime_type) const {
return !mime_type_.empty();
}
+void URLRequestChromeJob::GetResponseInfo(net::HttpResponseInfo* info) {
+ DCHECK(!info->headers);
+ // Set the headers so that requests serviced by ChromeURLDataManager return a
+ // status code of 200. Without this they return a 0, which makes the status
+ // indistiguishable from other error types. Instant relies on getting a 200.
+ info->headers = new net::HttpResponseHeaders("HTTP/1.1 200 OK");
+}
+
void URLRequestChromeJob::DataAvailable(RefCountedMemory* bytes) {
if (bytes) {
// The request completed, and we have all the data.
diff --git a/chrome/browser/ui/webui/chrome_url_data_manager_browsertest.cc b/chrome/browser/ui/webui/chrome_url_data_manager_browsertest.cc
new file mode 100644
index 0000000..b1625e0
--- /dev/null
+++ b/chrome/browser/ui/webui/chrome_url_data_manager_browsertest.cc
@@ -0,0 +1,56 @@
+// 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 "chrome/test/in_process_browser_test.h"
+#include "chrome/test/ui_test_utils.h"
+#include "chrome/common/url_constants.h"
+#include "content/browser/tab_contents/navigation_controller.h"
+#include "content/common/notification_registrar.h"
+#include "content/common/notification_service.h"
+#include "content/common/notification_source.h"
+
+namespace {
+
+class NavigationNotificationObserver : public NotificationObserver {
+ public:
+ NavigationNotificationObserver()
+ : got_navigation_(false),
+ http_status_code_(0) {
+ registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
+ NotificationService::AllSources());
+ }
+
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) OVERRIDE {
+ DCHECK_EQ(NotificationType::NAV_ENTRY_COMMITTED, type.value);
+ got_navigation_ = true;
+ http_status_code_ =
+ Details<NavigationController::LoadCommittedDetails>(details)->
+ http_status_code;
+ }
+
+ int http_status_code() const { return http_status_code_; }
+ bool got_navigation() const { return got_navigation_; }
+
+ private:
+ NotificationRegistrar registrar_;
+ int got_navigation_;
+ int http_status_code_;
+
+ DISALLOW_COPY_AND_ASSIGN(NavigationNotificationObserver);
+};
+
+} // namespace
+
+typedef InProcessBrowserTest ChromeURLDataManagerTest;
+
+// Makes sure navigating to the new tab page results in a http status code
+// of 200.
+IN_PROC_BROWSER_TEST_F(ChromeURLDataManagerTest, 200) {
+ NavigationNotificationObserver observer;
+ ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL));
+ EXPECT_TRUE(observer.got_navigation());
+ EXPECT_EQ(200, observer.http_status_code());
+}
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 1a3f1dc..7a00a96 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -2285,6 +2285,7 @@
'browser/ui/views/browser_actions_container_browsertest.cc',
'browser/ui/views/dom_view_browsertest.cc',
'browser/ui/views/html_dialog_view_browsertest.cc',
+ 'browser/ui/webui/chrome_url_data_manager_browsertest.cc',
'browser/ui/webui/file_browse_browsertest.cc',
'browser/ui/webui/mediaplayer_browsertest.cc',
'browser/ui/webui/settings_browsertest.cc',