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

Unified 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: Update to master: Vector<WeakMember> no longer ok. Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/resize-observer/resources/resizeTestHelper.js
diff --git a/third_party/WebKit/LayoutTests/resize-observer/resources/resizeTestHelper.js b/third_party/WebKit/LayoutTests/resize-observer/resources/resizeTestHelper.js
new file mode 100644
index 0000000000000000000000000000000000000000..83b21ad86fc084d9c2084cd8f6e39ad43545588d
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/resize-observer/resources/resizeTestHelper.js
@@ -0,0 +1,90 @@
+'use strict';
+
+/**
+ ResizeTestHelper is a framework to test ResizeObserver
+ notifications. Use it to make assertions about ResizeObserverEntries.
+
+ It handles timeouts, and queueing of multiple steps in a test.
+
+*/
+function ResizeTestHelper() {
+ this._pendingTests = [];
+ this._observer = new ResizeObserver(this._handleNotification.bind(this));
+}
+
+ResizeTestHelper.prototype = {
+
+ TIMEOUT: 2000,
+
+ // @return ResizeObserver
+ get observer() {
+ return this._observer;
+ },
+
+ _handleNotification: function(entries) {
+ if (this._currentTest) {
+ // console.log("notification");
+ let current = this._currentTest;
+ delete this._currentTest;
+ window.clearTimeout(current.timeoutId);
+ current.test.step(_ => {
+ // console.log("step");
+ let caughtEx = false;
+ try {
+ current.completion(entries);
+ current.test.done();
+ }
+ catch(ex) {
+ caughtEx = ex;
+ }
+ this.startTests();
+ if (caughtEx)
+ throw caughtEx;
+ });
+ }
+ },
+ _handleTimeout: function() {
+ if (this._currentTest) {
+ let current = this._currentTest;
+ delete this._currentTest;
+ if (current.timeout) { // timeout is not an error
+ current.timeout();
+ current.test.done();
+ this.startTests();
+ }
+ else {
+ current.test.step(_ => {
+ assert_unreached("Timed out waiting for notification. (" + this.TIMEOUT + "ms)");
+ current.test.done();
+ this.startTests();
+ });
+ }
+ }
+ },
+
+ /*
+ Kicks off tests. Processes all the tests in order, until
+ _pendingTests is empty
+ */
+ startTests: function() {
+ if (this._currentTest) // only one test at a time
+ return;
+ if (this._pendingTests.length > 0) {
+ this._currentTest = this._pendingTests.shift();
+ this._currentTest.setup();
+ this._currentTest.timeoutId = this._currentTest.test.step_timeout(this._handleTimeout.bind(this), this.TIMEOUT);
+ }
+ },
+
+ /**
+ Adds new test to _pendingTests.
+ */
+ createTest: function(name, setup, completion, timeoutCb) {
+ this._pendingTests.push( {
+ test: async_test(name),
+ setup: setup,
+ completion: completion,
+ timeout: timeoutCb });
+ }
+
+}

Powered by Google App Engine
This is Rietveld 408576698