Bug 1353319 - Fix cyrillic text test after re-adding the HTML preview. r?Honza draft
authorBrandon Cheng <brandon.cheng@protonmail.com>
Sat, 28 Oct 2017 23:33:41 -0400
changeset 696857 9c36dc64972b23418814ba1f224153e0d0a28c76
parent 696856 e14abefe4e49f438993b10fbe57d955a2f159932
child 739946 ade7c393b0f0db6fb2da5ffc4d5ada49a38c32ef
push id88809
push userbmo:brandon.cheng@protonmail.com
push dateSun, 12 Nov 2017 02:18:53 +0000
Bug 1353319 - Fix cyrillic text test after re-adding the HTML preview. r?Honza Adding an HTML preview above the raw payload viewer on the developer tools response tab caused browser_net_cyrillic-02.js to fail since CodeMirror only renders visible lines to the DOM. The new HTML preview shares space with the CodeMirror editor, so the resulting height became shorter; enough to hide the line this test was looking for. This solution uses CodeMirror.getValue() to retrieve the contents of all lines stored in memory. Checking against that will allow the test to pass since it contains the cyrillic text. One downside is that this makes the test less reliable since it may not be guaranteed that what CodeMirror has buffered to render will actually be what's inserted into the DOM. Two other solutions were explored before settling on the one above. The first was simulating scroll events through EventUtils.sendWheelAndPaint. const event = { deltaMode: WheelEvent.DOM_DELTA_LINE, deltaY: 20 } yield new Promise(resolve => { EventUtils.sendWheelAndPaint( document.querySelector(".CodeMirror-scroll"), 10, 10, event, resolve, monitor.panelWin ); }) This did scroll the editor enough to render content and pass the test, but caused additional errors since monitor.panelWin did not have a .waitForAllPaintsFlushed() method that EventUtils.sendWheelAndPaint expected. The below alternative uses a hard-coded scroll amount and a requestAnimationFrame as a rough estimate of when scrolling finished. It worked in the ten or so runs I tested, but there's nothing guaranteed about requestAnimationFrame that indicates when CodeMirror's rendering has finished. document.querySelector(".CodeMirror-scroll").scrollBy(0, 200); yield new Promise(resolve => requestAnimationFrame(resolve)); MozReview-Commit-ID: H95HjR8UNpx
--- a/devtools/client/netmonitor/test/browser_net_cyrillic-02.js
+++ b/devtools/client/netmonitor/test/browser_net_cyrillic-02.js
@@ -42,15 +42,18 @@ add_task(function* () {
   wait = waitForDOM(document, "#headers-panel");
   EventUtils.sendMouseEvent({ type: "mousedown" },
   yield wait;
   wait = waitForDOM(document, "#response-panel .CodeMirror-code");
   EventUtils.sendMouseEvent({ type: "click" },
   yield wait;
-  let text = document.querySelector(".CodeMirror-lines").textContent;
+  // CodeMirror will only load lines currently in view to the DOM. getValue()
+  // retrieves all lines pending render after a user begins scrolling.
+  let text = document.querySelector(".CodeMirror").CodeMirror.getValue();
     "The text shown in the source editor is correct.");
   return teardown(monitor);