Reland "Add ExecuteJavaScriptForTest and make all tests use it"
Original issue's description: > Additionally, restrict the URLs that ExecuteJavaScript can be invoked on > to chrome-controlled URLs. > > R=jam@chromium.org > BUG=507809 > > Review URL: https://codereview.chromium.org/1123783002 > > Cr-Commit-Position: refs/heads/master@{#340231} R=mkwst@chromium.org TBR=jam@chromium.org BUG=507809 CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel Review URL: https://codereview.chromium.org/1258593002 . Cr-Commit-Position: refs/heads/master@{#340260}
This commit is contained in:
android_webview
browser
java
src
org
chromium
android_webview
javatests
src
org
chromium
android_webview
chrome
android
javatests
src
org
chromium
browser
apps
chromeos
login
download
errorpage_browsertest.ccextensions
geolocation
mouseleave_browsertest.ccprerender
safe_browsing
task_manager
ui
renderer
components
dom_distiller
printing
content
browser
accessibility
frame_host
web_contents
public
android
java
src
org
chromium
javatests
browser
test
renderer
shell
browser
extensions/browser/api/system_storage
@@ -19,6 +19,7 @@
|
|||||||
#include "base/files/file_path.h"
|
#include "base/files/file_path.h"
|
||||||
#include "base/path_service.h"
|
#include "base/path_service.h"
|
||||||
#include "content/public/browser/android/synchronous_compositor.h"
|
#include "content/public/browser/android/synchronous_compositor.h"
|
||||||
|
#include "content/public/browser/render_frame_host.h"
|
||||||
#include "content/public/browser/render_process_host.h"
|
#include "content/public/browser/render_process_host.h"
|
||||||
#include "content/public/common/content_client.h"
|
#include "content/public/common/content_client.h"
|
||||||
#include "content/public/common/content_switches.h"
|
#include "content/public/common/content_switches.h"
|
||||||
@@ -118,6 +119,8 @@ void AwBrowserMainParts::PreMainMessageLoopRun() {
|
|||||||
gfx::GLSurface::InitializeOneOff();
|
gfx::GLSurface::InitializeOneOff();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
content::RenderFrameHost::AllowInjectingJavaScriptForAndroidWebView();
|
||||||
|
|
||||||
// This is needed for WebView Classic backwards compatibility
|
// This is needed for WebView Classic backwards compatibility
|
||||||
// See crbug.com/298495
|
// See crbug.com/298495
|
||||||
content::SetMaxURLChars(20 * 1024 * 1024);
|
content::SetMaxURLChars(20 * 1024 * 1024);
|
||||||
|
@@ -2069,6 +2069,22 @@ public class AwContents implements SmartClipProvider,
|
|||||||
mWebContents.evaluateJavaScript(script, jsCallback);
|
mWebContents.evaluateJavaScript(script, jsCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void evaluateJavaScriptForTests(String script, final ValueCallback<String> callback) {
|
||||||
|
if (TRACE) Log.d(TAG, "evaluateJavascriptForTests=" + script);
|
||||||
|
if (isDestroyed()) return;
|
||||||
|
JavaScriptCallback jsCallback = null;
|
||||||
|
if (callback != null) {
|
||||||
|
jsCallback = new JavaScriptCallback() {
|
||||||
|
@Override
|
||||||
|
public void handleJavaScriptResult(String jsonResult) {
|
||||||
|
callback.onReceiveValue(jsonResult);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
mWebContents.evaluateJavaScriptForTests(script, jsCallback);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Post a message to a frame.
|
* Post a message to a frame.
|
||||||
*
|
*
|
||||||
|
@@ -403,7 +403,7 @@ public class AwContentsTest extends AwTestBase {
|
|||||||
AwSettings awSettings = awContents.getSettings();
|
AwSettings awSettings = awContents.getSettings();
|
||||||
awSettings.setJavaScriptEnabled(true);
|
awSettings.setJavaScriptEnabled(true);
|
||||||
awContents.addJavascriptInterface(new JavaScriptObject(callback), "bridge");
|
awContents.addJavascriptInterface(new JavaScriptObject(callback), "bridge");
|
||||||
awContents.evaluateJavaScript("window.bridge.run();", null);
|
awContents.evaluateJavaScriptForTests("window.bridge.run();", null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
callback.waitForCallback(0, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
callback.waitForCallback(0, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||||
|
@@ -70,7 +70,7 @@ public class AwJavaBridgeTest extends AwTestBase {
|
|||||||
assertEquals("\"function\"", executeJavaScriptAndWaitForResult(
|
assertEquals("\"function\"", executeJavaScriptAndWaitForResult(
|
||||||
awContents, mContentsClient, "typeof test.destroy"));
|
awContents, mContentsClient, "typeof test.destroy"));
|
||||||
int currentCallCount = client2.getOnPageFinishedHelper().getCallCount();
|
int currentCallCount = client2.getOnPageFinishedHelper().getCallCount();
|
||||||
awContents.evaluateJavaScript("test.destroy()", null);
|
awContents.evaluateJavaScriptForTests("test.destroy()", null);
|
||||||
|
|
||||||
client2.getOnPageFinishedHelper().waitForCallback(currentCallCount);
|
client2.getOnPageFinishedHelper().waitForCallback(currentCallCount);
|
||||||
}
|
}
|
||||||
|
@@ -588,7 +588,7 @@ public class AwTestBase
|
|||||||
TestAwContentsClient.OnCreateWindowHelper onCreateWindowHelper =
|
TestAwContentsClient.OnCreateWindowHelper onCreateWindowHelper =
|
||||||
parentAwContentsClient.getOnCreateWindowHelper();
|
parentAwContentsClient.getOnCreateWindowHelper();
|
||||||
int currentCallCount = onCreateWindowHelper.getCallCount();
|
int currentCallCount = onCreateWindowHelper.getCallCount();
|
||||||
parentAwContents.evaluateJavaScript(triggerScript, null);
|
parentAwContents.evaluateJavaScriptForTests(triggerScript, null);
|
||||||
onCreateWindowHelper.waitForCallback(
|
onCreateWindowHelper.waitForCallback(
|
||||||
currentCallCount, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
currentCallCount, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
@@ -113,7 +113,7 @@ public class GeolocationTest extends AwTestBase {
|
|||||||
loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(),
|
loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(),
|
||||||
RAW_HTML, "text/html", false);
|
RAW_HTML, "text/html", false);
|
||||||
|
|
||||||
mAwContents.evaluateJavaScript("initiate_getCurrentPosition();", null);
|
mAwContents.evaluateJavaScriptForTests("initiate_getCurrentPosition();", null);
|
||||||
|
|
||||||
poll(new Callable<Boolean>() {
|
poll(new Callable<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -122,7 +122,7 @@ public class GeolocationTest extends AwTestBase {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mAwContents.evaluateJavaScript("initiate_getCurrentPosition();", null);
|
mAwContents.evaluateJavaScriptForTests("initiate_getCurrentPosition();", null);
|
||||||
poll(new Callable<Boolean>() {
|
poll(new Callable<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public Boolean call() throws Exception {
|
public Boolean call() throws Exception {
|
||||||
@@ -140,7 +140,7 @@ public class GeolocationTest extends AwTestBase {
|
|||||||
loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(),
|
loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(),
|
||||||
RAW_HTML, "text/html", false);
|
RAW_HTML, "text/html", false);
|
||||||
|
|
||||||
mAwContents.evaluateJavaScript("initiate_watchPosition();", null);
|
mAwContents.evaluateJavaScriptForTests("initiate_watchPosition();", null);
|
||||||
|
|
||||||
poll(new Callable<Boolean>() {
|
poll(new Callable<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -157,7 +157,7 @@ public class GeolocationTest extends AwTestBase {
|
|||||||
loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(),
|
loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(),
|
||||||
RAW_HTML, "text/html", false);
|
RAW_HTML, "text/html", false);
|
||||||
|
|
||||||
mAwContents.evaluateJavaScript("initiate_watchPosition();", null);
|
mAwContents.evaluateJavaScriptForTests("initiate_watchPosition();", null);
|
||||||
|
|
||||||
poll(new Callable<Boolean>() {
|
poll(new Callable<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -215,7 +215,7 @@ public class GeolocationTest extends AwTestBase {
|
|||||||
loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(),
|
loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(),
|
||||||
RAW_HTML, "text/html", false);
|
RAW_HTML, "text/html", false);
|
||||||
|
|
||||||
mAwContents.evaluateJavaScript("initiate_watchPosition();", null);
|
mAwContents.evaluateJavaScriptForTests("initiate_watchPosition();", null);
|
||||||
|
|
||||||
assertEquals(0, getPositionCountFromJS());
|
assertEquals(0, getPositionCountFromJS());
|
||||||
|
|
||||||
|
@@ -47,7 +47,7 @@ public class JSUtils {
|
|||||||
testCase.getInstrumentation().runOnMainSync(new Runnable() {
|
testCase.getInstrumentation().runOnMainSync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
awContents.getWebContents().evaluateJavaScript(
|
awContents.getWebContents().evaluateJavaScriptForTests(
|
||||||
"var evObj = document.createEvent('Events'); "
|
"var evObj = document.createEvent('Events'); "
|
||||||
+ "evObj.initEvent('click', true, false); "
|
+ "evObj.initEvent('click', true, false); "
|
||||||
+ "document.getElementById('" + linkId + "').dispatchEvent(evObj);"
|
+ "document.getElementById('" + linkId + "').dispatchEvent(evObj);"
|
||||||
@@ -65,7 +65,7 @@ public class JSUtils {
|
|||||||
testCase.getInstrumentation().runOnMainSync(new Runnable() {
|
testCase.getInstrumentation().runOnMainSync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
onEvaluateJavaScriptResultHelper.evaluateJavaScript(
|
onEvaluateJavaScriptResultHelper.evaluateJavaScriptForTests(
|
||||||
awContents.getWebContents(), code);
|
awContents.getWebContents(), code);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -55,8 +55,8 @@ public class JavaScriptEvalChromeTest extends ChromeTabbedActivityTestBase {
|
|||||||
for (int i = 1; i <= 30; ++i) {
|
for (int i = 1; i <= 30; ++i) {
|
||||||
for (int j = 0; j < 5; ++j) {
|
for (int j = 0; j < 5; ++j) {
|
||||||
// Start evaluation of a JavaScript script -- we don't need a result.
|
// Start evaluation of a JavaScript script -- we don't need a result.
|
||||||
tab1.getWebContents().evaluateJavaScript("foobar();", null);
|
tab1.getWebContents().evaluateJavaScriptForTests("foobar();", null);
|
||||||
tab2.getWebContents().evaluateJavaScript("foobar();", null);
|
tab2.getWebContents().evaluateJavaScriptForTests("foobar();", null);
|
||||||
}
|
}
|
||||||
assertEquals("Incorrect JavaScript evaluation result on tab1",
|
assertEquals("Incorrect JavaScript evaluation result on tab1",
|
||||||
i * 2,
|
i * 2,
|
||||||
@@ -65,8 +65,8 @@ public class JavaScriptEvalChromeTest extends ChromeTabbedActivityTestBase {
|
|||||||
tab1.getWebContents(), "add2()")));
|
tab1.getWebContents(), "add2()")));
|
||||||
for (int j = 0; j < 5; ++j) {
|
for (int j = 0; j < 5; ++j) {
|
||||||
// Start evaluation of a JavaScript script -- we don't need a result.
|
// Start evaluation of a JavaScript script -- we don't need a result.
|
||||||
tab1.getWebContents().evaluateJavaScript("foobar();", null);
|
tab1.getWebContents().evaluateJavaScriptForTests("foobar();", null);
|
||||||
tab2.getWebContents().evaluateJavaScript("foobar();", null);
|
tab2.getWebContents().evaluateJavaScriptForTests("foobar();", null);
|
||||||
}
|
}
|
||||||
assertEquals("Incorrect JavaScript evaluation result on tab2",
|
assertEquals("Incorrect JavaScript evaluation result on tab2",
|
||||||
i * 2 + 1,
|
i * 2 + 1,
|
||||||
|
@@ -264,7 +264,8 @@ public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
|
|||||||
clickCancel(jsDialog);
|
clickCancel(jsDialog);
|
||||||
scriptEvent.waitUntilHasValue();
|
scriptEvent.waitUntilHasValue();
|
||||||
|
|
||||||
scriptEvent.evaluateJavaScript(getActivity().getCurrentContentViewCore().getWebContents(),
|
scriptEvent.evaluateJavaScriptForTests(
|
||||||
|
getActivity().getCurrentContentViewCore().getWebContents(),
|
||||||
"alert('Android');");
|
"alert('Android');");
|
||||||
assertTrue("No further dialog boxes should be shown.", scriptEvent.waitUntilHasValue());
|
assertTrue("No further dialog boxes should be shown.", scriptEvent.waitUntilHasValue());
|
||||||
}
|
}
|
||||||
@@ -310,7 +311,8 @@ public class ModalDialogTest extends ChromeActivityTestCaseBase<ChromeActivity>
|
|||||||
private OnEvaluateJavaScriptResultHelper executeJavaScriptAndWaitForDialog(
|
private OnEvaluateJavaScriptResultHelper executeJavaScriptAndWaitForDialog(
|
||||||
final OnEvaluateJavaScriptResultHelper helper, String script)
|
final OnEvaluateJavaScriptResultHelper helper, String script)
|
||||||
throws InterruptedException {
|
throws InterruptedException {
|
||||||
helper.evaluateJavaScript(getActivity().getCurrentContentViewCore().getWebContents(),
|
helper.evaluateJavaScriptForTests(
|
||||||
|
getActivity().getCurrentContentViewCore().getWebContents(),
|
||||||
script);
|
script);
|
||||||
boolean criteriaSatisfied = CriteriaHelper.pollForCriteria(
|
boolean criteriaSatisfied = CriteriaHelper.pollForCriteria(
|
||||||
new JavascriptAppModalDialogShownCriteria(true));
|
new JavascriptAppModalDialogShownCriteria(true));
|
||||||
|
@@ -133,7 +133,7 @@ public class TabsTest extends ChromeTabbedActivityTestBase {
|
|||||||
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
tab.getWebContents().evaluateJavaScript(
|
tab.getWebContents().evaluateJavaScriptForTests(
|
||||||
"(function() {"
|
"(function() {"
|
||||||
+ " window.open('www.google.com');"
|
+ " window.open('www.google.com');"
|
||||||
+ "})()",
|
+ "})()",
|
||||||
@@ -158,7 +158,7 @@ public class TabsTest extends ChromeTabbedActivityTestBase {
|
|||||||
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
tab.getWebContents().evaluateJavaScript(
|
tab.getWebContents().evaluateJavaScriptForTests(
|
||||||
"(function() {"
|
"(function() {"
|
||||||
+ " alert('hi');"
|
+ " alert('hi');"
|
||||||
+ "})()",
|
+ "})()",
|
||||||
|
@@ -113,8 +113,8 @@ class CustomLauncherPageBrowserTest
|
|||||||
enabled ? "launcherPageEnabled" : "launcherPageDisabled";
|
enabled ? "launcherPageEnabled" : "launcherPageDisabled";
|
||||||
|
|
||||||
ExtensionTestMessageListener listener(test_message, false);
|
ExtensionTestMessageListener listener(test_message, false);
|
||||||
custom_page_frame->ExecuteJavaScript(enabled ? kLauncherPageEnableScript
|
custom_page_frame->ExecuteJavaScriptForTests(
|
||||||
: kLauncherPageDisableScript);
|
enabled ? kLauncherPageEnableScript : kLauncherPageDisableScript);
|
||||||
listener.WaitUntilSatisfied();
|
listener.WaitUntilSatisfied();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,7 +339,7 @@ IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, LauncherPageShowAndHide) {
|
|||||||
// if the app launcher is already showing.
|
// if the app launcher is already showing.
|
||||||
{
|
{
|
||||||
ExtensionTestMessageListener listener("onPageProgressAt1", false);
|
ExtensionTestMessageListener listener("onPageProgressAt1", false);
|
||||||
custom_page_frame->ExecuteJavaScript(kLauncherPageShowScript);
|
custom_page_frame->ExecuteJavaScriptForTests(kLauncherPageShowScript);
|
||||||
|
|
||||||
listener.WaitUntilSatisfied();
|
listener.WaitUntilSatisfied();
|
||||||
EXPECT_TRUE(contents_view->IsStateActive(
|
EXPECT_TRUE(contents_view->IsStateActive(
|
||||||
@@ -353,7 +353,7 @@ IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, LauncherPageShowAndHide) {
|
|||||||
app_list_view->GetWidget()->Close();
|
app_list_view->GetWidget()->Close();
|
||||||
|
|
||||||
ExtensionTestMessageListener listener("onPageProgressAt1", false);
|
ExtensionTestMessageListener listener("onPageProgressAt1", false);
|
||||||
custom_page_frame->ExecuteJavaScript(kLauncherPageShowScript);
|
custom_page_frame->ExecuteJavaScriptForTests(kLauncherPageShowScript);
|
||||||
|
|
||||||
listener.WaitUntilSatisfied();
|
listener.WaitUntilSatisfied();
|
||||||
|
|
||||||
@@ -367,7 +367,7 @@ IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, LauncherPageShowAndHide) {
|
|||||||
// Ensure launcherPage.hide() hides the launcher page when it's showing.
|
// Ensure launcherPage.hide() hides the launcher page when it's showing.
|
||||||
{
|
{
|
||||||
ExtensionTestMessageListener listener("onPageProgressAt0", false);
|
ExtensionTestMessageListener listener("onPageProgressAt0", false);
|
||||||
custom_page_frame->ExecuteJavaScript(kLauncherPageHideScript);
|
custom_page_frame->ExecuteJavaScriptForTests(kLauncherPageHideScript);
|
||||||
|
|
||||||
listener.WaitUntilSatisfied();
|
listener.WaitUntilSatisfied();
|
||||||
|
|
||||||
@@ -380,7 +380,7 @@ IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, LauncherPageShowAndHide) {
|
|||||||
contents_view->SetActiveState(app_list::AppListModel::STATE_APPS, false);
|
contents_view->SetActiveState(app_list::AppListModel::STATE_APPS, false);
|
||||||
|
|
||||||
ExtensionTestMessageListener listener("launcherPageHidden", false);
|
ExtensionTestMessageListener listener("launcherPageHidden", false);
|
||||||
custom_page_frame->ExecuteJavaScript(kLauncherPageHideScript);
|
custom_page_frame->ExecuteJavaScriptForTests(kLauncherPageHideScript);
|
||||||
listener.WaitUntilSatisfied();
|
listener.WaitUntilSatisfied();
|
||||||
|
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
|
@@ -118,7 +118,7 @@ class WebUIScreenLockerTester : public ScreenLockerTester {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void WebUIScreenLockerTester::SetPassword(const std::string& password) {
|
void WebUIScreenLockerTester::SetPassword(const std::string& password) {
|
||||||
webui()->GetWebContents()->GetMainFrame()->ExecuteJavaScript(
|
webui()->GetWebContents()->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
base::ASCIIToUTF16(base::StringPrintf(
|
base::ASCIIToUTF16(base::StringPrintf(
|
||||||
"$('pod-row').pods[0].passwordElement.value = '%s';",
|
"$('pod-row').pods[0].passwordElement.value = '%s';",
|
||||||
password.c_str())));
|
password.c_str())));
|
||||||
|
@@ -2237,7 +2237,8 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaPost) {
|
|||||||
&web_contents->GetController()));
|
&web_contents->GetController()));
|
||||||
content::RenderFrameHost* render_frame_host = web_contents->GetMainFrame();
|
content::RenderFrameHost* render_frame_host = web_contents->GetMainFrame();
|
||||||
ASSERT_TRUE(render_frame_host != NULL);
|
ASSERT_TRUE(render_frame_host != NULL);
|
||||||
render_frame_host->ExecuteJavaScript(base::ASCIIToUTF16("SubmitForm()"));
|
render_frame_host->ExecuteJavaScriptForTests(
|
||||||
|
base::ASCIIToUTF16("SubmitForm()"));
|
||||||
observer.Wait();
|
observer.Wait();
|
||||||
EXPECT_EQ(jpeg_url, web_contents->GetURL());
|
EXPECT_EQ(jpeg_url, web_contents->GetURL());
|
||||||
|
|
||||||
|
@@ -621,7 +621,7 @@ IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_DoSearch) {
|
|||||||
// Can't use content::ExecuteScript because it waits for scripts to send
|
// Can't use content::ExecuteScript because it waits for scripts to send
|
||||||
// notification that they've run, and scripts that trigger a navigation may
|
// notification that they've run, and scripts that trigger a navigation may
|
||||||
// not send that notification.
|
// not send that notification.
|
||||||
web_contents->GetMainFrame()->ExecuteJavaScript(
|
web_contents->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
base::ASCIIToUTF16("document.getElementById('search-button').click();"));
|
base::ASCIIToUTF16("document.getElementById('search-button').click();"));
|
||||||
nav_observer.Wait();
|
nav_observer.Wait();
|
||||||
EXPECT_EQ(base::ASCIIToUTF16("Title Of More Awesomeness"),
|
EXPECT_EQ(base::ASCIIToUTF16("Title Of More Awesomeness"),
|
||||||
@@ -666,7 +666,7 @@ IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_DoReload) {
|
|||||||
// Can't use content::ExecuteScript because it waits for scripts to send
|
// Can't use content::ExecuteScript because it waits for scripts to send
|
||||||
// notification that they've run, and scripts that trigger a navigation may
|
// notification that they've run, and scripts that trigger a navigation may
|
||||||
// not send that notification.
|
// not send that notification.
|
||||||
web_contents->GetMainFrame()->ExecuteJavaScript(
|
web_contents->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
base::ASCIIToUTF16("document.getElementById('reload-button').click();"));
|
base::ASCIIToUTF16("document.getElementById('reload-button').click();"));
|
||||||
nav_observer.Wait();
|
nav_observer.Wait();
|
||||||
ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
|
ExpectDisplayingNavigationCorrections(browser(), net::ERR_NAME_NOT_RESOLVED);
|
||||||
@@ -699,12 +699,12 @@ IN_PROC_BROWSER_TEST_F(ErrorPageTest, DNSError_DoClickLink) {
|
|||||||
"document.querySelector('a[href=\"http://mock.http/title2.html\"]')";
|
"document.querySelector('a[href=\"http://mock.http/title2.html\"]')";
|
||||||
// The tracking request is triggered by onmousedown, so it catches middle
|
// The tracking request is triggered by onmousedown, so it catches middle
|
||||||
// mouse button clicks, as well as left clicks.
|
// mouse button clicks, as well as left clicks.
|
||||||
web_contents->GetMainFrame()->ExecuteJavaScript(
|
web_contents->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
base::ASCIIToUTF16(link_selector + ".onmousedown();"));
|
base::ASCIIToUTF16(link_selector + ".onmousedown();"));
|
||||||
// Can't use content::ExecuteScript because it waits for scripts to send
|
// Can't use content::ExecuteScript because it waits for scripts to send
|
||||||
// notification that they've run, and scripts that trigger a navigation may
|
// notification that they've run, and scripts that trigger a navigation may
|
||||||
// not send that notification.
|
// not send that notification.
|
||||||
web_contents->GetMainFrame()->ExecuteJavaScript(
|
web_contents->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
base::ASCIIToUTF16(link_selector + ".click();"));
|
base::ASCIIToUTF16(link_selector + ".click();"));
|
||||||
EXPECT_EQ(base::ASCIIToUTF16("Title Of Awesomeness"),
|
EXPECT_EQ(base::ASCIIToUTF16("Title Of Awesomeness"),
|
||||||
title_watcher.WaitAndGetTitle());
|
title_watcher.WaitAndGetTitle());
|
||||||
@@ -790,7 +790,7 @@ IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_JavaScript) {
|
|||||||
content::WindowedNotificationObserver load_observer(
|
content::WindowedNotificationObserver load_observer(
|
||||||
content::NOTIFICATION_LOAD_STOP,
|
content::NOTIFICATION_LOAD_STOP,
|
||||||
content::Source<NavigationController>(&wc->GetController()));
|
content::Source<NavigationController>(&wc->GetController()));
|
||||||
wc->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16(script));
|
wc->GetMainFrame()->ExecuteJavaScriptForTests(base::ASCIIToUTF16(script));
|
||||||
load_observer.Wait();
|
load_observer.Wait();
|
||||||
|
|
||||||
// Ensure we saw the expected failure.
|
// Ensure we saw the expected failure.
|
||||||
@@ -810,7 +810,7 @@ IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_JavaScript) {
|
|||||||
content::WindowedNotificationObserver load_observer(
|
content::WindowedNotificationObserver load_observer(
|
||||||
content::NOTIFICATION_LOAD_STOP,
|
content::NOTIFICATION_LOAD_STOP,
|
||||||
content::Source<NavigationController>(&wc->GetController()));
|
content::Source<NavigationController>(&wc->GetController()));
|
||||||
wc->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16(script));
|
wc->GetMainFrame()->ExecuteJavaScriptForTests(base::ASCIIToUTF16(script));
|
||||||
load_observer.Wait();
|
load_observer.Wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -821,7 +821,7 @@ IN_PROC_BROWSER_TEST_F(ErrorPageTest, IFrameDNSError_JavaScript) {
|
|||||||
content::WindowedNotificationObserver load_observer(
|
content::WindowedNotificationObserver load_observer(
|
||||||
content::NOTIFICATION_LOAD_STOP,
|
content::NOTIFICATION_LOAD_STOP,
|
||||||
content::Source<NavigationController>(&wc->GetController()));
|
content::Source<NavigationController>(&wc->GetController()));
|
||||||
wc->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16(script));
|
wc->GetMainFrame()->ExecuteJavaScriptForTests(base::ASCIIToUTF16(script));
|
||||||
load_observer.Wait();
|
load_observer.Wait();
|
||||||
|
|
||||||
EXPECT_EQ(fail_url, fail_observer.fail_url());
|
EXPECT_EQ(fail_url, fail_observer.fail_url());
|
||||||
@@ -1000,7 +1000,7 @@ IN_PROC_BROWSER_TEST_F(ErrorPageAutoReloadTest, ManualReloadNotSuppressed) {
|
|||||||
content::WebContents* web_contents =
|
content::WebContents* web_contents =
|
||||||
browser()->tab_strip_model()->GetActiveWebContents();
|
browser()->tab_strip_model()->GetActiveWebContents();
|
||||||
content::TestNavigationObserver nav_observer(web_contents, 1);
|
content::TestNavigationObserver nav_observer(web_contents, 1);
|
||||||
web_contents->GetMainFrame()->ExecuteJavaScript(
|
web_contents->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
base::ASCIIToUTF16("document.getElementById('reload-button').click();"));
|
base::ASCIIToUTF16("document.getElementById('reload-button').click();"));
|
||||||
nav_observer.Wait();
|
nav_observer.Wait();
|
||||||
EXPECT_FALSE(IsDisplayingText(browser(), "error.page.auto.reload"));
|
EXPECT_FALSE(IsDisplayingText(browser(), "error.page.auto.reload"));
|
||||||
|
@@ -21,7 +21,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, AlertBasic) {
|
|||||||
extensions::ProcessManager::Get(browser()->profile())
|
extensions::ProcessManager::Get(browser()->profile())
|
||||||
->GetBackgroundHostForExtension(extension->id());
|
->GetBackgroundHostForExtension(extension->id());
|
||||||
ASSERT_TRUE(host);
|
ASSERT_TRUE(host);
|
||||||
host->host_contents()->GetMainFrame()->ExecuteJavaScript(
|
host->host_contents()->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
base::ASCIIToUTF16("alert('This should not crash.');"));
|
base::ASCIIToUTF16("alert('This should not crash.');"));
|
||||||
|
|
||||||
app_modal::AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
|
app_modal::AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
|
||||||
|
@@ -108,7 +108,7 @@ class MediaGalleriesGalleryWatchApiTest : public ExtensionApiTest {
|
|||||||
void ExecuteCmdAndCheckReply(const std::string& js_command,
|
void ExecuteCmdAndCheckReply(const std::string& js_command,
|
||||||
const std::string& ok_message) {
|
const std::string& ok_message) {
|
||||||
ExtensionTestMessageListener listener(ok_message, false);
|
ExtensionTestMessageListener listener(ok_message, false);
|
||||||
background_host_->GetMainFrame()->ExecuteJavaScript(
|
background_host_->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
base::ASCIIToUTF16(js_command));
|
base::ASCIIToUTF16(js_command));
|
||||||
EXPECT_TRUE(listener.WaitUntilSatisfied());
|
EXPECT_TRUE(listener.WaitUntilSatisfied());
|
||||||
}
|
}
|
||||||
|
@@ -213,7 +213,8 @@ class DelayLoadStartAndExecuteJavascript
|
|||||||
rvh_->GetMainFrame()->ExecuteJavaScriptWithUserGestureForTests(
|
rvh_->GetMainFrame()->ExecuteJavaScriptWithUserGestureForTests(
|
||||||
base::UTF8ToUTF16(script_));
|
base::UTF8ToUTF16(script_));
|
||||||
} else {
|
} else {
|
||||||
rvh_->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16(script_));
|
rvh_->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
|
base::UTF8ToUTF16(script_));
|
||||||
}
|
}
|
||||||
script_was_executed_ = true;
|
script_was_executed_ = true;
|
||||||
}
|
}
|
||||||
@@ -674,7 +675,8 @@ IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, CrossProcessAbort) {
|
|||||||
// Ensure the cross-site navigation has started, then execute JavaScript
|
// Ensure the cross-site navigation has started, then execute JavaScript
|
||||||
// to cause the renderer-initiated, non-user navigation.
|
// to cause the renderer-initiated, non-user navigation.
|
||||||
cross_site_load.Wait();
|
cross_site_load.Wait();
|
||||||
tab->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16("navigate2()"));
|
tab->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
|
base::UTF8ToUTF16("navigate2()"));
|
||||||
|
|
||||||
// Wait for the same-site navigation to start and resume the cross-site
|
// Wait for the same-site navigation to start and resume the cross-site
|
||||||
// one, allowing it to commit.
|
// one, allowing it to commit.
|
||||||
|
@@ -90,7 +90,8 @@ IFrameLoader::IFrameLoader(Browser* browser, int iframe_id, const GURL& url)
|
|||||||
"window.domAutomationController.setAutomationId(0);"
|
"window.domAutomationController.setAutomationId(0);"
|
||||||
"window.domAutomationController.send(addIFrame(%d, \"%s\"));",
|
"window.domAutomationController.send(addIFrame(%d, \"%s\"));",
|
||||||
iframe_id, url.spec().c_str()));
|
iframe_id, url.spec().c_str()));
|
||||||
web_contents->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16(script));
|
web_contents->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
|
base::UTF8ToUTF16(script));
|
||||||
content::RunMessageLoop();
|
content::RunMessageLoop();
|
||||||
|
|
||||||
EXPECT_EQ(base::StringPrintf("\"%d\"", iframe_id), javascript_response_);
|
EXPECT_EQ(base::StringPrintf("\"%d\"", iframe_id), javascript_response_);
|
||||||
|
@@ -130,7 +130,7 @@ IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ContextMenu) {
|
|||||||
// Wait until the context menu is opened and closed.
|
// Wait until the context menu is opened and closed.
|
||||||
menu_observer.WaitForMenuOpenAndClose();
|
menu_observer.WaitForMenuOpenAndClose();
|
||||||
|
|
||||||
tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()"));
|
tab->GetMainFrame()->ExecuteJavaScriptForTests(base::ASCIIToUTF16("done()"));
|
||||||
const base::string16 success_title = base::ASCIIToUTF16("without mouseleave");
|
const base::string16 success_title = base::ASCIIToUTF16("without mouseleave");
|
||||||
const base::string16 failure_title = base::ASCIIToUTF16("with mouseleave");
|
const base::string16 failure_title = base::ASCIIToUTF16("with mouseleave");
|
||||||
content::TitleWatcher done_title_watcher(tab, success_title);
|
content::TitleWatcher done_title_watcher(tab, success_title);
|
||||||
@@ -156,12 +156,12 @@ IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ModalDialog) {
|
|||||||
|
|
||||||
EXPECT_NO_FATAL_FAILURE(LoadTestPageAndWaitForMouseOver(tab));
|
EXPECT_NO_FATAL_FAILURE(LoadTestPageAndWaitForMouseOver(tab));
|
||||||
|
|
||||||
tab->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16("alert()"));
|
tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()"));
|
||||||
app_modal::AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
|
app_modal::AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
|
||||||
// Cancel the dialog.
|
// Cancel the dialog.
|
||||||
alert->CloseModalDialog();
|
alert->CloseModalDialog();
|
||||||
|
|
||||||
tab->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("done()"));
|
tab->GetMainFrame()->ExecuteJavaScriptForTests(base::ASCIIToUTF16("done()"));
|
||||||
const base::string16 success_title = base::ASCIIToUTF16("without mouseleave");
|
const base::string16 success_title = base::ASCIIToUTF16("without mouseleave");
|
||||||
const base::string16 failure_title = base::ASCIIToUTF16("with mouseleave");
|
const base::string16 failure_title = base::ASCIIToUTF16("with mouseleave");
|
||||||
content::TitleWatcher done_title_watcher(tab, success_title);
|
content::TitleWatcher done_title_watcher(tab, success_title);
|
||||||
|
@@ -1263,14 +1263,15 @@ class PrerenderBrowserTest : virtual public InProcessBrowserTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RemoveLinkElement(int i) const {
|
void RemoveLinkElement(int i) const {
|
||||||
GetActiveWebContents()->GetMainFrame()->ExecuteJavaScript(
|
GetActiveWebContents()->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
base::ASCIIToUTF16(base::StringPrintf("RemoveLinkElement(%d)", i)));
|
base::ASCIIToUTF16(base::StringPrintf("RemoveLinkElement(%d)", i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClickToNextPageAfterPrerender() {
|
void ClickToNextPageAfterPrerender() {
|
||||||
TestNavigationObserver nav_observer(GetActiveWebContents());
|
TestNavigationObserver nav_observer(GetActiveWebContents());
|
||||||
RenderFrameHost* render_frame_host = GetActiveWebContents()->GetMainFrame();
|
RenderFrameHost* render_frame_host = GetActiveWebContents()->GetMainFrame();
|
||||||
render_frame_host->ExecuteJavaScript(base::ASCIIToUTF16("ClickOpenLink()"));
|
render_frame_host->ExecuteJavaScriptForTests(
|
||||||
|
base::ASCIIToUTF16("ClickOpenLink()"));
|
||||||
nav_observer.Wait();
|
nav_observer.Wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1528,7 +1529,8 @@ class PrerenderBrowserTest : virtual public InProcessBrowserTest {
|
|||||||
std::string javascript = base::StringPrintf(
|
std::string javascript = base::StringPrintf(
|
||||||
"AddPrerender('%s', %d)", url.spec().c_str(), index);
|
"AddPrerender('%s', %d)", url.spec().c_str(), index);
|
||||||
RenderFrameHost* render_frame_host = GetActiveWebContents()->GetMainFrame();
|
RenderFrameHost* render_frame_host = GetActiveWebContents()->GetMainFrame();
|
||||||
render_frame_host->ExecuteJavaScript(base::ASCIIToUTF16(javascript));
|
render_frame_host->ExecuteJavaScriptForTests(
|
||||||
|
base::ASCIIToUTF16(javascript));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a string for pattern-matching TaskManager tab entries.
|
// Returns a string for pattern-matching TaskManager tab entries.
|
||||||
@@ -1678,7 +1680,8 @@ class PrerenderBrowserTest : virtual public InProcessBrowserTest {
|
|||||||
} else {
|
} else {
|
||||||
NavigationOrSwapObserver observer(current_browser()->tab_strip_model(),
|
NavigationOrSwapObserver observer(current_browser()->tab_strip_model(),
|
||||||
web_contents);
|
web_contents);
|
||||||
render_frame_host->ExecuteJavaScript(base::ASCIIToUTF16(javascript));
|
render_frame_host->ExecuteJavaScriptForTests(
|
||||||
|
base::ASCIIToUTF16(javascript));
|
||||||
observer.Wait();
|
observer.Wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -568,7 +568,7 @@ class SafeBrowsingBlockingPageBrowserTest
|
|||||||
// We don't use ExecuteScriptAndGetValue for this one, since clicking
|
// We don't use ExecuteScriptAndGetValue for this one, since clicking
|
||||||
// the button/link may navigate away before the injected javascript can
|
// the button/link may navigate away before the injected javascript can
|
||||||
// reply, hanging the test.
|
// reply, hanging the test.
|
||||||
rvh->GetMainFrame()->ExecuteJavaScript(
|
rvh->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
base::ASCIIToUTF16(
|
base::ASCIIToUTF16(
|
||||||
"document.getElementById('" + node_id + "').click();\n"));
|
"document.getElementById('" + node_id + "').click();\n"));
|
||||||
return true;
|
return true;
|
||||||
|
@@ -257,7 +257,8 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest,
|
|||||||
tab1->GetMainFrame()->ExecuteJavaScriptWithUserGestureForTests(
|
tab1->GetMainFrame()->ExecuteJavaScriptWithUserGestureForTests(
|
||||||
base::ASCIIToUTF16("window.open('title3.html', '_blank');"));
|
base::ASCIIToUTF16("window.open('title3.html', '_blank');"));
|
||||||
// ... then immediately hang the renderer so that title3.html can't load.
|
// ... then immediately hang the renderer so that title3.html can't load.
|
||||||
tab1->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("while(1);"));
|
tab1->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
|
base::ASCIIToUTF16("while(1);"));
|
||||||
|
|
||||||
// Blocks until a new WebContents appears.
|
// Blocks until a new WebContents appears.
|
||||||
WebContents* tab2 = web_contents_added_observer.GetWebContents();
|
WebContents* tab2 = web_contents_added_observer.GetWebContents();
|
||||||
|
@@ -491,13 +491,13 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ClosableAfterNavigation) {
|
|||||||
|
|
||||||
// Navigate it elsewhere.
|
// Navigate it elsewhere.
|
||||||
content::TestNavigationObserver nav_observer(popup);
|
content::TestNavigationObserver nav_observer(popup);
|
||||||
popup->GetMainFrame()->ExecuteJavaScript(
|
popup->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
base::UTF8ToUTF16("location.href = '/empty.html'"));
|
base::UTF8ToUTF16("location.href = '/empty.html'"));
|
||||||
nav_observer.Wait();
|
nav_observer.Wait();
|
||||||
|
|
||||||
// Have it close itself.
|
// Have it close itself.
|
||||||
CloseObserver close_observer(popup);
|
CloseObserver close_observer(popup);
|
||||||
popup->GetMainFrame()->ExecuteJavaScript(
|
popup->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
base::UTF8ToUTF16("window.close()"));
|
base::UTF8ToUTF16("window.close()"));
|
||||||
close_observer.Wait();
|
close_observer.Wait();
|
||||||
}
|
}
|
||||||
@@ -574,7 +574,7 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnder) {
|
|||||||
ASSERT_NE(popup_browser, browser());
|
ASSERT_NE(popup_browser, browser());
|
||||||
|
|
||||||
// Showing an alert will raise the tab over the popup.
|
// Showing an alert will raise the tab over the popup.
|
||||||
tab->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16("alert()"));
|
tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()"));
|
||||||
app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog();
|
app_modal::AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog();
|
||||||
|
|
||||||
// Verify that after the dialog was closed, the popup is in front again.
|
// Verify that after the dialog was closed, the popup is in front again.
|
||||||
|
@@ -544,7 +544,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, JavascriptAlertActivatesTab) {
|
|||||||
EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
|
EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
|
||||||
WebContents* second_tab = browser()->tab_strip_model()->GetWebContentsAt(1);
|
WebContents* second_tab = browser()->tab_strip_model()->GetWebContentsAt(1);
|
||||||
ASSERT_TRUE(second_tab);
|
ASSERT_TRUE(second_tab);
|
||||||
second_tab->GetMainFrame()->ExecuteJavaScript(
|
second_tab->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
ASCIIToUTF16("alert('Activate!');"));
|
ASCIIToUTF16("alert('Activate!');"));
|
||||||
AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
|
AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
|
||||||
alert->CloseModalDialog();
|
alert->CloseModalDialog();
|
||||||
@@ -651,7 +651,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, DISABLED_CrossProcessNavCancelsDialogs) {
|
|||||||
// even if the renderer tries to synchronously create more.
|
// even if the renderer tries to synchronously create more.
|
||||||
// See http://crbug.com/312490.
|
// See http://crbug.com/312490.
|
||||||
WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
|
WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
|
||||||
contents->GetMainFrame()->ExecuteJavaScript(
|
contents->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
ASCIIToUTF16("alert('one'); alert('two');"));
|
ASCIIToUTF16("alert('one'); alert('two');"));
|
||||||
AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
|
AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
|
||||||
EXPECT_TRUE(alert->IsValid());
|
EXPECT_TRUE(alert->IsValid());
|
||||||
@@ -677,7 +677,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsDialogs) {
|
|||||||
|
|
||||||
// Start a navigation to trigger the beforeunload dialog.
|
// Start a navigation to trigger the beforeunload dialog.
|
||||||
WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
|
WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
|
||||||
contents->GetMainFrame()->ExecuteJavaScript(
|
contents->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
ASCIIToUTF16("window.location.href = 'data:text/html,foo'"));
|
ASCIIToUTF16("window.location.href = 'data:text/html,foo'"));
|
||||||
AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
|
AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
|
||||||
EXPECT_TRUE(alert->IsValid());
|
EXPECT_TRUE(alert->IsValid());
|
||||||
@@ -703,7 +703,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsDialogs) {
|
|||||||
IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsSubframeDialogs) {
|
IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsSubframeDialogs) {
|
||||||
// Navigate to an iframe that opens an alert dialog.
|
// Navigate to an iframe that opens an alert dialog.
|
||||||
WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
|
WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
|
||||||
contents->GetMainFrame()->ExecuteJavaScript(
|
contents->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
ASCIIToUTF16("window.location.href = 'data:text/html,"
|
ASCIIToUTF16("window.location.href = 'data:text/html,"
|
||||||
"<iframe srcdoc=\"<script>alert(1)</script>\">'"));
|
"<iframe srcdoc=\"<script>alert(1)</script>\">'"));
|
||||||
AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
|
AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
|
||||||
@@ -767,7 +767,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, ReloadThenCancelBeforeUnload) {
|
|||||||
|
|
||||||
// Clear the beforeunload handler so the test can easily exit.
|
// Clear the beforeunload handler so the test can easily exit.
|
||||||
browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()->
|
browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()->
|
||||||
ExecuteJavaScript(ASCIIToUTF16("onbeforeunload=null;"));
|
ExecuteJavaScriptForTests(ASCIIToUTF16("onbeforeunload=null;"));
|
||||||
}
|
}
|
||||||
|
|
||||||
class RedirectObserver : public content::WebContentsObserver {
|
class RedirectObserver : public content::WebContentsObserver {
|
||||||
@@ -928,7 +928,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, CancelBeforeUnloadResetsURL) {
|
|||||||
|
|
||||||
// Clear the beforeunload handler so the test can easily exit.
|
// Clear the beforeunload handler so the test can easily exit.
|
||||||
browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()->
|
browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()->
|
||||||
ExecuteJavaScript(ASCIIToUTF16("onbeforeunload=null;"));
|
ExecuteJavaScriptForTests(ASCIIToUTF16("onbeforeunload=null;"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test for crbug.com/11647. A page closed with window.close() should not have
|
// Test for crbug.com/11647. A page closed with window.close() should not have
|
||||||
@@ -2068,7 +2068,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, InterstitialClosesDialogs) {
|
|||||||
ui_test_utils::NavigateToURL(browser(), url);
|
ui_test_utils::NavigateToURL(browser(), url);
|
||||||
|
|
||||||
WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
|
WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
|
||||||
contents->GetMainFrame()->ExecuteJavaScript(
|
contents->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
ASCIIToUTF16("alert('Dialog showing!');"));
|
ASCIIToUTF16("alert('Dialog showing!');"));
|
||||||
AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
|
AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
|
||||||
EXPECT_TRUE(alert->IsValid());
|
EXPECT_TRUE(alert->IsValid());
|
||||||
|
@@ -212,7 +212,7 @@ class SelectFileDialogExtensionBrowserTest : public ExtensionBrowserTest {
|
|||||||
"document.querySelector(\'" + button_class + "\').click();");
|
"document.querySelector(\'" + button_class + "\').click();");
|
||||||
// The file selection handler closes the dialog and does not return control
|
// The file selection handler closes the dialog and does not return control
|
||||||
// to JavaScript, so do not wait for return values.
|
// to JavaScript, so do not wait for return values.
|
||||||
host->GetMainFrame()->ExecuteJavaScript(script);
|
host->GetMainFrame()->ExecuteJavaScriptForTests(script);
|
||||||
LOG(INFO) << "Waiting for window close notification.";
|
LOG(INFO) << "Waiting for window close notification.";
|
||||||
listener_->WaitForCalled();
|
listener_->WaitForCalled();
|
||||||
|
|
||||||
|
@@ -765,20 +765,20 @@ void GaiaScreenHandler::SubmitLoginFormForTest() {
|
|||||||
code += "document.getElementById('Passwd').value = '" + test_pass_ + "';";
|
code += "document.getElementById('Passwd').value = '" + test_pass_ + "';";
|
||||||
code += "document.getElementById('signIn').click();";
|
code += "document.getElementById('signIn').click();";
|
||||||
|
|
||||||
frame->ExecuteJavaScript(base::ASCIIToUTF16(code));
|
frame->ExecuteJavaScriptForTests(base::ASCIIToUTF16(code));
|
||||||
} else {
|
} else {
|
||||||
std::string code;
|
std::string code;
|
||||||
|
|
||||||
code =
|
code =
|
||||||
"document.getElementById('identifier').value = '" + test_user_ + "';";
|
"document.getElementById('identifier').value = '" + test_user_ + "';";
|
||||||
code += "document.getElementById('nextButton').click();";
|
code += "document.getElementById('nextButton').click();";
|
||||||
frame->ExecuteJavaScript(base::ASCIIToUTF16(code));
|
frame->ExecuteJavaScriptForTests(base::ASCIIToUTF16(code));
|
||||||
|
|
||||||
if (!test_pass_.empty()) {
|
if (!test_pass_.empty()) {
|
||||||
code =
|
code =
|
||||||
"document.getElementById('password').value = '" + test_pass_ + "';";
|
"document.getElementById('password').value = '" + test_pass_ + "';";
|
||||||
code += "document.getElementById('nextButton').click();";
|
code += "document.getElementById('nextButton').click();";
|
||||||
frame->ExecuteJavaScript(base::ASCIIToUTF16(code));
|
frame->ExecuteJavaScriptForTests(base::ASCIIToUTF16(code));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -248,7 +248,7 @@ void NetInternalsTest::MessageHandler::NavigateToPrerender(
|
|||||||
ASSERT_TRUE(list_value->GetString(0, &url));
|
ASSERT_TRUE(list_value->GetString(0, &url));
|
||||||
content::RenderFrameHost* frame =
|
content::RenderFrameHost* frame =
|
||||||
browser()->tab_strip_model()->GetWebContentsAt(1)->GetMainFrame();
|
browser()->tab_strip_model()->GetWebContentsAt(1)->GetMainFrame();
|
||||||
frame->ExecuteJavaScript(
|
frame->ExecuteJavaScriptForTests(
|
||||||
base::ASCIIToUTF16(base::StringPrintf("Click('%s')", url.c_str())));
|
base::ASCIIToUTF16(base::StringPrintf("Click('%s')", url.c_str())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -37,7 +37,8 @@ void WebUITestHandler::PreloadJavaScript(const base::string16& js_text,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WebUITestHandler::RunJavaScript(const base::string16& js_text) {
|
void WebUITestHandler::RunJavaScript(const base::string16& js_text) {
|
||||||
web_ui()->GetWebContents()->GetMainFrame()->ExecuteJavaScript(js_text);
|
web_ui()->GetWebContents()->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
|
js_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebUITestHandler::RunJavaScriptTestWithResult(
|
bool WebUITestHandler::RunJavaScriptTestWithResult(
|
||||||
@@ -45,9 +46,9 @@ bool WebUITestHandler::RunJavaScriptTestWithResult(
|
|||||||
test_succeeded_ = false;
|
test_succeeded_ = false;
|
||||||
run_test_succeeded_ = false;
|
run_test_succeeded_ = false;
|
||||||
content::RenderFrameHost* frame = web_ui()->GetWebContents()->GetMainFrame();
|
content::RenderFrameHost* frame = web_ui()->GetWebContents()->GetMainFrame();
|
||||||
frame->ExecuteJavaScript(js_text,
|
frame->ExecuteJavaScriptForTests(
|
||||||
base::Bind(&WebUITestHandler::JavaScriptComplete,
|
js_text, base::Bind(&WebUITestHandler::JavaScriptComplete,
|
||||||
base::Unretained(this)));
|
base::Unretained(this)));
|
||||||
return WaitForResult();
|
return WaitForResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -122,7 +122,7 @@ TEST_F(AutofillRendererTest, SendForms) {
|
|||||||
|
|
||||||
// Dynamically create a new form. A new message should be sent for it, but
|
// Dynamically create a new form. A new message should be sent for it, but
|
||||||
// not for the previous form.
|
// not for the previous form.
|
||||||
ExecuteJavaScript(
|
ExecuteJavaScriptForTests(
|
||||||
"var newForm=document.createElement('form');"
|
"var newForm=document.createElement('form');"
|
||||||
"newForm.id='new_testform';"
|
"newForm.id='new_testform';"
|
||||||
"newForm.action='http://google.com';"
|
"newForm.action='http://google.com';"
|
||||||
@@ -220,7 +220,7 @@ TEST_F(AutofillRendererTest, DynamicallyAddedUnownedFormElements) {
|
|||||||
|
|
||||||
render_thread_->sink().ClearMessages();
|
render_thread_->sink().ClearMessages();
|
||||||
|
|
||||||
ExecuteJavaScript("AddFields()");
|
ExecuteJavaScriptForTests("AddFields()");
|
||||||
msg_loop_.RunUntilIdle();
|
msg_loop_.RunUntilIdle();
|
||||||
|
|
||||||
message = render_thread_->sink().GetFirstMessageMatching(
|
message = render_thread_->sink().GetFirstMessageMatching(
|
||||||
|
@@ -74,7 +74,7 @@ TEST_F(FormAutocompleteTest, NormalFormSubmit) {
|
|||||||
"<input name='lname' value='Deckard'/></form></html>");
|
"<input name='lname' value='Deckard'/></form></html>");
|
||||||
|
|
||||||
// Submit the form.
|
// Submit the form.
|
||||||
ExecuteJavaScript("document.getElementById('myForm').submit();");
|
ExecuteJavaScriptForTests("document.getElementById('myForm').submit();");
|
||||||
ProcessPendingMessages();
|
ProcessPendingMessages();
|
||||||
|
|
||||||
VerifyReceivedRendererMessages(render_thread_.get(),
|
VerifyReceivedRendererMessages(render_thread_.get(),
|
||||||
@@ -91,7 +91,7 @@ TEST_F(FormAutocompleteTest, SubmitEventPrevented) {
|
|||||||
"</html>");
|
"</html>");
|
||||||
|
|
||||||
// Submit the form.
|
// Submit the form.
|
||||||
ExecuteJavaScript(
|
ExecuteJavaScriptForTests(
|
||||||
"var form = document.forms[0];"
|
"var form = document.forms[0];"
|
||||||
"form.onsubmit = function(event) { event.preventDefault(); };"
|
"form.onsubmit = function(event) { event.preventDefault(); };"
|
||||||
"document.querySelector('input[type=submit]').click();");
|
"document.querySelector('input[type=submit]').click();");
|
||||||
@@ -111,7 +111,7 @@ TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) {
|
|||||||
"</form></html>");
|
"</form></html>");
|
||||||
|
|
||||||
// Submit the form.
|
// Submit the form.
|
||||||
ExecuteJavaScript("document.getElementById('myForm').submit();");
|
ExecuteJavaScriptForTests("document.getElementById('myForm').submit();");
|
||||||
ProcessPendingMessages();
|
ProcessPendingMessages();
|
||||||
|
|
||||||
VerifyReceivedRendererMessages(render_thread_.get(),
|
VerifyReceivedRendererMessages(render_thread_.get(),
|
||||||
@@ -127,7 +127,7 @@ TEST_F(FormAutocompleteTest, AutoCompleteOffInputSubmit) {
|
|||||||
"</form></html>");
|
"</form></html>");
|
||||||
|
|
||||||
// Submit the form.
|
// Submit the form.
|
||||||
ExecuteJavaScript("document.getElementById('myForm').submit();");
|
ExecuteJavaScriptForTests("document.getElementById('myForm').submit();");
|
||||||
ProcessPendingMessages();
|
ProcessPendingMessages();
|
||||||
|
|
||||||
VerifyReceivedRendererMessages(render_thread_.get(),
|
VerifyReceivedRendererMessages(render_thread_.get(),
|
||||||
@@ -148,13 +148,14 @@ TEST_F(FormAutocompleteTest, DynamicAutoCompleteOffFormSubmit) {
|
|||||||
EXPECT_TRUE(form.autoComplete());
|
EXPECT_TRUE(form.autoComplete());
|
||||||
|
|
||||||
// Dynamically mark the form as autocomplete off.
|
// Dynamically mark the form as autocomplete off.
|
||||||
ExecuteJavaScript("document.getElementById('myForm')."
|
ExecuteJavaScriptForTests(
|
||||||
"setAttribute('autocomplete', 'off');");
|
"document.getElementById('myForm')."
|
||||||
|
"setAttribute('autocomplete', 'off');");
|
||||||
ProcessPendingMessages();
|
ProcessPendingMessages();
|
||||||
EXPECT_FALSE(form.autoComplete());
|
EXPECT_FALSE(form.autoComplete());
|
||||||
|
|
||||||
// Submit the form.
|
// Submit the form.
|
||||||
ExecuteJavaScript("document.getElementById('myForm').submit();");
|
ExecuteJavaScriptForTests("document.getElementById('myForm').submit();");
|
||||||
ProcessPendingMessages();
|
ProcessPendingMessages();
|
||||||
|
|
||||||
VerifyReceivedRendererMessages(render_thread_.get(),
|
VerifyReceivedRendererMessages(render_thread_.get(),
|
||||||
|
@@ -2132,7 +2132,7 @@ TEST_F(FormAutofillTest, OnlyExtractNewForms) {
|
|||||||
ASSERT_TRUE(forms.empty());
|
ASSERT_TRUE(forms.empty());
|
||||||
|
|
||||||
// Append to the current form will re-extract.
|
// Append to the current form will re-extract.
|
||||||
ExecuteJavaScript(
|
ExecuteJavaScriptForTests(
|
||||||
"var newInput = document.createElement('input');"
|
"var newInput = document.createElement('input');"
|
||||||
"newInput.setAttribute('type', 'text');"
|
"newInput.setAttribute('type', 'text');"
|
||||||
"newInput.setAttribute('id', 'telephone');"
|
"newInput.setAttribute('id', 'telephone');"
|
||||||
@@ -2169,7 +2169,7 @@ TEST_F(FormAutofillTest, OnlyExtractNewForms) {
|
|||||||
forms.clear();
|
forms.clear();
|
||||||
|
|
||||||
// Completely new form will also be extracted.
|
// Completely new form will also be extracted.
|
||||||
ExecuteJavaScript(
|
ExecuteJavaScriptForTests(
|
||||||
"var newForm=document.createElement('form');"
|
"var newForm=document.createElement('form');"
|
||||||
"newForm.id='new_testform';"
|
"newForm.id='new_testform';"
|
||||||
"newForm.action='http://google.com';"
|
"newForm.action='http://google.com';"
|
||||||
|
@@ -126,7 +126,7 @@ TEST_F(PageClickTrackerTest, PageClickTrackerInputRightClicked) {
|
|||||||
|
|
||||||
TEST_F(PageClickTrackerTest, PageClickTrackerInputFocusedAndClicked) {
|
TEST_F(PageClickTrackerTest, PageClickTrackerInputFocusedAndClicked) {
|
||||||
// Focus the text field without a click.
|
// Focus the text field without a click.
|
||||||
ExecuteJavaScript("document.getElementById('text_1').focus();");
|
ExecuteJavaScriptForTests("document.getElementById('text_1').focus();");
|
||||||
EXPECT_FALSE(test_listener_.form_control_element_clicked_called_);
|
EXPECT_FALSE(test_listener_.form_control_element_clicked_called_);
|
||||||
test_listener_.ClearResults();
|
test_listener_.ClearResults();
|
||||||
|
|
||||||
@@ -161,7 +161,7 @@ TEST_F(PageClickTrackerTest, PageClickTrackerTextAreaClicked) {
|
|||||||
|
|
||||||
TEST_F(PageClickTrackerTest, PageClickTrackerTextAreaFocusedAndClicked) {
|
TEST_F(PageClickTrackerTest, PageClickTrackerTextAreaFocusedAndClicked) {
|
||||||
// Focus the textarea without a click.
|
// Focus the textarea without a click.
|
||||||
ExecuteJavaScript("document.getElementById('textarea_1').focus();");
|
ExecuteJavaScriptForTests("document.getElementById('textarea_1').focus();");
|
||||||
EXPECT_FALSE(test_listener_.form_control_element_clicked_called_);
|
EXPECT_FALSE(test_listener_.form_control_element_clicked_called_);
|
||||||
test_listener_.ClearResults();
|
test_listener_.ClearResults();
|
||||||
|
|
||||||
|
@@ -805,7 +805,7 @@ TEST_F(PasswordAutofillAgentTest, NoDOMActivationTest) {
|
|||||||
// Trigger the initial autocomplete.
|
// Trigger the initial autocomplete.
|
||||||
SimulateOnFillPasswordForm(fill_data_);
|
SimulateOnFillPasswordForm(fill_data_);
|
||||||
|
|
||||||
ExecuteJavaScript(kJavaScriptClick);
|
ExecuteJavaScriptForTests(kJavaScriptClick);
|
||||||
CheckTextFieldsDOMState(kAliceUsername, true, "", true);
|
CheckTextFieldsDOMState(kAliceUsername, true, "", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1680,7 +1680,7 @@ TEST_F(PasswordAutofillAgentTest, FindingFieldsWithAutofillPredictions) {
|
|||||||
"new_input.setAttribute('type', 'text');"
|
"new_input.setAttribute('type', 'text');"
|
||||||
"new_input.setAttribute('id', 'other_field');"
|
"new_input.setAttribute('id', 'other_field');"
|
||||||
"form.appendChild(new_input);";
|
"form.appendChild(new_input);";
|
||||||
ExecuteJavaScript(add_field_to_form.c_str());
|
ExecuteJavaScriptForTests(add_field_to_form.c_str());
|
||||||
|
|
||||||
static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
|
static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
|
||||||
->WillSendSubmitEvent(username_element_.form());
|
->WillSendSubmitEvent(username_element_.form());
|
||||||
|
@@ -51,7 +51,7 @@ class PasswordGenerationAgentTest : public ChromeRenderViewTest {
|
|||||||
blink::WebElement element =
|
blink::WebElement element =
|
||||||
document.getElementById(blink::WebString::fromUTF8(element_id));
|
document.getElementById(blink::WebString::fromUTF8(element_id));
|
||||||
ASSERT_FALSE(element.isNull());
|
ASSERT_FALSE(element.isNull());
|
||||||
ExecuteJavaScript(
|
ExecuteJavaScriptForTests(
|
||||||
base::StringPrintf("document.getElementById('%s').focus();",
|
base::StringPrintf("document.getElementById('%s').focus();",
|
||||||
element_id).c_str());
|
element_id).c_str());
|
||||||
}
|
}
|
||||||
@@ -418,12 +418,13 @@ TEST_F(PasswordGenerationAgentTest, MaximumOfferSize) {
|
|||||||
|
|
||||||
// Change focus. Bubble should be hidden, but that is handled by AutofilAgent,
|
// Change focus. Bubble should be hidden, but that is handled by AutofilAgent,
|
||||||
// so no messages are sent.
|
// so no messages are sent.
|
||||||
ExecuteJavaScript("document.getElementById('username').focus();");
|
ExecuteJavaScriptForTests("document.getElementById('username').focus();");
|
||||||
EXPECT_EQ(0u, password_generation_->messages().size());
|
EXPECT_EQ(0u, password_generation_->messages().size());
|
||||||
password_generation_->clear_messages();
|
password_generation_->clear_messages();
|
||||||
|
|
||||||
// Focusing the password field will bring up the generation UI again.
|
// Focusing the password field will bring up the generation UI again.
|
||||||
ExecuteJavaScript("document.getElementById('first_password').focus();");
|
ExecuteJavaScriptForTests(
|
||||||
|
"document.getElementById('first_password').focus();");
|
||||||
ASSERT_EQ(1u, password_generation_->messages().size());
|
ASSERT_EQ(1u, password_generation_->messages().size());
|
||||||
EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
|
EXPECT_EQ(AutofillHostMsg_ShowPasswordGenerationPopup::ID,
|
||||||
password_generation_->messages()[0]->type());
|
password_generation_->messages()[0]->type());
|
||||||
@@ -443,7 +444,7 @@ TEST_F(PasswordGenerationAgentTest, DynamicFormTest) {
|
|||||||
LoadHTMLWithUserGesture(kSigninFormHTML);
|
LoadHTMLWithUserGesture(kSigninFormHTML);
|
||||||
SetNotBlacklistedMessage(password_generation_, kSigninFormHTML);
|
SetNotBlacklistedMessage(password_generation_, kSigninFormHTML);
|
||||||
|
|
||||||
ExecuteJavaScript(
|
ExecuteJavaScriptForTests(
|
||||||
"var form = document.createElement('form');"
|
"var form = document.createElement('form');"
|
||||||
"var username = document.createElement('input');"
|
"var username = document.createElement('input');"
|
||||||
"username.type = 'text';"
|
"username.type = 'text';"
|
||||||
|
@@ -504,7 +504,7 @@ IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest,
|
|||||||
|
|
||||||
// Execute the JS to run the tests, and wait until it has finished.
|
// Execute the JS to run the tests, and wait until it has finished.
|
||||||
base::RunLoop run_loop;
|
base::RunLoop run_loop;
|
||||||
web_contents->GetMainFrame()->ExecuteJavaScript(
|
web_contents->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
base::UTF8ToUTF16("(function() {return pinchtest.run();})();"),
|
base::UTF8ToUTF16("(function() {return pinchtest.run();})();"),
|
||||||
base::Bind(&DistillerPageWebContentsTest::OnJsExecutionDone,
|
base::Bind(&DistillerPageWebContentsTest::OnJsExecutionDone,
|
||||||
base::Unretained(this), run_loop.QuitClosure()));
|
base::Unretained(this), run_loop.QuitClosure()));
|
||||||
|
@@ -121,7 +121,7 @@ IN_PROC_BROWSER_TEST_F(DomDistillerJsTest, RunJsTests) {
|
|||||||
// QuitClosure multiple times.
|
// QuitClosure multiple times.
|
||||||
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
|
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
|
||||||
FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromSeconds(15));
|
FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromSeconds(15));
|
||||||
web_contents->GetMainFrame()->ExecuteJavaScript(
|
web_contents->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
base::UTF8ToUTF16(kRunJsTestsJs),
|
base::UTF8ToUTF16(kRunJsTestsJs),
|
||||||
base::Bind(&DomDistillerJsTest::OnJsTestExecutionDone,
|
base::Bind(&DomDistillerJsTest::OnJsTestExecutionDone,
|
||||||
base::Unretained(this)));
|
base::Unretained(this)));
|
||||||
|
@@ -153,7 +153,7 @@ class PrintWebViewHelperTestBase : public content::RenderViewTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PrintWithJavaScript() {
|
void PrintWithJavaScript() {
|
||||||
ExecuteJavaScript("window.print();");
|
ExecuteJavaScriptForTests("window.print();");
|
||||||
ProcessPendingMessages();
|
ProcessPendingMessages();
|
||||||
}
|
}
|
||||||
// The renderer should be done calculating the number of rendered pages
|
// The renderer should be done calculating the number of rendered pages
|
||||||
|
@@ -108,7 +108,7 @@ IAccessible* AccessibilityWinBrowserTest::GetRendererAccessible() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AccessibilityWinBrowserTest::ExecuteScript(const std::wstring& script) {
|
void AccessibilityWinBrowserTest::ExecuteScript(const std::wstring& script) {
|
||||||
shell()->web_contents()->GetMainFrame()->ExecuteJavaScript(script);
|
shell()->web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(script);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loads a page with an input text field and places sample text in it. Also,
|
// Loads a page with an input text field and places sample text in it. Also,
|
||||||
|
@@ -89,7 +89,7 @@ std::vector<std::string> DumpAccessibilityEventsTest::Dump() {
|
|||||||
shell(), AccessibilityModeComplete, ui::AX_EVENT_NONE));
|
shell(), AccessibilityModeComplete, ui::AX_EVENT_NONE));
|
||||||
|
|
||||||
|
|
||||||
web_contents->GetMainFrame()->ExecuteJavaScript(
|
web_contents->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
base::ASCIIToUTF16("go()"));
|
base::ASCIIToUTF16("go()"));
|
||||||
|
|
||||||
// Wait for at least one accessibility event generated in response to
|
// Wait for at least one accessibility event generated in response to
|
||||||
|
@@ -92,6 +92,10 @@ int g_next_accessibility_reset_token = 1;
|
|||||||
// The next value to use for the javascript callback id.
|
// The next value to use for the javascript callback id.
|
||||||
int g_next_javascript_callback_id = 1;
|
int g_next_javascript_callback_id = 1;
|
||||||
|
|
||||||
|
// Whether to allow injecting javascript into any kind of frame (for Android
|
||||||
|
// WebView).
|
||||||
|
bool g_allow_injecting_javascript = false;
|
||||||
|
|
||||||
// The (process id, routing id) pair that identifies one RenderFrame.
|
// The (process id, routing id) pair that identifies one RenderFrame.
|
||||||
typedef std::pair<int32, int32> RenderFrameHostID;
|
typedef std::pair<int32, int32> RenderFrameHostID;
|
||||||
typedef base::hash_map<RenderFrameHostID, RenderFrameHostImpl*>
|
typedef base::hash_map<RenderFrameHostID, RenderFrameHostImpl*>
|
||||||
@@ -126,6 +130,11 @@ RenderFrameHost* RenderFrameHost::FromID(int render_process_id,
|
|||||||
return RenderFrameHostImpl::FromID(render_process_id, render_frame_id);
|
return RenderFrameHostImpl::FromID(render_process_id, render_frame_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
void RenderFrameHost::AllowInjectingJavaScriptForAndroidWebView() {
|
||||||
|
g_allow_injecting_javascript = true;
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
RenderFrameHostImpl* RenderFrameHostImpl::FromID(int process_id,
|
RenderFrameHostImpl* RenderFrameHostImpl::FromID(int process_id,
|
||||||
int routing_id) {
|
int routing_id) {
|
||||||
@@ -272,6 +281,7 @@ void RenderFrameHostImpl::AddMessageToConsole(ConsoleMessageLevel level,
|
|||||||
|
|
||||||
void RenderFrameHostImpl::ExecuteJavaScript(
|
void RenderFrameHostImpl::ExecuteJavaScript(
|
||||||
const base::string16& javascript) {
|
const base::string16& javascript) {
|
||||||
|
CHECK(CanExecuteJavaScript());
|
||||||
Send(new FrameMsg_JavaScriptExecuteRequest(routing_id_,
|
Send(new FrameMsg_JavaScriptExecuteRequest(routing_id_,
|
||||||
javascript,
|
javascript,
|
||||||
0, false));
|
0, false));
|
||||||
@@ -280,6 +290,7 @@ void RenderFrameHostImpl::ExecuteJavaScript(
|
|||||||
void RenderFrameHostImpl::ExecuteJavaScript(
|
void RenderFrameHostImpl::ExecuteJavaScript(
|
||||||
const base::string16& javascript,
|
const base::string16& javascript,
|
||||||
const JavaScriptResultCallback& callback) {
|
const JavaScriptResultCallback& callback) {
|
||||||
|
CHECK(CanExecuteJavaScript());
|
||||||
int key = g_next_javascript_callback_id++;
|
int key = g_next_javascript_callback_id++;
|
||||||
Send(new FrameMsg_JavaScriptExecuteRequest(routing_id_,
|
Send(new FrameMsg_JavaScriptExecuteRequest(routing_id_,
|
||||||
javascript,
|
javascript,
|
||||||
@@ -287,6 +298,23 @@ void RenderFrameHostImpl::ExecuteJavaScript(
|
|||||||
javascript_callbacks_.insert(std::make_pair(key, callback));
|
javascript_callbacks_.insert(std::make_pair(key, callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderFrameHostImpl::ExecuteJavaScriptForTests(
|
||||||
|
const base::string16& javascript) {
|
||||||
|
Send(new FrameMsg_JavaScriptExecuteRequestForTests(routing_id_,
|
||||||
|
javascript,
|
||||||
|
0, false, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderFrameHostImpl::ExecuteJavaScriptForTests(
|
||||||
|
const base::string16& javascript,
|
||||||
|
const JavaScriptResultCallback& callback) {
|
||||||
|
int key = g_next_javascript_callback_id++;
|
||||||
|
Send(new FrameMsg_JavaScriptExecuteRequestForTests(routing_id_, javascript,
|
||||||
|
key, true, false));
|
||||||
|
javascript_callbacks_.insert(std::make_pair(key, callback));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void RenderFrameHostImpl::ExecuteJavaScriptWithUserGestureForTests(
|
void RenderFrameHostImpl::ExecuteJavaScriptWithUserGestureForTests(
|
||||||
const base::string16& javascript) {
|
const base::string16& javascript) {
|
||||||
Send(new FrameMsg_JavaScriptExecuteRequestForTests(routing_id_,
|
Send(new FrameMsg_JavaScriptExecuteRequestForTests(routing_id_,
|
||||||
@@ -2132,4 +2160,16 @@ void RenderFrameHostImpl::UpdatePermissionsForNavigation(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RenderFrameHostImpl::CanExecuteJavaScript() {
|
||||||
|
return g_allow_injecting_javascript ||
|
||||||
|
frame_tree_node_->current_url().SchemeIs(kChromeDevToolsScheme) ||
|
||||||
|
ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
|
||||||
|
GetProcess()->GetID()) ||
|
||||||
|
// It's possible to load about:blank in a Web UI renderer.
|
||||||
|
// See http://crbug.com/42547
|
||||||
|
(frame_tree_node_->current_url().spec() == url::kAboutBlankURL) ||
|
||||||
|
// InterstitialPageImpl should be the only case matching this.
|
||||||
|
(delegate_->GetAsWebContents() == nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace content
|
} // namespace content
|
||||||
|
@@ -139,6 +139,10 @@ class CONTENT_EXPORT RenderFrameHostImpl
|
|||||||
void ExecuteJavaScript(const base::string16& javascript) override;
|
void ExecuteJavaScript(const base::string16& javascript) override;
|
||||||
void ExecuteJavaScript(const base::string16& javascript,
|
void ExecuteJavaScript(const base::string16& javascript,
|
||||||
const JavaScriptResultCallback& callback) override;
|
const JavaScriptResultCallback& callback) override;
|
||||||
|
void ExecuteJavaScriptForTests(const base::string16& javascript) override;
|
||||||
|
void ExecuteJavaScriptForTests(
|
||||||
|
const base::string16& javascript,
|
||||||
|
const JavaScriptResultCallback& callback) override;
|
||||||
void ExecuteJavaScriptWithUserGestureForTests(
|
void ExecuteJavaScriptWithUserGestureForTests(
|
||||||
const base::string16& javascript) override;
|
const base::string16& javascript) override;
|
||||||
void ExecuteJavaScriptInIsolatedWorld(
|
void ExecuteJavaScriptInIsolatedWorld(
|
||||||
@@ -584,6 +588,9 @@ class CONTENT_EXPORT RenderFrameHostImpl
|
|||||||
const CommonNavigationParams& common_params,
|
const CommonNavigationParams& common_params,
|
||||||
const RequestNavigationParams& request_params);
|
const RequestNavigationParams& request_params);
|
||||||
|
|
||||||
|
// Returns true if the ExecuteJavaScript() API can be used on this host.
|
||||||
|
bool CanExecuteJavaScript();
|
||||||
|
|
||||||
// For now, RenderFrameHosts indirectly keep RenderViewHosts alive via a
|
// For now, RenderFrameHosts indirectly keep RenderViewHosts alive via a
|
||||||
// refcount that calls Shutdown when it reaches zero. This allows each
|
// refcount that calls Shutdown when it reaches zero. This allows each
|
||||||
// RenderFrameHostManager to just care about RenderFrameHosts, while ensuring
|
// RenderFrameHostManager to just care about RenderFrameHosts, while ensuring
|
||||||
|
@@ -440,6 +440,39 @@ void WebContentsAndroid::EvaluateJavaScript(JNIEnv* env,
|
|||||||
ConvertJavaStringToUTF16(env, script), js_callback);
|
ConvertJavaStringToUTF16(env, script), js_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebContentsAndroid::EvaluateJavaScriptForTests(JNIEnv* env,
|
||||||
|
jobject obj,
|
||||||
|
jstring script,
|
||||||
|
jobject callback) {
|
||||||
|
RenderViewHost* rvh = web_contents_->GetRenderViewHost();
|
||||||
|
DCHECK(rvh);
|
||||||
|
|
||||||
|
if (!rvh->IsRenderViewLive()) {
|
||||||
|
if (!static_cast<WebContentsImpl*>(web_contents_)->
|
||||||
|
CreateRenderViewForInitialEmptyDocument()) {
|
||||||
|
LOG(ERROR) << "Failed to create RenderView in EvaluateJavaScriptForTests";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!callback) {
|
||||||
|
// No callback requested.
|
||||||
|
web_contents_->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
|
ConvertJavaStringToUTF16(env, script));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Secure the Java callback in a scoped object and give ownership of it to the
|
||||||
|
// base::Callback.
|
||||||
|
ScopedJavaGlobalRef<jobject> j_callback;
|
||||||
|
j_callback.Reset(env, callback);
|
||||||
|
RenderFrameHost::JavaScriptResultCallback js_callback =
|
||||||
|
base::Bind(&JavaScriptResultCallback, j_callback);
|
||||||
|
|
||||||
|
web_contents_->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
|
ConvertJavaStringToUTF16(env, script), js_callback);
|
||||||
|
}
|
||||||
|
|
||||||
void WebContentsAndroid::AddMessageToDevToolsConsole(JNIEnv* env,
|
void WebContentsAndroid::AddMessageToDevToolsConsole(JNIEnv* env,
|
||||||
jobject jobj,
|
jobject jobj,
|
||||||
jint level,
|
jint level,
|
||||||
|
@@ -86,6 +86,10 @@ class CONTENT_EXPORT WebContentsAndroid
|
|||||||
jobject obj,
|
jobject obj,
|
||||||
jstring script,
|
jstring script,
|
||||||
jobject callback);
|
jobject callback);
|
||||||
|
void EvaluateJavaScriptForTests(JNIEnv* env,
|
||||||
|
jobject obj,
|
||||||
|
jstring script,
|
||||||
|
jobject callback);
|
||||||
|
|
||||||
void AddMessageToDevToolsConsole(JNIEnv* env,
|
void AddMessageToDevToolsConsole(JNIEnv* env,
|
||||||
jobject jobj,
|
jobject jobj,
|
||||||
|
@@ -293,11 +293,16 @@ import java.util.UUID;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@VisibleForTesting
|
|
||||||
public void evaluateJavaScript(String script, JavaScriptCallback callback) {
|
public void evaluateJavaScript(String script, JavaScriptCallback callback) {
|
||||||
nativeEvaluateJavaScript(mNativeWebContentsAndroid, script, callback);
|
nativeEvaluateJavaScript(mNativeWebContentsAndroid, script, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@VisibleForTesting
|
||||||
|
public void evaluateJavaScriptForTests(String script, JavaScriptCallback callback) {
|
||||||
|
nativeEvaluateJavaScriptForTests(mNativeWebContentsAndroid, script, callback);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addMessageToDevToolsConsole(int level, String message) {
|
public void addMessageToDevToolsConsole(int level, String message) {
|
||||||
nativeAddMessageToDevToolsConsole(mNativeWebContentsAndroid, level, message);
|
nativeAddMessageToDevToolsConsole(mNativeWebContentsAndroid, level, message);
|
||||||
@@ -421,6 +426,8 @@ import java.util.UUID;
|
|||||||
private native void nativeResumeLoadingCreatedWebContents(long nativeWebContentsAndroid);
|
private native void nativeResumeLoadingCreatedWebContents(long nativeWebContentsAndroid);
|
||||||
private native void nativeEvaluateJavaScript(long nativeWebContentsAndroid,
|
private native void nativeEvaluateJavaScript(long nativeWebContentsAndroid,
|
||||||
String script, JavaScriptCallback callback);
|
String script, JavaScriptCallback callback);
|
||||||
|
private native void nativeEvaluateJavaScriptForTests(long nativeWebContentsAndroid,
|
||||||
|
String script, JavaScriptCallback callback);
|
||||||
private native void nativeAddMessageToDevToolsConsole(
|
private native void nativeAddMessageToDevToolsConsole(
|
||||||
long nativeWebContentsAndroid, int level, String message);
|
long nativeWebContentsAndroid, int level, String message);
|
||||||
private native boolean nativeHasAccessedInitialDocument(
|
private native boolean nativeHasAccessedInitialDocument(
|
||||||
|
@@ -214,6 +214,21 @@ public interface WebContents extends Parcelable {
|
|||||||
*/
|
*/
|
||||||
void resumeLoadingCreatedWebContents();
|
void resumeLoadingCreatedWebContents();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injects the passed Javascript code in the current page and evaluates it.
|
||||||
|
* If a result is required, pass in a callback.
|
||||||
|
*
|
||||||
|
* It is not possible to use this method to evaluate JavaScript on web
|
||||||
|
* content, only on WebUI pages.
|
||||||
|
*
|
||||||
|
* @param script The Javascript to execute.
|
||||||
|
* @param callback The callback to be fired off when a result is ready. The script's
|
||||||
|
* result will be json encoded and passed as the parameter, and the call
|
||||||
|
* will be made on the main thread.
|
||||||
|
* If no result is required, pass null.
|
||||||
|
*/
|
||||||
|
void evaluateJavaScript(String script, JavaScriptCallback callback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Injects the passed Javascript code in the current page and evaluates it.
|
* Injects the passed Javascript code in the current page and evaluates it.
|
||||||
* If a result is required, pass in a callback.
|
* If a result is required, pass in a callback.
|
||||||
@@ -225,7 +240,7 @@ public interface WebContents extends Parcelable {
|
|||||||
* If no result is required, pass null.
|
* If no result is required, pass null.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void evaluateJavaScript(String script, JavaScriptCallback callback);
|
void evaluateJavaScriptForTests(String script, JavaScriptCallback callback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a log message to dev tools console. |level| must be a value of
|
* Adds a log message to dev tools console. |level| must be a value of
|
||||||
|
@@ -45,7 +45,7 @@ public class ContentViewLocationTest extends ContentShellTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void pollForPositionCallback() throws Throwable {
|
private void pollForPositionCallback() throws Throwable {
|
||||||
mJavascriptHelper.evaluateJavaScript(getWebContents(),
|
mJavascriptHelper.evaluateJavaScriptForTests(getWebContents(),
|
||||||
"positionCount = 0");
|
"positionCount = 0");
|
||||||
mJavascriptHelper.waitUntilHasValue();
|
mJavascriptHelper.waitUntilHasValue();
|
||||||
assertEquals(0, Integer.parseInt(mJavascriptHelper.getJsonResultAndClear()));
|
assertEquals(0, Integer.parseInt(mJavascriptHelper.getJsonResultAndClear()));
|
||||||
@@ -53,7 +53,7 @@ public class ContentViewLocationTest extends ContentShellTestBase {
|
|||||||
assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
|
assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
|
||||||
@Override
|
@Override
|
||||||
public boolean isSatisfied() {
|
public boolean isSatisfied() {
|
||||||
mJavascriptHelper.evaluateJavaScript(getWebContents(), "positionCount");
|
mJavascriptHelper.evaluateJavaScriptForTests(getWebContents(), "positionCount");
|
||||||
try {
|
try {
|
||||||
mJavascriptHelper.waitUntilHasValue();
|
mJavascriptHelper.waitUntilHasValue();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -65,7 +65,7 @@ public class ContentViewLocationTest extends ContentShellTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void startGeolocationWatchPosition() throws Throwable {
|
private void startGeolocationWatchPosition() throws Throwable {
|
||||||
mJavascriptHelper.evaluateJavaScript(getWebContents(),
|
mJavascriptHelper.evaluateJavaScriptForTests(getWebContents(),
|
||||||
"initiate_watchPosition();");
|
"initiate_watchPosition();");
|
||||||
mJavascriptHelper.waitUntilHasValue();
|
mJavascriptHelper.waitUntilHasValue();
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,7 @@ public class ContentViewLocationTest extends ContentShellTestBase {
|
|||||||
hideContentViewOnUiThread();
|
hideContentViewOnUiThread();
|
||||||
ensureGeolocationRunning(false);
|
ensureGeolocationRunning(false);
|
||||||
|
|
||||||
mJavascriptHelper.evaluateJavaScript(getWebContents(),
|
mJavascriptHelper.evaluateJavaScriptForTests(getWebContents(),
|
||||||
"positionCount = 0");
|
"positionCount = 0");
|
||||||
mJavascriptHelper.waitUntilHasValue();
|
mJavascriptHelper.waitUntilHasValue();
|
||||||
|
|
||||||
|
@@ -40,7 +40,7 @@ public class JavaBridgeBareboneTest extends ContentShellTestBase {
|
|||||||
|
|
||||||
private String evaluateJsSync(String jsCode) throws Exception {
|
private String evaluateJsSync(String jsCode) throws Exception {
|
||||||
OnEvaluateJavaScriptResultHelper javascriptHelper = new OnEvaluateJavaScriptResultHelper();
|
OnEvaluateJavaScriptResultHelper javascriptHelper = new OnEvaluateJavaScriptResultHelper();
|
||||||
javascriptHelper.evaluateJavaScript(getWebContents(), jsCode);
|
javascriptHelper.evaluateJavaScriptForTests(getWebContents(), jsCode);
|
||||||
javascriptHelper.waitUntilHasValue();
|
javascriptHelper.waitUntilHasValue();
|
||||||
return javascriptHelper.getJsonResultAndClear();
|
return javascriptHelper.getJsonResultAndClear();
|
||||||
}
|
}
|
||||||
|
@@ -257,7 +257,7 @@ public class JavaBridgeChildFrameTest extends JavaBridgeTestBase {
|
|||||||
runTestOnUiThread(new Runnable() {
|
runTestOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
webContents.evaluateJavaScript(script, resultCallback);
|
webContents.evaluateJavaScriptForTests(script, resultCallback);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
resultCallback.waitForResult();
|
resultCallback.waitForResult();
|
||||||
|
@@ -118,7 +118,8 @@ public class NavigationTest extends ContentShellTestBase {
|
|||||||
OnEvaluateJavaScriptResultHelper javascriptHelper = new OnEvaluateJavaScriptResultHelper();
|
OnEvaluateJavaScriptResultHelper javascriptHelper = new OnEvaluateJavaScriptResultHelper();
|
||||||
|
|
||||||
// Grab the first timestamp.
|
// Grab the first timestamp.
|
||||||
javascriptHelper.evaluateJavaScript(contentViewCore.getWebContents(), "getLoadtime();");
|
javascriptHelper.evaluateJavaScriptForTests(
|
||||||
|
contentViewCore.getWebContents(), "getLoadtime();");
|
||||||
javascriptHelper.waitUntilHasValue();
|
javascriptHelper.waitUntilHasValue();
|
||||||
String firstTimestamp = javascriptHelper.getJsonResultAndClear();
|
String firstTimestamp = javascriptHelper.getJsonResultAndClear();
|
||||||
assertNotNull("Timestamp was null.", firstTimestamp);
|
assertNotNull("Timestamp was null.", firstTimestamp);
|
||||||
@@ -126,7 +127,8 @@ public class NavigationTest extends ContentShellTestBase {
|
|||||||
// Grab the timestamp after a reload and make sure they don't match.
|
// Grab the timestamp after a reload and make sure they don't match.
|
||||||
reload(contentViewCore.getWebContents().getNavigationController(),
|
reload(contentViewCore.getWebContents().getNavigationController(),
|
||||||
testCallbackHelperContainer);
|
testCallbackHelperContainer);
|
||||||
javascriptHelper.evaluateJavaScript(contentViewCore.getWebContents(), "getLoadtime();");
|
javascriptHelper.evaluateJavaScriptForTests(
|
||||||
|
contentViewCore.getWebContents(), "getLoadtime();");
|
||||||
javascriptHelper.waitUntilHasValue();
|
javascriptHelper.waitUntilHasValue();
|
||||||
String secondTimestamp = javascriptHelper.getJsonResultAndClear();
|
String secondTimestamp = javascriptHelper.getJsonResultAndClear();
|
||||||
assertNotNull("Timestamp was null.", secondTimestamp);
|
assertNotNull("Timestamp was null.", secondTimestamp);
|
||||||
|
@@ -39,7 +39,7 @@ public class TestsJavaScriptEvalTest extends ContentShellTestBase {
|
|||||||
for (int i = 0; i < 30; ++i) {
|
for (int i = 0; i < 30; ++i) {
|
||||||
for (int j = 0; j < 10; ++j) {
|
for (int j = 0; j < 10; ++j) {
|
||||||
// Start evaluation of a JavaScript script -- we don't need a result.
|
// Start evaluation of a JavaScript script -- we don't need a result.
|
||||||
webContents.evaluateJavaScript("foobar();", null);
|
webContents.evaluateJavaScriptForTests("foobar();", null);
|
||||||
}
|
}
|
||||||
// DOMUtils does need to evaluate a JavaScript and get its result to get DOM bounds.
|
// DOMUtils does need to evaluate a JavaScript and get its result to get DOM bounds.
|
||||||
assertNotNull("Failed to get bounds",
|
assertNotNull("Failed to get bounds",
|
||||||
|
@@ -35,6 +35,11 @@ class CONTENT_EXPORT RenderFrameHost : public IPC::Listener,
|
|||||||
// Returns nullptr if the IDs do not correspond to a live RenderFrameHost.
|
// Returns nullptr if the IDs do not correspond to a live RenderFrameHost.
|
||||||
static RenderFrameHost* FromID(int render_process_id, int render_frame_id);
|
static RenderFrameHost* FromID(int render_process_id, int render_frame_id);
|
||||||
|
|
||||||
|
// Globally allows for injecting JavaScript into the main world. This feature
|
||||||
|
// is present only to support Android WebView and must not be used in other
|
||||||
|
// configurations.
|
||||||
|
static void AllowInjectingJavaScriptForAndroidWebView();
|
||||||
|
|
||||||
~RenderFrameHost() override {}
|
~RenderFrameHost() override {}
|
||||||
|
|
||||||
// Returns the route id for this frame.
|
// Returns the route id for this frame.
|
||||||
@@ -74,17 +79,24 @@ class CONTENT_EXPORT RenderFrameHost : public IPC::Listener,
|
|||||||
|
|
||||||
// Runs some JavaScript in this frame's context. If a callback is provided, it
|
// Runs some JavaScript in this frame's context. If a callback is provided, it
|
||||||
// will be used to return the result, when the result is available.
|
// will be used to return the result, when the result is available.
|
||||||
|
// This API can only be called on chrome:// or chrome-devtools:// URLs.
|
||||||
typedef base::Callback<void(const base::Value*)> JavaScriptResultCallback;
|
typedef base::Callback<void(const base::Value*)> JavaScriptResultCallback;
|
||||||
virtual void ExecuteJavaScript(const base::string16& javascript) = 0;
|
virtual void ExecuteJavaScript(const base::string16& javascript) = 0;
|
||||||
virtual void ExecuteJavaScript(const base::string16& javascript,
|
virtual void ExecuteJavaScript(const base::string16& javascript,
|
||||||
const JavaScriptResultCallback& callback) = 0;
|
const JavaScriptResultCallback& callback) = 0;
|
||||||
|
|
||||||
|
// Runs some JavaScript in an isolated world of top of this frame's context.
|
||||||
virtual void ExecuteJavaScriptInIsolatedWorld(
|
virtual void ExecuteJavaScriptInIsolatedWorld(
|
||||||
const base::string16& javascript,
|
const base::string16& javascript,
|
||||||
const JavaScriptResultCallback& callback,
|
const JavaScriptResultCallback& callback,
|
||||||
int world_id) = 0;
|
int world_id) = 0;
|
||||||
|
|
||||||
// ONLY FOR TESTS: Same as above but adds a fake UserGestureIndicator around
|
// ONLY FOR TESTS: Same as above but without restrictions. Optionally, adds a
|
||||||
// execution. (crbug.com/408426)
|
// fake UserGestureIndicator around execution. (crbug.com/408426)
|
||||||
|
virtual void ExecuteJavaScriptForTests(const base::string16& javascript) = 0;
|
||||||
|
virtual void ExecuteJavaScriptForTests(
|
||||||
|
const base::string16& javascript,
|
||||||
|
const JavaScriptResultCallback& callback) = 0;
|
||||||
virtual void ExecuteJavaScriptWithUserGestureForTests(
|
virtual void ExecuteJavaScriptWithUserGestureForTests(
|
||||||
const base::string16& javascript) = 0;
|
const base::string16& javascript) = 0;
|
||||||
|
|
||||||
|
@@ -50,7 +50,7 @@ public class JavaScriptUtils {
|
|||||||
ThreadUtils.runOnUiThread(new Runnable() {
|
ThreadUtils.runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
helper.evaluateJavaScript(webContents, code);
|
helper.evaluateJavaScriptForTests(webContents, code);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
helper.waitUntilHasValue(timeout, timeoutUnits);
|
helper.waitUntilHasValue(timeout, timeoutUnits);
|
||||||
@@ -65,7 +65,7 @@ public class JavaScriptUtils {
|
|||||||
ThreadUtils.runOnUiThread(new Runnable() {
|
ThreadUtils.runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
webContents.evaluateJavaScript(code, null);
|
webContents.evaluateJavaScriptForTests(code, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -126,7 +126,7 @@ public class TestCallbackHelperContainer {
|
|||||||
* @param webContents A WebContents instance to be used.
|
* @param webContents A WebContents instance to be used.
|
||||||
* @param code A JavaScript code to be evaluated.
|
* @param code A JavaScript code to be evaluated.
|
||||||
*/
|
*/
|
||||||
public void evaluateJavaScript(WebContents webContents, String code) {
|
public void evaluateJavaScriptForTests(WebContents webContents, String code) {
|
||||||
JavaScriptCallback callback =
|
JavaScriptCallback callback =
|
||||||
new JavaScriptCallback() {
|
new JavaScriptCallback() {
|
||||||
@Override
|
@Override
|
||||||
@@ -134,12 +134,12 @@ public class TestCallbackHelperContainer {
|
|||||||
notifyCalled(jsonResult);
|
notifyCalled(jsonResult);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
webContents.evaluateJavaScript(code, callback);
|
webContents.evaluateJavaScriptForTests(code, callback);
|
||||||
mJsonResult = null;
|
mJsonResult = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the evaluation started by evaluateJavaScript() has completed.
|
* Returns true if the evaluation started by evaluateJavaScriptForTests() has completed.
|
||||||
*/
|
*/
|
||||||
public boolean hasValue() {
|
public boolean hasValue() {
|
||||||
return mJsonResult != null;
|
return mJsonResult != null;
|
||||||
|
@@ -145,7 +145,7 @@ WebLocalFrame* RenderViewTest::GetMainFrame() {
|
|||||||
return view_->GetWebView()->mainFrame()->toWebLocalFrame();
|
return view_->GetWebView()->mainFrame()->toWebLocalFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderViewTest::ExecuteJavaScript(const char* js) {
|
void RenderViewTest::ExecuteJavaScriptForTests(const char* js) {
|
||||||
GetMainFrame()->executeScript(WebScriptSource(WebString::fromUTF8(js)));
|
GetMainFrame()->executeScript(WebScriptSource(WebString::fromUTF8(js)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -73,7 +73,7 @@ class RenderViewTest : public testing::Test {
|
|||||||
|
|
||||||
// Executes the given JavaScript in the context of the main frame. The input
|
// Executes the given JavaScript in the context of the main frame. The input
|
||||||
// is a NULL-terminated UTF-8 string.
|
// is a NULL-terminated UTF-8 string.
|
||||||
void ExecuteJavaScript(const char* js);
|
void ExecuteJavaScriptForTests(const char* js);
|
||||||
|
|
||||||
// Executes the given JavaScript and sets the int value it evaluates to in
|
// Executes the given JavaScript and sets the int value it evaluates to in
|
||||||
// |result|.
|
// |result|.
|
||||||
|
@@ -175,7 +175,7 @@ scoped_ptr<base::Value> ExecuteScriptAndGetValue(
|
|||||||
RenderFrameHost* render_frame_host, const std::string& script) {
|
RenderFrameHost* render_frame_host, const std::string& script) {
|
||||||
ScriptCallback observer;
|
ScriptCallback observer;
|
||||||
|
|
||||||
render_frame_host->ExecuteJavaScript(
|
render_frame_host->ExecuteJavaScriptForTests(
|
||||||
base::UTF8ToUTF16(script),
|
base::UTF8ToUTF16(script),
|
||||||
base::Bind(&ScriptCallback::ResultCallback, base::Unretained(&observer)));
|
base::Bind(&ScriptCallback::ResultCallback, base::Unretained(&observer)));
|
||||||
base::MessageLoop* loop = base::MessageLoop::current();
|
base::MessageLoop* loop = base::MessageLoop::current();
|
||||||
|
@@ -248,10 +248,10 @@ TEST_F(RendererAccessibilityTest, HideAccessibilityObject) {
|
|||||||
WebAXObject node_c = node_b.childAt(0);
|
WebAXObject node_c = node_b.childAt(0);
|
||||||
|
|
||||||
// Hide node 'B' ('C' stays visible).
|
// Hide node 'B' ('C' stays visible).
|
||||||
ExecuteJavaScript(
|
ExecuteJavaScriptForTests(
|
||||||
"document.getElementById('B').style.visibility = 'hidden';");
|
"document.getElementById('B').style.visibility = 'hidden';");
|
||||||
// Force layout now.
|
// Force layout now.
|
||||||
ExecuteJavaScript("document.getElementById('B').offsetLeft;");
|
ExecuteJavaScriptForTests("document.getElementById('B').offsetLeft;");
|
||||||
|
|
||||||
// Send a childrenChanged on 'A'.
|
// Send a childrenChanged on 'A'.
|
||||||
sink_->ClearMessages();
|
sink_->ClearMessages();
|
||||||
@@ -294,9 +294,9 @@ TEST_F(RendererAccessibilityTest, ShowAccessibilityObject) {
|
|||||||
EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser());
|
EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser());
|
||||||
|
|
||||||
// Show node 'B', then send a childrenChanged on 'A'.
|
// Show node 'B', then send a childrenChanged on 'A'.
|
||||||
ExecuteJavaScript(
|
ExecuteJavaScriptForTests(
|
||||||
"document.getElementById('B').style.visibility = 'visible';");
|
"document.getElementById('B').style.visibility = 'visible';");
|
||||||
ExecuteJavaScript("document.getElementById('B').offsetLeft;");
|
ExecuteJavaScriptForTests("document.getElementById('B').offsetLeft;");
|
||||||
|
|
||||||
sink_->ClearMessages();
|
sink_->ClearMessages();
|
||||||
WebDocument document = view()->GetWebView()->mainFrame()->document();
|
WebDocument document = view()->GetWebView()->mainFrame()->document();
|
||||||
@@ -355,10 +355,10 @@ TEST_F(RendererAccessibilityTest, DetachAccessibilityObject) {
|
|||||||
|
|
||||||
// Change the display of the second 'span' back to inline, which causes the
|
// Change the display of the second 'span' back to inline, which causes the
|
||||||
// anonymous block to be destroyed.
|
// anonymous block to be destroyed.
|
||||||
ExecuteJavaScript(
|
ExecuteJavaScriptForTests(
|
||||||
"document.querySelectorAll('span')[1].style.display = 'inline';");
|
"document.querySelectorAll('span')[1].style.display = 'inline';");
|
||||||
// Force layout now.
|
// Force layout now.
|
||||||
ExecuteJavaScript("document.body.offsetLeft;");
|
ExecuteJavaScriptForTests("document.body.offsetLeft;");
|
||||||
|
|
||||||
// Send a childrenChanged on the body.
|
// Send a childrenChanged on the body.
|
||||||
sink_->ClearMessages();
|
sink_->ClearMessages();
|
||||||
|
@@ -30,7 +30,7 @@ class V8SamplingProfilerTest : public RenderViewTest {
|
|||||||
RenderViewTest::TearDown();
|
RenderViewTest::TearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KickV8() { ExecuteJavaScript("1"); }
|
void KickV8() { ExecuteJavaScriptForTests("1"); }
|
||||||
|
|
||||||
void SyncFlush(TraceLog* trace_log) {
|
void SyncFlush(TraceLog* trace_log) {
|
||||||
base::WaitableEvent flush_complete_event(false, false);
|
base::WaitableEvent flush_complete_event(false, false);
|
||||||
|
@@ -427,7 +427,8 @@ TEST_F(RenderViewImplTest, DISABLED_OnNavStateChanged) {
|
|||||||
|
|
||||||
// Change the value of the input. We should have gotten an update state
|
// Change the value of the input. We should have gotten an update state
|
||||||
// notification. We need to spin the message loop to catch this update.
|
// notification. We need to spin the message loop to catch this update.
|
||||||
ExecuteJavaScript("document.getElementById('elt_text').value = 'foo';");
|
ExecuteJavaScriptForTests(
|
||||||
|
"document.getElementById('elt_text').value = 'foo';");
|
||||||
ProcessPendingMessages();
|
ProcessPendingMessages();
|
||||||
EXPECT_TRUE(render_thread_->sink().GetUniqueMessageMatching(
|
EXPECT_TRUE(render_thread_->sink().GetUniqueMessageMatching(
|
||||||
ViewHostMsg_UpdateState::ID));
|
ViewHostMsg_UpdateState::ID));
|
||||||
@@ -963,7 +964,7 @@ TEST_F(RenderViewImplTest, OnImeTypeChanged) {
|
|||||||
for (int i = 0; i < kRepeatCount; i++) {
|
for (int i = 0; i < kRepeatCount; i++) {
|
||||||
// Move the input focus to the first <input> element, where we should
|
// Move the input focus to the first <input> element, where we should
|
||||||
// activate IMEs.
|
// activate IMEs.
|
||||||
ExecuteJavaScript("document.getElementById('test1').focus();");
|
ExecuteJavaScriptForTests("document.getElementById('test1').focus();");
|
||||||
ProcessPendingMessages();
|
ProcessPendingMessages();
|
||||||
render_thread_->sink().ClearMessages();
|
render_thread_->sink().ClearMessages();
|
||||||
|
|
||||||
@@ -983,7 +984,7 @@ TEST_F(RenderViewImplTest, OnImeTypeChanged) {
|
|||||||
|
|
||||||
// Move the input focus to the second <input> element, where we should
|
// Move the input focus to the second <input> element, where we should
|
||||||
// de-activate IMEs.
|
// de-activate IMEs.
|
||||||
ExecuteJavaScript("document.getElementById('test2').focus();");
|
ExecuteJavaScriptForTests("document.getElementById('test2').focus();");
|
||||||
ProcessPendingMessages();
|
ProcessPendingMessages();
|
||||||
render_thread_->sink().ClearMessages();
|
render_thread_->sink().ClearMessages();
|
||||||
|
|
||||||
@@ -1033,7 +1034,7 @@ TEST_F(RenderViewImplTest, OnImeTypeChanged) {
|
|||||||
// the window focus while composing a CJK text. To handle such complicated
|
// the window focus while composing a CJK text. To handle such complicated
|
||||||
// cases, this test should not only call IME-related functions in the
|
// cases, this test should not only call IME-related functions in the
|
||||||
// RenderWidget class, but also call some RenderWidget members, e.g.
|
// RenderWidget class, but also call some RenderWidget members, e.g.
|
||||||
// ExecuteJavaScript(), RenderWidget::OnSetFocus(), etc.
|
// ExecuteJavaScriptForTests(), RenderWidget::OnSetFocus(), etc.
|
||||||
TEST_F(RenderViewImplTest, ImeComposition) {
|
TEST_F(RenderViewImplTest, ImeComposition) {
|
||||||
enum ImeCommand {
|
enum ImeCommand {
|
||||||
IME_INITIALIZE,
|
IME_INITIALIZE,
|
||||||
@@ -1108,7 +1109,7 @@ TEST_F(RenderViewImplTest, ImeComposition) {
|
|||||||
"<div id=\"test1\" contenteditable=\"true\"></div>"
|
"<div id=\"test1\" contenteditable=\"true\"></div>"
|
||||||
"</body>"
|
"</body>"
|
||||||
"</html>");
|
"</html>");
|
||||||
ExecuteJavaScript("document.getElementById('test1').focus();");
|
ExecuteJavaScriptForTests("document.getElementById('test1').focus();");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IME_SETINPUTMODE:
|
case IME_SETINPUTMODE:
|
||||||
@@ -1186,17 +1187,18 @@ TEST_F(RenderViewImplTest, OnSetTextDirection) {
|
|||||||
};
|
};
|
||||||
for (size_t i = 0; i < arraysize(kTextDirection); ++i) {
|
for (size_t i = 0; i < arraysize(kTextDirection); ++i) {
|
||||||
// Set the text direction of the <textarea> element.
|
// Set the text direction of the <textarea> element.
|
||||||
ExecuteJavaScript("document.getElementById('test').focus();");
|
ExecuteJavaScriptForTests("document.getElementById('test').focus();");
|
||||||
view()->OnSetTextDirection(kTextDirection[i].direction);
|
view()->OnSetTextDirection(kTextDirection[i].direction);
|
||||||
|
|
||||||
// Write the values of its DOM 'dir' attribute and its CSS 'direction'
|
// Write the values of its DOM 'dir' attribute and its CSS 'direction'
|
||||||
// property to the <div> element.
|
// property to the <div> element.
|
||||||
ExecuteJavaScript("var result = document.getElementById('result');"
|
ExecuteJavaScriptForTests(
|
||||||
"var node = document.getElementById('test');"
|
"var result = document.getElementById('result');"
|
||||||
"var style = getComputedStyle(node, null);"
|
"var node = document.getElementById('test');"
|
||||||
"result.innerText ="
|
"var style = getComputedStyle(node, null);"
|
||||||
" node.getAttribute('dir') + ',' +"
|
"result.innerText ="
|
||||||
" style.getPropertyValue('direction');");
|
" node.getAttribute('dir') + ',' +"
|
||||||
|
" style.getPropertyValue('direction');");
|
||||||
|
|
||||||
// Copy the document content to std::wstring and compare with the
|
// Copy the document content to std::wstring and compare with the
|
||||||
// expected result.
|
// expected result.
|
||||||
@@ -1248,7 +1250,7 @@ TEST_F(RenderViewImplTest, OnHandleKeyboardEvent) {
|
|||||||
"</div>"
|
"</div>"
|
||||||
"</body>"
|
"</body>"
|
||||||
"</html>");
|
"</html>");
|
||||||
ExecuteJavaScript("document.getElementById('test').focus();");
|
ExecuteJavaScriptForTests("document.getElementById('test').focus();");
|
||||||
render_thread_->sink().ClearMessages();
|
render_thread_->sink().ClearMessages();
|
||||||
|
|
||||||
static const MockKeyboard::Layout kLayouts[] = {
|
static const MockKeyboard::Layout kLayouts[] = {
|
||||||
@@ -1515,7 +1517,7 @@ TEST_F(RenderViewImplTest, MAYBE_InsertCharacters) {
|
|||||||
"</div>"
|
"</div>"
|
||||||
"</body>"
|
"</body>"
|
||||||
"</html>");
|
"</html>");
|
||||||
ExecuteJavaScript("document.getElementById('test').focus();");
|
ExecuteJavaScriptForTests("document.getElementById('test').focus();");
|
||||||
render_thread_->sink().ClearMessages();
|
render_thread_->sink().ClearMessages();
|
||||||
|
|
||||||
// For each key code, we send three keyboard events.
|
// For each key code, we send three keyboard events.
|
||||||
@@ -1741,7 +1743,7 @@ TEST_F(RenderViewImplTest, GetCompositionCharacterBoundsTest) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
LoadHTML("<textarea id=\"test\"></textarea>");
|
LoadHTML("<textarea id=\"test\"></textarea>");
|
||||||
ExecuteJavaScript("document.getElementById('test').focus();");
|
ExecuteJavaScriptForTests("document.getElementById('test').focus();");
|
||||||
|
|
||||||
const base::string16 empty_string;
|
const base::string16 empty_string;
|
||||||
const std::vector<blink::WebCompositionUnderline> empty_underline;
|
const std::vector<blink::WebCompositionUnderline> empty_underline;
|
||||||
@@ -1843,7 +1845,7 @@ TEST_F(RenderViewImplTest, SetEditableSelectionAndComposition) {
|
|||||||
"<input id=\"test1\" value=\"some test text hello\"></input>"
|
"<input id=\"test1\" value=\"some test text hello\"></input>"
|
||||||
"</body>"
|
"</body>"
|
||||||
"</html>");
|
"</html>");
|
||||||
ExecuteJavaScript("document.getElementById('test1').focus();");
|
ExecuteJavaScriptForTests("document.getElementById('test1').focus();");
|
||||||
frame()->SetEditableSelectionOffsets(4, 8);
|
frame()->SetEditableSelectionOffsets(4, 8);
|
||||||
const std::vector<blink::WebCompositionUnderline> empty_underline;
|
const std::vector<blink::WebCompositionUnderline> empty_underline;
|
||||||
frame()->SetCompositionFromExistingText(7, 10, empty_underline);
|
frame()->SetCompositionFromExistingText(7, 10, empty_underline);
|
||||||
@@ -1868,7 +1870,7 @@ TEST_F(RenderViewImplTest, OnExtendSelectionAndDelete) {
|
|||||||
"<input id=\"test1\" value=\"abcdefghijklmnopqrstuvwxyz\"></input>"
|
"<input id=\"test1\" value=\"abcdefghijklmnopqrstuvwxyz\"></input>"
|
||||||
"</body>"
|
"</body>"
|
||||||
"</html>");
|
"</html>");
|
||||||
ExecuteJavaScript("document.getElementById('test1').focus();");
|
ExecuteJavaScriptForTests("document.getElementById('test1').focus();");
|
||||||
frame()->SetEditableSelectionOffsets(10, 10);
|
frame()->SetEditableSelectionOffsets(10, 10);
|
||||||
frame()->ExtendSelectionAndDelete(3, 4);
|
frame()->ExtendSelectionAndDelete(3, 4);
|
||||||
blink::WebTextInputInfo info = view()->webview()->textInputInfo();
|
blink::WebTextInputInfo info = view()->webview()->textInputInfo();
|
||||||
@@ -1941,7 +1943,7 @@ TEST_F(RenderViewImplTest, MessageOrderInDidChangeSelection) {
|
|||||||
LoadHTML("<textarea id=\"test\"></textarea>");
|
LoadHTML("<textarea id=\"test\"></textarea>");
|
||||||
|
|
||||||
view()->handling_input_event_ = true;
|
view()->handling_input_event_ = true;
|
||||||
ExecuteJavaScript("document.getElementById('test').focus();");
|
ExecuteJavaScriptForTests("document.getElementById('test').focus();");
|
||||||
|
|
||||||
bool is_input_type_called = false;
|
bool is_input_type_called = false;
|
||||||
bool is_selection_called = false;
|
bool is_selection_called = false;
|
||||||
@@ -2129,7 +2131,7 @@ TEST_F(RenderViewImplTest, FocusElementCallsFocusedNodeChanged) {
|
|||||||
LoadHTML("<input id='test1' value='hello1'></input>"
|
LoadHTML("<input id='test1' value='hello1'></input>"
|
||||||
"<input id='test2' value='hello2'></input>");
|
"<input id='test2' value='hello2'></input>");
|
||||||
|
|
||||||
ExecuteJavaScript("document.getElementById('test1').focus();");
|
ExecuteJavaScriptForTests("document.getElementById('test1').focus();");
|
||||||
const IPC::Message* msg1 = render_thread_->sink().GetFirstMessageMatching(
|
const IPC::Message* msg1 = render_thread_->sink().GetFirstMessageMatching(
|
||||||
ViewHostMsg_FocusedNodeChanged::ID);
|
ViewHostMsg_FocusedNodeChanged::ID);
|
||||||
EXPECT_TRUE(msg1);
|
EXPECT_TRUE(msg1);
|
||||||
@@ -2139,7 +2141,7 @@ TEST_F(RenderViewImplTest, FocusElementCallsFocusedNodeChanged) {
|
|||||||
EXPECT_TRUE(base::get<0>(params));
|
EXPECT_TRUE(base::get<0>(params));
|
||||||
render_thread_->sink().ClearMessages();
|
render_thread_->sink().ClearMessages();
|
||||||
|
|
||||||
ExecuteJavaScript("document.getElementById('test2').focus();");
|
ExecuteJavaScriptForTests("document.getElementById('test2').focus();");
|
||||||
const IPC::Message* msg2 = render_thread_->sink().GetFirstMessageMatching(
|
const IPC::Message* msg2 = render_thread_->sink().GetFirstMessageMatching(
|
||||||
ViewHostMsg_FocusedNodeChanged::ID);
|
ViewHostMsg_FocusedNodeChanged::ID);
|
||||||
EXPECT_TRUE(msg2);
|
EXPECT_TRUE(msg2);
|
||||||
@@ -2354,7 +2356,7 @@ TEST_F(DevToolsAgentTest, DevToolsResumeOnClose) {
|
|||||||
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
||||||
FROM_HERE,
|
FROM_HERE,
|
||||||
base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this)));
|
base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this)));
|
||||||
ExecuteJavaScript("debugger;");
|
ExecuteJavaScriptForTests("debugger;");
|
||||||
|
|
||||||
// CloseWhilePaused should resume execution and continue here.
|
// CloseWhilePaused should resume execution and continue here.
|
||||||
EXPECT_FALSE(IsPaused());
|
EXPECT_FALSE(IsPaused());
|
||||||
|
@@ -103,7 +103,7 @@ TEST_F(RenderViewTest, MacTestCmdUp) {
|
|||||||
EditCommands(1, EditCommand("moveToEndOfDocument", "")));
|
EditCommands(1, EditCommand("moveToEndOfDocument", "")));
|
||||||
SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown));
|
SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown));
|
||||||
ProcessPendingMessages();
|
ProcessPendingMessages();
|
||||||
ExecuteJavaScript("scroll.textContent = window.pageYOffset");
|
ExecuteJavaScriptForTests("scroll.textContent = window.pageYOffset");
|
||||||
output = GetMainFrame()->contentAsText(kMaxOutputCharacters);
|
output = GetMainFrame()->contentAsText(kMaxOutputCharacters);
|
||||||
EXPECT_EQ(kArrowDownScrollDown, base::UTF16ToASCII(output));
|
EXPECT_EQ(kArrowDownScrollDown, base::UTF16ToASCII(output));
|
||||||
|
|
||||||
@@ -112,21 +112,21 @@ TEST_F(RenderViewTest, MacTestCmdUp) {
|
|||||||
EditCommands(1, EditCommand("moveToBeginningOfDocument", "")));
|
EditCommands(1, EditCommand("moveToBeginningOfDocument", "")));
|
||||||
SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown));
|
SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown));
|
||||||
ProcessPendingMessages();
|
ProcessPendingMessages();
|
||||||
ExecuteJavaScript("scroll.textContent = window.pageYOffset");
|
ExecuteJavaScriptForTests("scroll.textContent = window.pageYOffset");
|
||||||
output = GetMainFrame()->contentAsText(kMaxOutputCharacters);
|
output = GetMainFrame()->contentAsText(kMaxOutputCharacters);
|
||||||
EXPECT_EQ(kArrowUpScrollUp, base::UTF16ToASCII(output));
|
EXPECT_EQ(kArrowUpScrollUp, base::UTF16ToASCII(output));
|
||||||
|
|
||||||
// Now let javascript eat the key events -- no scrolling should happen.
|
// Now let javascript eat the key events -- no scrolling should happen.
|
||||||
// Set a scroll position slightly down the page to ensure that it does not
|
// Set a scroll position slightly down the page to ensure that it does not
|
||||||
// move.
|
// move.
|
||||||
ExecuteJavaScript("allowKeyEvents = false; window.scrollTo(0, 100)");
|
ExecuteJavaScriptForTests("allowKeyEvents = false; window.scrollTo(0, 100)");
|
||||||
|
|
||||||
const char* kArrowDownNoScroll = "40,false,false,true,false\n100\np1";
|
const char* kArrowDownNoScroll = "40,false,false,true,false\n100\np1";
|
||||||
view->OnSetEditCommandsForNextKeyEvent(
|
view->OnSetEditCommandsForNextKeyEvent(
|
||||||
EditCommands(1, EditCommand("moveToEndOfDocument", "")));
|
EditCommands(1, EditCommand("moveToEndOfDocument", "")));
|
||||||
SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown));
|
SendNativeKeyEvent(NativeWebKeyboardEvent(arrowDownKeyDown));
|
||||||
ProcessPendingMessages();
|
ProcessPendingMessages();
|
||||||
ExecuteJavaScript("scroll.textContent = window.pageYOffset");
|
ExecuteJavaScriptForTests("scroll.textContent = window.pageYOffset");
|
||||||
output = GetMainFrame()->contentAsText(kMaxOutputCharacters);
|
output = GetMainFrame()->contentAsText(kMaxOutputCharacters);
|
||||||
EXPECT_EQ(kArrowDownNoScroll, base::UTF16ToASCII(output));
|
EXPECT_EQ(kArrowDownNoScroll, base::UTF16ToASCII(output));
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ TEST_F(RenderViewTest, MacTestCmdUp) {
|
|||||||
EditCommands(1, EditCommand("moveToBeginningOfDocument", "")));
|
EditCommands(1, EditCommand("moveToBeginningOfDocument", "")));
|
||||||
SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown));
|
SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown));
|
||||||
ProcessPendingMessages();
|
ProcessPendingMessages();
|
||||||
ExecuteJavaScript("scroll.textContent = window.pageYOffset");
|
ExecuteJavaScriptForTests("scroll.textContent = window.pageYOffset");
|
||||||
output = GetMainFrame()->contentAsText(kMaxOutputCharacters);
|
output = GetMainFrame()->contentAsText(kMaxOutputCharacters);
|
||||||
EXPECT_EQ(kArrowUpNoScroll, base::UTF16ToASCII(output));
|
EXPECT_EQ(kArrowUpNoScroll, base::UTF16ToASCII(output));
|
||||||
}
|
}
|
||||||
|
@@ -194,7 +194,7 @@ void ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend(
|
|||||||
params->GetSize() == 1 && params->GetString(0, &browser_message)) {
|
params->GetSize() == 1 && params->GetString(0, &browser_message)) {
|
||||||
agent_host_->DispatchProtocolMessage(browser_message);
|
agent_host_->DispatchProtocolMessage(browser_message);
|
||||||
} else if (method == "loadCompleted") {
|
} else if (method == "loadCompleted") {
|
||||||
web_contents()->GetMainFrame()->ExecuteJavaScript(
|
web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
base::ASCIIToUTF16("DevToolsAPI.setUseSoftMenu(true);"));
|
base::ASCIIToUTF16("DevToolsAPI.setUseSoftMenu(true);"));
|
||||||
} else if (method == "loadNetworkResource" && params->GetSize() == 3) {
|
} else if (method == "loadNetworkResource" && params->GetSize() == 3) {
|
||||||
// TODO(pfeldman): handle some of the embedder messages in content.
|
// TODO(pfeldman): handle some of the embedder messages in content.
|
||||||
@@ -261,7 +261,7 @@ void ShellDevToolsFrontend::DispatchProtocolMessage(
|
|||||||
if (message.length() < kMaxMessageChunkSize) {
|
if (message.length() < kMaxMessageChunkSize) {
|
||||||
base::string16 javascript = base::UTF8ToUTF16(
|
base::string16 javascript = base::UTF8ToUTF16(
|
||||||
"DevToolsAPI.dispatchMessage(" + message + ");");
|
"DevToolsAPI.dispatchMessage(" + message + ");");
|
||||||
web_contents()->GetMainFrame()->ExecuteJavaScript(javascript);
|
web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(javascript);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,7 +272,7 @@ void ShellDevToolsFrontend::DispatchProtocolMessage(
|
|||||||
base::StringValue(message.substr(pos, kMaxMessageChunkSize)), ¶m);
|
base::StringValue(message.substr(pos, kMaxMessageChunkSize)), ¶m);
|
||||||
std::string code = "DevToolsAPI.dispatchMessageChunk(" + param + ");";
|
std::string code = "DevToolsAPI.dispatchMessageChunk(" + param + ");";
|
||||||
base::string16 javascript = base::UTF8ToUTF16(code);
|
base::string16 javascript = base::UTF8ToUTF16(code);
|
||||||
web_contents()->GetMainFrame()->ExecuteJavaScript(javascript);
|
web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(javascript);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,7 +320,7 @@ void ShellDevToolsFrontend::CallClientFunction(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
javascript.append(");");
|
javascript.append(");");
|
||||||
web_contents()->GetMainFrame()->ExecuteJavaScript(
|
web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
base::UTF8ToUTF16(javascript));
|
base::UTF8ToUTF16(javascript));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -58,7 +58,8 @@ class SystemStorageEjectApiTest : public extensions::ShellApiTest {
|
|||||||
const std::string& js_command,
|
const std::string& js_command,
|
||||||
const std::string& ok_message) {
|
const std::string& ok_message) {
|
||||||
ExtensionTestMessageListener listener(ok_message, false);
|
ExtensionTestMessageListener listener(ok_message, false);
|
||||||
host->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16(js_command));
|
host->GetMainFrame()->ExecuteJavaScriptForTests(
|
||||||
|
base::ASCIIToUTF16(js_command));
|
||||||
EXPECT_TRUE(listener.WaitUntilSatisfied());
|
EXPECT_TRUE(listener.WaitUntilSatisfied());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user