diff --git a/chrome/browser/content_settings/content_settings_browsertest.cc b/chrome/browser/content_settings/content_settings_browsertest.cc index 4f07fce91a8c0..899babe4fc1f0 100644 --- a/chrome/browser/content_settings/content_settings_browsertest.cc +++ b/chrome/browser/content_settings/content_settings_browsertest.cc @@ -310,7 +310,7 @@ class CookieSettingsTest // Read a cookie with JavaScript cookie-store API std::string JSAsyncReadCookie(Browser* browser) { - return content::EvalJsWithManualReply( + return content::EvalJs( browser->tab_strip_model()->GetActiveWebContents(), "async function doGet() {" " const cookies = await window.cookieStore.getAll();" @@ -319,7 +319,8 @@ class CookieSettingsTest " cookie_str += `${cookie.name}=${cookie.value};`;" " window.domAutomationController.send(cookie_str);" "}" - "doGet()") + "doGet()", + content::EXECUTE_SCRIPT_USE_MANUAL_REPLY) .ExtractString(); } @@ -343,17 +344,18 @@ class CookieSettingsTest // Set a cookie with JavaScript cookie-store api. void JSAsyncWriteCookie(Browser* browser) { - content::EvalJsResult result = content::EvalJsWithManualReply( - browser->tab_strip_model()->GetActiveWebContents(), - "async function doSet() {" - " await window.cookieStore.set(" - " { name: 'name'," - " value: 'Good'," - " expires: Date.now() + 3600*1000," - " sameSite: 'none' });" - " window.domAutomationController.send(true);" - "}" - "doSet()"); + content::EvalJsResult result = + content::EvalJs(browser->tab_strip_model()->GetActiveWebContents(), + "async function doSet() {" + " await window.cookieStore.set(" + " { name: 'name'," + " value: 'Good'," + " expires: Date.now() + 3600*1000," + " sameSite: 'none' });" + " window.domAutomationController.send(true);" + "}" + "doSet()", + content::EXECUTE_SCRIPT_USE_MANUAL_REPLY); // Failure ignored here since some tests purposefully try to set disallowed // cookies. } diff --git a/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc b/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc index 2afb073c2d02d..30c06cdf07214 100644 --- a/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc +++ b/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc @@ -368,10 +368,9 @@ IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, EXPECT_TRUE(content::WaitForLoadStop(contents)); // Execute in isolated world; where all distiller scripts are run. - EXPECT_EQ(true, content::EvalJsWithManualReply( - contents, kTestDistillerObject, - content::EXECUTE_SCRIPT_DEFAULT_OPTIONS, - ISOLATED_WORLD_ID_CHROME_INTERNAL)); + EXPECT_EQ(true, content::EvalJs(contents, kTestDistillerObject, + content::EXECUTE_SCRIPT_USE_MANUAL_REPLY, + ISOLATED_WORLD_ID_CHROME_INTERNAL)); } IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, diff --git a/chrome/browser/metrics/tab_stats/tab_stats_tracker_browsertest.cc b/chrome/browser/metrics/tab_stats/tab_stats_tracker_browsertest.cc index 99d62bf939521..3e497f7322cee 100644 --- a/chrome/browser/metrics/tab_stats/tab_stats_tracker_browsertest.cc +++ b/chrome/browser/metrics/tab_stats/tab_stats_tracker_browsertest.cc @@ -553,7 +553,8 @@ IN_PROC_BROWSER_TEST_F(TabStatsTrackerBrowserTest, AddObserverAudibleTab) { // Start the audio. base::RunLoop run_loop; AudioStartObserver audio_start_observer(web_contents, run_loop.QuitClosure()); - EXPECT_EQ("OK", EvalJsWithManualReply(web_contents, "StartOscillator();")); + EXPECT_EQ("OK", content::EvalJs(web_contents, "StartOscillator();", + content::EXECUTE_SCRIPT_USE_MANUAL_REPLY)); run_loop.Run(); // Adding an observer now should receive the OnTabIsAudibleChanged() call. diff --git a/chrome/browser/page_load_metrics/observers/ad_metrics/ads_page_load_metrics_observer_browsertest.cc b/chrome/browser/page_load_metrics/observers/ad_metrics/ads_page_load_metrics_observer_browsertest.cc index d332a7f714029..048c4fbabebf2 100644 --- a/chrome/browser/page_load_metrics/observers/ad_metrics/ads_page_load_metrics_observer_browsertest.cc +++ b/chrome/browser/page_load_metrics/observers/ad_metrics/ads_page_load_metrics_observer_browsertest.cc @@ -1134,7 +1134,8 @@ IN_PROC_BROWSER_TEST_F(AdsPageLoadMetricsObserverBrowserTest, "video.onplaying = () => { " "window.domAutomationController.send('true'); };" "video.play();"; - EXPECT_EQ("true", content::EvalJsWithManualReply(ad_frame, play_script)); + EXPECT_EQ("true", content::EvalJs(ad_frame, play_script, + content::EXECUTE_SCRIPT_USE_MANUAL_REPLY)); ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); diff --git a/chrome/browser/page_load_metrics/page_load_metrics_browsertest.cc b/chrome/browser/page_load_metrics/page_load_metrics_browsertest.cc index 42a206d768584..f72f9c143aa92 100644 --- a/chrome/browser/page_load_metrics/page_load_metrics_browsertest.cc +++ b/chrome/browser/page_load_metrics/page_load_metrics_browsertest.cc @@ -3121,11 +3121,11 @@ IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, PortalActivation) { EXPECT_TRUE( ExecJs(outer_contents, "document.querySelector('portal').activate()")); - EXPECT_EQ(true, - EvalJsWithManualReply(portal_contents, + EXPECT_EQ(true, content::EvalJs(portal_contents, "activatePromise.then(r => { " " window.domAutomationController.send(r);" - "});")); + "});", + content::EXECUTE_SCRIPT_USE_MANUAL_REPLY)); // The activated portal contents should be the currently active contents. EXPECT_EQ(portal_contents, diff --git a/chrome/browser/payments/payment_handler_change_shipping_address_option_browsertest.cc b/chrome/browser/payments/payment_handler_change_shipping_address_option_browsertest.cc index 86d7cef63bbd4..f287448077acd 100644 --- a/chrome/browser/payments/payment_handler_change_shipping_address_option_browsertest.cc +++ b/chrome/browser/payments/payment_handler_change_shipping_address_option_browsertest.cc @@ -72,17 +72,18 @@ class PaymentHandlerChangeShippingAddressOptionTest IN_PROC_BROWSER_TEST_P(PaymentHandlerChangeShippingAddressOptionTest, Test) { EXPECT_EQ("instruments.set(): Payment handler installed.", - content::EvalJsWithManualReply( + content::EvalJs( GetActiveWebContents(), - "install('change_shipping_" + getTestType() + "_app.js');")); + "install('change_shipping_" + getTestType() + "_app.js');", + content::EXECUTE_SCRIPT_USE_MANUAL_REPLY)); EXPECT_TRUE( content::ExecJs(GetActiveWebContents(), GetParam().init_test_code)); std::string actual_output = - content::EvalJsWithManualReply( - GetActiveWebContents(), - "outputChangeShippingAddressOptionReturnValue(request);") + content::EvalJs(GetActiveWebContents(), + "outputChangeShippingAddressOptionReturnValue(request);", + content::EXECUTE_SCRIPT_USE_MANUAL_REPLY) .ExtractString(); // The test expectations are hard-coded, but the embedded test server changes diff --git a/chrome/browser/permissions/permission_request_manager_browsertest.cc b/chrome/browser/permissions/permission_request_manager_browsertest.cc index 329286f88a6d5..ecebdd0583f73 100644 --- a/chrome/browser/permissions/permission_request_manager_browsertest.cc +++ b/chrome/browser/permissions/permission_request_manager_browsertest.cc @@ -883,15 +883,16 @@ IN_PROC_BROWSER_TEST_F( permissions::PermissionRequestManager::AutoResponseType::ACCEPT_ONCE); // Request 'geolocation' permission. - std::string result = content::EvalJsWithManualReply(GetActiveMainFrame(), - kQueryCurrentPosition) - .ExtractString(); + std::string result = + content::EvalJs(GetActiveMainFrame(), kQueryCurrentPosition, + content::EXECUTE_SCRIPT_USE_MANUAL_REPLY) + .ExtractString(); EXPECT_EQ("success", result); EXPECT_EQ(1, bubble_factory()->TotalRequestCount()); // Request 'geolocation' permission. There should not be a 2nd prompt. - result = content::EvalJsWithManualReply(GetActiveMainFrame(), - kQueryCurrentPosition) + result = content::EvalJs(GetActiveMainFrame(), kQueryCurrentPosition, + content::EXECUTE_SCRIPT_USE_MANUAL_REPLY) .ExtractString(); EXPECT_EQ("success", result); EXPECT_EQ(1, bubble_factory()->TotalRequestCount()); @@ -909,8 +910,8 @@ IN_PROC_BROWSER_TEST_F( GetPermissionRequestManager())); // Request 'geolocation' permission. - result = content::EvalJsWithManualReply(GetActiveMainFrame(), - kQueryCurrentPosition) + result = content::EvalJs(GetActiveMainFrame(), kQueryCurrentPosition, + content::EXECUTE_SCRIPT_USE_MANUAL_REPLY) .ExtractString(); EXPECT_EQ("success", result); // There should be no permission prompt. @@ -946,8 +947,8 @@ IN_PROC_BROWSER_TEST_F( permissions::PermissionRequestManager::AutoResponseType::ACCEPT_ONCE); // Request 'geolocation' permission. We should get a prompt. - result = content::EvalJsWithManualReply(GetActiveMainFrame(), - kQueryCurrentPosition) + result = content::EvalJs(GetActiveMainFrame(), kQueryCurrentPosition, + content::EXECUTE_SCRIPT_USE_MANUAL_REPLY) .ExtractString(); EXPECT_EQ("success", result); diff --git a/chrome/browser/ui/web_applications/create_shortcut_browsertest.cc b/chrome/browser/ui/web_applications/create_shortcut_browsertest.cc index c041149140d24..c3f4706db7a33 100644 --- a/chrome/browser/ui/web_applications/create_shortcut_browsertest.cc +++ b/chrome/browser/ui/web_applications/create_shortcut_browsertest.cc @@ -164,10 +164,11 @@ IN_PROC_BROWSER_TEST_F(CreateShortcutBrowserTest, WorksAfterDelayedIFrameLoad) { iframe.srcdoc = 'inner page'; document.body.appendChild(iframe); )"; - EXPECT_EQ(content::EvalJsWithManualReply( - browser()->tab_strip_model()->GetActiveWebContents(), script) - .ExtractString(), - "success"); + EXPECT_EQ( + content::EvalJs(browser()->tab_strip_model()->GetActiveWebContents(), + script, content::EXECUTE_SCRIPT_USE_MANUAL_REPLY) + .ExtractString(), + "success"); InstallShortcutAppForCurrentUrl(); } diff --git a/components/ukm/content/source_url_recorder_browsertest.cc b/components/ukm/content/source_url_recorder_browsertest.cc index b62e4b157695a..c7440d756ad6c 100644 --- a/components/ukm/content/source_url_recorder_browsertest.cc +++ b/components/ukm/content/source_url_recorder_browsertest.cc @@ -242,10 +242,8 @@ IN_PROC_BROWSER_TEST_F(SourceUrlRecorderWebContentsObserverBrowserTest, window.domAutomationController.send(true); }, 10); )"; - // EvalJsWithManualReply returns an EvalJsResult, whose docs say to use - // EXPECT_EQ(true, ...) rather than EXPECT_TRUE(), as the latter does not - // compile. - EXPECT_EQ(true, EvalJsWithManualReply(portal_contents, activated_poll)); + EXPECT_EQ(true, EvalJs(portal_contents, activated_poll, + content::EXECUTE_SCRIPT_USE_MANUAL_REPLY)); // The activated portal contents should be the currently active contents. EXPECT_EQ(portal_contents, shell()->web_contents()); diff --git a/content/browser/site_per_process_browsertest.cc b/content/browser/site_per_process_browsertest.cc index 84f61dc4cc51f..d8845f3e2dcf1 100644 --- a/content/browser/site_per_process_browsertest.cc +++ b/content/browser/site_per_process_browsertest.cc @@ -14759,7 +14759,8 @@ IN_PROC_BROWSER_TEST_P(SitePerProcessBrowserTestWithSadFrameTabReload, GURL out_of_view_url( embedded_test_server()->GetURL("a.com", "/iframe_out_of_view.html")); EXPECT_TRUE(NavigateToURL(shell(), out_of_view_url)); - EXPECT_EQ("LOADED", EvalJsWithManualReply(shell(), "notifyWhenLoaded();")); + EXPECT_EQ("LOADED", EvalJs(shell(), "notifyWhenLoaded();", + EXECUTE_SCRIPT_USE_MANUAL_REPLY)); NavigateIframeToURL(web_contents(), "test_iframe", embedded_test_server()->GetURL("b.com", "/title1.html")); @@ -15801,18 +15802,19 @@ IN_PROC_BROWSER_TEST_P(SitePerProcessBrowserTest, ASSERT_TRUE(NavigateToURL(shell(), main_frame_url)); GURL cross_origin(embedded_test_server()->GetURL("b.com", "/title1.html")); std::string msg = - EvalJsWithManualReply( - shell(), JsReplace("var object = document.createElement('object');" - "document.body.appendChild(object);" - "object.data = $1;" - "object.type='text/html';" - "object.notify = true;" - "object.onload = () => {" - " if (!object.notify) return;" - " object.notify = false;" - " window.domAutomationController.send('done');" - "};", - cross_origin)) + EvalJs(shell(), + JsReplace("var object = document.createElement('object');" + "document.body.appendChild(object);" + "object.data = $1;" + "object.type='text/html';" + "object.notify = true;" + "object.onload = () => {" + " if (!object.notify) return;" + " object.notify = false;" + " window.domAutomationController.send('done');" + "};", + cross_origin), + EXECUTE_SCRIPT_USE_MANUAL_REPLY) .ExtractString(); ASSERT_EQ("done", msg); // To track the frame's visibility an EmbeddedContentView is needed. The diff --git a/content/public/test/browser_test_utils.cc b/content/public/test/browser_test_utils.cc index f5573480f8b84..8965de3ab8fc7 100644 --- a/content/public/test/browser_test_utils.cc +++ b/content/public/test/browser_test_utils.cc @@ -1601,10 +1601,11 @@ EvalJsResult EvalRunnerScript(const ToRenderFrameHost& execution_target, << "['" << token << "', [result]]; but got instead: " << *response << " ... This is potentially because a script tried to call " "domAutomationController.send itself -- that is only allowed " - "when using EvalJsWithManualReply(). When using EvalJs(), result " - "values are just the result of calling eval() on the script -- " - "the completion value is the value of the last executed " - "statement. When using ExecJs(), there is no result value."; + "when using EXECUTE_SCRIPT_USE_MANUAL_REPLY. When using " + "EvalJs(), result values are just the result of calling eval() on " + "the script -- the completion value is the value of the last " + "executed statement. When using ExecJs(), there is no result " + "value."; } } @@ -1698,14 +1699,6 @@ EvalJsResult EvalJs(const ToRenderFrameHost& execution_target, token); } -EvalJsResult EvalJsWithManualReply(const ToRenderFrameHost& execution_target, - const std::string& script, - int options, - int32_t world_id) { - return EvalJs(execution_target, script, - options | EXECUTE_SCRIPT_USE_MANUAL_REPLY, world_id); -} - EvalJsResult EvalJsAfterLifecycleUpdate( const ToRenderFrameHost& execution_target, const std::string& raf_script, diff --git a/content/public/test/browser_test_utils.h b/content/public/test/browser_test_utils.h index 29688103ee52f..0f8874f116805 100644 --- a/content/public/test/browser_test_utils.h +++ b/content/public/test/browser_test_utils.h @@ -445,7 +445,7 @@ class ToRenderFrameHost { RenderFrameHost* ConvertToRenderFrameHost(RenderFrameHost* render_view_host); RenderFrameHost* ConvertToRenderFrameHost(WebContents* web_contents); -// Semi-deprecated: in new code, prefer ExecJs() -- it works the same, but has +// Deprecated: in new code, prefer ExecJs() -- it works the same, but has // better error handling. (Note: still use ExecuteScript() on pages with a // Content Security Policy). // @@ -490,9 +490,7 @@ void ExecuteScriptAsync(const ToRenderFrameHost& adapter, // the executed script. They return true on success, false if the script // execution failed or did not evaluate to the expected type. // -// Semi-deprecated: Consider using EvalJs() or EvalJsWithManualReply() instead, -// which handle errors better and don't require an out-param. If the target -// document doesn't have a CSP. See the comment on EvalJs() for migration tips. +// Deprecated: Use EvalJs(). bool ExecuteScriptAndExtractDouble(const ToRenderFrameHost& adapter, const std::string& script, double* result) WARN_UNUSED_RESULT; @@ -788,8 +786,8 @@ enum EvalJsOptions { // * Preferred, but more rewriting: Use EvalJs with a Promise which // resolves to the value you previously passed to send(). // * Less rewriting of |script|, but with some drawbacks: Use -// EXECUTE_SCRIPT_USE_MANUAL_REPLY in |options|, or EvalJsWithManualReply. -// When specified, this means that |script| must continue to call +// EXECUTE_SCRIPT_USE_MANUAL_REPLY in |options|. When specified, this +// means that |script| must continue to call // domAutomationController.send(). Note that this option option disables // some error-catching safeguards, but you still get the benefit of having // an EvalJsResult that can be passed to EXPECT. @@ -819,15 +817,6 @@ EvalJsResult EvalJs(const ToRenderFrameHost& execution_target, int32_t world_id = ISOLATED_WORLD_ID_GLOBAL) WARN_UNUSED_RESULT; -// Like EvalJs(), except that |script| must call domAutomationController.send() -// itself. This is the same as specifying the EXECUTE_SCRIPT_USE_MANUAL_REPLY -// option to EvalJs. -EvalJsResult EvalJsWithManualReply(const ToRenderFrameHost& execution_target, - const std::string& script, - int options = EXECUTE_SCRIPT_DEFAULT_OPTIONS, - int32_t world_id = ISOLATED_WORLD_ID_GLOBAL) - WARN_UNUSED_RESULT; - // Like EvalJs(), but runs |raf_script| inside a requestAnimationFrame handler, // and runs |script| after the rendering update has completed. By the time // this method returns, any IPCs sent from the renderer process to the browser diff --git a/content/test/browser_test_utils_browsertest.cc b/content/test/browser_test_utils_browsertest.cc index 6f8609351cf6c..73a6cf33fa022 100644 --- a/content/test/browser_test_utils_browsertest.cc +++ b/content/test/browser_test_utils_browsertest.cc @@ -155,8 +155,9 @@ IN_PROC_BROWSER_TEST_F(EvalJsBrowserTest, EvalJsWithManualReply) { std::string script = "window.domAutomationController.send(20); 'hi';"; - // Calling domAutomationController is required for EvalJsWithManualReply. - EXPECT_EQ(20, EvalJsWithManualReply(shell(), script)); + // Calling domAutomationController is required for + // EXECUTE_SCRIPT_USE_MANUAL_REPLY. + EXPECT_EQ(20, EvalJs(shell(), script, EXECUTE_SCRIPT_USE_MANUAL_REPLY)); // Calling domAutomationController is an error with EvalJs. auto result = EvalJs(shell(), script); @@ -169,9 +170,10 @@ IN_PROC_BROWSER_TEST_F(EvalJsBrowserTest, EvalJsWithManualReply) { result.error, ::testing::EndsWith("This is potentially because a script tried to call " "domAutomationController.send itself -- that is only " - "allowed when using EvalJsWithManualReply(). When " - "using EvalJs(), result values are just the result " - "of calling eval() on the script -- the completion " + "allowed when using " + "EXECUTE_SCRIPT_USE_MANUAL_REPLY. When using " + "EvalJs(), result values are just the result of " + "calling eval() on the script -- the completion " "value is the value of the last executed statement. " "When using ExecJs(), there is no result value.")); }