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

Unified Diff: extensions/test/data/unit_test_environment_specific_bindings.js

Issue 509813002: Implement the client side of Serial I/O on data pipe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@serial-io
Patch Set: Created 6 years, 4 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: extensions/test/data/unit_test_environment_specific_bindings.js
diff --git a/extensions/test/data/unit_test_environment_specific_bindings.js b/extensions/test/data/unit_test_environment_specific_bindings.js
index 245d050d6325400bc5c7722c790620dc9a8d83aa..19ceb7672b4a9d90ad141afe5bb506497af561fb 100644
--- a/extensions/test/data/unit_test_environment_specific_bindings.js
+++ b/extensions/test/data/unit_test_environment_specific_bindings.js
@@ -3,6 +3,7 @@
// found in the LICENSE file.
var nativesPromise = requireAsync('testNatives');
+var sendRequestNatives = requireNative('sendRequest');
function registerHooks(api) {
var chromeTest = api.compiledApi;
@@ -41,10 +42,75 @@ function exportTests(tests, runTests, exports) {
exports[test.name] = function() {
runTests([test]);
return true;
- }
+ };
});
}
+function TimeoutManager() {
raymes 2014/08/29 06:07:16 Comment about what this does would be nice and wha
Sam McNally 2014/09/01 06:35:19 Done.
+ this.timeouts_ = {};
+ this.nextTimeoutId_ = 0;
+ this.currentTime = 0;
+ this.timeoutCreationPromise_ = null;
+ this.timeoutCreationPromiseResolve__ = null;
+}
+
+TimeoutManager.prototype.setTimeout_ = function(target, timeoutMs) {
+ var timeoutId = this.nextTimeoutId_++;
+ this.timeouts_[timeoutId] = {
+ target: target,
+ timeMs: timeoutMs + this.currentTime,
+ };
+ if (this.timeoutCreationPromiseResolve_) {
+ this.timeoutCreationPromiseResolve_();
+ this.timeoutCreationPromiseResolve_ = null;
+ } else {
+ this.timeoutCreationPromise_ = Promise.resolve();
+ }
+ return timeoutId;
+};
+
+TimeoutManager.prototype.clearTimeout_ = function(timeoutId) {
+ if (this.timeouts_[timeoutId])
+ delete this.timeouts_[timeoutId];
+};
+
+TimeoutManager.prototype.installGlobals = function() {
+ var global = sendRequestNatives.GetGlobal({});
+ global.setTimeout = this.setTimeout_.bind(this);
+ global.clearTimeout = this.clearTimeout_.bind(this);
+};
+
+TimeoutManager.prototype.advanceTime = function(timeDeltaMs) {
+ this.currentTime += timeDeltaMs;
+ var keys = $Object.keys(this.timeouts_);
+ for (var i = 0; i < keys.length; i++) {
+ var timeout = this.timeouts_[keys[i]];
+ if (this.currentTime >= timeout.timeMs) {
+ delete this.timeouts_[keys[i]];
+ try {
+ timeout.target();
+ } catch (e) {
+ console.log('error calling timeout target ' + e.stack);
+ }
+ }
+ }
+};
+
+TimeoutManager.prototype.timeoutCreated = function() {
raymes 2014/08/29 06:07:16 Maybe we can just have a function which sets the a
Sam McNally 2014/09/01 06:35:19 Reworked as discussed.
+ if (!this.timeoutCreationPromise_) {
+ this.timeoutCreationPromise_ = new Promise(function(resolve, reject) {
+ this.timeoutCreationPromiseResolve_ = resolve;
+ });
+ }
+ return this.timeoutCreationPromise_;
+};
+
+TimeoutManager.prototype.clearTimeoutCreated = function() {
+ this.timeoutCreationPromise_ = null;
+ this.timeoutCreationPromiseResolve_ = null;
+};
+
exports.registerHooks = registerHooks;
exports.testDone = testDone;
exports.exportTests = exportTests;
+exports.TimeoutManager = TimeoutManager;
« extensions/test/data/serial_unittest.js ('K') | « extensions/test/data/serial_unittest.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698