Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Side by Side Diff: chrome/browser/errorpage_uitest.cc

Issue 159575: Move alternate error page loading out of WebFrame.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/renderer/navigation_state.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/test/automation/tab_proxy.h"
6 #include "chrome/test/ui/ui_test.h" 7 #include "chrome/test/ui/ui_test.h"
7 #include "chrome/browser/net/url_request_failed_dns_job.h" 8 #include "chrome/browser/net/url_request_failed_dns_job.h"
9 #include "chrome/browser/net/url_request_mock_http_job.h"
8 #include "net/url_request/url_request_unittest.h" 10 #include "net/url_request/url_request_unittest.h"
9 11
10 class ErrorPageTest : public UITest { 12 class ErrorPageTest : public UITest {
13 protected:
14 std::wstring WaitForTitle() {
15 std::wstring title;
16 for (int i = 0; i < 10; ++i) {
17 PlatformThread::Sleep(sleep_timeout_ms());
18 title = GetActiveTabTitle();
19 if (!title.empty())
20 break;
21 }
22 return title;
23 }
11 }; 24 };
12 25
13 TEST_F(ErrorPageTest, DNSError) { 26 TEST_F(ErrorPageTest, DNSError_Basic) {
14 GURL test_url(URLRequestFailedDnsJob::kTestUrl); 27 GURL test_url(URLRequestFailedDnsJob::kTestUrl);
15 std::wstring test_host = UTF8ToWide(test_url.host()); 28 std::wstring test_host = UTF8ToWide(test_url.host());
16 NavigateToURL(test_url); 29 NavigateToURL(test_url);
17 30
18 // Verify that the url is in the title. Since it's set via Javascript, we 31 // Verify that the title contains test_host.
19 // need to give it a chance to run. 32 std::wstring title = WaitForTitle();
20 int i; 33 EXPECT_NE(std::wstring(), title);
21 std::wstring title; 34 EXPECT_TRUE(title.find(test_host) != std::wstring::npos) <<
22 for (i = 0; i < 10; ++i) { 35 "Title was: " << title;
23 PlatformThread::Sleep(sleep_timeout_ms()); 36 }
24 title = GetActiveTabTitle();
25 if (title.find(test_host) != std::wstring::npos) {
26 // Success, bail out.
27 break;
28 }
29 }
30 37
31 if (i == 10) { 38 TEST_F(ErrorPageTest, DNSError_GoBack1) {
32 FAIL() << "failed to get error page title; got " << title; 39 // Test that a DNS error occuring in the main frame does not result in an
33 } 40 // additional session history entry.
34 }; 41
42 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
43 NavigateToURL(GURL(URLRequestFailedDnsJob::kTestUrl));
44
45 GetActiveTab()->GoBack();
46
47 EXPECT_EQ(L"Title Of Awesomeness", WaitForTitle());
48 }
49
50 TEST_F(ErrorPageTest, DNSError_GoBack2) {
51 // Test that a DNS error occuring in the main frame does not result in an
52 // additional session history entry.
53
54 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
55 NavigateToURL(GURL(URLRequestFailedDnsJob::kTestUrl));
56 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title1.html"));
57
58 GetActiveTab()->GoBack();
59 GetActiveTab()->GoBack();
60
61 EXPECT_EQ(L"Title Of Awesomeness", WaitForTitle());
62 }
63
64 TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) {
65 // Test that a DNS error occuring in the main frame does not result in an
66 // additional session history entry.
67
68 GURL test_url(URLRequestFailedDnsJob::kTestUrl);
69 std::wstring test_host = UTF8ToWide(test_url.host());
70
71 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
72 NavigateToURL(test_url);
73 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title1.html"));
74
75 GetActiveTab()->GoBack();
76 GetActiveTab()->GoBack();
77 GetActiveTab()->GoForward();
78
79 // Verify that the title contains test_host.
80 std::wstring title = WaitForTitle();
81 EXPECT_NE(std::wstring(), title);
82 EXPECT_TRUE(title.find(test_host) != std::wstring::npos) <<
83 "Title was: " << title;
84 }
85
86 TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) {
87 // Test that a DNS error occuring in the main frame does not result in an
88 // additional session history entry.
89
90 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title1.html"));
91 NavigateToURL(GURL(URLRequestFailedDnsJob::kTestUrl));
92 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
93
94 GetActiveTab()->GoBack();
95 GetActiveTab()->GoBack();
96 GetActiveTab()->GoForward();
97 GetActiveTab()->GoForward();
98
99 EXPECT_EQ(L"Title Of Awesomeness", WaitForTitle());
100 }
101
102 TEST_F(ErrorPageTest, IFrameDNSError_Basic) {
103 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"iframe_dns_error.html"));
104 EXPECT_EQ(L"Blah", WaitForTitle());
105 }
106
107 TEST_F(ErrorPageTest, IFrameDNSError_GoBack) {
108 // Test that a DNS error occuring in an iframe does not result in an
109 // additional session history entry.
110
111 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
112 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"iframe_dns_error.html"));
113
114 GetActiveTab()->GoBack();
115
116 EXPECT_EQ(L"Title Of Awesomeness", WaitForTitle());
117 }
118
119 TEST_F(ErrorPageTest, IFrameDNSError_GoBackAndForward) {
120 // Test that a DNS error occuring in an iframe does not result in an
121 // additional session history entry.
122
123 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
124 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"iframe_dns_error.html"));
125
126 GetActiveTab()->GoBack();
127 GetActiveTab()->GoForward();
128
129 EXPECT_EQ(L"Blah", WaitForTitle());
130 }
35 131
36 TEST_F(ErrorPageTest, IFrame404) { 132 TEST_F(ErrorPageTest, IFrame404) {
37 // iframes that have 404 pages should not trigger an alternate error page. 133 // 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" 134 // 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 135 // 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". 136 // error page loads instead), then the title will remain as "FAIL".
41 scoped_refptr<HTTPTestServer> server = 137 scoped_refptr<HTTPTestServer> server =
42 HTTPTestServer::CreateServer(L"chrome/test/data", NULL); 138 HTTPTestServer::CreateServer(L"chrome/test/data", NULL);
43 ASSERT_TRUE(NULL != server.get()); 139 ASSERT_TRUE(NULL != server.get());
44 GURL test_url = server->TestServerPage("files/iframe404.html"); 140 GURL test_url = server->TestServerPage("files/iframe404.html");
45 NavigateToURL(test_url); 141 NavigateToURL(test_url);
46 142
47 // Verify that the url is in the title. Since it's set via Javascript, we 143 EXPECT_EQ(L"SUCCESS", WaitForTitle());
48 // need to give it a chance to run. 144 }
49 int i;
50 std::wstring title;
51 for (i = 0; i < 10; ++i) {
52 PlatformThread::Sleep(sleep_timeout_ms());
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 };
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/navigation_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698