Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Unified Diff: third_party/WebKit/LayoutTests/intersection-observer/observer-exceptions.html

Issue 2560253004: IntersectionObserver: convert tests to testharness.js (Closed)
Patch Set: Formatting tweaks and explicit resource paths Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/intersection-observer/observer-exceptions.html
diff --git a/third_party/WebKit/LayoutTests/intersection-observer/observer-exceptions.html b/third_party/WebKit/LayoutTests/intersection-observer/observer-exceptions.html
index a266655239ff77d0c76910f2633f965edd49d8c6..81bff3f51a222521061a01307a02b25d26de110c 100644
--- a/third_party/WebKit/LayoutTests/intersection-observer/observer-exceptions.html
+++ b/third_party/WebKit/LayoutTests/intersection-observer/observer-exceptions.html
@@ -1,119 +1,49 @@
<!DOCTYPE html>
-<div id="root"></div>
-<div id="target"></div>
-<script src="../resources/js-test.js"></script>
-<script src="../resources/gc.js"></script>
-<script>
- description("Test for observer exceptions.");
- var exc;
-
- try {
- new IntersectionObserver(e => {}, {threshold: [1.1]});
- testFailed("IntersectionObserver constructor did not throw due to invalid threshold.");
- } catch(e) {
- exc = e;
- shouldBeType("exc", "RangeError");
- }
-
- try {
- new IntersectionObserver(e => {}, {threshold: ["foo"]});
- testFailed("IntersectionObserver constructor did not throw due to invalid threshold.");
- } catch(e) {
- exc = e;
- shouldBeType("exc", "RangeError");
- }
-
- try {
- new IntersectionObserver(e => {}, {rootMargin: "1"});
- testFailed("IntersectionObserver constructor did not throw due to invalid rootMargin.");
- } catch(e) {
- exc = e;
- shouldBeType("exc", "DOMException");
- shouldBe("exc.code", "DOMException.SYNTAX_ERR");
- }
-
- try {
- new IntersectionObserver(e => {}, {rootMargin: "2em"});
- testFailed("IntersectionObserver constructor did not throw due to invalid rootMargin.");
- } catch(e) {
- exc = e;
- shouldBeType("exc", "DOMException");
- shouldBe("exc.code", "DOMException.SYNTAX_ERR");
- }
-
- try {
- new IntersectionObserver(e => {}, {rootMargin: "auto"});
- testFailed("IntersectionObserver constructor did not throw due to invalid rootMargin.");
- } catch(e) {
- exc = e;
- shouldBeType("exc", "DOMException");
- shouldBe("exc.code", "DOMException.SYNTAX_ERR");
- }
-
- try {
- new IntersectionObserver(e => {}, {rootMargin: "1px 1px 1px 1px 1px"});
- testFailed("IntersectionObserver constructor did not throw due to too many rootMargin value.");
- } catch(e) {
- exc = e;
- shouldBeType("exc", "DOMException");
- shouldBe("exc.code", "DOMException.SYNTAX_ERR");
- }
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
- let observer = new IntersectionObserver(c => {}, {});
- try {
+<script>
+test(function () {
+ assert_throws(RangeError(), function() {
+ new IntersectionObserver(e => {}, {threshold: [1.1]})
+ })
+}, "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.
+
+test(function () {
+ assert_throws(RangeError(), function() {
+ new IntersectionObserver(e => {}, {threshold: ["foo"]})
+ })
+}, "IntersectionObserver constructor throws RangeError due to threshold='foo'.");
+
+test(function () {
+ assert_throws("SYNTAX_ERR", function() {
+ new IntersectionObserver(e => {}, {rootMargin: "1"})
+ })
+}, "IntersectionObserver constructor throws SYNTAX_ERR due to rootMargin='1'.");
+
+test(function () {
+ assert_throws("SYNTAX_ERR", function() {
+ new IntersectionObserver(e => {}, {rootMargin: "2em"})
+ })
+}, "IntersectionObserver constructor throws SYNTAX_ERR due to rootMargin='2em'.");
+
+test(function () {
+ assert_throws("SYNTAX_ERR", function() {
+ new IntersectionObserver(e => {}, {rootMargin: "auto"})
+ })
+}, "IntersectionObserver constructor throws SYNTAX_ERR due to rootMargin='auto'.");
+
+test(function () {
+ assert_throws("SYNTAX_ERR", function() {
+ new IntersectionObserver(e => {}, {rootMargin: "1px 1px 1px 1px 1px"})
+ })
+}, "IntersectionObserver constructor throws SYNTAX_ERR due to invalid rootMargin='1px 1px 1px 1px 1px'.");
+
+test(function () {
+ assert_throws(TypeError(), function() {
+ let observer = new IntersectionObserver(c => {}, {});
observer.observe("foo");
- testFailed("IntersectionObserver.observe with a bad target argument did not throw.");
- } catch(e) {
- exc = e;
- shouldBeType("exc", "TypeError");
- }
-
- // Initialize observer and remove root in an inner function to avoid
- // references to rootDiv remaining live on this function's stack frame
- // (http://crbug.com/595672/).
- function initializeObserverThenRemoveRootDiv() {
- let rootDiv = document.getElementById("root");
- let observer = new IntersectionObserver(c => {}, {root: rootDiv});
- rootDiv.parentNode.removeChild(rootDiv);
- return observer;
- }
-
- observer = initializeObserverThenRemoveRootDiv();
- gc();
-
- try {
- observer.observe(target);
- testFailed("IntersectionObserver.observe() with a deleted root did not throw.");
- } catch(e) {
- exc = e;
- shouldBeType("exc", "DOMException");
- shouldBe("exc.code", "DOMException.INVALID_STATE_ERR");
- }
-
- try {
- observer.unobserve(target);
- testFailed("IntersectionObserver.unobserve() with a deleted root did not throw.");
- } catch(e) {
- exc = e;
- shouldBeType("exc", "DOMException");
- shouldBe("exc.code", "DOMException.INVALID_STATE_ERR");
- }
-
- try {
- observer.disconnect();
- testFailed("IntersectionObserver.disconnect() with a deleted root did not throw.");
- } catch(e) {
- exc = e;
- shouldBeType("exc", "DOMException");
- shouldBe("exc.code", "DOMException.INVALID_STATE_ERR");
- }
+ })
+}, "IntersectionObserver.observe with an invalid target throws TypeError.");
- try {
- observer.takeRecords();
- testFailed("IntersectionObserver.takeRecords() with a deleted root did not throw.");
- } catch(e) {
- exc = e;
- shouldBeType("exc", "DOMException");
- shouldBe("exc.code", "DOMException.INVALID_STATE_ERR");
- }
</script>

Powered by Google App Engine
This is Rietveld 408576698