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

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

Issue 12930: Third time's a charm?... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years 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 | « base/nss_init.cc ('k') | chrome/test/data/ssl/certificates/expired_cert.pem » ('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 <Windows.h> 5 #include <Windows.h>
6 #include <Wincrypt.h> 6 #include <Wincrypt.h>
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "chrome/common/pref_names.h" 10 #include "chrome/common/pref_names.h"
11 #include "chrome/test/automation/browser_proxy.h" 11 #include "chrome/test/automation/browser_proxy.h"
12 #include "chrome/test/automation/tab_proxy.h" 12 #include "chrome/test/automation/tab_proxy.h"
13 #include "chrome/test/ui/ui_test.h" 13 #include "chrome/test/ui/ui_test.h"
14 #include "net/base/ssl_test_util.h"
14 #include "net/url_request/url_request_unittest.h" 15 #include "net/url_request/url_request_unittest.h"
15 16
16 namespace { 17 namespace {
17 18
18 const wchar_t kDocRoot[] = L"chrome/test/data"; 19 const wchar_t kDocRoot[] = L"chrome/test/data";
19 const char kHostName[] = "127.0.0.1";
20
21 const int kOKHTTPSPort = 9443;
22 const int kBadHTTPSPort = 9666;
23
24 // The issuer name of the cert that should be trusted for the test to work.
25 const wchar_t kCertIssuerName[] = L"Test CA";
26 20
27 class SSLUITest : public UITest { 21 class SSLUITest : public UITest {
28 protected: 22 protected:
29 SSLUITest() { 23 SSLUITest() {
30 CheckCATrusted();
31 dom_automation_enabled_ = true; 24 dom_automation_enabled_ = true;
32 PathService::Get(base::DIR_SOURCE_ROOT, &cert_dir_); 25 EXPECT_TRUE(util_.CheckCATrusted());
33 cert_dir_ += L"/chrome/test/data/ssl/certificates/";
34 std::replace(cert_dir_.begin(), cert_dir_.end(),
35 L'/', FilePath::kSeparators[0]);
36 } 26 }
37 27
38 TabProxy* GetActiveTabProxy() { 28 TabProxy* GetActiveTabProxy() {
39 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); 29 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
40 EXPECT_TRUE(browser_proxy.get()); 30 EXPECT_TRUE(browser_proxy.get());
41 return browser_proxy->GetActiveTab(); 31 return browser_proxy->GetActiveTab();
42 } 32 }
43 33
44 void NavigateTab(TabProxy* tab_proxy, const GURL& url) { 34 void NavigateTab(TabProxy* tab_proxy, const GURL& url) {
45 ASSERT_TRUE(tab_proxy->NavigateToURL(url)); 35 ASSERT_TRUE(tab_proxy->NavigateToURL(url));
46 } 36 }
47 37
48 void AppendTab(const GURL& url) { 38 void AppendTab(const GURL& url) {
49 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); 39 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
50 EXPECT_TRUE(browser_proxy.get()); 40 EXPECT_TRUE(browser_proxy.get());
51 EXPECT_TRUE(browser_proxy->AppendTab(url)); 41 EXPECT_TRUE(browser_proxy->AppendTab(url));
52 } 42 }
53 43
54 std::wstring GetOKCertPath() { 44 TestServer* PlainServer() {
55 std::wstring path(cert_dir_); 45 return new TestServer(kDocRoot);
56 file_util::AppendToPath(&path, L"ok_cert.pem");
57 return path;
58 } 46 }
59 47
60 std::wstring GetInvalidCertPath() { 48 HTTPSTestServer* GoodCertServer() {
61 std::wstring path(cert_dir_); 49 return new HTTPSTestServer(util_.kHostName, util_.kOKHTTPSPort,
62 file_util::AppendToPath(&path, L"invalid_cert.pem"); 50 kDocRoot, util_.GetOKCertPath().ToWStringHack());
63 return path;
64 } 51 }
65 52
66 std::wstring GetExpiredCertPath() { 53 HTTPSTestServer* BadCertServer() {
67 std::wstring path(cert_dir_); 54 return new HTTPSTestServer(util_.kHostName, util_.kBadHTTPSPort,
68 file_util::AppendToPath(&path, L"expired_cert.pem"); 55 kDocRoot, util_.GetExpiredCertPath().ToWStringHack());
69 return path;
70 } 56 }
71 57
72 HTTPSTestServer GoodServer() { 58 protected:
73 return HTTPSTestServer(kHostName, kOKHTTPSPort, kDocRoot, GetOKCertPath()); 59 SSLTestUtil util_;
74 }
75 60
76 HTTPSTestServer BadServer() { 61 DISALLOW_COPY_AND_ASSIGN(SSLUITest);
77 return HTTPSTestServer(kHostName, kBadHTTPSPort, kDocRoot,
78 GetExpiredCertPath());
79 }
80
81 private:
82 void CheckCATrusted() {
83 HCERTSTORE cert_store = CertOpenSystemStore(NULL, L"ROOT");
84 if (!cert_store) {
85 FAIL() << " could not open trusted root CA store";
86 return;
87 }
88 PCCERT_CONTEXT cert =
89 CertFindCertificateInStore(cert_store,
90 X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
91 0,
92 CERT_FIND_ISSUER_STR,
93 kCertIssuerName,
94 NULL);
95 if (cert)
96 CertFreeCertificateContext(cert);
97 CertCloseStore(cert_store, 0);
98
99 if (!cert) {
100 FAIL() << " TEST CONFIGURATION ERROR: you need to import the test ca "
101 "certificate to your trusted roots for this test to work. For more "
102 "info visit:\n"
103 "http://wiki.corp.google.com/twiki/bin/view/Main/ChromeUnitUITests\n";
104 }
105 }
106
107 std::wstring cert_dir_;
108 }; 62 };
109 63
110 } // namespace 64 } // namespace
111 65
112 // Visits a regular page over http. 66 // Visits a regular page over http.
113 TEST_F(SSLUITest, TestHTTP) { 67 TEST_F(SSLUITest, TestHTTP) {
114 TestServer server(kDocRoot); 68 scoped_ptr<TestServer> server(PlainServer());
115 69
116 scoped_ptr<TabProxy> tab(GetActiveTabProxy()); 70 scoped_ptr<TabProxy> tab(GetActiveTabProxy());
117 NavigateTab(tab.get(), server.TestServerPageW(L"files/ssl/google.html")); 71 NavigateTab(tab.get(), server->TestServerPageW(L"files/ssl/google.html"));
118 72
119 NavigationEntry::PageType page_type; 73 NavigationEntry::PageType page_type;
120 EXPECT_TRUE(tab->GetPageType(&page_type)); 74 EXPECT_TRUE(tab->GetPageType(&page_type));
121 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type); 75 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type);
122 76
123 SecurityStyle security_style; 77 SecurityStyle security_style;
124 int cert_status; 78 int cert_status;
125 int mixed_content_state; 79 int mixed_content_state;
126 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 80 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
127 &mixed_content_state)); 81 &mixed_content_state));
128 EXPECT_EQ(SECURITY_STYLE_UNAUTHENTICATED, security_style); 82 EXPECT_EQ(SECURITY_STYLE_UNAUTHENTICATED, security_style);
129 EXPECT_EQ(0, cert_status); 83 EXPECT_EQ(0, cert_status);
130 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 84 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
131 } 85 }
132 86
133 // Visits a page over http which includes broken https resources (status should 87 // Visits a page over http which includes broken https resources (status should
134 // be OK). 88 // be OK).
135 TEST_F(SSLUITest, TestHTTPWithBrokenHTTPSResource) { 89 TEST_F(SSLUITest, TestHTTPWithBrokenHTTPSResource) {
136 TestServer http_server(kDocRoot); 90 scoped_ptr<TestServer> http_server(PlainServer());
137 HTTPSTestServer httpsServer(kHostName, kBadHTTPSPort, 91 scoped_ptr<HTTPSTestServer> bad_https_server(BadCertServer());
138 kDocRoot, GetExpiredCertPath());
139 scoped_ptr<TabProxy> tab(GetActiveTabProxy()); 92 scoped_ptr<TabProxy> tab(GetActiveTabProxy());
140 93
141 NavigateTab(tab.get(), 94 NavigateTab(tab.get(),
142 http_server.TestServerPageW(L"files/ssl/page_with_unsafe_contents.html")); 95 http_server->TestServerPageW(L"files/ssl/page_with_unsafe_contents.html")) ;
143 96
144 SecurityStyle security_style; 97 SecurityStyle security_style;
145 int cert_status; 98 int cert_status;
146 int mixed_content_state; 99 int mixed_content_state;
147 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 100 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
148 &mixed_content_state)); 101 &mixed_content_state));
149 EXPECT_EQ(SECURITY_STYLE_UNAUTHENTICATED, security_style); 102 EXPECT_EQ(SECURITY_STYLE_UNAUTHENTICATED, security_style);
150 EXPECT_EQ(0, cert_status); 103 EXPECT_EQ(0, cert_status);
151 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 104 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
152 } 105 }
153 106
154 // Visits a page over OK https: 107 // Visits a page over OK https:
155 TEST_F(SSLUITest, TestOKHTTPS) { 108 TEST_F(SSLUITest, TestOKHTTPS) {
156 HTTPSTestServer https_server = GoodServer(); 109 scoped_ptr<HTTPSTestServer> https_server(GoodCertServer());
157 scoped_ptr<TabProxy> tab(GetActiveTabProxy()); 110 scoped_ptr<TabProxy> tab(GetActiveTabProxy());
158 NavigateTab(tab.get(), 111 NavigateTab(tab.get(),
159 https_server.TestServerPageW(L"files/ssl/google.html")); 112 https_server->TestServerPageW(L"files/ssl/google.html"));
160 113
161 NavigationEntry::PageType page_type; 114 NavigationEntry::PageType page_type;
162 EXPECT_TRUE(tab->GetPageType(&page_type)); 115 EXPECT_TRUE(tab->GetPageType(&page_type));
163 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type); 116 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type);
164 117
165 SecurityStyle security_style; 118 SecurityStyle security_style;
166 int cert_status; 119 int cert_status;
167 int mixed_content_state; 120 int mixed_content_state;
168 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 121 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
169 &mixed_content_state)); 122 &mixed_content_state));
170 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style); 123 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style);
171 EXPECT_EQ(0, cert_status & net::CERT_STATUS_ALL_ERRORS); 124 EXPECT_EQ(0, cert_status & net::CERT_STATUS_ALL_ERRORS);
172 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 125 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
173 } 126 }
174 127
175 // Visits a page with https error: 128 // Visits a page with https error:
176 TEST_F(SSLUITest, TestHTTPSExpiredCert) { 129 TEST_F(SSLUITest, TestHTTPSExpiredCert) {
177 HTTPSTestServer https_server = BadServer(); 130 scoped_ptr<HTTPSTestServer> bad_https_server(BadCertServer());
178 scoped_ptr<TabProxy> tab(GetActiveTabProxy()); 131 scoped_ptr<TabProxy> tab(GetActiveTabProxy());
179 NavigateTab(tab.get(), 132 NavigateTab(tab.get(),
180 https_server.TestServerPageW(L"files/ssl/google.html")); 133 bad_https_server->TestServerPageW(L"files/ssl/google.html"));
181 134
182 NavigationEntry::PageType page_type; 135 NavigationEntry::PageType page_type;
183 EXPECT_TRUE(tab->GetPageType(&page_type)); 136 EXPECT_TRUE(tab->GetPageType(&page_type));
184 EXPECT_EQ(NavigationEntry::INTERSTITIAL_PAGE, page_type); 137 EXPECT_EQ(NavigationEntry::INTERSTITIAL_PAGE, page_type);
185 138
186 SecurityStyle security_style; 139 SecurityStyle security_style;
187 int cert_status; 140 int cert_status;
188 int mixed_content_state; 141 int mixed_content_state;
189 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 142 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
190 &mixed_content_state)); 143 &mixed_content_state));
(...skipping 12 matching lines...) Expand all
203 cert_status & net::CERT_STATUS_ALL_ERRORS); 156 cert_status & net::CERT_STATUS_ALL_ERRORS);
204 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 157 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
205 } 158 }
206 159
207 // 160 //
208 // Mixed contents 161 // Mixed contents
209 // 162 //
210 163
211 // Visits a page with mixed content. 164 // Visits a page with mixed content.
212 TEST_F(SSLUITest, TestMixedContents) { 165 TEST_F(SSLUITest, TestMixedContents) {
213 HTTPSTestServer https_server = GoodServer(); 166 scoped_ptr<HTTPSTestServer> https_server(GoodCertServer());
214 TestServer http_server(kDocRoot); 167 scoped_ptr<TestServer> http_server(PlainServer());
215 168
216 // Load a page with mixed-content, the default behavior is to show the mixed 169 // Load a page with mixed-content, the default behavior is to show the mixed
217 // content. 170 // content.
218 scoped_ptr<TabProxy> tab(GetActiveTabProxy()); 171 scoped_ptr<TabProxy> tab(GetActiveTabProxy());
219 NavigateTab(tab.get(), 172 NavigateTab(tab.get(),
220 https_server.TestServerPageW(L"files/ssl/page_with_mixed_contents.html")); 173 https_server->TestServerPageW(L"files/ssl/page_with_mixed_contents.html")) ;
221 NavigationEntry::PageType page_type; 174 NavigationEntry::PageType page_type;
222 EXPECT_TRUE(tab->GetPageType(&page_type)); 175 EXPECT_TRUE(tab->GetPageType(&page_type));
223 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type); 176 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type);
224 177
225 SecurityStyle security_style; 178 SecurityStyle security_style;
226 int cert_status; 179 int cert_status;
227 int mixed_content_state; 180 int mixed_content_state;
228 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 181 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
229 &mixed_content_state)); 182 &mixed_content_state));
230 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style); 183 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 &mixed_content_state)); 228 &mixed_content_state));
276 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style); 229 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style);
277 EXPECT_EQ(0, cert_status & net::CERT_STATUS_ALL_ERRORS); 230 EXPECT_EQ(0, cert_status & net::CERT_STATUS_ALL_ERRORS);
278 EXPECT_EQ(NavigationEntry::SSLStatus::MIXED_CONTENT, mixed_content_state); 231 EXPECT_EQ(NavigationEntry::SSLStatus::MIXED_CONTENT, mixed_content_state);
279 } 232 }
280 233
281 // Visits a page with unsafe content and make sure that: 234 // Visits a page with unsafe content and make sure that:
282 // - frames content is replaced with warning 235 // - frames content is replaced with warning
283 // - images and scripts are filtered out entirely 236 // - images and scripts are filtered out entirely
284 TEST_F(SSLUITest, TestUnsafeContents) { 237 TEST_F(SSLUITest, TestUnsafeContents) {
285 HTTPSTestServer good_https_server = GoodServer(); 238 scoped_ptr<HTTPSTestServer> good_https_server(GoodCertServer());
286 HTTPSTestServer bad_https_server = BadServer(); 239 scoped_ptr<HTTPSTestServer> bad_https_server(BadCertServer());
287 240
288 scoped_ptr<TabProxy> tab(GetActiveTabProxy()); 241 scoped_ptr<TabProxy> tab(GetActiveTabProxy());
289 NavigateTab(tab.get(), 242 NavigateTab(tab.get(),
290 good_https_server.TestServerPageW( 243 good_https_server->TestServerPageW(
291 L"files/ssl/page_with_unsafe_contents.html")); 244 L"files/ssl/page_with_unsafe_contents.html"));
292 NavigationEntry::PageType page_type; 245 NavigationEntry::PageType page_type;
293 EXPECT_TRUE(tab->GetPageType(&page_type)); 246 EXPECT_TRUE(tab->GetPageType(&page_type));
294 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type); 247 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type);
295 248
296 SecurityStyle security_style; 249 SecurityStyle security_style;
297 int cert_status; 250 int cert_status;
298 int mixed_content_state; 251 int mixed_content_state;
299 // When the bad content is filtered, the state is expected to be 252 // When the bad content is filtered, the state is expected to be
300 // authenticated. 253 // authenticated.
(...skipping 24 matching lines...) Expand all
325 278
326 bool js_result = false; 279 bool js_result = false;
327 EXPECT_TRUE(tab->ExecuteAndExtractBool(L"", 280 EXPECT_TRUE(tab->ExecuteAndExtractBool(L"",
328 L"window.domAutomationController.send(IsFooSet());", 281 L"window.domAutomationController.send(IsFooSet());",
329 &js_result)); 282 &js_result));
330 EXPECT_FALSE(js_result); 283 EXPECT_FALSE(js_result);
331 } 284 }
332 285
333 // Visits a page with mixed content loaded by JS (after the initial page load). 286 // Visits a page with mixed content loaded by JS (after the initial page load).
334 TEST_F(SSLUITest, TestMixedContentsLoadedFromJS) { 287 TEST_F(SSLUITest, TestMixedContentsLoadedFromJS) {
335 HTTPSTestServer https_server = GoodServer(); 288 scoped_ptr<HTTPSTestServer> https_server(GoodCertServer());
336 TestServer http_server(kDocRoot); 289 scoped_ptr<TestServer> http_server(PlainServer());
337 290
338 scoped_ptr<TabProxy> tab(GetActiveTabProxy()); 291 scoped_ptr<TabProxy> tab(GetActiveTabProxy());
339 NavigateTab(tab.get(), https_server.TestServerPageW( 292 NavigateTab(tab.get(), https_server->TestServerPageW(
340 L"files/ssl/page_with_dynamic_mixed_contents.html")); 293 L"files/ssl/page_with_dynamic_mixed_contents.html"));
341 NavigationEntry::PageType page_type; 294 NavigationEntry::PageType page_type;
342 EXPECT_TRUE(tab->GetPageType(&page_type)); 295 EXPECT_TRUE(tab->GetPageType(&page_type));
343 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type); 296 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type);
344 SecurityStyle security_style; 297 SecurityStyle security_style;
345 int cert_status; 298 int cert_status;
346 int mixed_content_state; 299 int mixed_content_state;
347 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 300 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
348 &mixed_content_state)); 301 &mixed_content_state));
349 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style); 302 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style);
(...skipping 14 matching lines...) Expand all
364 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style); 317 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style);
365 EXPECT_EQ(0, 318 EXPECT_EQ(0,
366 cert_status & net::CERT_STATUS_ALL_ERRORS); // No errors expected. 319 cert_status & net::CERT_STATUS_ALL_ERRORS); // No errors expected.
367 EXPECT_EQ(NavigationEntry::SSLStatus::MIXED_CONTENT, mixed_content_state); 320 EXPECT_EQ(NavigationEntry::SSLStatus::MIXED_CONTENT, mixed_content_state);
368 } 321 }
369 322
370 // Visits a page with an image over http. Visits another page over https 323 // Visits a page with an image over http. Visits another page over https
371 // referencing that same image over http (hoping it is coming from the webcore 324 // referencing that same image over http (hoping it is coming from the webcore
372 // memory cache). 325 // memory cache).
373 TEST_F(SSLUITest, TestCachedMixedContents) { 326 TEST_F(SSLUITest, TestCachedMixedContents) {
374 HTTPSTestServer https_server = GoodServer(); 327 scoped_ptr<HTTPSTestServer> https_server(GoodCertServer());
375 TestServer http_server(kDocRoot); 328 scoped_ptr<TestServer> http_server(PlainServer());
376 329
377 scoped_ptr<TabProxy> tab(GetActiveTabProxy()); 330 scoped_ptr<TabProxy> tab(GetActiveTabProxy());
378 NavigateTab(tab.get(), http_server.TestServerPageW( 331 NavigateTab(tab.get(), http_server->TestServerPageW(
379 L"files/ssl/page_with_mixed_contents.html")); 332 L"files/ssl/page_with_mixed_contents.html"));
380 333
381 NavigationEntry::PageType page_type; 334 NavigationEntry::PageType page_type;
382 EXPECT_TRUE(tab->GetPageType(&page_type)); 335 EXPECT_TRUE(tab->GetPageType(&page_type));
383 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type); 336 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type);
384 SecurityStyle security_style; 337 SecurityStyle security_style;
385 int cert_status; 338 int cert_status;
386 int mixed_content_state; 339 int mixed_content_state;
387 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 340 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
388 &mixed_content_state)); 341 &mixed_content_state));
389 EXPECT_EQ(SECURITY_STYLE_UNAUTHENTICATED, security_style); 342 EXPECT_EQ(SECURITY_STYLE_UNAUTHENTICATED, security_style);
390 EXPECT_EQ(0, 343 EXPECT_EQ(0,
391 cert_status & net::CERT_STATUS_ALL_ERRORS); // No errors expected. 344 cert_status & net::CERT_STATUS_ALL_ERRORS); // No errors expected.
392 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 345 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
393 346
394 // Load again but over SSL. It should have mixed-contents (even though the 347 // Load again but over SSL. It should have mixed-contents (even though the
395 // image comes from the WebCore memory cache). 348 // image comes from the WebCore memory cache).
396 NavigateTab(tab.get(), https_server.TestServerPageW( 349 NavigateTab(tab.get(), https_server->TestServerPageW(
397 L"files/ssl/page_with_mixed_contents.html")); 350 L"files/ssl/page_with_mixed_contents.html"));
398 351
399 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 352 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
400 &mixed_content_state)); 353 &mixed_content_state));
401 EXPECT_TRUE(tab->GetPageType(&page_type)); 354 EXPECT_TRUE(tab->GetPageType(&page_type));
402 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type); 355 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type);
403 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style); 356 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style);
404 EXPECT_EQ(0, 357 EXPECT_EQ(0,
405 cert_status & net::CERT_STATUS_ALL_ERRORS); // No errors expected. 358 cert_status & net::CERT_STATUS_ALL_ERRORS); // No errors expected.
406 EXPECT_EQ(NavigationEntry::SSLStatus::MIXED_CONTENT, mixed_content_state); 359 EXPECT_EQ(NavigationEntry::SSLStatus::MIXED_CONTENT, mixed_content_state);
407 } 360 }
408 361
409 // This test ensures the CN invalid status does not 'stick' to a certificate 362 // This test ensures the CN invalid status does not 'stick' to a certificate
410 // (see bug #1044942) and that it depends on the host-name. 363 // (see bug #1044942) and that it depends on the host-name.
411 // TODO (jcampan): this test is flacky and fails sometimes (bug #1065095) 364 // TODO(jcampan): this test is flacky and fails sometimes (bug #1065095)
412 TEST_F(SSLUITest, DISABLED_TestCNInvalidStickiness) { 365 TEST_F(SSLUITest, DISABLED_TestCNInvalidStickiness) {
413 const std::string kLocalHost = "localhost"; 366 const std::string kLocalHost = "localhost";
414 HTTPSTestServer https_server(kLocalHost, kOKHTTPSPort, 367 scoped_ptr<HTTPSTestServer> https_server(
415 kDocRoot, GetOKCertPath()); 368 new HTTPSTestServer(kLocalHost, util_.kOKHTTPSPort,
369 kDocRoot, util_.GetOKCertPath().ToWStringHack()));
416 370
417 // First we hit the server with hostname, this generates an invalid policy 371 // First we hit the server with hostname, this generates an invalid policy
418 // error. 372 // error.
419 scoped_ptr<TabProxy> tab(GetActiveTabProxy()); 373 scoped_ptr<TabProxy> tab(GetActiveTabProxy());
420 NavigateTab(tab.get(), https_server.TestServerPageW( 374 NavigateTab(tab.get(), https_server->TestServerPageW(
421 L"files/ssl/google.html")); 375 L"files/ssl/google.html"));
422 376
423 // We get an interstitial page as a result. 377 // We get an interstitial page as a result.
424 NavigationEntry::PageType page_type; 378 NavigationEntry::PageType page_type;
425 EXPECT_TRUE(tab->GetPageType(&page_type)); 379 EXPECT_TRUE(tab->GetPageType(&page_type));
426 EXPECT_EQ(NavigationEntry::INTERSTITIAL_PAGE, page_type); 380 EXPECT_EQ(NavigationEntry::INTERSTITIAL_PAGE, page_type);
427 381
428 SecurityStyle security_style; 382 SecurityStyle security_style;
429 int cert_status; 383 int cert_status;
430 int mixed_content_state; 384 int mixed_content_state;
431 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 385 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
432 &mixed_content_state)); 386 &mixed_content_state));
433 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATION_BROKEN, security_style); 387 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATION_BROKEN, security_style);
434 EXPECT_EQ(net::CERT_STATUS_COMMON_NAME_INVALID, 388 EXPECT_EQ(net::CERT_STATUS_COMMON_NAME_INVALID,
435 cert_status & net::CERT_STATUS_ALL_ERRORS); 389 cert_status & net::CERT_STATUS_ALL_ERRORS);
436 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 390 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
437 391
438 // We proceed through the interstitial page. 392 // We proceed through the interstitial page.
439 EXPECT_TRUE(tab->TakeActionOnSSLBlockingPage(true)); 393 EXPECT_TRUE(tab->TakeActionOnSSLBlockingPage(true));
440 EXPECT_TRUE(tab->GetPageType(&page_type)); 394 EXPECT_TRUE(tab->GetPageType(&page_type));
441 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type); 395 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type);
442 396
443 // Now we try again with the right host name this time. 397 // Now we try again with the right host name this time.
444 398
445 // Let's change the host-name in the url. 399 // Let's change the host-name in the url.
446 GURL url = https_server.TestServerPageW(L"files/ssl/google.html"); 400 GURL url = https_server->TestServerPageW(L"files/ssl/google.html");
447 std::string::size_type hostname_index = url.spec().find(kLocalHost); 401 std::string::size_type hostname_index = url.spec().find(kLocalHost);
448 ASSERT_TRUE(hostname_index != std::string::npos); // Test sanity check. 402 ASSERT_TRUE(hostname_index != std::string::npos); // Test sanity check.
449 std::string new_url; 403 std::string new_url;
450 new_url.append(url.spec().substr(0, hostname_index)); 404 new_url.append(url.spec().substr(0, hostname_index));
451 new_url.append(kHostName); 405 new_url.append(util_.kHostName);
452 new_url.append(url.spec().substr(hostname_index + kLocalHost.size())); 406 new_url.append(url.spec().substr(hostname_index + kLocalHost.size()));
453 407
454 NavigateTab(tab.get(), GURL(new_url)); 408 NavigateTab(tab.get(), GURL(new_url));
455 409
456 // Security state should be OK. 410 // Security state should be OK.
457 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 411 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
458 &mixed_content_state)); 412 &mixed_content_state));
459 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style); 413 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style);
460 EXPECT_EQ(0, 414 EXPECT_EQ(0,
461 cert_status & net::CERT_STATUS_ALL_ERRORS); // No errors expected. 415 cert_status & net::CERT_STATUS_ALL_ERRORS); // No errors expected.
462 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 416 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
463 417
464 // Now try again the broken one to make sure it is still broken. 418 // Now try again the broken one to make sure it is still broken.
465 NavigateTab(tab.get(), https_server.TestServerPageW( 419 NavigateTab(tab.get(), https_server->TestServerPageW(
466 L"files/ssl/google.html")); 420 L"files/ssl/google.html"));
467 421
468 EXPECT_TRUE(tab->GetPageType(&page_type)); 422 EXPECT_TRUE(tab->GetPageType(&page_type));
469 // Since we OKed the interstitial last time, we get right to the page. 423 // Since we OKed the interstitial last time, we get right to the page.
470 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type); 424 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type);
471 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 425 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
472 &mixed_content_state)); 426 &mixed_content_state));
473 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATION_BROKEN, security_style); 427 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATION_BROKEN, security_style);
474 EXPECT_EQ(net::CERT_STATUS_COMMON_NAME_INVALID, 428 EXPECT_EQ(net::CERT_STATUS_COMMON_NAME_INVALID,
475 cert_status & net::CERT_STATUS_ALL_ERRORS); 429 cert_status & net::CERT_STATUS_ALL_ERRORS);
476 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 430 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
477 } 431 }
478 432
479 // Test that navigating to a #ref does not change a bad security state. 433 // Test that navigating to a #ref does not change a bad security state.
480 TEST_F(SSLUITest, TestRefNavigation) { 434 TEST_F(SSLUITest, TestRefNavigation) {
481 HTTPSTestServer https_server = BadServer(); 435 scoped_ptr<HTTPSTestServer> bad_https_server(BadCertServer());
482 scoped_ptr<TabProxy> tab(GetActiveTabProxy()); 436 scoped_ptr<TabProxy> tab(GetActiveTabProxy());
483 NavigateTab(tab.get(), 437 NavigateTab(tab.get(),
484 https_server.TestServerPageW(L"files/ssl/page_with_refs.html")); 438 bad_https_server->TestServerPageW(L"files/ssl/page_with_refs.html" ));
485 439
486 NavigationEntry::PageType page_type; 440 NavigationEntry::PageType page_type;
487 EXPECT_TRUE(tab->GetPageType(&page_type)); 441 EXPECT_TRUE(tab->GetPageType(&page_type));
488 EXPECT_EQ(page_type, NavigationEntry::INTERSTITIAL_PAGE); 442 EXPECT_EQ(page_type, NavigationEntry::INTERSTITIAL_PAGE);
489 443
490 SecurityStyle security_style; 444 SecurityStyle security_style;
491 int cert_status; 445 int cert_status;
492 int mixed_content_state; 446 int mixed_content_state;
493 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 447 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
494 &mixed_content_state)); 448 &mixed_content_state));
495 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATION_BROKEN, security_style); 449 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATION_BROKEN, security_style);
496 EXPECT_EQ(net::CERT_STATUS_DATE_INVALID, cert_status); 450 EXPECT_EQ(net::CERT_STATUS_DATE_INVALID, cert_status);
497 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 451 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
498 452
499 EXPECT_TRUE(tab->TakeActionOnSSLBlockingPage(true)); 453 EXPECT_TRUE(tab->TakeActionOnSSLBlockingPage(true));
500 EXPECT_TRUE(tab->GetPageType(&page_type)); 454 EXPECT_TRUE(tab->GetPageType(&page_type));
501 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type); 455 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type);
502 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 456 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
503 &mixed_content_state)); 457 &mixed_content_state));
504 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATION_BROKEN, security_style); 458 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATION_BROKEN, security_style);
505 EXPECT_EQ(net::CERT_STATUS_DATE_INVALID, 459 EXPECT_EQ(net::CERT_STATUS_DATE_INVALID,
506 cert_status & net::CERT_STATUS_ALL_ERRORS); 460 cert_status & net::CERT_STATUS_ALL_ERRORS);
507 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 461 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
508 462
509 // Now navigate to a ref in the page. 463 // Now navigate to a ref in the page.
510 NavigateTab(tab.get(), 464 NavigateTab(tab.get(),
511 https_server.TestServerPageW(L"files/ssl/page_with_refs.html#jp")); 465 bad_https_server->TestServerPageW(L"files/ssl/page_with_refs.html#jp"));
512 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 466 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
513 &mixed_content_state)); 467 &mixed_content_state));
514 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATION_BROKEN, security_style); 468 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATION_BROKEN, security_style);
515 EXPECT_EQ(net::CERT_STATUS_DATE_INVALID, 469 EXPECT_EQ(net::CERT_STATUS_DATE_INVALID,
516 cert_status & net::CERT_STATUS_ALL_ERRORS); 470 cert_status & net::CERT_STATUS_ALL_ERRORS);
517 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 471 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
518 } 472 }
519 473
520 // Tests that closing a page that has a unsafe pop-up does not crash the browser 474 // Tests that closing a page that has a unsafe pop-up does not crash the browser
521 // (bug #1966). 475 // (bug #1966).
522 // Disabled because flaky (bug #2136). 476 // Disabled because flaky (bug #2136).
523 TEST_F(SSLUITest, DISABLED_TestCloseTabWithUnsafePopup) { 477 TEST_F(SSLUITest, DISABLED_TestCloseTabWithUnsafePopup) {
524 TestServer http_server(kDocRoot); 478 scoped_ptr<TestServer> http_server(PlainServer());
525 HTTPSTestServer bad_https_server = BadServer(); 479 scoped_ptr<HTTPSTestServer> bad_https_server(BadCertServer());
526 480
527 scoped_ptr<TabProxy> tab(GetActiveTabProxy()); 481 scoped_ptr<TabProxy> tab(GetActiveTabProxy());
528 NavigateTab(tab.get(), 482 NavigateTab(tab.get(),
529 http_server.TestServerPageW( 483 http_server->TestServerPageW(
530 L"files/ssl/page_with_unsafe_popup.html")); 484 L"files/ssl/page_with_unsafe_popup.html"));
531 485
532 int popup_count = 0; 486 int popup_count = 0;
533 EXPECT_TRUE(tab->GetConstrainedWindowCount(&popup_count)); 487 EXPECT_TRUE(tab->GetConstrainedWindowCount(&popup_count));
534 EXPECT_EQ(1, popup_count); 488 EXPECT_EQ(1, popup_count);
535 489
536 // Let's add another tab to make sure the browser does not exit when we close 490 // Let's add another tab to make sure the browser does not exit when we close
537 // the first tab. 491 // the first tab.
538 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); 492 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
539 EXPECT_TRUE(browser_proxy.get()); 493 EXPECT_TRUE(browser_proxy.get());
540 browser_proxy->AppendTab( 494 browser_proxy->AppendTab(
541 http_server.TestServerPageW(L"files/ssl/google.html")); 495 http_server->TestServerPageW(L"files/ssl/google.html"));
542 496
543 // Close the first tab. 497 // Close the first tab.
544 tab->Close(); 498 tab->Close();
545 } 499 }
546 500
547 // Visit a page over bad https that is a redirect to a page with good https. 501 // Visit a page over bad https that is a redirect to a page with good https.
548 TEST_F(SSLUITest, TestRedirectBadToGoodHTTPS) { 502 TEST_F(SSLUITest, TestRedirectBadToGoodHTTPS) {
549 HTTPSTestServer good_https_server = GoodServer(); 503 scoped_ptr<HTTPSTestServer> good_https_server(GoodCertServer());
550 HTTPSTestServer bad_https_server = BadServer(); 504 scoped_ptr<HTTPSTestServer> bad_https_server(BadCertServer());
551 505
552 scoped_ptr<TabProxy> tab(GetActiveTabProxy()); 506 scoped_ptr<TabProxy> tab(GetActiveTabProxy());
553 GURL url1 = bad_https_server.TestServerPageW(L"server-redirect?"); 507 GURL url1 = bad_https_server->TestServerPageW(L"server-redirect?");
554 GURL url2 = good_https_server.TestServerPageW(L"files/ssl/google.html"); 508 GURL url2 = good_https_server->TestServerPageW(L"files/ssl/google.html");
555 NavigateTab(tab.get(), GURL(url1.spec() + url2.spec())); 509 NavigateTab(tab.get(), GURL(url1.spec() + url2.spec()));
556 510
557 NavigationEntry::PageType page_type; 511 NavigationEntry::PageType page_type;
558 EXPECT_TRUE(tab->GetPageType(&page_type)); 512 EXPECT_TRUE(tab->GetPageType(&page_type));
559 EXPECT_EQ(page_type, NavigationEntry::INTERSTITIAL_PAGE); 513 EXPECT_EQ(page_type, NavigationEntry::INTERSTITIAL_PAGE);
560 514
561 SecurityStyle security_style; 515 SecurityStyle security_style;
562 int cert_status; 516 int cert_status;
563 int mixed_content_state; 517 int mixed_content_state;
564 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 518 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
565 &mixed_content_state)); 519 &mixed_content_state));
566 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATION_BROKEN, security_style); 520 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATION_BROKEN, security_style);
567 EXPECT_EQ(net::CERT_STATUS_DATE_INVALID, cert_status); 521 EXPECT_EQ(net::CERT_STATUS_DATE_INVALID, cert_status);
568 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 522 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
569 523
570 EXPECT_TRUE(tab->TakeActionOnSSLBlockingPage(true)); 524 EXPECT_TRUE(tab->TakeActionOnSSLBlockingPage(true));
571 // We have been redirected to the good page. 525 // We have been redirected to the good page.
572 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 526 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
573 &mixed_content_state)); 527 &mixed_content_state));
574 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style); 528 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style);
575 EXPECT_EQ(0, 529 EXPECT_EQ(0,
576 cert_status & net::CERT_STATUS_ALL_ERRORS); // No errors expected. 530 cert_status & net::CERT_STATUS_ALL_ERRORS); // No errors expected.
577 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 531 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
578 } 532 }
579 533
580 // Visit a page over good https that is a redirect to a page with bad https. 534 // Visit a page over good https that is a redirect to a page with bad https.
581 TEST_F(SSLUITest, TestRedirectGoodToBadHTTPS) { 535 TEST_F(SSLUITest, TestRedirectGoodToBadHTTPS) {
582 HTTPSTestServer good_https_server = GoodServer(); 536 scoped_ptr<HTTPSTestServer> good_https_server(GoodCertServer());
583 HTTPSTestServer bad_https_server = BadServer(); 537 scoped_ptr<HTTPSTestServer> bad_https_server(BadCertServer());
584 538
585 scoped_ptr<TabProxy> tab(GetActiveTabProxy()); 539 scoped_ptr<TabProxy> tab(GetActiveTabProxy());
586 GURL url1 = good_https_server.TestServerPageW(L"server-redirect?"); 540 GURL url1 = good_https_server->TestServerPageW(L"server-redirect?");
587 GURL url2 = bad_https_server.TestServerPageW(L"files/ssl/google.html"); 541 GURL url2 = bad_https_server->TestServerPageW(L"files/ssl/google.html");
588 NavigateTab(tab.get(), GURL(url1.spec() + url2.spec())); 542 NavigateTab(tab.get(), GURL(url1.spec() + url2.spec()));
589 543
590 NavigationEntry::PageType page_type; 544 NavigationEntry::PageType page_type;
591 EXPECT_TRUE(tab->GetPageType(&page_type)); 545 EXPECT_TRUE(tab->GetPageType(&page_type));
592 EXPECT_EQ(page_type, NavigationEntry::INTERSTITIAL_PAGE); 546 EXPECT_EQ(page_type, NavigationEntry::INTERSTITIAL_PAGE);
593 547
594 EXPECT_TRUE(tab->TakeActionOnSSLBlockingPage(true)); 548 EXPECT_TRUE(tab->TakeActionOnSSLBlockingPage(true));
595 549
596 SecurityStyle security_style; 550 SecurityStyle security_style;
597 int cert_status; 551 int cert_status;
598 int mixed_content_state; 552 int mixed_content_state;
599 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 553 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
600 &mixed_content_state)); 554 &mixed_content_state));
601 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATION_BROKEN, security_style); 555 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATION_BROKEN, security_style);
602 EXPECT_EQ(net::CERT_STATUS_DATE_INVALID, 556 EXPECT_EQ(net::CERT_STATUS_DATE_INVALID,
603 cert_status & net::CERT_STATUS_ALL_ERRORS); 557 cert_status & net::CERT_STATUS_ALL_ERRORS);
604 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 558 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
605 } 559 }
606 560
607 // Visit a page over http that is a redirect to a page with https (good and 561 // Visit a page over http that is a redirect to a page with https (good and
608 // bad). 562 // bad).
609 TEST_F(SSLUITest, TestRedirectHTTPToHTTPS) { 563 TEST_F(SSLUITest, TestRedirectHTTPToHTTPS) {
610 TestServer http_server(kDocRoot); 564 scoped_ptr<TestServer> http_server(PlainServer());
611 HTTPSTestServer good_https_server = GoodServer(); 565 scoped_ptr<HTTPSTestServer> good_https_server(GoodCertServer());
612 HTTPSTestServer bad_https_server = BadServer(); 566 scoped_ptr<HTTPSTestServer> bad_https_server(BadCertServer());
613 567
614 // HTTP redirects to good HTTPS. 568 // HTTP redirects to good HTTPS.
615 scoped_ptr<TabProxy> tab(GetActiveTabProxy()); 569 scoped_ptr<TabProxy> tab(GetActiveTabProxy());
616 GURL http_url = http_server.TestServerPageW(L"server-redirect?"); 570 GURL http_url = http_server->TestServerPageW(L"server-redirect?");
617 GURL good_https_url = 571 GURL good_https_url =
618 good_https_server.TestServerPageW(L"files/ssl/google.html"); 572 good_https_server->TestServerPageW(L"files/ssl/google.html");
619 NavigateTab(tab.get(), GURL(http_url.spec() + good_https_url.spec())); 573 NavigateTab(tab.get(), GURL(http_url.spec() + good_https_url.spec()));
620 574
621 SecurityStyle security_style; 575 SecurityStyle security_style;
622 int cert_status; 576 int cert_status;
623 int mixed_content_state; 577 int mixed_content_state;
624 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 578 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
625 &mixed_content_state)); 579 &mixed_content_state));
626 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style); 580 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style);
627 EXPECT_EQ(0, cert_status & net::CERT_STATUS_ALL_ERRORS); 581 EXPECT_EQ(0, cert_status & net::CERT_STATUS_ALL_ERRORS);
628 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 582 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
629 583
630 // HTTP redirects to bad HTTPS. 584 // HTTP redirects to bad HTTPS.
631 GURL bad_https_url = 585 GURL bad_https_url =
632 bad_https_server.TestServerPageW(L"files/ssl/google.html"); 586 bad_https_server->TestServerPageW(L"files/ssl/google.html");
633 NavigateTab(tab.get(), GURL(http_url.spec() + bad_https_url.spec())); 587 NavigateTab(tab.get(), GURL(http_url.spec() + bad_https_url.spec()));
634 588
635 NavigationEntry::PageType page_type; 589 NavigationEntry::PageType page_type;
636 EXPECT_TRUE(tab->GetPageType(&page_type)); 590 EXPECT_TRUE(tab->GetPageType(&page_type));
637 EXPECT_EQ(page_type, NavigationEntry::INTERSTITIAL_PAGE); 591 EXPECT_EQ(page_type, NavigationEntry::INTERSTITIAL_PAGE);
638 592
639 // Continue on the interstitial. 593 // Continue on the interstitial.
640 EXPECT_TRUE(tab->TakeActionOnSSLBlockingPage(true)); 594 EXPECT_TRUE(tab->TakeActionOnSSLBlockingPage(true));
641 595
642 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 596 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
643 &mixed_content_state)); 597 &mixed_content_state));
644 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATION_BROKEN, security_style); 598 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATION_BROKEN, security_style);
645 EXPECT_EQ(net::CERT_STATUS_DATE_INVALID, 599 EXPECT_EQ(net::CERT_STATUS_DATE_INVALID,
646 cert_status & net::CERT_STATUS_ALL_ERRORS); 600 cert_status & net::CERT_STATUS_ALL_ERRORS);
647 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 601 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
648 } 602 }
649 603
650 // Visit a page over https that is a redirect to a page with http (to make sure 604 // Visit a page over https that is a redirect to a page with http (to make sure
651 // we don't keep the secure state). 605 // we don't keep the secure state).
652 TEST_F(SSLUITest, TestRedirectHTTPSToHTTP) { 606 TEST_F(SSLUITest, TestRedirectHTTPSToHTTP) {
653 TestServer http_server(kDocRoot); 607 scoped_ptr<TestServer> http_server(PlainServer());
654 HTTPSTestServer https_server = GoodServer(); 608 scoped_ptr<HTTPSTestServer> https_server(GoodCertServer());
655 609
656 scoped_ptr<TabProxy> tab(GetActiveTabProxy()); 610 scoped_ptr<TabProxy> tab(GetActiveTabProxy());
657 GURL https_url = https_server.TestServerPageW(L"server-redirect?"); 611 GURL https_url = https_server->TestServerPageW(L"server-redirect?");
658 GURL http_url = http_server.TestServerPageW(L"files/ssl/google.html"); 612 GURL http_url = http_server->TestServerPageW(L"files/ssl/google.html");
659 NavigateTab(tab.get(), GURL(https_url.spec() + http_url.spec())); 613 NavigateTab(tab.get(), GURL(https_url.spec() + http_url.spec()));
660 614
661 SecurityStyle security_style; 615 SecurityStyle security_style;
662 int cert_status; 616 int cert_status;
663 int mixed_content_state; 617 int mixed_content_state;
664 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 618 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
665 &mixed_content_state)); 619 &mixed_content_state));
666 EXPECT_EQ(SECURITY_STYLE_UNAUTHENTICATED, security_style); 620 EXPECT_EQ(SECURITY_STYLE_UNAUTHENTICATED, security_style);
667 EXPECT_EQ(0, cert_status & net::CERT_STATUS_ALL_ERRORS); 621 EXPECT_EQ(0, cert_status & net::CERT_STATUS_ALL_ERRORS);
668 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 622 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
(...skipping 27 matching lines...) Expand all
696 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 650 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
697 } 651 }
698 652
699 // 653 //
700 // Frame navigation 654 // Frame navigation
701 // 655 //
702 656
703 // From a good HTTPS top frame: 657 // From a good HTTPS top frame:
704 // - navigate to an OK HTTPS frame 658 // - navigate to an OK HTTPS frame
705 // - navigate to a bad HTTPS (expect unsafe content and filtered frame), then 659 // - navigate to a bad HTTPS (expect unsafe content and filtered frame), then
706 // back 660 // back
707 // - navigate to HTTP (expect mixed content), then back 661 // - navigate to HTTP (expect mixed content), then back
708 TEST_F(SSLUITest, TestGoodFrameNavigation) { 662 TEST_F(SSLUITest, TestGoodFrameNavigation) {
709 TestServer http_server(kDocRoot); 663 scoped_ptr<TestServer> http_server(PlainServer());
710 HTTPSTestServer good_https_server = GoodServer(); 664 scoped_ptr<HTTPSTestServer> good_https_server(GoodCertServer());
711 HTTPSTestServer bad_https_server = BadServer(); 665 scoped_ptr<HTTPSTestServer> bad_https_server(BadCertServer());
712 666
713 scoped_ptr<TabProxy> tab(GetActiveTabProxy()); 667 scoped_ptr<TabProxy> tab(GetActiveTabProxy());
714 NavigateTab(tab.get(), 668 NavigateTab(tab.get(),
715 good_https_server.TestServerPageW(L"files/ssl/top_frame.html")); 669 good_https_server->TestServerPageW(L"files/ssl/top_frame.html"));
716 670
717 SecurityStyle security_style; 671 SecurityStyle security_style;
718 int cert_status; 672 int cert_status;
719 int mixed_content_state; 673 int mixed_content_state;
720 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 674 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
721 &mixed_content_state)); 675 &mixed_content_state));
722 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style); 676 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style);
723 EXPECT_EQ(0, cert_status & net::CERT_STATUS_ALL_ERRORS); 677 EXPECT_EQ(0, cert_status & net::CERT_STATUS_ALL_ERRORS);
724 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 678 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
725 679
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 749 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
796 &mixed_content_state)); 750 &mixed_content_state));
797 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style); 751 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATED, security_style);
798 EXPECT_EQ(0, cert_status & net::CERT_STATUS_ALL_ERRORS); 752 EXPECT_EQ(0, cert_status & net::CERT_STATUS_ALL_ERRORS);
799 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 753 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
800 } 754 }
801 755
802 // From a bad HTTPS top frame: 756 // From a bad HTTPS top frame:
803 // - navigate to an OK HTTPS frame (expected to be still authentication broken). 757 // - navigate to an OK HTTPS frame (expected to be still authentication broken).
804 TEST_F(SSLUITest, TestBadFrameNavigation) { 758 TEST_F(SSLUITest, TestBadFrameNavigation) {
805 HTTPSTestServer good_https_server = GoodServer(); 759 scoped_ptr<HTTPSTestServer> good_https_server(GoodCertServer());
806 HTTPSTestServer bad_https_server = BadServer(); 760 scoped_ptr<HTTPSTestServer> bad_https_server(BadCertServer());
807 761
808 scoped_ptr<TabProxy> tab(GetActiveTabProxy()); 762 scoped_ptr<TabProxy> tab(GetActiveTabProxy());
809 NavigateTab(tab.get(), 763 NavigateTab(tab.get(),
810 bad_https_server.TestServerPageW(L"files/ssl/top_frame.html")); 764 bad_https_server->TestServerPageW(L"files/ssl/top_frame.html"));
811 765
812 SecurityStyle security_style; 766 SecurityStyle security_style;
813 int cert_status; 767 int cert_status;
814 int mixed_content_state; 768 int mixed_content_state;
815 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 769 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
816 &mixed_content_state)); 770 &mixed_content_state));
817 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATION_BROKEN, security_style); 771 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATION_BROKEN, security_style);
818 EXPECT_EQ(net::CERT_STATUS_DATE_INVALID, 772 EXPECT_EQ(net::CERT_STATUS_DATE_INVALID,
819 cert_status & net::CERT_STATUS_ALL_ERRORS); 773 cert_status & net::CERT_STATUS_ALL_ERRORS);
820 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 774 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
821 775
822 // Continue on the interstitial. 776 // Continue on the interstitial.
823 EXPECT_TRUE(tab->TakeActionOnSSLBlockingPage(true)); 777 EXPECT_TRUE(tab->TakeActionOnSSLBlockingPage(true));
824 778
825 // Navigate to a good frame. 779 // Navigate to a good frame.
826 bool success = false; 780 bool success = false;
827 int64 last_nav_time = 0; 781 int64 last_nav_time = 0;
828 EXPECT_TRUE(tab->GetLastNavigationTime(&last_nav_time)); 782 EXPECT_TRUE(tab->GetLastNavigationTime(&last_nav_time));
829 EXPECT_TRUE(tab->ExecuteAndExtractBool(L"", 783 EXPECT_TRUE(tab->ExecuteAndExtractBool(L"",
830 L"window.domAutomationController.send(clickLink('goodHTTPSLink'));", 784 L"window.domAutomationController.send(clickLink('goodHTTPSLink'));",
831 &success)); 785 &success));
832 EXPECT_TRUE(success); 786 EXPECT_TRUE(success);
833 EXPECT_TRUE(tab->WaitForNavigation(last_nav_time)); 787 EXPECT_TRUE(tab->WaitForNavigation(last_nav_time));
834 788
835 // We should still be authentication broken. 789 // We should still be authentication broken.
836 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 790 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
837 &mixed_content_state)); 791 &mixed_content_state));
838 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATION_BROKEN, security_style); 792 EXPECT_EQ(SECURITY_STYLE_AUTHENTICATION_BROKEN, security_style);
839 EXPECT_EQ(net::CERT_STATUS_DATE_INVALID, 793 EXPECT_EQ(net::CERT_STATUS_DATE_INVALID,
840 cert_status & net::CERT_STATUS_ALL_ERRORS); 794 cert_status & net::CERT_STATUS_ALL_ERRORS);
841 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 795 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
842 } 796 }
843 797
844 // From an HTTP top frame, navigate to good and bad HTTPS (security state should 798 // From an HTTP top frame, navigate to good and bad HTTPS (security state should
845 // stay unauthenticated). 799 // stay unauthenticated).
846 TEST_F(SSLUITest, TestUnauthenticatedFrameNavigation) { 800 TEST_F(SSLUITest, TestUnauthenticatedFrameNavigation) {
847 TestServer http_server(kDocRoot); 801 scoped_ptr<TestServer> http_server(PlainServer());
848 HTTPSTestServer good_https_server = GoodServer(); 802 scoped_ptr<HTTPSTestServer> good_https_server(GoodCertServer());
849 HTTPSTestServer bad_https_server = BadServer(); 803 scoped_ptr<HTTPSTestServer> bad_https_server(BadCertServer());
850 804
851 scoped_ptr<TabProxy> tab(GetActiveTabProxy()); 805 scoped_ptr<TabProxy> tab(GetActiveTabProxy());
852 NavigateTab(tab.get(), 806 NavigateTab(tab.get(),
853 http_server.TestServerPageW(L"files/ssl/top_frame.html")); 807 http_server->TestServerPageW(L"files/ssl/top_frame.html"));
854 808
855 SecurityStyle security_style; 809 SecurityStyle security_style;
856 int cert_status; 810 int cert_status;
857 int mixed_content_state; 811 int mixed_content_state;
858 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status, 812 EXPECT_TRUE(tab->GetSecurityState(&security_style, &cert_status,
859 &mixed_content_state)); 813 &mixed_content_state));
860 EXPECT_EQ(SECURITY_STYLE_UNAUTHENTICATED, security_style); 814 EXPECT_EQ(SECURITY_STYLE_UNAUTHENTICATED, security_style);
861 EXPECT_EQ(0, cert_status & net::CERT_STATUS_ALL_ERRORS); 815 EXPECT_EQ(0, cert_status & net::CERT_STATUS_ALL_ERRORS);
862 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state); 816 EXPECT_EQ(NavigationEntry::SSLStatus::NORMAL_CONTENT, mixed_content_state);
863 817
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 std::wstring is_frame_evil_js( 853 std::wstring is_frame_evil_js(
900 L"window.domAutomationController" 854 L"window.domAutomationController"
901 L".send(document.getElementById('evilDiv') != null);"); 855 L".send(document.getElementById('evilDiv') != null);");
902 EXPECT_TRUE(tab->ExecuteAndExtractBool(content_frame_xpath, 856 EXPECT_TRUE(tab->ExecuteAndExtractBool(content_frame_xpath,
903 is_frame_evil_js, 857 is_frame_evil_js,
904 &is_content_evil)); 858 &is_content_evil));
905 EXPECT_FALSE(is_content_evil); 859 EXPECT_FALSE(is_content_evil);
906 } 860 }
907 861
908 862
909 // TODO (jcampan): more tests to do below. 863 // TODO(jcampan): more tests to do below.
910 864
911 // Visit a page over https that contains a frame with a redirect. 865 // Visit a page over https that contains a frame with a redirect.
912 866
913 // XMLHttpRequest mixed in synchronous mode. 867 // XMLHttpRequest mixed in synchronous mode.
914 868
915 // XMLHttpRequest mixed in asynchronous mode. 869 // XMLHttpRequest mixed in asynchronous mode.
916 870
917 // XMLHttpRequest over bad ssl in synchronous mode. 871 // XMLHttpRequest over bad ssl in synchronous mode.
918 872
919 // XMLHttpRequest over OK ssl in synchronous mode. 873 // XMLHttpRequest over OK ssl in synchronous mode.
OLDNEW
« no previous file with comments | « base/nss_init.cc ('k') | chrome/test/data/ssl/certificates/expired_cert.pem » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698