| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 11 #include "base/test/test_timeouts.h" | 11 #include "base/test/test_timeouts.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "base/win/windows_version.h" | 13 #include "base/win/windows_version.h" |
| 14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/installer/util/product.h" | 15 #include "chrome/installer/util/product.h" |
| 16 #include "chrome/installer/util/install_util.h" | 16 #include "chrome/installer/util/install_util.h" |
| 17 #include "chrome/installer/util/helper.h" | 17 #include "chrome/installer/util/helper.h" |
| 18 #include "chrome_frame/html_utils.h" | 18 #include "chrome_frame/html_utils.h" |
| 19 #include "chrome_frame/utils.h" | 19 #include "chrome_frame/utils.h" |
| 20 #include "chrome_frame/test/chrome_frame_test_utils.h" | 20 #include "chrome_frame/test/chrome_frame_test_utils.h" |
| 21 #include "chrome_frame/test/mock_ie_event_sink_actions.h" | 21 #include "chrome_frame/test/mock_ie_event_sink_actions.h" |
| 22 #include "chrome_frame/test/mock_ie_event_sink_test.h" | 22 #include "chrome_frame/test/mock_ie_event_sink_test.h" |
| 23 #include "chrome_frame/test/test_scrubber.h" |
| 23 #include "net/base/mime_util.h" | 24 #include "net/base/mime_util.h" |
| 24 #include "net/http/http_util.h" | 25 #include "net/http/http_util.h" |
| 25 | 26 |
| 26 using chrome_frame_test::kChromeFrameLongNavigationTimeoutInSeconds; | 27 using chrome_frame_test::kChromeFrameLongNavigationTimeoutInSeconds; |
| 27 using chrome_frame_test::kChromeFrameVeryLongNavigationTimeoutInSeconds; | 28 using chrome_frame_test::kChromeFrameVeryLongNavigationTimeoutInSeconds; |
| 28 | 29 |
| 29 using testing::_; | 30 using testing::_; |
| 30 using testing::StrCaseEq; | 31 using testing::StrCaseEq; |
| 31 | 32 |
| 32 const wchar_t kDocRoot[] = L"chrome_frame\\test\\data"; | 33 const wchar_t kDocRoot[] = L"chrome_frame\\test\\data"; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 47 ss << "Cache-Control: no-cache\r\n"; | 48 ss << "Cache-Control: no-cache\r\n"; |
| 48 return ss.str(); | 49 return ss.str(); |
| 49 } | 50 } |
| 50 | 51 |
| 51 std::string GetMockHttpHeaders(const FilePath& mock_http_headers_path) { | 52 std::string GetMockHttpHeaders(const FilePath& mock_http_headers_path) { |
| 52 std::string headers; | 53 std::string headers; |
| 53 file_util::ReadFileToString(mock_http_headers_path, &headers); | 54 file_util::ReadFileToString(mock_http_headers_path, &headers); |
| 54 return headers; | 55 return headers; |
| 55 } | 56 } |
| 56 | 57 |
| 57 } // namespace | |
| 58 | |
| 59 class ChromeFrameTestEnvironment: public testing::Environment { | 58 class ChromeFrameTestEnvironment: public testing::Environment { |
| 60 public: | 59 public: |
| 61 ~ChromeFrameTestEnvironment() {} | 60 virtual ~ChromeFrameTestEnvironment() {} |
| 62 void SetUp() { | 61 virtual void SetUp() OVERRIDE { |
| 63 ScopedChromeFrameRegistrar::RegisterDefaults(); | 62 ScopedChromeFrameRegistrar::RegisterDefaults(); |
| 64 } | 63 } |
| 65 void TearDown() {} | |
| 66 }; | 64 }; |
| 67 | 65 |
| 68 ::testing::Environment* const chrome_frame_env = | 66 ::testing::Environment* const chrome_frame_env = |
| 69 ::testing::AddGlobalTestEnvironment(new ChromeFrameTestEnvironment); | 67 ::testing::AddGlobalTestEnvironment(new ChromeFrameTestEnvironment); |
| 70 | 68 |
| 69 } // namespace |
| 70 |
| 71 FilePath ChromeFrameTestWithWebServer::test_file_path_; |
| 72 FilePath ChromeFrameTestWithWebServer::results_dir_; |
| 73 FilePath ChromeFrameTestWithWebServer::CFInstall_path_; |
| 74 FilePath ChromeFrameTestWithWebServer::CFInstance_path_; |
| 75 ScopedTempDir ChromeFrameTestWithWebServer::temp_dir_; |
| 76 FilePath ChromeFrameTestWithWebServer::chrome_user_data_dir_; |
| 77 |
| 71 ChromeFrameTestWithWebServer::ChromeFrameTestWithWebServer() | 78 ChromeFrameTestWithWebServer::ChromeFrameTestWithWebServer() |
| 72 : loop_(), | 79 : loop_(), |
| 73 server_mock_(1337, L"127.0.0.1", | 80 server_mock_(1337, L"127.0.0.1", |
| 74 chrome_frame_test::GetTestDataFolder()) { | 81 chrome_frame_test::GetTestDataFolder()) { |
| 75 } | 82 } |
| 76 | 83 |
| 77 void ChromeFrameTestWithWebServer::CloseAllBrowsers() { | 84 // static |
| 78 // Web browsers tend to relaunch themselves in other processes, meaning the | 85 void ChromeFrameTestWithWebServer::SetUpTestCase() { |
| 79 // KillProcess stuff above might not have actually cleaned up all our browser | |
| 80 // instances, so make really sure browsers are dead. | |
| 81 base::KillProcesses(chrome_frame_test::kIEImageName, 0, NULL); | |
| 82 base::KillProcesses(chrome_frame_test::kIEBrokerImageName, 0, NULL); | |
| 83 | |
| 84 // Endeavour to only kill off Chrome Frame derived Chrome processes. | |
| 85 KillAllNamedProcessesWithArgument( | |
| 86 UTF8ToWide(chrome_frame_test::kChromeImageName), | |
| 87 UTF8ToWide(switches::kChromeFrame)); | |
| 88 base::KillProcesses(chrome_frame_test::kChromeLauncher, 0, NULL); | |
| 89 } | |
| 90 | |
| 91 void ChromeFrameTestWithWebServer::SetUp() { | |
| 92 // Make sure our playground is clean before we start. | |
| 93 CloseAllBrowsers(); | |
| 94 | |
| 95 // Make sure that we are not accidentally enabling gcf protocol. | |
| 96 SetConfigBool(kAllowUnsafeURLs, false); | |
| 97 | |
| 98 FilePath chrome_frame_source_path; | 86 FilePath chrome_frame_source_path; |
| 99 PathService::Get(base::DIR_SOURCE_ROOT, &chrome_frame_source_path); | 87 PathService::Get(base::DIR_SOURCE_ROOT, &chrome_frame_source_path); |
| 100 chrome_frame_source_path = chrome_frame_source_path.Append( | 88 chrome_frame_source_path = chrome_frame_source_path.Append( |
| 101 FILE_PATH_LITERAL("chrome_frame")); | 89 FILE_PATH_LITERAL("chrome_frame")); |
| 102 | 90 |
| 103 test_file_path_ = chrome_frame_source_path; | 91 test_file_path_ = chrome_frame_source_path |
| 104 test_file_path_ = test_file_path_.Append(FILE_PATH_LITERAL("test")) | 92 .Append(FILE_PATH_LITERAL("test")) |
| 105 .Append(FILE_PATH_LITERAL("data")); | 93 .Append(FILE_PATH_LITERAL("data")); |
| 106 | 94 |
| 107 results_dir_ = chrome_frame_test::GetTestDataFolder(); | 95 results_dir_ = chrome_frame_test::GetTestDataFolder().AppendASCII("dump"); |
| 108 results_dir_.AppendASCII("dump"); | |
| 109 | 96 |
| 110 // Copy the CFInstance.js and CFInstall.js files from src\chrome_frame to | 97 // Copy the CFInstance.js and CFInstall.js files from src\chrome_frame to |
| 111 // src\chrome_frame\test\data. | 98 // src\chrome_frame\test\data. |
| 112 FilePath CFInstance_src_path; | 99 FilePath CFInstance_src_path; |
| 113 FilePath CFInstall_src_path; | 100 FilePath CFInstall_src_path; |
| 114 | 101 |
| 115 CFInstance_src_path = chrome_frame_source_path.AppendASCII("CFInstance.js"); | 102 CFInstance_src_path = chrome_frame_source_path.AppendASCII("CFInstance.js"); |
| 116 CFInstance_path_ = test_file_path_.AppendASCII("CFInstance.js"); | 103 CFInstance_path_ = test_file_path_.AppendASCII("CFInstance.js"); |
| 117 | 104 |
| 118 ASSERT_TRUE(file_util::CopyFile(CFInstance_src_path, CFInstance_path_)); | 105 ASSERT_TRUE(file_util::CopyFile(CFInstance_src_path, CFInstance_path_)); |
| 119 | 106 |
| 120 CFInstall_src_path = chrome_frame_source_path.AppendASCII("CFInstall.js"); | 107 CFInstall_src_path = chrome_frame_source_path.AppendASCII("CFInstall.js"); |
| 121 CFInstall_path_ = test_file_path_.AppendASCII("CFInstall.js"); | 108 CFInstall_path_ = test_file_path_.AppendASCII("CFInstall.js"); |
| 122 | 109 |
| 123 ASSERT_TRUE(file_util::CopyFile(CFInstall_src_path, CFInstall_path_)); | 110 ASSERT_TRUE(file_util::CopyFile(CFInstall_src_path, CFInstall_path_)); |
| 111 } |
| 112 |
| 113 // static |
| 114 void ChromeFrameTestWithWebServer::TearDownTestCase() { |
| 115 file_util::Delete(CFInstall_path_, false); |
| 116 file_util::Delete(CFInstance_path_, false); |
| 117 EXPECT_TRUE(temp_dir_.Delete()); |
| 118 } |
| 119 |
| 120 // static |
| 121 const FilePath& ChromeFrameTestWithWebServer::GetChromeUserDataDirectory() { |
| 122 if (!temp_dir_.IsValid()) { |
| 123 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 124 chrome_user_data_dir_ = temp_dir_.path().AppendASCII("User Data"); |
| 125 } |
| 126 return chrome_user_data_dir_; |
| 127 } |
| 128 |
| 129 void ChromeFrameTestWithWebServer::SetUp() { |
| 130 // Make sure that we are not accidentally enabling gcf protocol. |
| 131 SetConfigBool(kAllowUnsafeURLs, false); |
| 124 | 132 |
| 125 server_mock_.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); | 133 server_mock_.ExpectAndServeAnyRequests(CFInvocation(CFInvocation::NONE)); |
| 126 server_mock_.set_expected_result("OK"); | 134 server_mock_.set_expected_result("OK"); |
| 127 } | 135 } |
| 128 | 136 |
| 129 void ChromeFrameTestWithWebServer::TearDown() { | 137 void ChromeFrameTestWithWebServer::TearDown() { |
| 130 CloseBrowser(); | 138 CloseBrowser(); |
| 131 CloseAllBrowsers(); | |
| 132 file_util::Delete(CFInstall_path_, false); | |
| 133 file_util::Delete(CFInstance_path_, false); | |
| 134 } | 139 } |
| 135 | 140 |
| 136 bool ChromeFrameTestWithWebServer::LaunchBrowser(BrowserKind browser, | 141 bool ChromeFrameTestWithWebServer::LaunchBrowser(BrowserKind browser, |
| 137 const wchar_t* page) { | 142 const wchar_t* page) { |
| 138 std::wstring url = page; | 143 std::wstring url = page; |
| 139 | 144 |
| 140 // We should resolve the URL only if it is a relative url. | 145 // We should resolve the URL only if it is a relative url. |
| 141 GURL parsed_url(WideToUTF8(page)); | 146 GURL parsed_url(WideToUTF8(page)); |
| 142 if (!parsed_url.has_scheme()) { | 147 if (!parsed_url.has_scheme()) { |
| 143 url = server_mock_.Resolve(page); | 148 url = server_mock_.Resolve(page); |
| 144 } | 149 } |
| 145 | 150 |
| 146 browser_ = browser; | 151 browser_ = browser; |
| 147 if (browser == IE) { | 152 if (browser == IE) { |
| 148 browser_handle_.Set(chrome_frame_test::LaunchIE(url)); | 153 browser_handle_.Set(chrome_frame_test::LaunchIE(url)); |
| 149 } else if (browser == CHROME) { | 154 } else if (browser == CHROME) { |
| 150 browser_handle_.Set(chrome_frame_test::LaunchChrome(url)); | 155 const FilePath& user_data_dir = GetChromeUserDataDirectory(); |
| 156 chrome_frame_test::OverrideDataDirectoryForThisTest(user_data_dir.value()); |
| 157 browser_handle_.Set(chrome_frame_test::LaunchChrome(url, user_data_dir)); |
| 151 } else { | 158 } else { |
| 152 NOTREACHED(); | 159 NOTREACHED(); |
| 153 } | 160 } |
| 154 | 161 |
| 155 return browser_handle_.IsValid(); | 162 return browser_handle_.IsValid(); |
| 156 } | 163 } |
| 157 | 164 |
| 158 void ChromeFrameTestWithWebServer::CloseBrowser() { | 165 void ChromeFrameTestWithWebServer::CloseBrowser() { |
| 159 if (!browser_handle_.IsValid()) | 166 if (!browser_handle_.IsValid()) |
| 160 return; | 167 return; |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 | 707 |
| 701 const wchar_t kAnchorUrlNavigate[] = | 708 const wchar_t kAnchorUrlNavigate[] = |
| 702 L"fulltab_anchor_url_navigate.html#chrome_frame"; | 709 L"fulltab_anchor_url_navigate.html#chrome_frame"; |
| 703 | 710 |
| 704 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_AnchorUrlNavigateTest) { | 711 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_AnchorUrlNavigateTest) { |
| 705 SimpleBrowserTest(IE, kAnchorUrlNavigate); | 712 SimpleBrowserTest(IE, kAnchorUrlNavigate); |
| 706 } | 713 } |
| 707 | 714 |
| 708 // Test whether POST-ing a form from an mshtml page to a CF page will cause | 715 // Test whether POST-ing a form from an mshtml page to a CF page will cause |
| 709 // the request to get reissued. It should not. | 716 // the request to get reissued. It should not. |
| 710 // FLAKY: 114386. | 717 TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_TestPostReissue) { |
| 711 TEST_F(ChromeFrameTestWithWebServer, DISABLED_FullTabModeIE_TestPostReissue) { | |
| 712 // The order of pages in this array is assumed to be mshtml, cf, script. | 718 // The order of pages in this array is assumed to be mshtml, cf, script. |
| 713 const wchar_t* kPages[] = { | 719 const wchar_t* kPages[] = { |
| 714 L"full_tab_post_mshtml.html", | 720 L"full_tab_post_mshtml.html", |
| 715 L"full_tab_post_target_cf.html", | 721 L"full_tab_post_target_cf.html", |
| 716 L"chrome_frame_tester_helpers.js", | 722 L"chrome_frame_tester_helpers.js", |
| 717 }; | 723 }; |
| 718 | 724 |
| 719 SimpleWebServerTest server(46664); | 725 SimpleWebServerTest server(46664); |
| 720 server.PopulateStaticFileListT<test_server::FileResponse>(kPages, | 726 server.PopulateStaticFileListT<test_server::FileResponse>(kPages, |
| 721 arraysize(kPages), GetCFTestFilePath()); | 727 arraysize(kPages), GetCFTestFilePath()); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 server.web_server()->AddResponse(response); | 1017 server.web_server()->AddResponse(response); |
| 1012 | 1018 |
| 1013 std::wstring url(server.FormatHttpPath(L"form.html")); | 1019 std::wstring url(server.FormatHttpPath(L"form.html")); |
| 1014 | 1020 |
| 1015 ASSERT_TRUE(LaunchBrowser(IE, url.c_str())); | 1021 ASSERT_TRUE(LaunchBrowser(IE, url.c_str())); |
| 1016 loop_.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); | 1022 loop_.RunFor(kChromeFrameLongNavigationTimeoutInSeconds); |
| 1017 | 1023 |
| 1018 EXPECT_EQ(1, response->get_request_count()); | 1024 EXPECT_EQ(1, response->get_request_count()); |
| 1019 EXPECT_EQ(1, response->post_request_count()); | 1025 EXPECT_EQ(1, response->post_request_count()); |
| 1020 } | 1026 } |
| OLD | NEW |