Chromium Code Reviews| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/browser/google/google_util.h" | 7 #include "chrome/browser/google/google_util.h" |
| 8 #include "chrome/browser/net/url_request_mock_util.h" | 8 #include "chrome/browser/net/url_request_mock_util.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
| 13 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
| 14 #include "content/public/browser/render_view_host.h" | |
| 14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 15 #include "content/public/test/browser_test_utils.h" | 16 #include "content/public/test/browser_test_utils.h" |
| 16 #include "content/public/test/test_navigation_observer.h" | 17 #include "content/public/test/test_navigation_observer.h" |
| 17 #include "content/test/net/url_request_failed_job.h" | 18 #include "content/test/net/url_request_failed_job.h" |
| 18 #include "content/test/net/url_request_mock_http_job.h" | 19 #include "content/test/net/url_request_mock_http_job.h" |
| 19 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 20 #include "net/url_request/url_request_filter.h" | 21 #include "net/url_request/url_request_filter.h" |
| 21 #include "net/url_request/url_request_job_factory.h" | 22 #include "net/url_request/url_request_job_factory.h" |
| 22 | 23 |
| 23 using content::BrowserThread; | 24 using content::BrowserThread; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 GoForwardAndWaitForTitle("Title Of Awesomeness", 1); | 204 GoForwardAndWaitForTitle("Title Of Awesomeness", 1); |
| 204 } | 205 } |
| 205 | 206 |
| 206 // Test that a DNS error occuring in an iframe. | 207 // Test that a DNS error occuring in an iframe. |
| 207 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) { | 208 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_Basic) { |
| 208 NavigateToURLAndWaitForTitle( | 209 NavigateToURLAndWaitForTitle( |
| 209 content::URLRequestMockHTTPJob::GetMockUrl( | 210 content::URLRequestMockHTTPJob::GetMockUrl( |
| 210 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))), | 211 base::FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))), |
| 211 "Blah", | 212 "Blah", |
| 212 1); | 213 1); |
| 214 // We expect to have two history entries, since we started off with navigation | |
| 215 // to "about:blank" and then navigated to "iframe_dns_error.html". | |
| 216 EXPECT_EQ(2, | |
| 217 browser()->tab_strip_model()->GetActiveWebContents()-> | |
| 218 GetController().GetEntryCount()); | |
| 213 } | 219 } |
| 214 | 220 |
| 215 // This test fails regularly on win_rel trybots. See crbug.com/121540 | 221 // This test fails regularly on win_rel trybots. See crbug.com/121540 |
| 216 #if defined(OS_WIN) | 222 #if defined(OS_WIN) |
| 217 #define MAYBE_IFrameDNSError_GoBack DISABLED_IFrameDNSError_GoBack | 223 #define MAYBE_IFrameDNSError_GoBack DISABLED_IFrameDNSError_GoBack |
| 218 #else | 224 #else |
| 219 #define MAYBE_IFrameDNSError_GoBack IFrameDNSError_GoBack | 225 #define MAYBE_IFrameDNSError_GoBack IFrameDNSError_GoBack |
| 220 #endif | 226 #endif |
| 221 // Test that a DNS error occuring in an iframe does not result in an | 227 // Test that a DNS error occuring in an iframe does not result in an |
| 222 // additional session history entry. | 228 // additional session history entry. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 234 #endif | 240 #endif |
| 235 // Test that a DNS error occuring in an iframe does not result in an | 241 // Test that a DNS error occuring in an iframe does not result in an |
| 236 // additional session history entry. | 242 // additional session history entry. |
| 237 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_IFrameDNSError_GoBackAndForward) { | 243 IN_PROC_BROWSER_TEST_F(ErrorPageTest, MAYBE_IFrameDNSError_GoBackAndForward) { |
| 238 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); | 244 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); |
| 239 NavigateToFileURL(FILE_PATH_LITERAL("iframe_dns_error.html")); | 245 NavigateToFileURL(FILE_PATH_LITERAL("iframe_dns_error.html")); |
| 240 GoBackAndWaitForTitle("Title Of Awesomeness", 1); | 246 GoBackAndWaitForTitle("Title Of Awesomeness", 1); |
| 241 GoForwardAndWaitForTitle("Blah", 1); | 247 GoForwardAndWaitForTitle("Blah", 1); |
| 242 } | 248 } |
| 243 | 249 |
| 250 // Test that a DNS error occuring in an iframe, once the main document is | |
| 251 // completed loading, does not result in an additional session history entry. | |
| 252 // To ensure that the main document has completed loading, JavaScript is used to | |
| 253 // inject an iframe after loading is done. | |
| 254 IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_JavaScript) { | |
| 255 content::WebContents* wc = | |
| 256 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 257 GURL fail_url = | |
| 258 URLRequestFailedJob::GetMockHttpUrl(net::ERR_NAME_NOT_RESOLVED); | |
| 259 std::string script = "var frame = document.createElement('iframe');" | |
| 260 "frame.src = '" + fail_url.spec() + "';" | |
| 261 "document.body.appendChild(frame);" | |
| 262 "document.title = 'done';"; | |
|
mmenke
2013/05/22 17:25:50
This failed consistently prior to the fix? My con
nasko
2013/05/22 17:52:53
I see your concern. I haven't tried the test on th
| |
| 263 | |
| 264 // Load a regular web page, in which we will inject an iframe. | |
| 265 NavigateToFileURL(FILE_PATH_LITERAL("title2.html")); | |
| 266 | |
| 267 // We expect to have two history entries, since we started off with navigation | |
| 268 // to "about:blank" and then navigated to "title2.html". | |
| 269 EXPECT_EQ(2, wc->GetController().GetEntryCount()); | |
| 270 | |
| 271 string16 expected_title(ASCIIToUTF16("done")); | |
| 272 content::TitleWatcher title_watcher(wc, expected_title); | |
| 273 | |
| 274 wc->GetRenderViewHost()->ExecuteJavascriptInWebFrame( | |
| 275 string16(), ASCIIToUTF16(script)); | |
| 276 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | |
| 277 | |
| 278 // Failed initial navigation of an iframe shouldn't be adding any history | |
| 279 // entries. | |
| 280 EXPECT_EQ(2, wc->GetController().GetEntryCount()); | |
| 281 } | |
| 282 | |
| 244 // Checks that the Link Doctor is not loaded when we receive an actual 404 page. | 283 // Checks that the Link Doctor is not loaded when we receive an actual 404 page. |
| 245 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { | 284 IN_PROC_BROWSER_TEST_F(ErrorPageTest, Page404) { |
| 246 NavigateToURLAndWaitForTitle( | 285 NavigateToURLAndWaitForTitle( |
| 247 content::URLRequestMockHTTPJob::GetMockUrl( | 286 content::URLRequestMockHTTPJob::GetMockUrl( |
| 248 base::FilePath(FILE_PATH_LITERAL("page404.html"))), | 287 base::FilePath(FILE_PATH_LITERAL("page404.html"))), |
| 249 "SUCCESS", | 288 "SUCCESS", |
| 250 1); | 289 1); |
| 251 } | 290 } |
| 252 | 291 |
| 253 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE. | 292 // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 365 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 327 browser()->tab_strip_model()->GetActiveWebContents(), | 366 browser()->tab_strip_model()->GetActiveWebContents(), |
| 328 "var textContent = document.body.textContent;" | 367 "var textContent = document.body.textContent;" |
| 329 "var hasError = textContent.indexOf('ERR_NAME_NOT_RESOLVED') >= 0;" | 368 "var hasError = textContent.indexOf('ERR_NAME_NOT_RESOLVED') >= 0;" |
| 330 "domAutomationController.send(hasError);", | 369 "domAutomationController.send(hasError);", |
| 331 &result)); | 370 &result)); |
| 332 EXPECT_TRUE(result); | 371 EXPECT_TRUE(result); |
| 333 } | 372 } |
| 334 | 373 |
| 335 } // namespace | 374 } // namespace |
| OLD | NEW |