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

Side by Side Diff: third_party/WebKit/LayoutTests/bluetooth/resources/bluetooth-helpers.js

Issue 1382743002: bluetooth: Add characteristicvaluechanged event (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-notifications-1
Patch Set: Address more comments Created 5 years, 2 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 'use strict'; 1 'use strict';
2 2
3 // Sometimes we need to test that using either the name, alias, or UUID 3 // Sometimes we need to test that using either the name, alias, or UUID
4 // produces the same result. The following objects help us do that. 4 // produces the same result. The following objects help us do that.
5 var generic_access = { 5 var generic_access = {
6 alias: 0x1800, 6 alias: 0x1800,
7 name: 'generic_access', 7 name: 'generic_access',
8 uuid: '00001800-0000-1000-8000-00805f9b34fb' 8 uuid: '00001800-0000-1000-8000-00805f9b34fb'
9 }; 9 };
10 var device_name = { 10 var device_name = {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 125 }
126 126
127 function runGarbageCollection() 127 function runGarbageCollection()
128 { 128 {
129 // Run gc() as a promise. 129 // Run gc() as a promise.
130 return new Promise( 130 return new Promise(
131 function(resolve, reject) { 131 function(resolve, reject) {
132 GCController.collect(); 132 GCController.collect();
133 setTimeout(resolve, 0); 133 setTimeout(resolve, 0);
134 }); 134 });
135 return Promise.resolve();
136 } 135 }
136
137 // Creates |num_listeners| promises. Each adds an event listener
138 // to object. The promises resolve once the object fires |event| but
139 // reject if the event is fired before |object|.|func|() resolves.
140 // Returns a promise that fulfills with the result of |object|.|func()|
141 // and |event.target.value| of each of the other promises.
142 function assert_event_fires_after_promise(object, func, event, num_listeners) {
143 num_listeners = num_listeners !== undefined ? num_listeners : 1;
144
145 if (object[func] === undefined) {
146 return Promise.reject('Function \'' + func + '\' not available in object.');
147 }
148 let should_resolve = false;
149 let event_promises = [];
150 for (let i = 0; i < num_listeners; i++) {
151 event_promises.push(new Promise((resolve, reject) => {
152 let event_listener = (e) => {
153 object.removeEventListener(event, event_listener);
154 if (should_resolve) {
155 resolve(e.target.value);
156 } else {
157 reject(event + ' was triggered before the promise resolved.');
158 }
159 };
160 object.addEventListener(event, event_listener);
161 }));
162 }
163 return object[func]().then(result => {
164 should_resolve = true;
165 return Promise.all([result, ...event_promises]);
166 });
167 }
168
169 // Returns a promise that resolves after 100ms unless
scheib 2015/10/16 20:39:25 Timers in tests are super bad, causing flake or te
ortuno 2015/10/16 21:55:49 The idea behind the setTimeout is to add an event
scheib 2015/10/17 19:33:43 Either: The task just needs to be placed in the q
ortuno 2015/10/19 18:23:47 Added TODO that points to http://crbug.com/543884
170 // the the event is fired on the object in which case
171 // the promise rejects.
172 function assert_no_events(object, event_name) {
173 return new Promise((resolve, reject) => {
174 let event_listener = (e) => {
175 object.removeEventListener(event_name, event_listener);
176 assert_unreached('Object should not fire an event.');
177 };
178 object.addEventListener(event_name, event_listener);
179 setTimeout(() => {
180 object.removeEventListener(event_name, event_listener);
181 resolve();
182 }, 100);
183 });
184 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698