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

Side by Side Diff: chrome/browser/policy/policy_browsertest.cc

Issue 11728003: Change ExecuteJavaScript* helper functions in browser_test_utils.{h,cc} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding files for gpu_tests and NaCl browser tests. Created 7 years, 11 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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 content::WebContents* contents = chrome::GetActiveWebContents(browser); 226 content::WebContents* contents = chrome::GetActiveWebContents(browser);
227 EXPECT_EQ(url, contents->GetURL()); 227 EXPECT_EQ(url, contents->GetURL());
228 string16 title = UTF8ToUTF16(url.spec() + " is not available"); 228 string16 title = UTF8ToUTF16(url.spec() + " is not available");
229 EXPECT_EQ(title, contents->GetTitle()); 229 EXPECT_EQ(title, contents->GetTitle());
230 230
231 // Verify that the expected error page is being displayed. 231 // Verify that the expected error page is being displayed.
232 // (error 138 == NETWORK_ACCESS_DENIED) 232 // (error 138 == NETWORK_ACCESS_DENIED)
233 bool result = false; 233 bool result = false;
234 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( 234 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool(
235 contents->GetRenderViewHost(), 235 contents->GetRenderViewHost(),
236 std::wstring(), 236 "",
237 L"var hasError = false;" 237 "var hasError = false;"
238 L"var error = document.getElementById('errorDetails');" 238 "var error = document.getElementById('errorDetails');"
239 L"if (error)" 239 "if (error)"
240 L" hasError = error.textContent.indexOf('Error 138') == 0;" 240 " hasError = error.textContent.indexOf('Error 138') == 0;"
241 L"domAutomationController.send(hasError);", 241 "domAutomationController.send(hasError);",
242 &result)); 242 &result));
243 EXPECT_TRUE(result); 243 EXPECT_TRUE(result);
244 } 244 }
245 245
246 // Downloads a file named |file| and expects it to be saved to |dir|, which 246 // Downloads a file named |file| and expects it to be saved to |dir|, which
247 // must be empty. 247 // must be empty.
248 void DownloadAndVerifyFile( 248 void DownloadAndVerifyFile(
249 Browser* browser, const FilePath& dir, const FilePath& file) { 249 Browser* browser, const FilePath& dir, const FilePath& file) {
250 content::DownloadManager* download_manager = 250 content::DownloadManager* download_manager =
251 content::BrowserContext::GetDownloadManager(browser->profile()); 251 content::BrowserContext::GetDownloadManager(browser->profile());
(...skipping 28 matching lines...) Expand all
280 count++; 280 count++;
281 return count; 281 return count;
282 } 282 }
283 #endif 283 #endif
284 284
285 // Checks if WebGL is enabled in the given WebContents. 285 // Checks if WebGL is enabled in the given WebContents.
286 bool IsWebGLEnabled(content::WebContents* contents) { 286 bool IsWebGLEnabled(content::WebContents* contents) {
287 bool result = false; 287 bool result = false;
288 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( 288 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool(
289 contents->GetRenderViewHost(), 289 contents->GetRenderViewHost(),
290 std::wstring(), 290 "",
291 L"var canvas = document.createElement('canvas');" 291 "var canvas = document.createElement('canvas');"
292 L"var context = canvas.getContext('experimental-webgl');" 292 "var context = canvas.getContext('experimental-webgl');"
293 L"domAutomationController.send(context != null);", 293 "domAutomationController.send(context != null);",
294 &result)); 294 &result));
295 return result; 295 return result;
296 } 296 }
297 297
298 bool IsJavascriptEnabled(content::WebContents* contents) { 298 bool IsJavascriptEnabled(content::WebContents* contents) {
299 content::RenderViewHost* rvh = contents->GetRenderViewHost(); 299 content::RenderViewHost* rvh = contents->GetRenderViewHost();
300 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue( 300 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(
301 string16(), 301 string16(),
302 ASCIIToUTF16("123"))); 302 ASCIIToUTF16("123")));
303 int result = 0; 303 int result = 0;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 451
452 // Wait for feedback page to fully initialize. 452 // Wait for feedback page to fully initialize.
453 // setupCurrentScreenshot is called when feedback page loads and (among 453 // setupCurrentScreenshot is called when feedback page loads and (among
454 // other things) adds current-screenshots-thumbnailDiv-0-image element. 454 // other things) adds current-screenshots-thumbnailDiv-0-image element.
455 // The code below executes either before setupCurrentScreenshot was called 455 // The code below executes either before setupCurrentScreenshot was called
456 // (setupCurrentScreenshot is replaced with our hook) or after it has 456 // (setupCurrentScreenshot is replaced with our hook) or after it has
457 // completed (in that case send result immediately). 457 // completed (in that case send result immediately).
458 bool result = false; 458 bool result = false;
459 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( 459 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool(
460 web_contents->GetRenderViewHost(), 460 web_contents->GetRenderViewHost(),
461 std::wstring(), 461 "",
462 L"function btest_initCompleted(url) {" 462 "function btest_initCompleted(url) {"
463 L" var img = new Image();" 463 " var img = new Image();"
464 L" img.src = url;" 464 " img.src = url;"
465 L" img.onload = function() {" 465 " img.onload = function() {"
466 L" domAutomationController.send(img.width * img.height > 0);" 466 " domAutomationController.send(img.width * img.height > 0);"
467 L" };" 467 " };"
468 L" img.onerror = function() {" 468 " img.onerror = function() {"
469 L" domAutomationController.send(false);" 469 " domAutomationController.send(false);"
470 L" };" 470 " };"
471 L"}" 471 "}"
472 L"function setupCurrentScreenshot(url) {" 472 "function setupCurrentScreenshot(url) {"
473 L" btest_initCompleted(url);" 473 " btest_initCompleted(url);"
474 L"}" 474 "}"
475 L"var img = document.getElementById(" 475 "var img = document.getElementById("
476 L" 'current-screenshots-thumbnailDiv-0-image');" 476 " 'current-screenshots-thumbnailDiv-0-image');"
477 L"if (img)" 477 "if (img)"
478 L" btest_initCompleted(img.src);", 478 " btest_initCompleted(img.src);",
479 &result)); 479 &result));
480 EXPECT_EQ(enabled, result); 480 EXPECT_EQ(enabled, result);
481 481
482 // Feedback page is a singleton page, so close so future calls to this 482 // Feedback page is a singleton page, so close so future calls to this
483 // function work as expected. 483 // function work as expected.
484 web_contents->Close(); 484 web_contents->Close();
485 } 485 }
486 486
487 #if defined(OS_CHROMEOS) 487 #if defined(OS_CHROMEOS)
488 void TestScreenshotFile(bool enabled) { 488 void TestScreenshotFile(bool enabled) {
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1706 content::RunAllPendingInMessageLoop(); 1706 content::RunAllPendingInMessageLoop();
1707 1707
1708 GURL kAboutHistograms = GURL(std::string(chrome::kAboutScheme) + 1708 GURL kAboutHistograms = GURL(std::string(chrome::kAboutScheme) +
1709 std::string(content::kStandardSchemeSeparator) + 1709 std::string(content::kStandardSchemeSeparator) +
1710 std::string(chrome::kChromeUIHistogramHost)); 1710 std::string(chrome::kChromeUIHistogramHost));
1711 ui_test_utils::NavigateToURL(browser(), kAboutHistograms); 1711 ui_test_utils::NavigateToURL(browser(), kAboutHistograms);
1712 content::WebContents* contents = chrome::GetActiveWebContents(browser()); 1712 content::WebContents* contents = chrome::GetActiveWebContents(browser());
1713 std::string text; 1713 std::string text;
1714 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( 1714 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString(
1715 contents->GetRenderViewHost(), 1715 contents->GetRenderViewHost(),
1716 std::wstring(), 1716 "",
1717 L"var nodes = document.querySelectorAll('body > pre');" 1717 "var nodes = document.querySelectorAll('body > pre');"
1718 L"var result = '';" 1718 "var result = '';"
1719 L"for (var i = 0; i < nodes.length; ++i) {" 1719 "for (var i = 0; i < nodes.length; ++i) {"
1720 L" var text = nodes[i].innerHTML;" 1720 " var text = nodes[i].innerHTML;"
1721 L" if (text.indexOf('Histogram: Enterprise.Policies') === 0) {" 1721 " if (text.indexOf('Histogram: Enterprise.Policies') === 0) {"
1722 L" result = text;" 1722 " result = text;"
1723 L" break;" 1723 " break;"
1724 L" }" 1724 " }"
1725 L"}" 1725 "}"
1726 L"domAutomationController.send(result);", 1726 "domAutomationController.send(result);",
1727 &text)); 1727 &text));
1728 ASSERT_FALSE(text.empty()); 1728 ASSERT_FALSE(text.empty());
1729 const std::string kExpectedLabel = 1729 const std::string kExpectedLabel =
1730 "Histogram: Enterprise.Policies recorded 3 samples"; 1730 "Histogram: Enterprise.Policies recorded 3 samples";
1731 EXPECT_EQ(kExpectedLabel, text.substr(0, kExpectedLabel.size())); 1731 EXPECT_EQ(kExpectedLabel, text.substr(0, kExpectedLabel.size()));
1732 // HomepageLocation has policy ID 1. 1732 // HomepageLocation has policy ID 1.
1733 EXPECT_NE(std::string::npos, text.find("<br>1 ---")); 1733 EXPECT_NE(std::string::npos, text.find("<br>1 ---"));
1734 // ShowHomeButton has policy ID 35. 1734 // ShowHomeButton has policy ID 35.
1735 EXPECT_NE(std::string::npos, text.find("<br>35 ---")); 1735 EXPECT_NE(std::string::npos, text.find("<br>35 ---"));
1736 // BookmarkBarEnabled has policy ID 82. 1736 // BookmarkBarEnabled has policy ID 82.
1737 EXPECT_NE(std::string::npos, text.find("<br>82 ---")); 1737 EXPECT_NE(std::string::npos, text.find("<br>82 ---"));
1738 } 1738 }
1739 1739
1740 } // namespace policy 1740 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/notifications/notification_browsertest.cc ('k') | chrome/browser/policy/policy_prefs_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698