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

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

Issue 11753009: Simplify ExecuteJavaScript* functions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update prerender_browsertest.cc. 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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 GURL url(spec); 228 GURL url(spec);
229 ui_test_utils::NavigateToURL(browser, url); 229 ui_test_utils::NavigateToURL(browser, url);
230 content::WebContents* contents = chrome::GetActiveWebContents(browser); 230 content::WebContents* contents = chrome::GetActiveWebContents(browser);
231 EXPECT_EQ(url, contents->GetURL()); 231 EXPECT_EQ(url, contents->GetURL());
232 string16 title = UTF8ToUTF16(url.spec() + " is not available"); 232 string16 title = UTF8ToUTF16(url.spec() + " is not available");
233 EXPECT_EQ(title, contents->GetTitle()); 233 EXPECT_EQ(title, contents->GetTitle());
234 234
235 // Verify that the expected error page is being displayed. 235 // Verify that the expected error page is being displayed.
236 // (error 138 == NETWORK_ACCESS_DENIED) 236 // (error 138 == NETWORK_ACCESS_DENIED)
237 bool result = false; 237 bool result = false;
238 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( 238 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
239 contents->GetRenderViewHost(), 239 contents,
240 "",
241 "var hasError = false;" 240 "var hasError = false;"
242 "var error = document.getElementById('errorDetails');" 241 "var error = document.getElementById('errorDetails');"
243 "if (error)" 242 "if (error)"
244 " hasError = error.textContent.indexOf('Error 138') == 0;" 243 " hasError = error.textContent.indexOf('Error 138') == 0;"
245 "domAutomationController.send(hasError);", 244 "domAutomationController.send(hasError);",
246 &result)); 245 &result));
247 EXPECT_TRUE(result); 246 EXPECT_TRUE(result);
248 } 247 }
249 248
250 // Downloads a file named |file| and expects it to be saved to |dir|, which 249 // Downloads a file named |file| and expects it to be saved to |dir|, which
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 int count = 0; 281 int count = 0;
283 while (!enumerator.Next().empty()) 282 while (!enumerator.Next().empty())
284 count++; 283 count++;
285 return count; 284 return count;
286 } 285 }
287 #endif 286 #endif
288 287
289 // Checks if WebGL is enabled in the given WebContents. 288 // Checks if WebGL is enabled in the given WebContents.
290 bool IsWebGLEnabled(content::WebContents* contents) { 289 bool IsWebGLEnabled(content::WebContents* contents) {
291 bool result = false; 290 bool result = false;
292 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( 291 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
293 contents->GetRenderViewHost(), 292 contents,
294 "",
295 "var canvas = document.createElement('canvas');" 293 "var canvas = document.createElement('canvas');"
296 "var context = canvas.getContext('experimental-webgl');" 294 "var context = canvas.getContext('experimental-webgl');"
297 "domAutomationController.send(context != null);", 295 "domAutomationController.send(context != null);",
298 &result)); 296 &result));
299 return result; 297 return result;
300 } 298 }
301 299
302 bool IsJavascriptEnabled(content::WebContents* contents) { 300 bool IsJavascriptEnabled(content::WebContents* contents) {
303 content::RenderViewHost* rvh = contents->GetRenderViewHost(); 301 content::RenderViewHost* rvh = contents->GetRenderViewHost();
304 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue( 302 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 static_cast<content::Source<content::NavigationController> >( 451 static_cast<content::Source<content::NavigationController> >(
454 observer.source())->GetWebContents(); 452 observer.source())->GetWebContents();
455 453
456 // Wait for feedback page to fully initialize. 454 // Wait for feedback page to fully initialize.
457 // setupCurrentScreenshot is called when feedback page loads and (among 455 // setupCurrentScreenshot is called when feedback page loads and (among
458 // other things) adds current-screenshots-thumbnailDiv-0-image element. 456 // other things) adds current-screenshots-thumbnailDiv-0-image element.
459 // The code below executes either before setupCurrentScreenshot was called 457 // The code below executes either before setupCurrentScreenshot was called
460 // (setupCurrentScreenshot is replaced with our hook) or after it has 458 // (setupCurrentScreenshot is replaced with our hook) or after it has
461 // completed (in that case send result immediately). 459 // completed (in that case send result immediately).
462 bool result = false; 460 bool result = false;
463 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( 461 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
464 web_contents->GetRenderViewHost(), 462 web_contents,
465 "",
466 "function btest_initCompleted(url) {" 463 "function btest_initCompleted(url) {"
467 " var img = new Image();" 464 " var img = new Image();"
468 " img.src = url;" 465 " img.src = url;"
469 " img.onload = function() {" 466 " img.onload = function() {"
470 " domAutomationController.send(img.width * img.height > 0);" 467 " domAutomationController.send(img.width * img.height > 0);"
471 " };" 468 " };"
472 " img.onerror = function() {" 469 " img.onerror = function() {"
473 " domAutomationController.send(false);" 470 " domAutomationController.send(false);"
474 " };" 471 " };"
475 "}" 472 "}"
(...skipping 1240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1716 // BrowserPolicyConnector::Init() has already been called. Make sure the 1713 // BrowserPolicyConnector::Init() has already been called. Make sure the
1717 // CompleteInitialization() task has executed as well. 1714 // CompleteInitialization() task has executed as well.
1718 content::RunAllPendingInMessageLoop(); 1715 content::RunAllPendingInMessageLoop();
1719 1716
1720 GURL kAboutHistograms = GURL(std::string(chrome::kAboutScheme) + 1717 GURL kAboutHistograms = GURL(std::string(chrome::kAboutScheme) +
1721 std::string(content::kStandardSchemeSeparator) + 1718 std::string(content::kStandardSchemeSeparator) +
1722 std::string(chrome::kChromeUIHistogramHost)); 1719 std::string(chrome::kChromeUIHistogramHost));
1723 ui_test_utils::NavigateToURL(browser(), kAboutHistograms); 1720 ui_test_utils::NavigateToURL(browser(), kAboutHistograms);
1724 content::WebContents* contents = chrome::GetActiveWebContents(browser()); 1721 content::WebContents* contents = chrome::GetActiveWebContents(browser());
1725 std::string text; 1722 std::string text;
1726 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( 1723 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
1727 contents->GetRenderViewHost(), 1724 contents,
1728 "",
1729 "var nodes = document.querySelectorAll('body > pre');" 1725 "var nodes = document.querySelectorAll('body > pre');"
1730 "var result = '';" 1726 "var result = '';"
1731 "for (var i = 0; i < nodes.length; ++i) {" 1727 "for (var i = 0; i < nodes.length; ++i) {"
1732 " var text = nodes[i].innerHTML;" 1728 " var text = nodes[i].innerHTML;"
1733 " if (text.indexOf('Histogram: Enterprise.Policies') === 0) {" 1729 " if (text.indexOf('Histogram: Enterprise.Policies') === 0) {"
1734 " result = text;" 1730 " result = text;"
1735 " break;" 1731 " break;"
1736 " }" 1732 " }"
1737 "}" 1733 "}"
1738 "domAutomationController.send(result);", 1734 "domAutomationController.send(result);",
1739 &text)); 1735 &text));
1740 ASSERT_FALSE(text.empty()); 1736 ASSERT_FALSE(text.empty());
1741 const std::string kExpectedLabel = 1737 const std::string kExpectedLabel =
1742 "Histogram: Enterprise.Policies recorded 3 samples"; 1738 "Histogram: Enterprise.Policies recorded 3 samples";
1743 EXPECT_EQ(kExpectedLabel, text.substr(0, kExpectedLabel.size())); 1739 EXPECT_EQ(kExpectedLabel, text.substr(0, kExpectedLabel.size()));
1744 // HomepageLocation has policy ID 1. 1740 // HomepageLocation has policy ID 1.
1745 EXPECT_NE(std::string::npos, text.find("<br>1 ---")); 1741 EXPECT_NE(std::string::npos, text.find("<br>1 ---"));
1746 // ShowHomeButton has policy ID 35. 1742 // ShowHomeButton has policy ID 35.
1747 EXPECT_NE(std::string::npos, text.find("<br>35 ---")); 1743 EXPECT_NE(std::string::npos, text.find("<br>35 ---"));
1748 // BookmarkBarEnabled has policy ID 82. 1744 // BookmarkBarEnabled has policy ID 82.
1749 EXPECT_NE(std::string::npos, text.find("<br>82 ---")); 1745 EXPECT_NE(std::string::npos, text.find("<br>82 ---"));
1750 } 1746 }
1751 1747
1752 } // namespace policy 1748 } // 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