| OLD | NEW |
| 1 <html> | 1 <html> |
| 2 <head> | 2 <head> |
| 3 <script src="../../http/tests/inspector/inspector-test.js"></script> | 3 <script src="../../http/tests/inspector/inspector-test.js"></script> |
| 4 <script src="../../http/tests/inspector/console-test.js"></script> | 4 <script src="../../http/tests/inspector/console-test.js"></script> |
| 5 <script> | 5 <script> |
| 6 | 6 |
| 7 function runPromises(source) | 7 var tested = 0; |
| 8 function runNextPromiseTest() |
| 8 { | 9 { |
| 9 Promise.reject(new Error(source + ".err1")) | 10 ++tested; |
| 11 var name = "promiseTest" + tested; |
| 12 if (typeof window[name] !== "function") |
| 13 return false; |
| 14 // setTimeout to cut off VM call frames from the stack trace. |
| 15 setTimeout(function timeout() { |
| 16 window[name].call(window); |
| 17 }, 0); |
| 18 return true; |
| 19 } |
| 20 |
| 21 function promiseTest1() |
| 22 { |
| 23 Promise.reject(new Error("err1")) |
| 10 .then() | 24 .then() |
| 11 .then() | 25 .then() |
| 12 .then(); // Last is unhandled. | 26 .then(); // Last is unhandled. |
| 27 } |
| 13 | 28 |
| 29 function promiseTest2() |
| 30 { |
| 14 var reject | 31 var reject |
| 15 var m0 = new Promise(function(res, rej) { reject = rej; }); | 32 var m0 = new Promise(function(res, rej) { reject = rej; }); |
| 16 var m1 = m0.then(function() {}); | 33 var m1 = m0.then(function() {}); |
| 17 var m2 = m0.then(function() {}); | 34 var m2 = m0.then(function() {}); |
| 18 var m3 = m0.then(function() {}); | 35 var m3 = m0.then(function() {}); |
| 19 var m4 = 0; | 36 var m4 = 0; |
| 20 m0.catch(function() { | 37 m0.catch(function() { |
| 21 m2.catch(function() { | 38 m2.catch(function() { |
| 22 m1.catch(function() { | 39 m1.catch(function() { |
| 23 m4 = m3.then(function() {}); // Unhandled. | 40 m4 = m3.then(function() {}); // Unhandled. |
| 24 if (source === "onload") | |
| 25 scheduleRunTests(); | |
| 26 }); | 41 }); |
| 27 }); | 42 }); |
| 28 }); | 43 }); |
| 29 reject(new Error(source + ".err2")); | 44 reject(new Error("err2")); |
| 30 } | 45 } |
| 31 | 46 |
| 32 function onload() | 47 function promiseTest3() |
| 33 { | 48 { |
| 34 runPromises("onload"); | 49 var reject; |
| 50 var p = new Promise(function(res, rej) { |
| 51 reject = rej; |
| 52 }); |
| 53 p.then().catch(function catcher() { |
| 54 throwDOMException(); |
| 55 }); |
| 56 reject(new Error("FAIL: Should not be printed to console")); |
| 35 | 57 |
| 36 if (window.testRunner) { | 58 function throwDOMException() |
| 37 testRunner.dumpAsText(); | 59 { |
| 38 testRunner.waitUntilDone(); | 60 var a = document.createElement("div"); |
| 61 var b = document.createElement("div"); |
| 62 a.removeChild(b); |
| 39 } | 63 } |
| 40 } | 64 } |
| 41 | 65 |
| 42 function runPromisesFromInspector() | |
| 43 { | |
| 44 // setTimeout to cut off VM call frames from the stack trace. | |
| 45 setTimeout(function timeout() { | |
| 46 runPromises("inspector") | |
| 47 }, 0); | |
| 48 } | |
| 49 | |
| 50 function scheduleRunTests() | |
| 51 { | |
| 52 // Run tests after all microtasks. | |
| 53 Promise.resolve().then(function() { | |
| 54 setTimeout(runTest, 0); | |
| 55 }); | |
| 56 } | |
| 57 | |
| 58 function test() | 66 function test() |
| 59 { | 67 { |
| 60 InspectorTest.addConsoleViewSniffer(checkConsoleMessages, true); | 68 InspectorTest.addConsoleViewSniffer(checkConsoleMessages, true); |
| 61 WebInspector.console.showPromise().done(); | 69 WebInspector.console.showPromise().done(); |
| 62 | 70 |
| 63 checkConsoleMessages(); | 71 checkConsoleMessages(); |
| 64 | 72 |
| 65 function checkConsoleMessages() | 73 function checkConsoleMessages() |
| 66 { | 74 { |
| 67 var count = InspectorTest.consoleMessagesCount(); | 75 InspectorTest.evaluateInPage("runNextPromiseTest()", callback); |
| 68 if (count === 2) | 76 |
| 69 InspectorTest.evaluateInPage("runPromisesFromInspector()"); | 77 function callback(result) |
| 70 else if (count === 4) | 78 { |
| 71 InspectorTest.expandConsoleMessages(dump); | 79 if (!result.value) |
| 80 InspectorTest.expandConsoleMessages(dump); |
| 81 } |
| 72 } | 82 } |
| 73 | 83 |
| 74 function dump() | 84 function dump() |
| 75 { | 85 { |
| 76 InspectorTest.dumpConsoleMessages(false, false, InspectorTest.textConten
tWithLineBreaks); | 86 InspectorTest.dumpConsoleMessages(false, false, InspectorTest.textConten
tWithLineBreaks); |
| 77 InspectorTest.completeTest(); | 87 InspectorTest.completeTest(); |
| 78 } | 88 } |
| 79 } | 89 } |
| 80 | 90 |
| 81 </script> | 91 </script> |
| 82 </head> | 92 </head> |
| 83 | 93 |
| 84 <body onload="onload()"> | 94 <body onload="runTest()"> |
| 85 <p> | 95 <p> |
| 86 Tests that uncaught promise rejections are logged into console. | 96 Tests that uncaught promise rejections are logged into console. |
| 87 </p> | 97 </p> |
| 88 | 98 |
| 89 </body> | 99 </body> |
| 90 </html> | 100 </html> |
| OLD | NEW |