'Test conversion by hexlifying in javascript.
Since the conversion of QStrings to Python strings is broken in some
older PyQt versions in some corner cases, we load an HTML file which
generates an MD5 of the escaped text and use that for comparisons.'

def _test_escape_hexlified(self, text, qtbot, webframe):

    escaped = javascript.string_escape(text)
    path = os.path.join(os.path.dirname(__file__), 'test_javascript_string_escape.html')
    with open(path, encoding='utf-8') as f:
        html_source = f.read().replace('%INPUT%', escaped)
    with qtbot.waitSignal(webframe.loadFinished) as blocker:
        webframe.setHtml(html_source)
    assert (blocker.args == [True])
    result = webframe.evaluateJavaScript('window.qute_test_result')
    assert (result is not None)
    assert ('|' in result)
    (result_md5, result_text) = result.split('|', maxsplit=1)
    text_md5 = binascii.hexlify(text.encode('utf-8')).decode('ascii')
    assert (result_md5 == text_md5), result_text
