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

Side by Side Diff: third_party/WebKit/LayoutTests/resize-observer/observe.html

Issue 2005593002: Initial ResizeObserver implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix global-interface-listing test Created 4 years, 5 months 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 unified diff | Download patch
OLDNEW
(Empty)
1 <!doctype html>
2 <head>
3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script>
5 <script src="./resources/resizeTestHelper.js"></script>
6 </head>
7 <p>ResizeObserver tests</p>
8 <div id="target1" style="width:100px;height:100px;">t1</div>
9 <div id="target2" style="width:100px;height:100px;">t2</div>
10 <script>
11 'use strict';
12
13 var helper = new ResizeTestHelper();
14
15 let t1 = document.querySelector('#target1');
16 let t2 = document.querySelector('#target2');
17
18 function test0() {
19 helper.createTest(
20 "simple observation",
21 _ => {
22 helper.observer.disconnect();
23 helper.observer.observe(t1);
24 t1.style.width = "5px";
25 },
26 entries => {
27 assert_equals(entries.length, 1, "1 pending notification");
28 assert_equals(entries[0].target, t1, "target is t1");
29 assert_equals(entries[0].contentRect.width, 5, "target width");
30 test1();
31 }
32 );
33 }
34
35 function test1() {
36 helper.createTest(
37 "multiple observation on same element trigger only one",
38 _ => {
39 helper.observer.disconnect();
40 helper.observer.observe(t1);
41 helper.observer.observe(t1);
42 t1.style.width = "10px";
43 },
44 entries => {
45 assert_equals(entries.length, 1, "1 pending notification");
46 test2();
47 }
48 );
49 }
50
51 function test2() {
52 test(_ => {
53 assert_throws(null, _=> {
54 helper.observer.observe({});
55 });
56 test3();
57 },
58 "throw exception when observing non-element"
59 );
60 }
61
62 function test3() {
63 helper.createTest(
64 "disconnect stops all notifications",
65 _ => {
66 helper.observer.observe(t1);
67 helper.observer.observe(t2);
68 helper.observer.disconnect();
69 t1.style.width = "30px";
70 },
71 entries => {
72 assert_unreached("no entries should happen");
73 },
74 _ => {
75 // timeout happened, all is well.
76 test4();
77 }
78 );
79 }
80
81 function test4() {
82 helper.createTest(
83 "unobserve target stops notifications, unobserve non-observed does nothing",
84 _ => {
85 helper.observer.disconnect();
86 helper.observer.observe(t1);
87 helper.observer.observe(t2);
88 helper.observer.unobserve(t1);
89 helper.observer.unobserve(document.body);
90 t1.style.width = "40px";
91 t2.style.width = "40px";
92 },
93 entries => {
94 assert_equals(entries.length, 1, "only t2");
95 assert_equals(entries[0].target, t2, "t2 was observed");
96 }
97 );
98 }
99
100 test0();
101 helper.startTests();
102
103 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698