Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <html> | |
| 2 <head> | |
| 3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspecto r-protocol-test.js"></script> | |
| 4 <script> | |
| 5 | |
| 6 var callback; | |
| 7 function createPromise() | |
| 8 { | |
| 9 return new Promise(fulfill => callback = fulfill); | |
| 10 } | |
| 11 | |
| 12 function fulfillPromise() | |
| 13 { | |
| 14 callback(239); | |
| 15 callback = undefined; | |
| 16 } | |
| 17 | |
| 18 function runGC() | |
| 19 { | |
| 20 if (window.gc) | |
| 21 window.gc(); | |
| 22 } | |
| 23 | |
| 24 function test() | |
| 25 { | |
| 26 InspectorTest.runTestSuite([ | |
| 27 function testResolvedPromise(next) | |
| 28 { | |
| 29 InspectorTest.runtimeEvaluatePromise("Promise.resolve(239)") | |
| 30 .then((result) => InspectorTest.runtimePromiseThenPromise(result .result.result.objectId, /* returnByValue */ false, /* generatePreview */ true)) | |
| 31 .then((result) => InspectorTest.logObject(result.result)) | |
| 32 .then(() => next()); | |
| 33 }, | |
| 34 | |
| 35 function testRejectedPromise(next) | |
| 36 { | |
| 37 InspectorTest.runtimeEvaluatePromise("Promise.reject({ a : 1 })") | |
| 38 .then((result) => InspectorTest.runtimePromiseThenPromise(result .result.result.objectId, /* returnByValue */ true, /* generatePreview */ false)) | |
| 39 .then((result) => InspectorTest.logObject(result.result)) | |
| 40 .then(() => next()); | |
| 41 }, | |
| 42 | |
| 43 function testPengingPromise(next) | |
|
dgozman
2016/07/28 00:07:56
typo: pending
kozy
2016/07/28 22:54:09
Done.
| |
| 44 { | |
| 45 InspectorTest.runtimeEvaluatePromise("createPromise()") | |
| 46 .then((result) => scheduleFulfillAndPromiseThen(result)) | |
| 47 .then((result) => InspectorTest.logObject(result.result)) | |
| 48 .then(() => next()); | |
| 49 | |
| 50 function scheduleFulfillAndPromiseThen(result) | |
| 51 { | |
| 52 setTimeout(() => InspectorTest.runtimeEvaluatePromise("fulfillPr omise()"), 0); | |
| 53 return InspectorTest.runtimePromiseThenPromise(result.result.res ult.objectId); | |
| 54 } | |
| 55 }, | |
| 56 | |
| 57 function testResolvedWithoutArgsPromise(next) | |
| 58 { | |
| 59 InspectorTest.runtimeEvaluatePromise("Promise.resolve()") | |
| 60 .then((result) => InspectorTest.runtimePromiseThenPromise(result .result.result.objectId)) | |
| 61 .then((result) => InspectorTest.logObject(result.result)) | |
| 62 .then(() => next()); | |
| 63 }, | |
| 64 | |
| 65 function testGarbageCollectedPromise(next) | |
| 66 { | |
| 67 InspectorTest.runtimeEvaluatePromise("new Promise(() => undefined)") | |
| 68 .then((result) => scheduleGCAndPromiseThen(result)) | |
| 69 .then((result) => InspectorTest.logObject(result.error)) | |
| 70 .then(() => next()); | |
| 71 | |
| 72 function scheduleGCAndPromiseThen(result) | |
| 73 { | |
| 74 var objectId = result.result.result.objectId; | |
| 75 setTimeout(gcPromise.bind(null, objectId), 0); | |
|
dgozman
2016/07/28 00:07:56
Let's try without setTimeout.
kozy
2016/07/28 22:54:09
Done.
| |
| 76 return InspectorTest.runtimePromiseThenPromise(objectId); | |
| 77 } | |
| 78 | |
| 79 function gcPromise(objectId) | |
| 80 { | |
| 81 InspectorTest.runtimeReleaseObjectPromise(objectId) | |
| 82 .then(() => InspectorTest.runtimeEvaluatePromise("runGC()")) ; | |
| 83 } | |
| 84 } | |
| 85 ]); | |
| 86 } | |
| 87 </script> | |
| 88 </head> | |
| 89 <body onLoad="runTest();"> | |
| 90 Tests that Runtime.promiseThen works. | |
| 91 </body> | |
| 92 </html> | |
| OLD | NEW |