Introduce EvalJs, a replacement for ExecuteScript and friends.
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: 
Ben Greenstein <bengr@chromium.org>
Reviewed-by: 
Łukasz Anforowicz <lukasza@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580702}
Showing
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Please register or sign in to comment