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

Side by Side Diff: third_party/WebKit/LayoutTests/resize-observer/resources/resizeTestHelper.js

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 'use strict';
2
3 /**
4 ResizeTestHelper is a framework to test ResizeObserver
5 notifications. Use it to make assertions about ResizeObserverEntries.
6
7 It handles timeouts, and queueing of multiple steps in a test.
8
9 */
10 function ResizeTestHelper() {
11 this._pendingTests = [];
12 this._observer = new ResizeObserver(this._handleNotification.bind(this));
13 }
14
15 ResizeTestHelper.prototype = {
16
17 TIMEOUT: 2000,
18
19 // @return ResizeObserver
20 get observer() {
21 return this._observer;
22 },
23
24 _handleNotification: function(entries) {
25 if (this._currentTest) {
26 // console.log("notification");
27 let current = this._currentTest;
28 delete this._currentTest;
29 window.clearTimeout(current.timeoutId);
30 current.test.step(_ => {
31 // console.log("step");
32 let caughtEx = false;
33 try {
34 current.completion(entries);
35 current.test.done();
36 }
37 catch(ex) {
38 caughtEx = ex;
39 }
40 this.startTests();
41 if (caughtEx)
42 throw caughtEx;
43 });
44 }
45 },
46 _handleTimeout: function() {
47 if (this._currentTest) {
48 let current = this._currentTest;
49 delete this._currentTest;
50 if (current.timeout) { // timeout is not an error
51 current.timeout();
52 current.test.done();
53 this.startTests();
54 }
55 else {
56 current.test.step(_ => {
57 assert_unreached("Timed out waiting for notification. (" + this.TIMEOU T + "ms)");
58 current.test.done();
59 this.startTests();
60 });
61 }
62 }
63 },
64
65 /*
66 Kicks off tests. Processes all the tests in order, until
67 _pendingTests is empty
68 */
69 startTests: function() {
70 if (this._currentTest) // only one test at a time
71 return;
72 if (this._pendingTests.length > 0) {
73 this._currentTest = this._pendingTests.shift();
74 this._currentTest.setup();
75 this._currentTest.timeoutId = this._currentTest.test.step_timeout(this._ha ndleTimeout.bind(this), this.TIMEOUT);
76 }
77 },
78
79 /**
80 Adds new test to _pendingTests.
81 */
82 createTest: function(name, setup, completion, timeoutCb) {
83 this._pendingTests.push( {
84 test: async_test(name),
85 setup: setup,
86 completion: completion,
87 timeout: timeoutCb });
88 }
89
90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698