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

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

Issue 174179: Mock the LinkDoctor for tests. Should greatly decrease ErrorPage test flakiness. (Closed)
Patch Set: sync with trunk Created 11 years, 3 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
« no previous file with comments | « no previous file | chrome/browser/google_util.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/automation/tab_proxy.h"
7 #include "chrome/test/ui/ui_test.h" 7 #include "chrome/test/ui/ui_test.h"
8 #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" 9 #include "chrome/browser/net/url_request_mock_http_job.h"
10 #include "net/url_request/url_request_unittest.h" 10 #include "net/url_request/url_request_unittest.h"
11 11
12 class ErrorPageTest : public UITest { 12 class ErrorPageTest : public UITest {
13 protected: 13 protected:
14 bool WaitForTitleMatching(const std::wstring& title) { 14 bool WaitForTitleMatching(const std::wstring& title) {
15 for (int i = 0; i < 100; ++i) { 15 for (int i = 0; i < 100; ++i) {
16 if (GetActiveTabTitle() == title) 16 if (GetActiveTabTitle() == title)
17 return true; 17 return true;
18 PlatformThread::Sleep(sleep_timeout_ms() / 10); 18 PlatformThread::Sleep(sleep_timeout_ms() / 10);
19 } 19 }
20 EXPECT_EQ(title, GetActiveTabTitle()); 20 EXPECT_EQ(title, GetActiveTabTitle());
21 return false; 21 return false;
22 } 22 }
23 bool WaitForTitleContaining(const std::string& title_substring) {
24 for (int i = 0; i < 100; ++i) {
25 std::wstring title = GetActiveTabTitle();
26 if (title.find(UTF8ToWide(title_substring)) != std::wstring::npos)
27 return true;
28 PlatformThread::Sleep(sleep_timeout_ms() / 10);
29 }
30 LOG(ERROR) << "Could not find " << title_substring << " in "
31 << GetActiveTabTitle();
32 return false;
33 }
34 }; 23 };
35 24
36 TEST_F(ErrorPageTest, DNSError_Basic) { 25 TEST_F(ErrorPageTest, DNSError_Basic) {
37 GURL test_url(URLRequestFailedDnsJob::kTestUrl); 26 GURL test_url(URLRequestFailedDnsJob::kTestUrl);
38 27
39 // The first navigation should fail, and the second one should be the error 28 // The first navigation should fail, and the second one should be the error
40 // page. 29 // page.
41 NavigateToURLBlockUntilNavigationsComplete(test_url, 2); 30 NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
42 31
43 EXPECT_TRUE(WaitForTitleContaining(test_url.host())); 32 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
44 } 33 }
45 34
46 TEST_F(ErrorPageTest, DNSError_GoBack1) { 35 TEST_F(ErrorPageTest, DNSError_GoBack1) {
47 // Test that a DNS error occuring in the main frame does not result in an 36 // Test that a DNS error occuring in the main frame does not result in an
48 // additional session history entry. 37 // additional session history entry.
49 GURL test_url(URLRequestFailedDnsJob::kTestUrl); 38 GURL test_url(URLRequestFailedDnsJob::kTestUrl);
50 39
51 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); 40 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
52 // The first navigation should fail, and the second one should be the error 41 // The first navigation should fail, and the second one should be the error
53 // page. 42 // page.
54 NavigateToURLBlockUntilNavigationsComplete(test_url, 2); 43 NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
55 EXPECT_TRUE(WaitForTitleContaining(test_url.host())); 44 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
56 45
57 GetActiveTab()->GoBack(); 46 GetActiveTab()->GoBack();
58 47
59 EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness")); 48 EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness"));
60 } 49 }
61 50
62 TEST_F(ErrorPageTest, DNSError_GoBack2) { 51 TEST_F(ErrorPageTest, DNSError_GoBack2) {
63 // Test that a DNS error occuring in the main frame does not result in an 52 // Test that a DNS error occuring in the main frame does not result in an
64 // additional session history entry. 53 // additional session history entry.
65 GURL test_url(URLRequestFailedDnsJob::kTestUrl); 54 GURL test_url(URLRequestFailedDnsJob::kTestUrl);
66 55
67 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); 56 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
68 // The first navigation should fail, and the second one should be the error 57 // The first navigation should fail, and the second one should be the error
69 // page. 58 // page.
70 NavigateToURLBlockUntilNavigationsComplete(test_url, 2); 59 NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
71 EXPECT_TRUE(WaitForTitleContaining(test_url.host())); 60 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
72 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title3.html")); 61 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title3.html"));
73 62
74 // The first navigation should fail, and the second one should be the error 63 // The first navigation should fail, and the second one should be the error
75 // page. 64 // page.
76 GetActiveTab()->GoBackBlockUntilNavigationsComplete(2); 65 GetActiveTab()->GoBackBlockUntilNavigationsComplete(2);
77 EXPECT_TRUE(WaitForTitleContaining(test_url.host())); 66 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
78 GetActiveTab()->GoBack(); 67 GetActiveTab()->GoBack();
79 68
80 EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness")); 69 EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness"));
81 } 70 }
82 71
83 TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) { 72 TEST_F(ErrorPageTest, DNSError_GoBack2AndForward) {
84 // Test that a DNS error occuring in the main frame does not result in an 73 // Test that a DNS error occuring in the main frame does not result in an
85 // additional session history entry. 74 // additional session history entry.
86 75
87 GURL test_url(URLRequestFailedDnsJob::kTestUrl); 76 GURL test_url(URLRequestFailedDnsJob::kTestUrl);
88 77
89 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); 78 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
90 // The first navigation should fail, and the second one should be the error 79 // The first navigation should fail, and the second one should be the error
91 // page. 80 // page.
92 NavigateToURLBlockUntilNavigationsComplete(test_url, 2); 81 NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
93 EXPECT_TRUE(WaitForTitleContaining(test_url.host())); 82 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
94 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title3.html")); 83 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title3.html"));
95 84
96 // The first navigation should fail, and the second one should be the error 85 // The first navigation should fail, and the second one should be the error
97 // page. 86 // page.
98 GetActiveTab()->GoBackBlockUntilNavigationsComplete(2); 87 GetActiveTab()->GoBackBlockUntilNavigationsComplete(2);
99 EXPECT_TRUE(WaitForTitleContaining(test_url.host())); 88 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
100 GetActiveTab()->GoBack(); 89 GetActiveTab()->GoBack();
101 // The first navigation should fail, and the second one should be the error 90 // The first navigation should fail, and the second one should be the error
102 // page. 91 // page.
103 GetActiveTab()->GoForwardBlockUntilNavigationsComplete(2); 92 GetActiveTab()->GoForwardBlockUntilNavigationsComplete(2);
104 93
105 EXPECT_TRUE(WaitForTitleContaining(test_url.host())); 94 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
106 } 95 }
107 96
108 TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) { 97 TEST_F(ErrorPageTest, DNSError_GoBack2Forward2) {
109 // Test that a DNS error occuring in the main frame does not result in an 98 // Test that a DNS error occuring in the main frame does not result in an
110 // additional session history entry. 99 // additional session history entry.
111 100
112 GURL test_url(URLRequestFailedDnsJob::kTestUrl); 101 GURL test_url(URLRequestFailedDnsJob::kTestUrl);
113 102
114 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title3.html")); 103 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title3.html"));
115 // The first navigation should fail, and the second one should be the error 104 // The first navigation should fail, and the second one should be the error
116 // page. 105 // page.
117 NavigateToURLBlockUntilNavigationsComplete(test_url, 2); 106 NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
118 EXPECT_TRUE(WaitForTitleContaining(test_url.host())); 107 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
119 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); 108 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
120 109
121 // The first navigation should fail, and the second one should be the error 110 // The first navigation should fail, and the second one should be the error
122 // page. 111 // page.
123 GetActiveTab()->GoBackBlockUntilNavigationsComplete(2); 112 GetActiveTab()->GoBackBlockUntilNavigationsComplete(2);
124 EXPECT_TRUE(WaitForTitleContaining(test_url.host())); 113 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
125 GetActiveTab()->GoBack(); 114 GetActiveTab()->GoBack();
126 // The first navigation should fail, and the second one should be the error 115 // The first navigation should fail, and the second one should be the error
127 // page. 116 // page.
128 GetActiveTab()->GoForwardBlockUntilNavigationsComplete(2); 117 GetActiveTab()->GoForwardBlockUntilNavigationsComplete(2);
129 EXPECT_TRUE(WaitForTitleContaining(test_url.host())); 118 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
130 GetActiveTab()->GoForward(); 119 GetActiveTab()->GoForward();
131 120
132 EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness")); 121 EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness"));
133 } 122 }
134 123
135 TEST_F(ErrorPageTest, IFrameDNSError_Basic) { 124 TEST_F(ErrorPageTest, IFrameDNSError_Basic) {
136 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"iframe_dns_error.html")); 125 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"iframe_dns_error.html"));
137 EXPECT_TRUE(WaitForTitleMatching(L"Blah")); 126 EXPECT_TRUE(WaitForTitleMatching(L"Blah"));
138 } 127 }
139 128
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 EXPECT_TRUE(WaitForTitleMatching(L"SUCCESS")); 165 EXPECT_TRUE(WaitForTitleMatching(L"SUCCESS"));
177 } 166 }
178 167
179 TEST_F(ErrorPageTest, Page404) { 168 TEST_F(ErrorPageTest, Page404) {
180 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); 169 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
181 // The first navigation should fail, and the second one should be the error 170 // The first navigation should fail, and the second one should be the error
182 // page. 171 // page.
183 NavigateToURLBlockUntilNavigationsComplete( 172 NavigateToURLBlockUntilNavigationsComplete(
184 URLRequestMockHTTPJob::GetMockUrl(L"page404.html"), 2); 173 URLRequestMockHTTPJob::GetMockUrl(L"page404.html"), 2);
185 174
186 EXPECT_TRUE(WaitForTitleContaining("page404.html")); 175 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
187 } 176 }
188 177
189 TEST_F(ErrorPageTest, Page404_GoBack) { 178 TEST_F(ErrorPageTest, Page404_GoBack) {
190 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); 179 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
191 // The first navigation should fail, and the second one should be the error 180 // The first navigation should fail, and the second one should be the error
192 // page. 181 // page.
193 NavigateToURLBlockUntilNavigationsComplete( 182 NavigateToURLBlockUntilNavigationsComplete(
194 URLRequestMockHTTPJob::GetMockUrl(L"page404.html"), 2); 183 URLRequestMockHTTPJob::GetMockUrl(L"page404.html"), 2);
195 EXPECT_TRUE(WaitForTitleContaining("page404.html")); 184 EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
196 185
197 GetActiveTab()->GoBack(); 186 GetActiveTab()->GoBack();
198 187
199 EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness")); 188 EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness"));
200 } 189 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/google_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698