• Nick Carter's avatar
    Introduce EvalJs, a replacement for ExecuteScript and friends. · b7e7131a
    Nick Carter authored
    EvalJs has the following improvements over ExecuteScript:
     - One function that works for every return type
       (no AndExtractBool etc variants) and every fancy
       option (isolated worlds, user gestures).
     - No out-params; no out-param variables.
     - |script| doesn't need to call domAutomationController explicitly
       to return a value. Instead, it has eval() semantics -- the statement
       completion value becomes the result.
     - The result of EvalJs can be used directly in EXPECT_EQ; e.g.::
       EXPECT_EQ("about:blank", EvalJs(contents, "window.location.href"));
     - JS exceptions are reliably captured and will appear as C++ assertion
       failures.
     - JS stack traces arising from exceptions are annotated with the
       corresponding source code; this also appears in C++ assertion failures.
     - When a script doesn't produce a result, tests are much less likely
       to hang.
     - Doesn't get confused by crosstalk with other callers
       of domAutomationController.send().
     - Lists, dicts, null values, etc. can be returned as base::Values.
    
    Limitations/warts:
     - The reliance on eval() currently means that a CSP script-src
       directive can interfere with the script runner. There is
       a workaround (use an isolated world), but this limitation
       currently prevents ExecJs from being a drop-in replacement
       for ExecuteScript. Fixing that will be a follow-on.
    
    Change-Id: I260595094f71e7734d29a78e9ffd90b409d74f37
    Reviewed-on: https://chromium-review.googlesource.com/1125121
    Commit-Queue: Nick Carter <nick@chromium.org>
    Reviewed-by: default avatarBen Greenstein <bengr@chromium.org>
    Reviewed-by: default avatarŁukasz Anforowicz <lukasza@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#580702}
    b7e7131a
browser_test_utils_browsertest.cc 6 KB