OLD | NEW |
| (Empty) |
1 // Copyright (c) 2009 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. | |
4 | |
5 #include "base/string_util.h" | |
6 #include "chrome/browser/browser.h" | |
7 #include "chrome/browser/net/url_request_failed_dns_job.h" | |
8 #include "chrome/browser/net/url_request_mock_http_job.h" | |
9 #include "chrome/test/in_process_browser_test.h" | |
10 #include "chrome/test/ui_test_utils.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 #include "webkit/glue/window_open_disposition.h" | |
13 | |
14 namespace { | |
15 | |
16 class ErrorPageBrowserTest : public InProcessBrowserTest { | |
17 protected: | |
18 // We're generally not sure what the title will be exactly (it comes from | |
19 // external source, and may be localized etc), but it will alway contain the | |
20 // hostname, so we check for that. | |
21 // For a proper way to do that http://crbug.com/18365 has been filed. | |
22 void AssertCurrentTabTitleContains(const std::string& text) { | |
23 string16 title; | |
24 EXPECT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title)); | |
25 EXPECT_NE(string16::npos, title.find(ASCIIToUTF16(text))) << | |
26 "could not find \"" << text << "\" in \"" << title << "\""; | |
27 } | |
28 }; | |
29 | |
30 using ui_test_utils::NavigateToURL; | |
31 | |
32 // We want to wait for two navigations: first will be the failing one, | |
33 // and the second will be the error page. | |
34 using ui_test_utils::NavigateToURLBlockUntilNavigationsComplete; | |
35 | |
36 IN_PROC_BROWSER_TEST_F(ErrorPageBrowserTest, DNSError_Basic) { | |
37 GURL test_url(URLRequestFailedDnsJob::kTestUrl); | |
38 NavigateToURLBlockUntilNavigationsComplete(browser(), test_url, 2); | |
39 AssertCurrentTabTitleContains(test_url.host()); | |
40 } | |
41 | |
42 // Test that a DNS error occuring in the main frame does not result in an | |
43 // additional session history entry. | |
44 IN_PROC_BROWSER_TEST_F(ErrorPageBrowserTest, DNSError_GoBack1) { | |
45 GURL test_url(URLRequestFailedDnsJob::kTestUrl); | |
46 | |
47 NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); | |
48 NavigateToURLBlockUntilNavigationsComplete(browser(), test_url, 2); | |
49 AssertCurrentTabTitleContains(test_url.host()); | |
50 | |
51 browser()->GoBack(CURRENT_TAB); | |
52 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); | |
53 | |
54 string16 title; | |
55 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title)); | |
56 EXPECT_EQ(ASCIIToUTF16("Title Of Awesomeness"), title); | |
57 } | |
58 | |
59 // Test that a DNS error occuring in the main frame does not result in an | |
60 // additional session history entry. | |
61 IN_PROC_BROWSER_TEST_F(ErrorPageBrowserTest, DNSError_GoBack2) { | |
62 GURL test_url(URLRequestFailedDnsJob::kTestUrl); | |
63 | |
64 NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); | |
65 NavigateToURLBlockUntilNavigationsComplete(browser(), test_url, 2); | |
66 AssertCurrentTabTitleContains(test_url.host()); | |
67 NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title3.html")); | |
68 | |
69 browser()->GoBack(CURRENT_TAB); | |
70 ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 2)); | |
71 AssertCurrentTabTitleContains(test_url.host()); | |
72 | |
73 browser()->GoBack(CURRENT_TAB); | |
74 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); | |
75 | |
76 string16 title; | |
77 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title)); | |
78 EXPECT_EQ(ASCIIToUTF16("Title Of Awesomeness"), title); | |
79 } | |
80 | |
81 // Test that a DNS error occuring in the main frame does not result in an | |
82 // additional session history entry. | |
83 IN_PROC_BROWSER_TEST_F(ErrorPageBrowserTest, DNSError_GoBackAndForward1) { | |
84 GURL test_url(URLRequestFailedDnsJob::kTestUrl); | |
85 | |
86 NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); | |
87 NavigateToURLBlockUntilNavigationsComplete(browser(), test_url, 2); | |
88 AssertCurrentTabTitleContains(test_url.host()); | |
89 NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title3.html")); | |
90 | |
91 browser()->GoBack(CURRENT_TAB); | |
92 ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 2)); | |
93 AssertCurrentTabTitleContains(test_url.host()); | |
94 | |
95 browser()->GoBack(CURRENT_TAB); | |
96 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); | |
97 | |
98 browser()->GoForward(CURRENT_TAB); | |
99 ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 2)); | |
100 AssertCurrentTabTitleContains(test_url.host()); | |
101 } | |
102 | |
103 // Test that a DNS error occuring in the main frame does not result in an | |
104 // additional session history entry. | |
105 IN_PROC_BROWSER_TEST_F(ErrorPageBrowserTest, DNSError_GoBackAndForward2) { | |
106 GURL test_url(URLRequestFailedDnsJob::kTestUrl); | |
107 | |
108 NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title3.html")); | |
109 NavigateToURLBlockUntilNavigationsComplete(browser(), test_url, 2); | |
110 AssertCurrentTabTitleContains(test_url.host()); | |
111 NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); | |
112 | |
113 browser()->GoBack(CURRENT_TAB); | |
114 ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 2)); | |
115 AssertCurrentTabTitleContains(test_url.host()); | |
116 | |
117 browser()->GoBack(CURRENT_TAB); | |
118 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); | |
119 | |
120 browser()->GoForward(CURRENT_TAB); | |
121 ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 2)); | |
122 AssertCurrentTabTitleContains(test_url.host()); | |
123 | |
124 browser()->GoForward(CURRENT_TAB); | |
125 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); | |
126 | |
127 string16 title; | |
128 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title)); | |
129 EXPECT_EQ(ASCIIToUTF16("Title Of Awesomeness"), title); | |
130 } | |
131 | |
132 } // namespace | |
OLD | NEW |