summaryrefslogtreecommitdiff
path: root/dom/base/test/test_bug116083.html
blob: 0d37242f82e84496ab45887e732eb296aaac76ae (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=116083
-->
<head>
  <title>Test for Bug 116083</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=116083">Mozilla Bug 116083</a>
<div id="content">
<div style="white-space: pre">foo  bar</div>
<div style="white-space: pre-wrap">foo  bar</div>
<div style="white-space: pre-line">foo  bar</div>
<div style="white-space: -moz-pre-space">foo  bar</div>
<div data-result="bar  baz"><span style="white-space: pre">bar  </span>baz</div>
<div data-result="bar  baz"><span style="white-space: pre-wrap">bar  </span>baz</div>
<div data-result="bar  baz"><span style="white-space: pre-line">bar  </span>baz</div>
<div data-result="bar  baz"><span style="white-space: -moz-pre-space">bar  </span>baz</div>
<div data-result="foo  &#10;  bar&#10;&#10;!&#10;&#10;&#10;baz" style="white-space: pre"><div>foo  </div><div>  bar</div><div><br></div><div>!</div><div><br><br></div><div>baz</div></div>
<div data-result="foo &#10; bar&#10;&#10;!&#10;&#10;&#10;baz" style="white-space: pre" contenteditable><div>foo </div><div> bar</div><div><br></div><div>!</div><div><br><br></div><div>baz</div></div>
<div data-result="foo  &#10;  bar&#10;&#10;!&#10;&#10;&#10;baz" style="white-space: pre-wrap"><div>foo  </div><div>  bar</div><div><br></div><div>!</div><div><br><br></div><div>baz</div></div>
<div data-result="foo &#10; bar&#10;&#10;!&#10;&#10;&#10;baz" style="white-space: pre-wrap" contenteditable><div>foo </div><div> bar</div><div><br></div><div>!</div><div><br><br></div><div>baz</div></div>
<div data-result="foo  &#10;  bar&#10;&#10;!&#10;&#10;&#10;baz" style="white-space: pre-line"><div>foo  </div><div>  bar</div><div><br></div><div>!</div><div><br><br></div><div>baz</div></div>
<div data-result="foo &#10; bar&#10;&#10;!&#10;&#10;&#10;baz" style="white-space: pre-line" contenteditable><div>foo </div><div> bar</div><div><br></div><div>!</div><div><br><br></div><div>baz</div></div>
<div data-result="foo  &#10;  bar&#10;&#10;!&#10;&#10;&#10;baz" style="white-space: -moz-pre-space"><div>foo  </div><div>  bar</div><div><br></div><div>!</div><div><br><br></div><div>baz</div></div>
<div data-result="foo &#10; bar&#10;&#10;!&#10;&#10;&#10;baz" style="white-space: -moz-pre-space" contenteditable><div>foo </div><div> bar</div><div><br></div><div>!</div><div><br><br></div><div>baz</div></div>
<div data-result="foo&#10;bar&#10;baz&#10;qux"><div>foo<br></div><span>bar<br>baz<br>qux</span></div>
<div data-result="foo&#10;bar&#10;baz&#10;qux" contenteditable><div>foo<br></div><span>bar<br>baz<br>qux</span></div>
<div data-result="foo&#10;&#10;"><div>foo</div><span><br></span></div>
<div data-result="foo&#10;&#10;" contenteditable><div>foo</div><span><br></span></div>
<div data-result="foo&#10;&#10;bar"><div>foo</div><span><br></span><div>bar</div></div>
<div data-result="foo&#10;&#10;bar" contenteditable><div>foo</div><span><br></span><div>bar</div></div>
<div data-result="foo&#10;bar&#10;"><div>foo</div><span>bar<br></span></div>
<div data-result="foo&#10;bar" contenteditable><div>foo</div><span>bar<br></span></div>
<div data-result="foo&#10;bar&#10;baz"><div>foo</div><span>bar<br></span><div>baz</div></div>
<div data-result="foo&#10;bar&#10;baz" contenteditable><div>foo</div><span>bar<br></span><div>baz</div></div>
<div data-result="&#10;&#10;foo"><div><br><br><div>foo</div></div></div>
<div data-result="&#10;&#10;foo" contenteditable><div><br><br><div>foo</div></div></div>
<div data-result="foo&#10;bar"><div>foo<br>bar</div></div>
<div data-result="foo&#10;bar" contenteditable><div>foo<br>bar</div></div>
<div data-result="foo&#10;bar&#10;"><div>foo<br>bar<br></div></div>
<div data-result="foo&#10;bar" contenteditable><div>foo<br>bar<br></div></div>
<div data-result="&#10;foo bar&#10;">foo  bar</div>
</div>
<script type="application/javascript">

const Cc = SpecialPowers.Cc;
const Ci = SpecialPowers.Ci;

function hasExpectedFlavors() {
  var cb = Cc["@mozilla.org/widget/clipboard;1"].
           getService(Ci.nsIClipboard);

  ok(cb.hasDataMatchingFlavors(["text/unicode"], 1, cb.kGlobalClipboard),
     "The clipboard has text/unicode");

  // Android only supports plain text
  if (navigator.appVersion.indexOf("Android") == -1) {
    ok(cb.hasDataMatchingFlavors(["text/html"], 1, cb.kGlobalClipboard),
       "The clipboard has text/html");
  }

  if (navigator.appVersion.indexOf("Win") >= 0) {
    ok(cb.hasDataMatchingFlavors(["application/x-moz-nativehtml"], 1, cb.kGlobalClipboard),
       "The clipboard has application/x-moz-nativehtml");
  }
}

function nextTest() {
  var div = document.querySelector("#content>div");
  if (!div) {
    SimpleTest.finish();
    return;
  }
  getSelection().selectAllChildren(div);
  var expected = div.hasAttribute("data-result") ?
                 div.getAttribute("data-result") :
                 div.textContent;
  SimpleTest.waitForClipboard(expected, function() {
    synthesizeKey("C", {accelKey: true});
  }, function() {
    ok(true, div.getAttribute("style") + " passed");
    hasExpectedFlavors();
    div.parentNode.removeChild(div);
    nextTest();
  }, function() {
    ok(false, "failed to copy the expected content to the clipboard");
    SimpleTest.finish();
  });
}

SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(function() {
  SpecialPowers.pushPrefEnv({"set": [["clipboard.plainTextOnly", false]]}, nextTest);
});

</script>
</body>
</html>