license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
| 5 | #include "base/string_util.h" |
| 6 | #include "chrome/test/ui/ui_test.h" |
| 7 | #include "chrome/browser/automation/url_request_failed_dns_job.h" |
[email protected] | 022d781a | 2008-09-29 18:45:11 | [diff] [blame] | 8 | #include "net/url_request/url_request_unittest.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 9 | |
| 10 | class ErrorPageTest : public UITest { |
| 11 | }; |
| 12 | |
| 13 | TEST_F(ErrorPageTest, DNSError) { |
| 14 | GURL test_url(URLRequestFailedDnsJob::kTestUrl); |
| 15 | std::wstring test_host = UTF8ToWide(test_url.host()); |
| 16 | NavigateToURL(test_url); |
| 17 | |
| 18 | // Verify that the url is in the title. Since it's set via Javascript, we |
| 19 | // need to give it a chance to run. |
| 20 | int i; |
| 21 | std::wstring title; |
| 22 | for (i = 0; i < 10; ++i) { |
[email protected] | 5cc06369 | 2009-04-07 23:21:31 | [diff] [blame] | 23 | PlatformThread::Sleep(sleep_timeout_ms()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 24 | title = GetActiveTabTitle(); |
| 25 | if (title.find(test_host) != std::wstring::npos) { |
| 26 | // Success, bail out. |
| 27 | break; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | if (i == 10) { |
| 32 | FAIL() << "failed to get error page title; got " << title; |
| 33 | } |
| 34 | }; |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 35 | |
[email protected] | 022d781a | 2008-09-29 18:45:11 | [diff] [blame] | 36 | TEST_F(ErrorPageTest, IFrame404) { |
| 37 | // iframes that have 404 pages should not trigger an alternate error page. |
| 38 | // In this test, the iframe sets the title of the parent page to "SUCCESS" |
| 39 | // when the iframe loads. If the iframe fails to load (because an alternate |
| 40 | // error page loads instead), then the title will remain as "FAIL". |
[email protected] | dd26501 | 2009-01-08 20:45:27 | [diff] [blame] | 41 | scoped_refptr<HTTPTestServer> server = |
[email protected] | cad01431 | 2009-01-29 21:59:55 | [diff] [blame] | 42 | HTTPTestServer::CreateServer(L"chrome/test/data", NULL); |
[email protected] | dd26501 | 2009-01-08 20:45:27 | [diff] [blame] | 43 | ASSERT_TRUE(NULL != server.get()); |
| 44 | GURL test_url = server->TestServerPage("files/iframe404.html"); |
[email protected] | 022d781a | 2008-09-29 18:45:11 | [diff] [blame] | 45 | NavigateToURL(test_url); |
| 46 | |
| 47 | // Verify that the url is in the title. Since it's set via Javascript, we |
| 48 | // need to give it a chance to run. |
| 49 | int i; |
| 50 | std::wstring title; |
| 51 | for (i = 0; i < 10; ++i) { |
[email protected] | 5cc06369 | 2009-04-07 23:21:31 | [diff] [blame] | 52 | PlatformThread::Sleep(sleep_timeout_ms()); |
[email protected] | 022d781a | 2008-09-29 18:45:11 | [diff] [blame] | 53 | title = GetActiveTabTitle(); |
| 54 | if (title == L"SUCCESS") { |
| 55 | // Success, bail out. |
| 56 | break; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | if (i == 10) { |
| 61 | FAIL() << "iframe 404 didn't load properly"; |
| 62 | } |
| 63 | }; |