Index: third_party/WebKit/LayoutTests/resize-observer/observe.html |
diff --git a/third_party/WebKit/LayoutTests/resize-observer/observe.html b/third_party/WebKit/LayoutTests/resize-observer/observe.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3972047200d7b17a11d553a19199634ea5f73ba5 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/resize-observer/observe.html |
@@ -0,0 +1,162 @@ |
+<!doctype html> |
+<head> |
+ <script src="../resources/testharness.js"></script> |
+ <script src="../resources/testharnessreport.js"></script> |
+ <script src="./resources/resizeTestHelper.js"></script> |
+</head> |
+<p>ResizeObserver tests</p> |
+<div id="target1" style="width:100px;height:100px;">t1</div> |
+<div id="target2" style="width:100px;height:100px;">t2</div> |
+<img id="target3" style="width:100px;height:100px;"> |
+<iframe src="./resources/iframe.html" width="300px" height="100px" style="display:block"></iframe> |
+<script> |
+'use strict'; |
+ |
+var helper = new ResizeTestHelper(); |
+ |
+let t1 = document.querySelector('#target1'); |
+let t2 = document.querySelector('#target2'); |
+ |
+// allow uncaught exception because ResizeObserver posts exceptions |
+// to window error handler when limit is exceeded. |
+setup({allow_uncaught_exception: true}); |
+ |
+function test0() { |
+ helper.createTest( |
+ "simple observation", |
+ _ => { |
+ helper.observer.disconnect(); |
+ helper.observer.observe(t1); |
+ t1.style.width = "5px"; |
+ }, |
+ entries => { |
+ assert_equals(entries.length, 1, "1 pending notification"); |
+ assert_equals(entries[0].target, t1, "target is t1"); |
+ assert_equals(entries[0].contentRect.width, 5, "target width"); |
+ test1(); |
+ } |
+ ); |
+ helper.nextTest(); |
+} |
+ |
+function test1() { |
+ helper.createTest( |
+ "multiple observation on same element trigger only one", |
+ _ => { |
+ helper.observer.observe(t1); |
+ helper.observer.observe(t1); |
+ t1.style.width = "10px"; |
+ }, |
+ entries => { |
+ assert_equals(entries.length, 1, "1 pending notification"); |
+ helper.observer.disconnect(); |
+ test2(); |
+ } |
+ ); |
+ helper.nextTestRaf(); |
+} |
+ |
+function test2() { |
+ test(_ => { |
+ assert_throws(null, _=> { |
+ helper.observer.observe({}); |
+ }); |
+ test3(); |
+ }, |
+ "throw exception when observing non-element" |
+ ); |
+} |
+ |
+function test3() { |
+ helper.createTest( |
+ "disconnect stops all notifications", |
+ setup => { |
+ helper.observer.observe(t1); |
+ helper.observer.observe(t2); |
+ helper.observer.disconnect(); |
+ t1.style.width = "30px"; |
+ }, |
+ entries => { |
+ assert_unreached("no entries should happen"); |
+ }, |
+ timeout => { |
+ // timeout happened, all is well. |
+ test4(); |
+ } |
+ ); |
+ helper.nextTestRaf(); |
+} |
+ |
+function test4() { |
+ helper.createTest( |
+ "unobserve target stops notifications, unobserve non-observed does nothing", |
+ setup => { |
+ helper.observer.observe(t1); |
+ helper.observer.observe(t2); |
+ helper.observer.unobserve(t1); |
+ helper.observer.unobserve(document.body); |
+ t1.style.width = "40px"; |
+ t2.style.width = "40px"; |
+ }, |
+ entries => { |
+ assert_equals(entries.length, 1, "only t2"); |
+ assert_equals(entries[0].target, t2, "t2 was observed"); |
+ helper.observer.disconnect(); |
+ test5(); |
+ } |
+ ); |
+ helper.nextTestRaf(); |
+} |
+ |
+function test5() { |
+ let t4 = document.querySelector('#target3'); |
+ helper.createTest( |
+ "observe img", |
+ setup => { |
+ helper.observer.observe(t4); |
+ }, |
+ entries => { |
+ helper.nextTest(); |
+ } |
+ ); |
+ helper.createTest( |
+ "observe img, part 2", |
+ setup => { |
+ t4.style.width = "100.5px"; |
+ }, |
+ entries => { |
+ assert_equals(entries.length, 1); |
+ assert_equals(entries[0].contentRect.width, 100.5); |
+ helper.observer.disconnect(); |
+ test6(); |
+ } |
+ ); |
+ helper.nextTestRaf(); |
+} |
+ |
+function test6() { |
+ let test = async_test('iframe notifications'); |
+ let testRequested = false; |
+ let iframe = document.querySelector('iframe'); |
+ window.addEventListener('message', event => { |
+ switch(event.data) { |
+ case 'readyToTest': |
+ if (!testRequested) { |
+ iframe.contentWindow.postMessage('startTest', '*'); |
+ testRequested = true; |
+ } |
+ break; |
+ case 'success': |
+ case 'fail': |
+ test.step( () => { |
+ assert_equals(event.data, 'success'); |
+ test.done(); |
+ }); |
+ break; |
+ } |
+ }, false); |
+} |
+ |
+test0(); |
+ |
+</script> |