diff options
author | tommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-06 00:19:53 +0000 |
---|---|---|
committer | tommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-06 00:19:53 +0000 |
commit | 74dd1e844ad0f2e46f177d70a3b0c5c0b6a8a2dc (patch) | |
tree | b748f163082aef54ce9c98ded0eb27f4372d75dc /chrome_frame | |
parent | a3354454938083e933e2c988777a1c53d94b4277 (diff) | |
download | chromium_src-74dd1e844ad0f2e46f177d70a3b0c5c0b6a8a2dc.zip chromium_src-74dd1e844ad0f2e46f177d70a3b0c5c0b6a8a2dc.tar.gz chromium_src-74dd1e844ad0f2e46f177d70a3b0c5c0b6a8a2dc.tar.bz2 |
A new unit test for the latest issue with switching renderers.
This affects both the httpequiv and IInternetProtocol mechanisms we've been using.
The problem is going from mshtml to a CF page via POST. In this case the original
POST request is issued once, but then a subsequent GET is issued for the same URL.
On top of that, the referrer is missing.
TEST=This test is disabled for now.
BUG=none
Review URL: http://codereview.chromium.org/580001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38282 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame')
-rw-r--r-- | chrome_frame/test/data/full_tab_post_mshtml.html | 25 | ||||
-rw-r--r-- | chrome_frame/test/data/full_tab_post_target_cf.html | 23 | ||||
-rw-r--r-- | chrome_frame/test/test_server.cc | 28 | ||||
-rw-r--r-- | chrome_frame/test/test_server.h | 36 | ||||
-rw-r--r-- | chrome_frame/test/test_server_test.cc | 2 | ||||
-rw-r--r-- | chrome_frame/test/test_with_web_server.cc | 60 |
6 files changed, 151 insertions, 23 deletions
diff --git a/chrome_frame/test/data/full_tab_post_mshtml.html b/chrome_frame/test/data/full_tab_post_mshtml.html new file mode 100644 index 0000000..48e506e --- /dev/null +++ b/chrome_frame/test/data/full_tab_post_mshtml.html @@ -0,0 +1,25 @@ +<html> + <head> + <title>FullTab mode POST test</title> + </head> + + <script type="text/javascript" src="chrome_frame_tester_helpers.js"></script> + + <script type="text/javascript"> + function onLoad() { + if (isRunningInChrome()) { + location.href = "/quit?unexpectedly_running_in_chrome";
+ } else {
+ document.getElementById("myform").submit(); + } + } + </script> + + <body onload="onLoad();"> + <form id="myform" action="full_tab_post_target_cf.html" method="POST"> + Field nr 1: <input type="text" name="field1" value="test1"/><br/> + Field nr 2: <input type="text" name="field1" value="test2"/><br/> + <input type="submit" value="Submit"/> + </form> + </body> +</html> diff --git a/chrome_frame/test/data/full_tab_post_target_cf.html b/chrome_frame/test/data/full_tab_post_target_cf.html new file mode 100644 index 0000000..30601b4 --- /dev/null +++ b/chrome_frame/test/data/full_tab_post_target_cf.html @@ -0,0 +1,23 @@ +<html> + <head> + <meta http-equiv="x-ua-compatible" content="chrome=1" /> + <title>FullTab mode POST test</title> + </head> + + <script type="text/javascript" + src="chrome_frame_tester_helpers.js"></script> + + <script type="text/javascript"> + function onLoad() { + if (!isRunningInChrome()) { + location.href = "/quit?not_running_in_chrome"; + return; + } + location.href = "/quit?OK"; + } + </script> + + <body onload="onLoad();"> + This page should be rendered in chrome. + </body> +</html> diff --git a/chrome_frame/test/test_server.cc b/chrome_frame/test/test_server.cc index 79ea2cf..ce096aa 100644 --- a/chrome_frame/test/test_server.cc +++ b/chrome_frame/test/test_server.cc @@ -22,6 +22,8 @@ const char kStatusNotFound[] = "404 Not Found"; const char kDefaultContentType[] = "text/html; charset=UTF-8"; void Request::ParseHeaders(const std::string& headers) { + DCHECK(method_.length() == 0); + size_t pos = headers.find("\r\n"); DCHECK(pos != std::string::npos); if (pos != std::string::npos) { @@ -47,24 +49,19 @@ void Request::ParseHeaders(const std::string& headers) { } } -bool Connection::CheckRequestReceived() { - bool ready = false; - if (request_.method().length()) { - // Headers have already been parsed. Just check content length. - ready = (data_.size() >= request_.content_length()); - } else { - size_t index = data_.find("\r\n\r\n"); +void Request::OnDataReceived(const std::string& data) { + content_ += data; + + if (method_.length() == 0) { + size_t index = content_.find("\r\n\r\n"); if (index != std::string::npos) { // Parse the headers before returning and chop them of the // data buffer we've already received. - std::string headers(data_.substr(0, index + 2)); - request_.ParseHeaders(headers); - data_.erase(0, index + 4); - ready = (data_.size() >= request_.content_length()); + std::string headers(content_.substr(0, index + 2)); + ParseHeaders(headers); + content_.erase(0, index + 4); } } - - return ready; } bool FileResponse::GetContentType(std::string* content_type) const { @@ -169,8 +166,9 @@ void SimpleWebServer::DidRead(ListenSocket* connection, const std::string& data) { Connection* c = FindConnection(connection); DCHECK(c); - c->AddData(data); - if (c->CheckRequestReceived()) { + Request& r = c->request(); + r.OnDataReceived(data); + if (r.AllContentReceived()) { const Request& request = c->request(); Response* response = FindResponse(request); if (response) { diff --git a/chrome_frame/test/test_server.h b/chrome_frame/test/test_server.h index 896b2b3..1e61b7b 100644 --- a/chrome_frame/test/test_server.h +++ b/chrome_frame/test/test_server.h @@ -59,19 +59,40 @@ class Request { return path_; } + // Returns the argument section of a GET path. + // Note: does currently not work for POST request. + std::string arguments() const { + std::string ret; + std::string::size_type pos = path_.find('?'); + if (pos != std::string::npos) + ret = path_.substr(pos + 1); + return ret; + } + const std::string& headers() const { return headers_; } + const std::string& content() const { + return content_; + } + size_t content_length() const { return content_length_; } + bool AllContentReceived() const { + return method_.length() && content_.size() >= content_length_; + } + + void OnDataReceived(const std::string& data); + protected: std::string method_; std::string path_; std::string version_; std::string headers_; + std::string content_; size_t content_length_; private: @@ -94,19 +115,16 @@ class Connection { return socket_ == socket; } - void AddData(const std::string& data) { - data_ += data; + const Request& request() const { + return request_; } - bool CheckRequestReceived(); - - const Request& request() const { + Request& request() { return request_; } protected: scoped_refptr<ListenSocket> socket_; - std::string data_; Request request_; private: @@ -170,7 +188,11 @@ class ResponseForPath : public Response { } virtual bool Matches(const Request& r) const { - return r.path().compare(request_path_) == 0; + std::string path = r.path(); + std::string::size_type pos = path.find('?'); + if (pos != std::string::npos) + path = path.substr(0, pos); + return path.compare(request_path_) == 0; } protected: diff --git a/chrome_frame/test/test_server_test.cc b/chrome_frame/test/test_server_test.cc index 902eb0c..bd5c0c3 100644 --- a/chrome_frame/test/test_server_test.cc +++ b/chrome_frame/test/test_server_test.cc @@ -147,7 +147,7 @@ void QuitMessageLoop(QuitMessageHit* msg) { } // end namespace -TEST_F(TestServerTest, DISABLED_TestServer) { +TEST_F(TestServerTest, TestServer) { // The web server needs a loop to exist on this thread during construction // the loop must be created before we construct the server. MessageLoopForUI loop; diff --git a/chrome_frame/test/test_with_web_server.cc b/chrome_frame/test/test_with_web_server.cc index ddefb00..5ae8ac9 100644 --- a/chrome_frame/test/test_with_web_server.cc +++ b/chrome_frame/test/test_with_web_server.cc @@ -9,6 +9,7 @@ #include "chrome/installer/util/helper.h" #include "chrome_frame/utils.h" #include "chrome_frame/test/chrome_frame_test_utils.h" +#include "chrome_frame/test/test_server.h" const wchar_t kDocRoot[] = L"chrome_frame\\test\\data"; const int kLongWaitTimeout = 60 * 1000; @@ -825,3 +826,62 @@ TEST_F(ChromeFrameTestWithWebServer, ASSERT_TRUE(CheckResultFile(L"FullTab_AnchorURLNavigateTest", "OK")); } +// DISABLED as it currently fails for both approaches for switching +// renderers (httpequiv and IInternetProtocol). +// TODO(tommi): Enable this test once the issue has been fixed. +TEST_F(ChromeFrameTestWithWebServer, DISABLED_FullTabModeIE_TestPostReissue) { + // Test whether POST-ing a form from an mshtml page to a CF page will cause + // the request to get reissued. It should not. + + + FilePath source_path; + PathService::Get(base::DIR_SOURCE_ROOT, &source_path); + source_path = source_path.Append(FILE_PATH_LITERAL("chrome_frame")) + .Append(FILE_PATH_LITERAL("test")) + .Append(FILE_PATH_LITERAL("data")); + + // The order of pages in this array is assumed to be mshtml, cf, script. + const wchar_t* kPages[] = { + L"full_tab_post_mshtml.html", + L"full_tab_post_target_cf.html", + L"chrome_frame_tester_helpers.js", + }; + + scoped_ptr<test_server::FileResponse> responses[arraysize(kPages)]; + + MessageLoopForUI loop; // must come before the server. + test_server::SimpleWebServer server(46664); + + for (int i = 0; i < arraysize(kPages); ++i) { + responses[i].reset(new test_server::FileResponse( + StringPrintf("/%ls", kPages[i]).c_str(), + source_path.Append(kPages[i]))); + server.AddResponse(responses[i].get()); + } + + ASSERT_TRUE(LaunchBrowser(IE, + StringPrintf(L"http://localhost:46664/%ls", kPages[0]).c_str())); + + loop.MessageLoop::Run(); + + // Check if the last request to /quit gave us the OK signal. + const test_server::ConnectionList& connections = server.connections(); + const test_server::Connection* c = connections.back(); + EXPECT_EQ("OK", c->request().arguments()); + + if (c->request().arguments().compare("OK") == 0) { + // Check how many requests we got for the cf page. + test_server::ConnectionList::const_iterator it; + int requests_for_cf_page = 0; + for (it = connections.begin(); it != connections.end(); ++it) { + c = (*it); + const test_server::Request& r = c->request(); + if (ASCIIToWide(r.path().substr(1)).compare(kPages[1]) == 0) { + EXPECT_EQ("POST", r.method()); + requests_for_cf_page++; + } + } + EXPECT_EQ(1, requests_for_cf_page); + } +} + |