summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/http/tests/misc/copy-resolves-urls.html
blob: d416c40a62b9acd805558a6b8371afc8e72d99c6 (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
<p>This tests to make sure that copying/pasting HTML results in URLs being full paths so
pasting between websites works.  To test manually, copy the selection and paste it into
the blue box.  If this is a file:/// url, the links should be relative.  If this is an
http:// url, the links should be absolute.</p>
<div id="test">
<a href="../relative/path/foo.html">link</a><img src="resources/compass.jpg">
</div>
<div id="pastehere" contenteditable="true" style="border: 1px solid blue" onpaste="paste()">
</div>
<div id="results"></div>
<script>
function test()
{
    var s = window.getSelection();
    var test = document.getElementById("test");
    s.selectAllChildren(test);

    if (!window.testRunner)
        return;
    testRunner.dumpAsText();
    testRunner.waitUntilDone();

    document.execCommand("Copy");
    // It looks like on a mac, URLs are resolved only if the page we're pasting
    // into is different from the page we copied from.
    document.location.href = "http://localhost:8080/misc/copy-resolves-urls.html?paste";
}

function doPaste()
{
    var pasteHere = document.getElementById("pastehere");
    window.getSelection().setPosition(pasteHere, 0);
    document.execCommand("Paste");
}

function paste()
{
    setTimeout(afterPaste, 0);
}

function afterPaste()
{
    var pasteHere = document.getElementById("pastehere");
    var results = document.getElementById("results");
    results.appendChild(document.createTextNode(pasteHere.innerHTML));
    if (window.testRunner)
        testRunner.notifyDone();
}

if (document.location.search == "?paste")
    doPaste();
else
    test();
</script>