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 throws RangeError due to threshold=1.1."); | |
foolip
2017/01/11 13:42:53
Optional nit: "IntersectionObserver constructor wi
szager1
2017/01/23 23:18:04
Fixed the descriptions.
| |
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 throws RangeError due to 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 throws SYNTAX_ERR due to 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 throws SYNTAX_ERR due to 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 throws SYNTAX_ERR due to 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 throws SYNTAX_ERR due to invalid 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) { | 45 observer.observe("foo"); |
57 exc = e; | 46 }) |
58 shouldBeType("exc", "DOMException"); | 47 }, "IntersectionObserver.observe with an invalid target throws TypeError."); |
59 shouldBe("exc.code", "DOMException.SYNTAX_ERR"); | |
60 } | |
61 | 48 |
62 let observer = new IntersectionObserver(c => {}, {}); | |
63 try { | |
64 observer.observe("foo"); | |
65 testFailed("IntersectionObserver.observe with a bad target argument did not throw."); | |
66 } catch(e) { | |
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 | |
84 try { | |
85 observer.observe(target); | |
86 testFailed("IntersectionObserver.observe() with a deleted root did not throw ."); | |
87 } catch(e) { | |
88 exc = e; | |
89 shouldBeType("exc", "DOMException"); | |
90 shouldBe("exc.code", "DOMException.INVALID_STATE_ERR"); | |
91 } | |
92 | |
93 try { | |
94 observer.unobserve(target); | |
95 testFailed("IntersectionObserver.unobserve() with a deleted root did not thr ow."); | |
96 } catch(e) { | |
97 exc = e; | |
98 shouldBeType("exc", "DOMException"); | |
99 shouldBe("exc.code", "DOMException.INVALID_STATE_ERR"); | |
100 } | |
101 | |
102 try { | |
103 observer.disconnect(); | |
104 testFailed("IntersectionObserver.disconnect() with a deleted root did not th row."); | |
105 } catch(e) { | |
106 exc = e; | |
107 shouldBeType("exc", "DOMException"); | |
108 shouldBe("exc.code", "DOMException.INVALID_STATE_ERR"); | |
109 } | |
110 | |
111 try { | |
112 observer.takeRecords(); | |
113 testFailed("IntersectionObserver.takeRecords() with a deleted root did not t hrow."); | |
114 } catch(e) { | |
115 exc = e; | |
116 shouldBeType("exc", "DOMException"); | |
117 shouldBe("exc.code", "DOMException.INVALID_STATE_ERR"); | |
118 } | |
119 </script> | 49 </script> |
OLD | NEW |