OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome_frame/test/test_with_web_server.h" | 5 #include "chrome_frame/test/test_with_web_server.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/file_version_info.h" | 8 #include "base/file_version_info.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "base/win_util.h" | 11 #include "base/win_util.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/installer/util/install_util.h" | 13 #include "chrome/installer/util/install_util.h" |
14 #include "chrome/installer/util/helper.h" | 14 #include "chrome/installer/util/helper.h" |
15 #include "chrome_frame/html_utils.h" | 15 #include "chrome_frame/html_utils.h" |
16 #include "chrome_frame/utils.h" | 16 #include "chrome_frame/utils.h" |
17 #include "chrome_frame/test/chrome_frame_test_utils.h" | 17 #include "chrome_frame/test/chrome_frame_test_utils.h" |
18 #include "chrome_frame/test/mock_ie_event_sink_actions.h" | 18 #include "chrome_frame/test/mock_ie_event_sink_actions.h" |
19 #include "net/base/mime_util.h" | 19 #include "net/base/mime_util.h" |
| 20 #include "net/http/http_util.h" |
20 | 21 |
21 using chrome_frame_test::kChromeFrameLongNavigationTimeoutInSeconds; | 22 using chrome_frame_test::kChromeFrameLongNavigationTimeoutInSeconds; |
22 using testing::_; | 23 using testing::_; |
23 using testing::StrCaseEq; | 24 using testing::StrCaseEq; |
24 | 25 |
25 const wchar_t kDocRoot[] = L"chrome_frame\\test\\data"; | 26 const wchar_t kDocRoot[] = L"chrome_frame\\test\\data"; |
26 const int kLongWaitTimeout = 15 * 1000; | 27 const int kLongWaitTimeout = 15 * 1000; |
27 const int kShortWaitTimeout = 5 * 1000; | 28 const int kShortWaitTimeout = 5 * 1000; |
28 | 29 |
29 namespace { | 30 namespace { |
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 } | 940 } |
940 | 941 |
941 // The order of pages in this array is assumed to be mshtml, cf, script. | 942 // The order of pages in this array is assumed to be mshtml, cf, script. |
942 const wchar_t* kPages[] = { | 943 const wchar_t* kPages[] = { |
943 L"full_tab_post_mshtml.html", | 944 L"full_tab_post_mshtml.html", |
944 L"full_tab_post_target_cf.html", | 945 L"full_tab_post_target_cf.html", |
945 L"chrome_frame_tester_helpers.js", | 946 L"chrome_frame_tester_helpers.js", |
946 }; | 947 }; |
947 | 948 |
948 SimpleWebServerTest server(46664); | 949 SimpleWebServerTest server(46664); |
949 server.PopulateStaticFileList(kPages, arraysize(kPages), GetCFTestFilePath()); | 950 server.PopulateStaticFileListT<test_server::FileResponse>(kPages, |
| 951 arraysize(kPages), GetCFTestFilePath()); |
950 | 952 |
951 ASSERT_TRUE(LaunchBrowser(IE, server.FormatHttpPath(kPages[0]).c_str())); | 953 ASSERT_TRUE(LaunchBrowser(IE, server.FormatHttpPath(kPages[0]).c_str())); |
952 | 954 |
953 loop_.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); | 955 loop_.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); |
954 | 956 |
955 const test_server::Request* request = NULL; | 957 const test_server::Request* request = NULL; |
956 server.FindRequest("/quit?OK", &request); | 958 server.FindRequest("/quit?OK", &request); |
957 ASSERT_TRUE(request != NULL); | 959 ASSERT_TRUE(request != NULL); |
958 EXPECT_EQ("OK", request->arguments()); | 960 EXPECT_EQ("OK", request->arguments()); |
959 | 961 |
(...skipping 15 matching lines...) Expand all Loading... |
975 | 977 |
976 // The order of pages in this array is assumed to be mshtml, cf, script. | 978 // The order of pages in this array is assumed to be mshtml, cf, script. |
977 const wchar_t* kPages[] = { | 979 const wchar_t* kPages[] = { |
978 L"full_tab_get_mshtml.html", | 980 L"full_tab_get_mshtml.html", |
979 L"full_tab_get_target_cf.html", | 981 L"full_tab_get_target_cf.html", |
980 L"chrome_frame_tester_helpers.js", | 982 L"chrome_frame_tester_helpers.js", |
981 }; | 983 }; |
982 | 984 |
983 SimpleWebServerTest server(46664); | 985 SimpleWebServerTest server(46664); |
984 | 986 |
985 server.PopulateStaticFileList(kPages, arraysize(kPages), GetCFTestFilePath()); | 987 server.PopulateStaticFileListT<test_server::FileResponse>(kPages, |
| 988 arraysize(kPages), GetCFTestFilePath()); |
986 | 989 |
987 ASSERT_TRUE(LaunchBrowser(IE, server.FormatHttpPath(kPages[0]).c_str())); | 990 ASSERT_TRUE(LaunchBrowser(IE, server.FormatHttpPath(kPages[0]).c_str())); |
988 | 991 |
989 loop_.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); | 992 loop_.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); |
990 | 993 |
991 const test_server::Request* request = NULL; | 994 const test_server::Request* request = NULL; |
992 server.FindRequest("/quit?OK", &request); | 995 server.FindRequest("/quit?OK", &request); |
993 ASSERT_TRUE(request != NULL); | 996 ASSERT_TRUE(request != NULL); |
994 EXPECT_EQ("OK", request->arguments()); | 997 EXPECT_EQ("OK", request->arguments()); |
995 | 998 |
(...skipping 12 matching lines...) Expand all Loading... |
1008 SimpleBrowserTest(IE, kSetCookieTest); | 1011 SimpleBrowserTest(IE, kSetCookieTest); |
1009 } | 1012 } |
1010 | 1013 |
1011 const wchar_t kXHRConditionalHeaderTestUrl[] = | 1014 const wchar_t kXHRConditionalHeaderTestUrl[] = |
1012 L"xmlhttprequest_conditional_header_test.html"; | 1015 L"xmlhttprequest_conditional_header_test.html"; |
1013 | 1016 |
1014 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_XHRConditionalHeaderTest) { | 1017 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_XHRConditionalHeaderTest) { |
1015 SimpleBrowserTest(IE, kXHRConditionalHeaderTestUrl); | 1018 SimpleBrowserTest(IE, kXHRConditionalHeaderTestUrl); |
1016 } | 1019 } |
1017 | 1020 |
| 1021 std::string GetHeaderValue(const std::string& headers, |
| 1022 const char* header_name) { |
| 1023 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), |
| 1024 "\r\n"); |
| 1025 while (it.GetNext()) { |
| 1026 if (lstrcmpiA(it.name().c_str(), header_name) == 0) { |
| 1027 return it.values(); |
| 1028 } |
| 1029 } |
| 1030 return ""; |
| 1031 } |
| 1032 |
| 1033 // Specialized implementation of test_server::FileResponse that supports |
| 1034 // adding the request's User-Agent header to the returned document. |
| 1035 // The class also supports $request_id$ which will be replaced with an |
| 1036 // id that's incremented each time the response is sent over a socket. |
| 1037 class UaTemplateFileResponse : public test_server::FileResponse { |
| 1038 public: |
| 1039 typedef test_server::FileResponse SuperClass; |
| 1040 |
| 1041 UaTemplateFileResponse(const char* request_path, const FilePath& file_path) |
| 1042 : test_server::FileResponse(request_path, file_path), request_id_(0) { |
| 1043 } |
| 1044 |
| 1045 virtual bool Matches(const test_server::Request& r) const { |
| 1046 bool ret = SuperClass::Matches(r); |
| 1047 if (ret) |
| 1048 ua_ = GetHeaderValue(r.headers(), "User-Agent"); |
| 1049 return ret; |
| 1050 } |
| 1051 |
| 1052 virtual size_t ContentLength() const { |
| 1053 const char kRequestIdTemplate[] = "$request_id$"; |
| 1054 const char kUserAgentTemplate[] = "$UA$"; |
| 1055 |
| 1056 size_t length = SuperClass::ContentLength(); |
| 1057 DCHECK(length); |
| 1058 content_.assign(reinterpret_cast<const char*>(file_->data()), |
| 1059 file_->length()); |
| 1060 size_t i = content_.find(kUserAgentTemplate); |
| 1061 if (i != std::string::npos) |
| 1062 content_.replace(i, arraysize(kUserAgentTemplate) - 1, ua_); |
| 1063 i = content_.find(kRequestIdTemplate); |
| 1064 if (i != std::string::npos) { |
| 1065 content_.replace(i, arraysize(kRequestIdTemplate) - 1, |
| 1066 StringPrintf("%i", request_id_)); |
| 1067 } |
| 1068 return content_.length(); |
| 1069 } |
| 1070 |
| 1071 virtual void WriteContents(ListenSocket* socket) const { |
| 1072 DCHECK(content_.length()); |
| 1073 socket->Send(content_.c_str(), content_.length(), false); |
| 1074 request_id_++; |
| 1075 } |
| 1076 |
| 1077 protected: |
| 1078 mutable std::string ua_; |
| 1079 mutable std::string content_; |
| 1080 mutable int request_id_; |
| 1081 }; |
| 1082 |
| 1083 // This test simulates a URL that on first request returns a document |
| 1084 // that should be rendered in mshtml, then pops up a sign-in page that |
| 1085 // after signing in, refreshes the original page that should then return |
| 1086 // a page that needs to be rendered in GCF. |
| 1087 // |
| 1088 // This test currently fails because GCF does not add the chromeframe header |
| 1089 // to requests that mshtml initiates via IInternetSession::CreateBinding. |
| 1090 TEST_F(ChromeFrameTestWithWebServer, FAILS_FullTabModeIE_RefreshMshtmlTest) { |
| 1091 const wchar_t* kPages[] = { |
| 1092 L"mshtml_refresh_test.html", |
| 1093 L"mshtml_refresh_test_popup.html", |
| 1094 }; |
| 1095 |
| 1096 SimpleWebServerTest server(46664); |
| 1097 server.PopulateStaticFileListT<UaTemplateFileResponse>(kPages, |
| 1098 arraysize(kPages), GetCFTestFilePath()); |
| 1099 |
| 1100 ASSERT_TRUE(LaunchBrowser(IE, server.FormatHttpPath(kPages[0]).c_str())); |
| 1101 |
| 1102 loop_.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); |
| 1103 |
| 1104 test_server::SimpleWebServer* ws = server.web_server(); |
| 1105 const test_server::ConnectionList& connections = ws->connections(); |
| 1106 test_server::ConnectionList::const_iterator it = connections.begin(); |
| 1107 int requests_for_first_page = 0; |
| 1108 for (; it != connections.end(); ++it) { |
| 1109 test_server::Connection* c = (*it); |
| 1110 const test_server::Request& r = c->request(); |
| 1111 if (ASCIIToWide(r.path().substr(1)).compare(kPages[0]) == 0) { |
| 1112 requests_for_first_page++; |
| 1113 std::string ua(GetHeaderValue(r.headers(), "User-Agent")); |
| 1114 EXPECT_NE(std::string::npos, ua.find("chromeframe")); |
| 1115 } |
| 1116 } |
| 1117 EXPECT_GT(requests_for_first_page, 1); |
| 1118 } |
| 1119 |
OLD | NEW |