OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <div id="root"></div> | 2 <script src="../resources/testharness.js"></script> |
3 <div id="target"></div> | 3 <script src="../resources/testharnessreport.js"></script> |
4 <script src="../resources/js-test.js"></script> | 4 |
5 <script src="../resources/gc.js"></script> | |
6 <script> | 5 <script> |
7 description("Test for observer exceptions."); | 6 test(function () { |
8 var exc; | 7 assert_throws(RangeError(), function() { |
| 8 new IntersectionObserver(e => {}, {threshold: [1.1]}) |
| 9 }) |
| 10 }, "IntersectionObserver constructor with { threshold: [1.1] }"); |
9 | 11 |
10 try { | 12 test(function () { |
11 new IntersectionObserver(e => {}, {threshold: [1.1]}); | 13 assert_throws(RangeError(), function() { |
12 testFailed("IntersectionObserver constructor did not throw due to invalid th
reshold."); | 14 new IntersectionObserver(e => {}, {threshold: ["foo"]}) |
13 } catch(e) { | 15 }) |
14 exc = e; | 16 }, 'IntersectionObserver constructor with { threshold: ["foo"] }'); |
15 shouldBeType("exc", "RangeError"); | |
16 } | |
17 | 17 |
18 try { | 18 test(function () { |
19 new IntersectionObserver(e => {}, {threshold: ["foo"]}); | 19 assert_throws("SYNTAX_ERR", function() { |
20 testFailed("IntersectionObserver constructor did not throw due to invalid th
reshold."); | 20 new IntersectionObserver(e => {}, {rootMargin: "1"}) |
21 } catch(e) { | 21 }) |
22 exc = e; | 22 }, 'IntersectionObserver constructor witth { rootMargin: "1" }'); |
23 shouldBeType("exc", "RangeError"); | |
24 } | |
25 | 23 |
26 try { | 24 test(function () { |
27 new IntersectionObserver(e => {}, {rootMargin: "1"}); | 25 assert_throws("SYNTAX_ERR", function() { |
28 testFailed("IntersectionObserver constructor did not throw due to invalid ro
otMargin."); | 26 new IntersectionObserver(e => {}, {rootMargin: "2em"}) |
29 } catch(e) { | 27 }) |
30 exc = e; | 28 }, 'IntersectionObserver constructor with { rootMargin: "2em" }'); |
31 shouldBeType("exc", "DOMException"); | |
32 shouldBe("exc.code", "DOMException.SYNTAX_ERR"); | |
33 } | |
34 | 29 |
35 try { | 30 test(function () { |
36 new IntersectionObserver(e => {}, {rootMargin: "2em"}); | 31 assert_throws("SYNTAX_ERR", function() { |
37 testFailed("IntersectionObserver constructor did not throw due to invalid ro
otMargin."); | 32 new IntersectionObserver(e => {}, {rootMargin: "auto"}) |
38 } catch(e) { | 33 }) |
39 exc = e; | 34 }, 'IntersectionObserver constructor width { rootMargin: "auto" }'); |
40 shouldBeType("exc", "DOMException"); | |
41 shouldBe("exc.code", "DOMException.SYNTAX_ERR"); | |
42 } | |
43 | 35 |
44 try { | 36 test(function () { |
45 new IntersectionObserver(e => {}, {rootMargin: "auto"}); | 37 assert_throws("SYNTAX_ERR", function() { |
46 testFailed("IntersectionObserver constructor did not throw due to invalid ro
otMargin."); | 38 new IntersectionObserver(e => {}, {rootMargin: "1px 1px 1px 1px 1px"}) |
47 } catch(e) { | 39 }) |
48 exc = e; | 40 }, 'IntersectionObserver constructor with { rootMargin: "1px 1px 1px 1px 1px" }'
); |
49 shouldBeType("exc", "DOMException"); | |
50 shouldBe("exc.code", "DOMException.SYNTAX_ERR"); | |
51 } | |
52 | 41 |
53 try { | 42 test(function () { |
54 new IntersectionObserver(e => {}, {rootMargin: "1px 1px 1px 1px 1px"}); | 43 assert_throws(TypeError(), function() { |
55 testFailed("IntersectionObserver constructor did not throw due to too many r
ootMargin value."); | 44 let observer = new IntersectionObserver(c => {}, {}); |
56 } catch(e) { | |
57 exc = e; | |
58 shouldBeType("exc", "DOMException"); | |
59 shouldBe("exc.code", "DOMException.SYNTAX_ERR"); | |
60 } | |
61 | |
62 let observer = new IntersectionObserver(c => {}, {}); | |
63 try { | |
64 observer.observe("foo"); | 45 observer.observe("foo"); |
65 testFailed("IntersectionObserver.observe with a bad target argument did not
throw."); | 46 }) |
66 } catch(e) { | 47 }, 'IntersectionObserver.observe("foo")'); |
67 exc = e; | |
68 shouldBeType("exc", "TypeError"); | |
69 } | |
70 | |
71 // Initialize observer and remove root in an inner function to avoid | |
72 // references to rootDiv remaining live on this function's stack frame | |
73 // (http://crbug.com/595672/). | |
74 function initializeObserverThenRemoveRootDiv() { | |
75 let rootDiv = document.getElementById("root"); | |
76 let observer = new IntersectionObserver(c => {}, {root: rootDiv}); | |
77 rootDiv.parentNode.removeChild(rootDiv); | |
78 return observer; | |
79 } | |
80 | |
81 observer = initializeObserverThenRemoveRootDiv(); | |
82 gc(); | |
83 observer.observe(target); | |
84 observer.unobserve(target); | |
85 observer.disconnect(); | |
86 shouldBeEqualToNumber("0", observer.takeRecords().length); | |
87 </script> | 48 </script> |
OLD | NEW |