| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/string_util.h" | 5 #include "base/string_util.h" |
| 6 #if defined(OS_WIN) |
| 7 #include "base/win_util.h" |
| 8 #endif // defined(OS_WIN) |
| 6 #include "chrome/test/automation/tab_proxy.h" | 9 #include "chrome/test/automation/tab_proxy.h" |
| 7 #include "chrome/test/ui/ui_test.h" | 10 #include "chrome/test/ui/ui_test.h" |
| 8 #include "chrome/browser/net/url_request_failed_dns_job.h" | 11 #include "chrome/browser/net/url_request_failed_dns_job.h" |
| 9 #include "chrome/browser/net/url_request_mock_http_job.h" | 12 #include "chrome/browser/net/url_request_mock_http_job.h" |
| 10 #include "net/url_request/url_request_unittest.h" | 13 #include "net/url_request/url_request_unittest.h" |
| 11 | 14 |
| 12 class ErrorPageTest : public UITest { | 15 class ErrorPageTest : public UITest { |
| 13 protected: | 16 protected: |
| 14 bool WaitForTitleMatching(const std::wstring& title) { | 17 bool WaitForTitleMatching(const std::wstring& title) { |
| 15 for (int i = 0; i < 100; ++i) { | 18 for (int i = 0; i < 100; ++i) { |
| 16 if (GetActiveTabTitle() == title) | 19 if (GetActiveTabTitle() == title) |
| 17 return true; | 20 return true; |
| 18 PlatformThread::Sleep(sleep_timeout_ms() / 10); | 21 PlatformThread::Sleep(sleep_timeout_ms() / 10); |
| 19 } | 22 } |
| 20 EXPECT_EQ(title, GetActiveTabTitle()); | 23 EXPECT_EQ(title, GetActiveTabTitle()); |
| 21 return false; | 24 return false; |
| 22 } | 25 } |
| 23 }; | 26 }; |
| 24 | 27 |
| 25 TEST_F(ErrorPageTest, DNSError_Basic) { | 28 TEST_F(ErrorPageTest, DNSError_Basic) { |
| 29 #if defined(OS_WIN) |
| 30 // Flaky on XP, http://crbug.com/19361. |
| 31 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) |
| 32 return; |
| 33 #endif // defined(OS_WIN) |
| 26 GURL test_url(URLRequestFailedDnsJob::kTestUrl); | 34 GURL test_url(URLRequestFailedDnsJob::kTestUrl); |
| 27 | 35 |
| 28 // The first navigation should fail, and the second one should be the error | 36 // The first navigation should fail, and the second one should be the error |
| 29 // page. | 37 // page. |
| 30 NavigateToURLBlockUntilNavigationsComplete(test_url, 2); | 38 NavigateToURLBlockUntilNavigationsComplete(test_url, 2); |
| 31 | 39 |
| 32 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); | 40 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); |
| 33 } | 41 } |
| 34 | 42 |
| 35 TEST_F(ErrorPageTest, DNSError_GoBack1) { | 43 TEST_F(ErrorPageTest, DNSError_GoBack1) { |
| 44 #if defined(OS_WIN) |
| 45 // Flaky on XP, http://crbug.com/19361. |
| 46 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) |
| 47 return; |
| 48 #endif // defined(OS_WIN) |
| 36 // Test that a DNS error occuring in the main frame does not result in an | 49 // Test that a DNS error occuring in the main frame does not result in an |
| 37 // additional session history entry. | 50 // additional session history entry. |
| 38 GURL test_url(URLRequestFailedDnsJob::kTestUrl); | 51 GURL test_url(URLRequestFailedDnsJob::kTestUrl); |
| 39 | 52 |
| 40 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); | 53 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); |
| 41 // The first navigation should fail, and the second one should be the error | 54 // The first navigation should fail, and the second one should be the error |
| 42 // page. | 55 // page. |
| 43 NavigateToURLBlockUntilNavigationsComplete(test_url, 2); | 56 NavigateToURLBlockUntilNavigationsComplete(test_url, 2); |
| 44 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); | 57 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); |
| 45 | 58 |
| 46 GetActiveTab()->GoBack(); | 59 GetActiveTab()->GoBack(); |
| 47 | 60 |
| 48 EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness")); | 61 EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness")); |
| 49 } | 62 } |
| 50 | 63 |
| 51 TEST_F(ErrorPageTest, DNSError_GoBack2) { | 64 TEST_F(ErrorPageTest, DNSError_GoBack2) { |
| 65 #if defined(OS_WIN) |
| 66 // Flaky on XP, http://crbug.com/19361. |
| 67 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) |
| 68 return; |
| 69 #endif // defined(OS_WIN) |
| 52 // Test that a DNS error occuring in the main frame does not result in an | 70 // Test that a DNS error occuring in the main frame does not result in an |
| 53 // additional session history entry. | 71 // additional session history entry. |
| 54 GURL test_url(URLRequestFailedDnsJob::kTestUrl); | 72 GURL test_url(URLRequestFailedDnsJob::kTestUrl); |
| 55 | 73 |
| 56 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); | 74 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); |
| 57 // The first navigation should fail, and the second one should be the error | 75 // The first navigation should fail, and the second one should be the error |
| 58 // page. | 76 // page. |
| 59 NavigateToURLBlockUntilNavigationsComplete(test_url, 2); | 77 NavigateToURLBlockUntilNavigationsComplete(test_url, 2); |
| 60 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); | 78 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); |
| 61 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title3.html")); | 79 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title3.html")); |
| 62 | 80 |
| 63 // The first navigation should fail, and the second one should be the error | 81 // The first navigation should fail, and the second one should be the error |
| 64 // page. | 82 // page. |
| 65 GetActiveTab()->GoBackBlockUntilNavigationsComplete(2); | 83 GetActiveTab()->GoBackBlockUntilNavigationsComplete(2); |
| 66 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); | 84 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); |
| 67 GetActiveTab()->GoBack(); | 85 GetActiveTab()->GoBack(); |
| 68 | 86 |
| 69 EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness")); | 87 EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness")); |
| 70 } | 88 } |
| 71 | 89 |
| 72 TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) { | 90 TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) { |
| 91 #if defined(OS_WIN) |
| 92 // Flaky on XP, http://crbug.com/19361. |
| 93 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) |
| 94 return; |
| 95 #endif // defined(OS_WIN) |
| 73 // Test that a DNS error occuring in the main frame does not result in an | 96 // Test that a DNS error occuring in the main frame does not result in an |
| 74 // additional session history entry. | 97 // additional session history entry. |
| 75 | 98 |
| 76 GURL test_url(URLRequestFailedDnsJob::kTestUrl); | 99 GURL test_url(URLRequestFailedDnsJob::kTestUrl); |
| 77 | 100 |
| 78 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); | 101 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); |
| 79 // The first navigation should fail, and the second one should be the error | 102 // The first navigation should fail, and the second one should be the error |
| 80 // page. | 103 // page. |
| 81 NavigateToURLBlockUntilNavigationsComplete(test_url, 2); | 104 NavigateToURLBlockUntilNavigationsComplete(test_url, 2); |
| 82 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); | 105 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); |
| 83 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title3.html")); | 106 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title3.html")); |
| 84 | 107 |
| 85 // The first navigation should fail, and the second one should be the error | 108 // The first navigation should fail, and the second one should be the error |
| 86 // page. | 109 // page. |
| 87 GetActiveTab()->GoBackBlockUntilNavigationsComplete(2); | 110 GetActiveTab()->GoBackBlockUntilNavigationsComplete(2); |
| 88 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); | 111 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); |
| 89 GetActiveTab()->GoBack(); | 112 GetActiveTab()->GoBack(); |
| 90 // The first navigation should fail, and the second one should be the error | 113 // The first navigation should fail, and the second one should be the error |
| 91 // page. | 114 // page. |
| 92 GetActiveTab()->GoForwardBlockUntilNavigationsComplete(2); | 115 GetActiveTab()->GoForwardBlockUntilNavigationsComplete(2); |
| 93 | 116 |
| 94 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); | 117 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); |
| 95 } | 118 } |
| 96 | 119 |
| 97 TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) { | 120 TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) { |
| 121 #if defined(OS_WIN) |
| 122 // Flaky on XP, http://crbug.com/19361. |
| 123 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) |
| 124 return; |
| 125 #endif // defined(OS_WIN) |
| 98 // Test that a DNS error occuring in the main frame does not result in an | 126 // Test that a DNS error occuring in the main frame does not result in an |
| 99 // additional session history entry. | 127 // additional session history entry. |
| 100 | 128 |
| 101 GURL test_url(URLRequestFailedDnsJob::kTestUrl); | 129 GURL test_url(URLRequestFailedDnsJob::kTestUrl); |
| 102 | 130 |
| 103 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title3.html")); | 131 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title3.html")); |
| 104 // The first navigation should fail, and the second one should be the error | 132 // The first navigation should fail, and the second one should be the error |
| 105 // page. | 133 // page. |
| 106 NavigateToURLBlockUntilNavigationsComplete(test_url, 2); | 134 NavigateToURLBlockUntilNavigationsComplete(test_url, 2); |
| 107 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); | 135 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); |
| 108 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); | 136 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); |
| 109 | 137 |
| 110 // The first navigation should fail, and the second one should be the error | 138 // The first navigation should fail, and the second one should be the error |
| 111 // page. | 139 // page. |
| 112 GetActiveTab()->GoBackBlockUntilNavigationsComplete(2); | 140 GetActiveTab()->GoBackBlockUntilNavigationsComplete(2); |
| 113 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); | 141 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); |
| 114 GetActiveTab()->GoBack(); | 142 GetActiveTab()->GoBack(); |
| 115 // The first navigation should fail, and the second one should be the error | 143 // The first navigation should fail, and the second one should be the error |
| 116 // page. | 144 // page. |
| 117 GetActiveTab()->GoForwardBlockUntilNavigationsComplete(2); | 145 GetActiveTab()->GoForwardBlockUntilNavigationsComplete(2); |
| 118 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); | 146 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); |
| 119 GetActiveTab()->GoForward(); | 147 GetActiveTab()->GoForward(); |
| 120 | 148 |
| 121 EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness")); | 149 EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness")); |
| 122 } | 150 } |
| 123 | 151 |
| 124 TEST_F(ErrorPageTest, IFrameDNSError_Basic) { | 152 TEST_F(ErrorPageTest, IFrameDNSError_Basic) { |
| 153 #if defined(OS_WIN) |
| 154 // Flaky on XP, http://crbug.com/19361. |
| 155 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) |
| 156 return; |
| 157 #endif // defined(OS_WIN) |
| 125 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"iframe_dns_error.html")); | 158 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"iframe_dns_error.html")); |
| 126 EXPECT_TRUE(WaitForTitleMatching(L"Blah")); | 159 EXPECT_TRUE(WaitForTitleMatching(L"Blah")); |
| 127 } | 160 } |
| 128 | 161 |
| 129 TEST_F(ErrorPageTest, IFrameDNSError_GoBack) { | 162 TEST_F(ErrorPageTest, IFrameDNSError_GoBack) { |
| 163 #if defined(OS_WIN) |
| 164 // Flaky on XP, http://crbug.com/19361. |
| 165 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) |
| 166 return; |
| 167 #endif // defined(OS_WIN) |
| 130 // Test that a DNS error occuring in an iframe does not result in an | 168 // Test that a DNS error occuring in an iframe does not result in an |
| 131 // additional session history entry. | 169 // additional session history entry. |
| 132 | 170 |
| 133 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); | 171 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); |
| 134 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"iframe_dns_error.html")); | 172 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"iframe_dns_error.html")); |
| 135 | 173 |
| 136 GetActiveTab()->GoBack(); | 174 GetActiveTab()->GoBack(); |
| 137 | 175 |
| 138 EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness")); | 176 EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness")); |
| 139 } | 177 } |
| 140 | 178 |
| 141 TEST_F(ErrorPageTest, IFrameDNSError_GoBackAndForward) { | 179 TEST_F(ErrorPageTest, IFrameDNSError_GoBackAndForward) { |
| 180 #if defined(OS_WIN) |
| 181 // Flaky on XP, http://crbug.com/19361. |
| 182 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) |
| 183 return; |
| 184 #endif // defined(OS_WIN) |
| 142 // Test that a DNS error occuring in an iframe does not result in an | 185 // Test that a DNS error occuring in an iframe does not result in an |
| 143 // additional session history entry. | 186 // additional session history entry. |
| 144 | 187 |
| 145 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); | 188 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); |
| 146 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"iframe_dns_error.html")); | 189 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"iframe_dns_error.html")); |
| 147 | 190 |
| 148 GetActiveTab()->GoBack(); | 191 GetActiveTab()->GoBack(); |
| 149 GetActiveTab()->GoForward(); | 192 GetActiveTab()->GoForward(); |
| 150 | 193 |
| 151 EXPECT_TRUE(WaitForTitleMatching(L"Blah")); | 194 EXPECT_TRUE(WaitForTitleMatching(L"Blah")); |
| 152 } | 195 } |
| 153 | 196 |
| 154 TEST_F(ErrorPageTest, IFrame404) { | 197 TEST_F(ErrorPageTest, IFrame404) { |
| 198 #if defined(OS_WIN) |
| 199 // Flaky on XP, http://crbug.com/19361. |
| 200 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) |
| 201 return; |
| 202 #endif // defined(OS_WIN) |
| 155 // iframes that have 404 pages should not trigger an alternate error page. | 203 // iframes that have 404 pages should not trigger an alternate error page. |
| 156 // In this test, the iframe sets the title of the parent page to "SUCCESS" | 204 // In this test, the iframe sets the title of the parent page to "SUCCESS" |
| 157 // when the iframe loads. If the iframe fails to load (because an alternate | 205 // when the iframe loads. If the iframe fails to load (because an alternate |
| 158 // error page loads instead), then the title will remain as "FAIL". | 206 // error page loads instead), then the title will remain as "FAIL". |
| 159 scoped_refptr<HTTPTestServer> server = | 207 scoped_refptr<HTTPTestServer> server = |
| 160 HTTPTestServer::CreateServer(L"chrome/test/data", NULL); | 208 HTTPTestServer::CreateServer(L"chrome/test/data", NULL); |
| 161 ASSERT_TRUE(NULL != server.get()); | 209 ASSERT_TRUE(NULL != server.get()); |
| 162 GURL test_url = server->TestServerPage("files/iframe404.html"); | 210 GURL test_url = server->TestServerPage("files/iframe404.html"); |
| 163 NavigateToURL(test_url); | 211 NavigateToURL(test_url); |
| 164 | 212 |
| 165 EXPECT_TRUE(WaitForTitleMatching(L"SUCCESS")); | 213 EXPECT_TRUE(WaitForTitleMatching(L"SUCCESS")); |
| 166 } | 214 } |
| 167 | 215 |
| 168 TEST_F(ErrorPageTest, Page404) { | 216 TEST_F(ErrorPageTest, Page404) { |
| 217 #if defined(OS_WIN) |
| 218 // Flaky on XP, http://crbug.com/19361. |
| 219 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) |
| 220 return; |
| 221 #endif // defined(OS_WIN) |
| 169 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); | 222 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); |
| 170 // The first navigation should fail, and the second one should be the error | 223 // The first navigation should fail, and the second one should be the error |
| 171 // page. | 224 // page. |
| 172 NavigateToURLBlockUntilNavigationsComplete( | 225 NavigateToURLBlockUntilNavigationsComplete( |
| 173 URLRequestMockHTTPJob::GetMockUrl(L"page404.html"), 2); | 226 URLRequestMockHTTPJob::GetMockUrl(L"page404.html"), 2); |
| 174 | 227 |
| 175 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); | 228 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); |
| 176 } | 229 } |
| 177 | 230 |
| 178 TEST_F(ErrorPageTest, Page404_GoBack) { | 231 TEST_F(ErrorPageTest, Page404_GoBack) { |
| 232 #if defined(OS_WIN) |
| 233 // Flaky on XP, http://crbug.com/19361. |
| 234 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) |
| 235 return; |
| 236 #endif // defined(OS_WIN) |
| 179 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); | 237 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); |
| 180 // The first navigation should fail, and the second one should be the error | 238 // The first navigation should fail, and the second one should be the error |
| 181 // page. | 239 // page. |
| 182 NavigateToURLBlockUntilNavigationsComplete( | 240 NavigateToURLBlockUntilNavigationsComplete( |
| 183 URLRequestMockHTTPJob::GetMockUrl(L"page404.html"), 2); | 241 URLRequestMockHTTPJob::GetMockUrl(L"page404.html"), 2); |
| 184 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); | 242 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor")); |
| 185 | 243 |
| 186 GetActiveTab()->GoBack(); | 244 GetActiveTab()->GoBack(); |
| 187 | 245 |
| 188 EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness")); | 246 EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness")); |
| 189 } | 247 } |
| OLD | NEW |