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

Side by Side 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, 3 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var nativesPromise = requireAsync('testNatives'); 5 var nativesPromise = requireAsync('testNatives');
6 var sendRequestNatives = requireNative('sendRequest');
6 7
7 function registerHooks(api) { 8 function registerHooks(api) {
8 var chromeTest = api.compiledApi; 9 var chromeTest = api.compiledApi;
9 var apiFunctions = api.apiFunctions; 10 var apiFunctions = api.apiFunctions;
10 11
11 apiFunctions.setHandleRequest('notifyPass', function() { 12 apiFunctions.setHandleRequest('notifyPass', function() {
12 nativesPromise.then(function(natives) { 13 nativesPromise.then(function(natives) {
13 natives.NotifyPass(); 14 natives.NotifyPass();
14 }); 15 });
15 }); 16 });
(...skipping 18 matching lines...) Expand all
34 Promise.resolve().then(function() { 35 Promise.resolve().then(function() {
35 runNextTest(); 36 runNextTest();
36 }); 37 });
37 } 38 }
38 39
39 function exportTests(tests, runTests, exports) { 40 function exportTests(tests, runTests, exports) {
40 $Array.forEach(tests, function(test) { 41 $Array.forEach(tests, function(test) {
41 exports[test.name] = function() { 42 exports[test.name] = function() {
42 runTests([test]); 43 runTests([test]);
43 return true; 44 return true;
44 } 45 };
45 }); 46 });
46 } 47 }
47 48
49 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.
50 this.timeouts_ = {};
51 this.nextTimeoutId_ = 0;
52 this.currentTime = 0;
53 this.timeoutCreationPromise_ = null;
54 this.timeoutCreationPromiseResolve__ = null;
55 }
56
57 TimeoutManager.prototype.setTimeout_ = function(target, timeoutMs) {
58 var timeoutId = this.nextTimeoutId_++;
59 this.timeouts_[timeoutId] = {
60 target: target,
61 timeMs: timeoutMs + this.currentTime,
62 };
63 if (this.timeoutCreationPromiseResolve_) {
64 this.timeoutCreationPromiseResolve_();
65 this.timeoutCreationPromiseResolve_ = null;
66 } else {
67 this.timeoutCreationPromise_ = Promise.resolve();
68 }
69 return timeoutId;
70 };
71
72 TimeoutManager.prototype.clearTimeout_ = function(timeoutId) {
73 if (this.timeouts_[timeoutId])
74 delete this.timeouts_[timeoutId];
75 };
76
77 TimeoutManager.prototype.installGlobals = function() {
78 var global = sendRequestNatives.GetGlobal({});
79 global.setTimeout = this.setTimeout_.bind(this);
80 global.clearTimeout = this.clearTimeout_.bind(this);
81 };
82
83 TimeoutManager.prototype.advanceTime = function(timeDeltaMs) {
84 this.currentTime += timeDeltaMs;
85 var keys = $Object.keys(this.timeouts_);
86 for (var i = 0; i < keys.length; i++) {
87 var timeout = this.timeouts_[keys[i]];
88 if (this.currentTime >= timeout.timeMs) {
89 delete this.timeouts_[keys[i]];
90 try {
91 timeout.target();
92 } catch (e) {
93 console.log('error calling timeout target ' + e.stack);
94 }
95 }
96 }
97 };
98
99 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.
100 if (!this.timeoutCreationPromise_) {
101 this.timeoutCreationPromise_ = new Promise(function(resolve, reject) {
102 this.timeoutCreationPromiseResolve_ = resolve;
103 });
104 }
105 return this.timeoutCreationPromise_;
106 };
107
108 TimeoutManager.prototype.clearTimeoutCreated = function() {
109 this.timeoutCreationPromise_ = null;
110 this.timeoutCreationPromiseResolve_ = null;
111 };
112
48 exports.registerHooks = registerHooks; 113 exports.registerHooks = registerHooks;
49 exports.testDone = testDone; 114 exports.testDone = testDone;
50 exports.exportTests = exportTests; 115 exports.exportTests = exportTests;
116 exports.TimeoutManager = TimeoutManager;
OLDNEW
« 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