diff options
author | tommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-25 00:10:51 +0000 |
---|---|---|
committer | tommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-25 00:10:51 +0000 |
commit | c01e3e3998b597e95617d8721593841c0ff5be3d (patch) | |
tree | 8cfab975ccdc929a91ec4ccec02dbf783fc3858d /chrome_frame/test | |
parent | f84233c60d5c6d64abd253cc5c9fd61b6381d3cc (diff) | |
download | chromium_src-c01e3e3998b597e95617d8721593841c0ff5be3d.zip chromium_src-c01e3e3998b597e95617d8721593841c0ff5be3d.tar.gz chromium_src-c01e3e3998b597e95617d8721593841c0ff5be3d.tar.bz2 |
Unit test for the multiple request issues we've been seeing.
The test is disabled until we fix the actual problem.
TEST=n/a
BUG=33332
Review URL: http://codereview.chromium.org/661017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39954 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/test')
-rw-r--r-- | chrome_frame/test/data/full_tab_get_mshtml.html | 21 | ||||
-rw-r--r-- | chrome_frame/test/data/full_tab_get_target_cf.html | 23 | ||||
-rw-r--r-- | chrome_frame/test/test_server.cc | 11 | ||||
-rw-r--r-- | chrome_frame/test/test_server.h | 10 | ||||
-rw-r--r-- | chrome_frame/test/test_with_web_server.cc | 83 | ||||
-rw-r--r-- | chrome_frame/test/test_with_web_server.h | 65 |
6 files changed, 178 insertions, 35 deletions
diff --git a/chrome_frame/test/data/full_tab_get_mshtml.html b/chrome_frame/test/data/full_tab_get_mshtml.html new file mode 100644 index 0000000..b5e3242 --- /dev/null +++ b/chrome_frame/test/data/full_tab_get_mshtml.html @@ -0,0 +1,21 @@ +<html> + <head> + <title>FullTab mode GET 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("clickme").click(); + } + } + </script> + + <body onload="onLoad();"> + <a href="full_tab_get_target_cf.html" id="clickme">Click me!</a> + </body> +</html> diff --git a/chrome_frame/test/data/full_tab_get_target_cf.html b/chrome_frame/test/data/full_tab_get_target_cf.html new file mode 100644 index 0000000..a5e4b25 --- /dev/null +++ b/chrome_frame/test/data/full_tab_get_target_cf.html @@ -0,0 +1,23 @@ +<html> + <head> + <meta http-equiv="x-ua-compatible" content="chrome=1" /> + <title>FullTab mode GET 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 ce096aa..79950e9 100644 --- a/chrome_frame/test/test_server.cc +++ b/chrome_frame/test/test_server.cc @@ -127,7 +127,7 @@ SimpleWebServer::SimpleWebServer(int port) { SimpleWebServer::~SimpleWebServer() { ConnectionList::const_iterator it; - for (it = connections_.begin(); it != connections_.end(); it++) + for (it = connections_.begin(); it != connections_.end(); ++it) delete (*it); connections_.clear(); } @@ -136,6 +136,15 @@ void SimpleWebServer::AddResponse(Response* response) { responses_.push_back(response); } +void SimpleWebServer::DeleteAllResponses() { + std::list<Response*>::const_iterator it; + for (it = responses_.begin(); it != responses_.end(); ++it) { + if ((*it) != &quit_) + delete (*it); + } + connections_.clear(); +} + Response* SimpleWebServer::FindResponse(const Request& request) const { std::list<Response*>::const_iterator it; for (it = responses_.begin(); it != responses_.end(); it++) { diff --git a/chrome_frame/test/test_server.h b/chrome_frame/test/test_server.h index 1e61b7b..462d7aa 100644 --- a/chrome_frame/test/test_server.h +++ b/chrome_frame/test/test_server.h @@ -278,12 +278,20 @@ class SimpleWebServer : public ListenSocket::ListenSocketDelegate { void AddResponse(Response* response); + // Ownership of response objects is by default assumed to be outside + // of the SimpleWebServer class. + // However, if the caller doesn't wish to maintain a list of response objects + // but rather let this class hold the only references to those objects, + // the caller can call this method to delete the objects as part of + // the cleanup process. + void DeleteAllResponses(); + // ListenSocketDelegate overrides. virtual void DidAccept(ListenSocket* server, ListenSocket* connection); virtual void DidRead(ListenSocket* connection, const std::string& data); virtual void DidClose(ListenSocket* sock); - const ConnectionList& connections() { + const ConnectionList& connections() const { return connections_; } diff --git a/chrome_frame/test/test_with_web_server.cc b/chrome_frame/test/test_with_web_server.cc index 52d6518..74f0d65 100644 --- a/chrome_frame/test/test_with_web_server.cc +++ b/chrome_frame/test/test_with_web_server.cc @@ -9,7 +9,6 @@ #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; @@ -50,6 +49,11 @@ void ChromeFrameTestWithWebServer::SetUp() { // Make sure that we are not accidently enabling gcf protocol. SetConfigBool(kEnableGCFProtocol, false); + PathService::Get(base::DIR_SOURCE_ROOT, &test_file_path_); + test_file_path_ = test_file_path_.Append(FILE_PATH_LITERAL("chrome_frame")) + .Append(FILE_PATH_LITERAL("test")) + .Append(FILE_PATH_LITERAL("data")); + server_.SetUp(); results_dir_ = server_.GetDataDir(); file_util::AppendToPath(&results_dir_, L"dump"); @@ -776,11 +780,8 @@ TEST_F(ChromeFrameTestWithWebServer, 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")); + + MessageLoopForUI loop; // must come before the server. // The order of pages in this array is assumed to be mshtml, cf, script. const wchar_t* kPages[] = { @@ -789,41 +790,57 @@ TEST_F(ChromeFrameTestWithWebServer, DISABLED_FullTabModeIE_TestPostReissue) { L"chrome_frame_tester_helpers.js", }; - scoped_ptr<test_server::FileResponse> responses[arraysize(kPages)]; + SimpleWebServerTest server(46664); + server.PopulateStaticFileList(kPages, arraysize(kPages), GetCFTestFilePath()); - MessageLoopForUI loop; // must come before the server. - test_server::SimpleWebServer server(46664); + ASSERT_TRUE(LaunchBrowser(IE, server.FormatHttpPath(kPages[0]).c_str())); + + loop.MessageLoop::Run(); - 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()); + // Check if the last request to /quit gave us the OK signal. + const test_server::Request& r = server.last_request(); + EXPECT_EQ("OK", r.arguments()); + + if (r.arguments().compare("OK") == 0) { + // Check how many requests we got for the cf page. Also expect it to be + // a POST. + int requests = server.GetRequestCountForPage(kPages[1], "POST"); + EXPECT_EQ(1, requests); } +} - ASSERT_TRUE(LaunchBrowser(IE, - StringPrintf(L"http://localhost:46664/%ls", kPages[0]).c_str())); +// 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_TestMultipleGet) { + // Test whether following a link from an mshtml page to a CF page will cause + // multiple network requests. It should not. + + MessageLoopForUI loop; // must come before the server. + + // The order of pages in this array is assumed to be mshtml, cf, script. + const wchar_t* kPages[] = { + L"full_tab_get_mshtml.html", + L"full_tab_get_target_cf.html", + L"chrome_frame_tester_helpers.js", + }; + + SimpleWebServerTest server(46664); + server.PopulateStaticFileList(kPages, arraysize(kPages), GetCFTestFilePath()); + + ASSERT_TRUE(LaunchBrowser(IE, server.FormatHttpPath(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); + const test_server::Request& r = server.last_request(); + EXPECT_EQ("OK", r.arguments()); + + if (r.arguments().compare("OK") == 0) { + // Check how many requests we got for the cf page and check that it was + // a GET. + int requests = server.GetRequestCountForPage(kPages[1], "GET"); + EXPECT_EQ(1, requests); } } diff --git a/chrome_frame/test/test_with_web_server.h b/chrome_frame/test/test_with_web_server.h index baf3471..d68a6b3 100644 --- a/chrome_frame/test/test_with_web_server.h +++ b/chrome_frame/test/test_with_web_server.h @@ -8,6 +8,7 @@ #include <string> #include "chrome_frame/test/http_server.h" +#include "chrome_frame/test/test_server.h" #include "testing/gtest/include/gtest/gtest.h" // Include without path to make GYP build see it. @@ -61,6 +62,10 @@ class ChromeFrameTestWithWebServer: public testing::Test { bool CheckResultFile(const std::wstring& file_name, const std::string& expected_result); + const FilePath& GetCFTestFilePath() { + return test_file_path_; + } + virtual void SetUp(); virtual void TearDown(); @@ -88,6 +93,66 @@ class ChromeFrameTestWithWebServer: public testing::Test { std::wstring results_dir_; ScopedHandle browser_handle_; ChromeFrameHTTPServer server_; + // The on-disk path to our html test files. + FilePath test_file_path_; +}; + +// A helper class for doing some bookkeeping when using the +// SimpleWebServer class. +class SimpleWebServerTest { + public: + SimpleWebServerTest(int port) : server_(port), port_(port) { + } + + ~SimpleWebServerTest() { + server_.DeleteAllResponses(); + } + + void PopulateStaticFileList(const wchar_t* pages[], int count, + const FilePath& directory) { + for (int i = 0; i < count; ++i) { + server_.AddResponse(new test_server::FileResponse( + StringPrintf("/%ls", pages[i]).c_str(), directory.Append(pages[i]))); + } + } + + std::wstring FormatHttpPath(const wchar_t* document_path) { + return StringPrintf(L"http://localhost:%i/%ls", port_, document_path); + } + + // Returns the last client request object. + // Under normal circumstances this will be the request for /quit. + const test_server::Request& last_request() const { + const test_server::ConnectionList& connections = server_.connections(); + DCHECK(connections.size()); + const test_server::Connection* c = connections.back(); + return c->request(); + } + + // Counts the number of times a page was requested. + // Optionally checks if the request method for each is equal to + // |expected_method|. If expected_method is NULL no such check is made. + int GetRequestCountForPage(const wchar_t* page, const char* expected_method) { + // Check how many requests we got for the cf page. + test_server::ConnectionList::const_iterator it; + int requests = 0; + const test_server::ConnectionList& connections = server_.connections(); + for (it = connections.begin(); it != connections.end(); ++it) { + const test_server::Connection* c = (*it); + const test_server::Request& r = c->request(); + if (ASCIIToWide(r.path().substr(1)).compare(page) == 0) { + if (expected_method) { + EXPECT_EQ(expected_method, r.method()); + } + requests++; + } + } + return requests; + } + + protected: + test_server::SimpleWebServer server_; + int port_; }; #endif // CHROME_FRAME_TEST_WITH_WEB_SERVER_H_ |