summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html-imports/fetching/loading-attempt.html
blob: 7c1b442b11a6364abe22c409cec76802ff38ffa9 (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
<!DOCTYPE html>
<html>
<head>
<title>Fetching import</title>
<link rel="help" href="http://w3c.github.io/webcomponents/spec/imports/#fetching-import">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script>
var onloadWasCalledOnSuccess = false;
var onerrorWasCalledOnSuccess = false;
function helloLoadHandler() { onloadWasCalledOnSuccess = true; }
function helloErrorHandler() { onerrorWasCalledOnSuccess = true; }

var onloadWasCalledOnFail = false;
var onerrorWasCalledOnFail = false;
function nosuchLoadHandler() { onloadWasCalledOnFail = true; }
function nosuchErrorHandler() { onerrorWasCalledOnFail = true; }
</script>

<link rel="import" href="resources/hello.html" onload="helloLoadHandler()" onerror="helloLoadHandler()">
<link rel="import" href="resources/no-such.html" onload="nosuchLoadHandler()" onerror="nosuchErrorHandler()">

<script>
test(function() {
    assert_true(onloadWasCalledOnSuccess);
    assert_false(onerrorWasCalledOnSuccess);
}, 'The loading attempt must be considered successful if IMPORT is not null on the algorithm completion, and failed otherwise. (1)');

test(function() {
    assert_false(onloadWasCalledOnFail);
    assert_true(onerrorWasCalledOnFail);
}, 'The loading attempt must be considered successful if IMPORT is not null on the algorithm completion, and failed otherwise. (2)');

t1 = async_test('The loading attempt must be considered successful if IMPORT is not null on the algorithm completion, and failed otherwise. (3)')
t1.step(function() {
   var importElement = document.createElement('link');
   importElement.setAttribute('rel', 'import');
   importElement.setAttribute('href', 'resources/dynamic.html');
   importElement.addEventListener("error", assert_unreached);
   importElement.addEventListener("load", function() {
       t1.done();
   });

   document.head.appendChild(importElement);
});

var onloadWasCalledOnAsync = false;
var onerrorWasCalledOnAsync = false;
var asyncAttemptDone = function() { assert_unreached(); };

function asyncLoadHandler() {
    onloadWasCalledOnAsync = true;
    asyncAttemptDone();
}
function asyncErrorHandler() {
    onerrorWasCalledOnAsync = true;
    asyncAttemptDone();
}

t2 = async_test('Every import that is not marked as async delays the load event in the Document.');
asyncAttemptDone = function() {
    t2.step(function() {
        assert_true(onloadWasCalledOnAsync);
        assert_false(onerrorWasCalledOnAsync);
        t2.done();
    });
};

</script>
<link rel="import" href="resources/async.html" onload="asyncLoadHandler()" onerror="asyncErrorHandler()" async>
</head>
<body>
<div id="log"></div>
</body>
</html>