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

Side by Side Diff: chrome/browser/ssl/ssl_browser_tests.cc

Issue 10795090: Move ExecuteJavaScript functions from ui_test_utils.h to browser_test_utils.h so they can be reused… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/path_service.h" 6 #include "base/path_service.h"
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 void CheckWorkerLoadResult(WebContents* tab, bool expectLoaded) { 157 void CheckWorkerLoadResult(WebContents* tab, bool expectLoaded) {
158 // Workers are async and we don't have notifications for them passing 158 // Workers are async and we don't have notifications for them passing
159 // messages since they do it between renderer and worker processes. 159 // messages since they do it between renderer and worker processes.
160 // So have a polling loop, check every 200ms, timeout at 30s. 160 // So have a polling loop, check every 200ms, timeout at 30s.
161 const int timeout_ms = 200; 161 const int timeout_ms = 200;
162 base::Time timeToQuit = base::Time::Now() + 162 base::Time timeToQuit = base::Time::Now() +
163 base::TimeDelta::FromMilliseconds(30000); 163 base::TimeDelta::FromMilliseconds(30000);
164 164
165 while (base::Time::Now() < timeToQuit) { 165 while (base::Time::Now() < timeToQuit) {
166 bool workerFinished = false; 166 bool workerFinished = false;
167 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 167 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
168 tab->GetRenderViewHost(), std::wstring(), 168 tab->GetRenderViewHost(), std::wstring(),
169 L"window.domAutomationController.send(IsWorkerFinished());", 169 L"window.domAutomationController.send(IsWorkerFinished());",
170 &workerFinished)); 170 &workerFinished));
171 171
172 if (workerFinished) 172 if (workerFinished)
173 break; 173 break;
174 174
175 // Wait a bit. 175 // Wait a bit.
176 MessageLoop::current()->PostDelayedTask( 176 MessageLoop::current()->PostDelayedTask(
177 FROM_HERE, 177 FROM_HERE,
178 MessageLoop::QuitClosure(), 178 MessageLoop::QuitClosure(),
179 base::TimeDelta::FromMilliseconds(timeout_ms)); 179 base::TimeDelta::FromMilliseconds(timeout_ms));
180 ui_test_utils::RunMessageLoop(); 180 ui_test_utils::RunMessageLoop();
181 } 181 }
182 182
183 bool actuallyLoadedContent = false; 183 bool actuallyLoadedContent = false;
184 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 184 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
185 tab->GetRenderViewHost(), std::wstring(), 185 tab->GetRenderViewHost(), std::wstring(),
186 L"window.domAutomationController.send(IsContentLoaded());", 186 L"window.domAutomationController.send(IsContentLoaded());",
187 &actuallyLoadedContent)); 187 &actuallyLoadedContent));
188 EXPECT_EQ(expectLoaded, actuallyLoadedContent); 188 EXPECT_EQ(expectLoaded, actuallyLoadedContent);
189 } 189 }
190 190
191 void ProceedThroughInterstitial(WebContents* tab) { 191 void ProceedThroughInterstitial(WebContents* tab) {
192 InterstitialPage* interstitial_page = tab->GetInterstitialPage(); 192 InterstitialPage* interstitial_page = tab->GetInterstitialPage();
193 ASSERT_TRUE(interstitial_page); 193 ASSERT_TRUE(interstitial_page);
194 content::WindowedNotificationObserver observer( 194 content::WindowedNotificationObserver observer(
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 CheckAuthenticatedState(tab, false); 728 CheckAuthenticatedState(tab, false);
729 729
730 // Because of cross-frame scripting restrictions, we cannot access the iframe 730 // Because of cross-frame scripting restrictions, we cannot access the iframe
731 // content. So to know if the frame was loaded, we just check if a popup was 731 // content. So to know if the frame was loaded, we just check if a popup was
732 // opened (the iframe content opens one). 732 // opened (the iframe content opens one).
733 // Note: because of bug 1115868, no constrained window is opened right now. 733 // Note: because of bug 1115868, no constrained window is opened right now.
734 // Once the bug is fixed, this will do the real check. 734 // Once the bug is fixed, this will do the real check.
735 EXPECT_EQ(0, GetConstrainedWindowCount()); 735 EXPECT_EQ(0, GetConstrainedWindowCount());
736 736
737 int img_width; 737 int img_width;
738 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt( 738 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractInt(
739 tab->GetRenderViewHost(), std::wstring(), 739 tab->GetRenderViewHost(), std::wstring(),
740 L"window.domAutomationController.send(ImageWidth());", &img_width)); 740 L"window.domAutomationController.send(ImageWidth());", &img_width));
741 // In order to check that the image was not loaded, we check its width. 741 // In order to check that the image was not loaded, we check its width.
742 // The actual image (Google logo) is 114 pixels wide, we assume the broken 742 // The actual image (Google logo) is 114 pixels wide, we assume the broken
743 // image is less than 100. 743 // image is less than 100.
744 EXPECT_LT(img_width, 100); 744 EXPECT_LT(img_width, 100);
745 745
746 bool js_result = false; 746 bool js_result = false;
747 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 747 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool(
748 tab->GetRenderViewHost(), std::wstring(), 748 tab->GetRenderViewHost(), std::wstring(),
749 L"window.domAutomationController.send(IsFooSet());", &js_result)); 749 L"window.domAutomationController.send(IsFooSet());", &js_result));
750 EXPECT_FALSE(js_result); 750 EXPECT_FALSE(js_result);
751 } 751 }
752 752
753 // Visits a page with insecure content loaded by JS (after the initial page 753 // Visits a page with insecure content loaded by JS (after the initial page
754 // load). 754 // load).
755 IN_PROC_BROWSER_TEST_F(SSLUITest, TestDisplaysInsecureContentLoadedFromJS) { 755 IN_PROC_BROWSER_TEST_F(SSLUITest, TestDisplaysInsecureContentLoadedFromJS) {
756 ASSERT_TRUE(test_server()->Start()); 756 ASSERT_TRUE(test_server()->Start());
757 ASSERT_TRUE(https_server_.Start()); 757 ASSERT_TRUE(https_server_.Start());
758 758
759 std::string replacement_path; 759 std::string replacement_path;
760 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( 760 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
761 "files/ssl/page_with_dynamic_insecure_content.html", 761 "files/ssl/page_with_dynamic_insecure_content.html",
762 test_server()->host_port_pair(), 762 test_server()->host_port_pair(),
763 &replacement_path)); 763 &replacement_path));
764 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL( 764 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL(
765 replacement_path)); 765 replacement_path));
766 766
767 WebContents* tab = chrome::GetActiveWebContents(browser()); 767 WebContents* tab = chrome::GetActiveWebContents(browser());
768 CheckAuthenticatedState(tab, false); 768 CheckAuthenticatedState(tab, false);
769 769
770 // Load the insecure image. 770 // Load the insecure image.
771 bool js_result = false; 771 bool js_result = false;
772 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 772 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool(
773 tab->GetRenderViewHost(), std::wstring(), L"loadBadImage();", 773 tab->GetRenderViewHost(), std::wstring(), L"loadBadImage();",
774 &js_result)); 774 &js_result));
775 EXPECT_TRUE(js_result); 775 EXPECT_TRUE(js_result);
776 776
777 // We should now have insecure content. 777 // We should now have insecure content.
778 CheckAuthenticatedState(tab, true); 778 CheckAuthenticatedState(tab, true);
779 } 779 }
780 780
781 // Visits two pages from the same origin: one that displays insecure content and 781 // Visits two pages from the same origin: one that displays insecure content and
782 // one that doesn't. The test checks that we do not propagate the insecure 782 // one that doesn't. The test checks that we do not propagate the insecure
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 https_server_.GetURL(top_frame_path)); 1164 https_server_.GetURL(top_frame_path));
1165 1165
1166 CheckAuthenticatedState(tab, false); 1166 CheckAuthenticatedState(tab, false);
1167 1167
1168 bool success = false; 1168 bool success = false;
1169 // Now navigate inside the frame. 1169 // Now navigate inside the frame.
1170 { 1170 {
1171 content::WindowedNotificationObserver observer( 1171 content::WindowedNotificationObserver observer(
1172 content::NOTIFICATION_LOAD_STOP, 1172 content::NOTIFICATION_LOAD_STOP,
1173 content::Source<NavigationController>(&tab->GetController())); 1173 content::Source<NavigationController>(&tab->GetController()));
1174 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 1174 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool(
1175 tab->GetRenderViewHost(), std::wstring(), 1175 tab->GetRenderViewHost(), std::wstring(),
1176 L"window.domAutomationController.send(clickLink('goodHTTPSLink'));", 1176 L"window.domAutomationController.send(clickLink('goodHTTPSLink'));",
1177 &success)); 1177 &success));
1178 ASSERT_TRUE(success); 1178 ASSERT_TRUE(success);
1179 observer.Wait(); 1179 observer.Wait();
1180 } 1180 }
1181 1181
1182 // We should still be fine. 1182 // We should still be fine.
1183 CheckAuthenticatedState(tab, false); 1183 CheckAuthenticatedState(tab, false);
1184 1184
1185 // Now let's hit a bad page. 1185 // Now let's hit a bad page.
1186 { 1186 {
1187 content::WindowedNotificationObserver observer( 1187 content::WindowedNotificationObserver observer(
1188 content::NOTIFICATION_LOAD_STOP, 1188 content::NOTIFICATION_LOAD_STOP,
1189 content::Source<NavigationController>(&tab->GetController())); 1189 content::Source<NavigationController>(&tab->GetController()));
1190 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 1190 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool(
1191 tab->GetRenderViewHost(), std::wstring(), 1191 tab->GetRenderViewHost(), std::wstring(),
1192 L"window.domAutomationController.send(clickLink('badHTTPSLink'));", 1192 L"window.domAutomationController.send(clickLink('badHTTPSLink'));",
1193 &success)); 1193 &success));
1194 ASSERT_TRUE(success); 1194 ASSERT_TRUE(success);
1195 observer.Wait(); 1195 observer.Wait();
1196 } 1196 }
1197 1197
1198 // The security style should still be secure. 1198 // The security style should still be secure.
1199 CheckAuthenticatedState(tab, false); 1199 CheckAuthenticatedState(tab, false);
1200 1200
1201 // And the frame should be blocked. 1201 // And the frame should be blocked.
1202 bool is_content_evil = true; 1202 bool is_content_evil = true;
1203 std::wstring content_frame_xpath(L"html/frameset/frame[2]"); 1203 std::wstring content_frame_xpath(L"html/frameset/frame[2]");
1204 std::wstring is_evil_js(L"window.domAutomationController.send(" 1204 std::wstring is_evil_js(L"window.domAutomationController.send("
1205 L"document.getElementById('evilDiv') != null);"); 1205 L"document.getElementById('evilDiv') != null);");
1206 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 1206 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool(
1207 tab->GetRenderViewHost(), content_frame_xpath, is_evil_js, 1207 tab->GetRenderViewHost(), content_frame_xpath, is_evil_js,
1208 &is_content_evil)); 1208 &is_content_evil));
1209 EXPECT_FALSE(is_content_evil); 1209 EXPECT_FALSE(is_content_evil);
1210 1210
1211 // Now go back, our state should still be OK. 1211 // Now go back, our state should still be OK.
1212 { 1212 {
1213 content::WindowedNotificationObserver observer( 1213 content::WindowedNotificationObserver observer(
1214 content::NOTIFICATION_LOAD_STOP, 1214 content::NOTIFICATION_LOAD_STOP,
1215 content::Source<NavigationController>(&tab->GetController())); 1215 content::Source<NavigationController>(&tab->GetController()));
1216 tab->GetController().GoBack(); 1216 tab->GetController().GoBack();
1217 observer.Wait(); 1217 observer.Wait();
1218 } 1218 }
1219 CheckAuthenticatedState(tab, false); 1219 CheckAuthenticatedState(tab, false);
1220 1220
1221 // Navigate to a page served over HTTP. 1221 // Navigate to a page served over HTTP.
1222 { 1222 {
1223 content::WindowedNotificationObserver observer( 1223 content::WindowedNotificationObserver observer(
1224 content::NOTIFICATION_LOAD_STOP, 1224 content::NOTIFICATION_LOAD_STOP,
1225 content::Source<NavigationController>(&tab->GetController())); 1225 content::Source<NavigationController>(&tab->GetController()));
1226 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 1226 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool(
1227 tab->GetRenderViewHost(), std::wstring(), 1227 tab->GetRenderViewHost(), std::wstring(),
1228 L"window.domAutomationController.send(clickLink('HTTPLink'));", 1228 L"window.domAutomationController.send(clickLink('HTTPLink'));",
1229 &success)); 1229 &success));
1230 ASSERT_TRUE(success); 1230 ASSERT_TRUE(success);
1231 observer.Wait(); 1231 observer.Wait();
1232 } 1232 }
1233 1233
1234 // Our state should be insecure. 1234 // Our state should be insecure.
1235 CheckAuthenticatedState(tab, true); 1235 CheckAuthenticatedState(tab, true);
1236 1236
(...skipping 26 matching lines...) Expand all
1263 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID, false, 1263 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID, false,
1264 true); // Interstitial showing 1264 true); // Interstitial showing
1265 1265
1266 ProceedThroughInterstitial(tab); 1266 ProceedThroughInterstitial(tab);
1267 1267
1268 // Navigate to a good frame. 1268 // Navigate to a good frame.
1269 bool success = false; 1269 bool success = false;
1270 content::WindowedNotificationObserver observer( 1270 content::WindowedNotificationObserver observer(
1271 content::NOTIFICATION_LOAD_STOP, 1271 content::NOTIFICATION_LOAD_STOP,
1272 content::Source<NavigationController>(&tab->GetController())); 1272 content::Source<NavigationController>(&tab->GetController()));
1273 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 1273 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool(
1274 tab->GetRenderViewHost(), std::wstring(), 1274 tab->GetRenderViewHost(), std::wstring(),
1275 L"window.domAutomationController.send(clickLink('goodHTTPSLink'));", 1275 L"window.domAutomationController.send(clickLink('goodHTTPSLink'));",
1276 &success)); 1276 &success));
1277 ASSERT_TRUE(success); 1277 ASSERT_TRUE(success);
1278 observer.Wait(); 1278 observer.Wait();
1279 1279
1280 // We should still be authentication broken. 1280 // We should still be authentication broken.
1281 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID, false, 1281 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID, false,
1282 false); 1282 false);
1283 } 1283 }
(...skipping 16 matching lines...) Expand all
1300 ui_test_utils::NavigateToURL(browser(), 1300 ui_test_utils::NavigateToURL(browser(),
1301 test_server()->GetURL(top_frame_path)); 1301 test_server()->GetURL(top_frame_path));
1302 CheckUnauthenticatedState(tab); 1302 CheckUnauthenticatedState(tab);
1303 1303
1304 // Now navigate inside the frame to a secure HTTPS frame. 1304 // Now navigate inside the frame to a secure HTTPS frame.
1305 { 1305 {
1306 bool success = false; 1306 bool success = false;
1307 content::WindowedNotificationObserver observer( 1307 content::WindowedNotificationObserver observer(
1308 content::NOTIFICATION_LOAD_STOP, 1308 content::NOTIFICATION_LOAD_STOP,
1309 content::Source<NavigationController>(&tab->GetController())); 1309 content::Source<NavigationController>(&tab->GetController()));
1310 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 1310 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool(
1311 tab->GetRenderViewHost(), std::wstring(), 1311 tab->GetRenderViewHost(), std::wstring(),
1312 L"window.domAutomationController.send(clickLink('goodHTTPSLink'));", 1312 L"window.domAutomationController.send(clickLink('goodHTTPSLink'));",
1313 &success)); 1313 &success));
1314 ASSERT_TRUE(success); 1314 ASSERT_TRUE(success);
1315 observer.Wait(); 1315 observer.Wait();
1316 } 1316 }
1317 1317
1318 // We should still be unauthenticated. 1318 // We should still be unauthenticated.
1319 CheckUnauthenticatedState(tab); 1319 CheckUnauthenticatedState(tab);
1320 1320
1321 // Now navigate to a bad HTTPS frame. 1321 // Now navigate to a bad HTTPS frame.
1322 { 1322 {
1323 bool success = false; 1323 bool success = false;
1324 content::WindowedNotificationObserver observer( 1324 content::WindowedNotificationObserver observer(
1325 content::NOTIFICATION_LOAD_STOP, 1325 content::NOTIFICATION_LOAD_STOP,
1326 content::Source<NavigationController>(&tab->GetController())); 1326 content::Source<NavigationController>(&tab->GetController()));
1327 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 1327 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool(
1328 tab->GetRenderViewHost(), std::wstring(), 1328 tab->GetRenderViewHost(), std::wstring(),
1329 L"window.domAutomationController.send(clickLink('badHTTPSLink'));", 1329 L"window.domAutomationController.send(clickLink('badHTTPSLink'));",
1330 &success)); 1330 &success));
1331 ASSERT_TRUE(success); 1331 ASSERT_TRUE(success);
1332 observer.Wait(); 1332 observer.Wait();
1333 } 1333 }
1334 1334
1335 // State should not have changed. 1335 // State should not have changed.
1336 CheckUnauthenticatedState(tab); 1336 CheckUnauthenticatedState(tab);
1337 1337
1338 // And the frame should have been blocked (see bug #2316). 1338 // And the frame should have been blocked (see bug #2316).
1339 bool is_content_evil = true; 1339 bool is_content_evil = true;
1340 std::wstring content_frame_xpath(L"html/frameset/frame[2]"); 1340 std::wstring content_frame_xpath(L"html/frameset/frame[2]");
1341 std::wstring is_evil_js(L"window.domAutomationController.send(" 1341 std::wstring is_evil_js(L"window.domAutomationController.send("
1342 L"document.getElementById('evilDiv') != null);"); 1342 L"document.getElementById('evilDiv') != null);");
1343 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 1343 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool(
1344 tab->GetRenderViewHost(), content_frame_xpath, is_evil_js, 1344 tab->GetRenderViewHost(), content_frame_xpath, is_evil_js,
1345 &is_content_evil)); 1345 &is_content_evil));
1346 EXPECT_FALSE(is_content_evil); 1346 EXPECT_FALSE(is_content_evil);
1347 } 1347 }
1348 1348
1349 IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContentsInWorkerFiltered) { 1349 IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContentsInWorkerFiltered) {
1350 ASSERT_TRUE(https_server_.Start()); 1350 ASSERT_TRUE(https_server_.Start());
1351 ASSERT_TRUE(https_server_expired_.Start()); 1351 ASSERT_TRUE(https_server_expired_.Start());
1352 1352
1353 // This page will spawn a Worker which will try to load content from 1353 // This page will spawn a Worker which will try to load content from
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1454 1454
1455 // Visit a page over https that contains a frame with a redirect. 1455 // Visit a page over https that contains a frame with a redirect.
1456 1456
1457 // XMLHttpRequest insecure content in synchronous mode. 1457 // XMLHttpRequest insecure content in synchronous mode.
1458 1458
1459 // XMLHttpRequest insecure content in asynchronous mode. 1459 // XMLHttpRequest insecure content in asynchronous mode.
1460 1460
1461 // XMLHttpRequest over bad ssl in synchronous mode. 1461 // XMLHttpRequest over bad ssl in synchronous mode.
1462 1462
1463 // XMLHttpRequest over OK ssl in synchronous mode. 1463 // XMLHttpRequest over OK ssl in synchronous mode.
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_browsertest.cc ('k') | chrome/browser/ui/find_bar/find_bar_host_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698