Brandon Cheng 7501af8a70 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

--HG--
extra : rebase_source : 03e4cd1e3a9042fa565373487c5cbb1118530917
2017-10-28 23:33:41 -04:00
..