summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/tests/test_sanitizer_on_paste.html
blob: 09c6ff4fb2d83fa059e416a7cfe24cca6772bc4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test pasting table rows</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<textarea></textarea>
<div contenteditable="true">Paste target</div>
<script>
  SimpleTest.waitForExplicitFinish();
  function fail() {
    ok(false, "Should not run event handlers.");
  }
  document.addEventListener('copy', ev => {
    dump("IN LISTENER\n");
    const payload = `<svg><style><image href=file_sanitizer_on_paste.sjs onerror=fail() onload=fail()>`
    
    ev.preventDefault();
    ev.clipboardData.setData('text/html', payload);
    ev.clipboardData.setData('text/plain', payload);
  });

  document.getElementsByTagName("textarea")[0].focus();
  synthesizeKey("c", { accelKey: true } /* aEvent*/);

  let div = document.getElementsByTagName("div")[0];
  div.focus(); 
  synthesizeKey("v", { accelKey: true } /* aEvent*/);

  let svg = div.firstChild;
  is(svg.nodeName, "svg", "Node name should be svg");

  let style = svg.firstChild;
  if (style) {
    is(style.firstChild, null, "Style should not have child nodes.");
  } else {
    ok(false, "Should have gotten a node.");
  }

  var s = document.createElement("script");
  s.src = "file_sanitizer_on_paste.sjs?report=1";
  document.body.appendChild(s);
</script>
</body>