 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| OLD | NEW | 
|---|---|
| 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 Loading... | |
| 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 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
 | |
| 138 if (object[func] === undefined) { | |
| 139 return Promise.reject('Function \'' + func + '\' not available in object.'); | |
| 140 } | |
| 141 let should_resolve = false; | |
| 142 let event_promise = new Promise((resolve, reject) => { | |
| 143 let event_listener = (e) => { | |
| 144 object.removeEventListener(event_listener); | |
| 145 if (should_resolve) { | |
| 146 resolve(e.target.value); | |
| 147 } else { | |
| 148 reject(event + ' was triggered before the promise resolved.'); | |
| 149 } | |
| 150 }; | |
| 151 object.addEventListener(event, event_listener); | |
| 152 }); | |
| 153 return object[func]().then(result => { | |
| 154 should_resolve = true; | |
| 155 return Promise.all([Promise.resolve(result), | |
| 156 event_promise]); | |
| 157 }); | |
| 158 } | |
| 159 | |
| 160 // Returns a promise that resolves after 100ms unless | |
| 161 // the the event is fired on the object in which case | |
| 162 // the promise rejects. | |
| 163 function assert_no_events(object, event_name) { | |
| 164 return new Promise((resolve, reject) => { | |
| 165 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.
 | |
| 166 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
 | |
| 167 }); | |
| 168 setTimeout(resolve, 100); | |
| 169 }); | |
| 170 } | |
| OLD | NEW |