 Chromium Code Reviews
 Chromium Code Reviews Issue 1382743002:
  bluetooth: Add characteristicvaluechanged event  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-notifications-1
    
  
    Issue 1382743002:
  bluetooth: Add characteristicvaluechanged event  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-notifications-1| Index: third_party/WebKit/LayoutTests/bluetooth/resources/bluetooth-helpers.js | 
| diff --git a/third_party/WebKit/LayoutTests/bluetooth/resources/bluetooth-helpers.js b/third_party/WebKit/LayoutTests/bluetooth/resources/bluetooth-helpers.js | 
| index bb1450720a564819b6bcdd92a741092ca0d00040..ffd70fb8fe03e5f0b77db0f7f94d29a2417dc02c 100644 | 
| --- a/third_party/WebKit/LayoutTests/bluetooth/resources/bluetooth-helpers.js | 
| +++ b/third_party/WebKit/LayoutTests/bluetooth/resources/bluetooth-helpers.js | 
| @@ -132,5 +132,39 @@ function runGarbageCollection() | 
| GCController.collect(); | 
| setTimeout(resolve, 0); | 
| }); | 
| - return Promise.resolve(); | 
| +} | 
| + | 
| +function event_after_promise(object, func, event) { | 
| 
Jeffrey Yasskin
2015/10/15 23:00:51
Comment what this does.
A better name might be as
 
ortuno
2015/10/16 01:24:21
Yeah I thought about that but I wasn't sure if I a
 | 
| + if (object[func] === undefined) { | 
| + return Promise.reject('Function \'' + func + '\' not available in object.'); | 
| + } | 
| + let should_resolve = false; | 
| + let event_promise = new Promise((resolve, reject) => { | 
| + let event_listener = (e) => { | 
| + object.removeEventListener(event_listener); | 
| + if (should_resolve) { | 
| + resolve(e.target.value); | 
| + } else { | 
| + reject(event + ' was triggered before the promise resolved.'); | 
| + } | 
| + }; | 
| + object.addEventListener(event, event_listener); | 
| + }); | 
| + return object[func]().then(result => { | 
| + should_resolve = true; | 
| + return Promise.all([Promise.resolve(result), | 
| + event_promise]); | 
| + }); | 
| +} | 
| + | 
| +// Returns a promise that resolves after 100ms unless | 
| +// the the event is fired on the object in which case | 
| +// the promise rejects. | 
| +function assert_no_events(object, event_name) { | 
| + return new Promise((resolve, reject) => { | 
| + object.addEventListener(event_name, event => { | 
| 
Jeffrey Yasskin
2015/10/15 23:00:51
You probably need to remove this listener, so that
 
ortuno
2015/10/16 01:24:21
Done.
 | 
| + assert_unreached('Object should not throw an event'); | 
| 
Jeffrey Yasskin
2015/10/15 23:00:51
s/throw/fire/, matching https://dom.spec.whatwg.or
 
ortuno
2015/10/16 01:24:21
Ah I was wondering what was the correct term.
Done
 | 
| + }); | 
| + setTimeout(resolve, 100); | 
| + }); | 
| } |