Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 var UnitTest = {}; | 1 var UnitTest = {}; |
| 2 (function() | 2 var startTest; |
| 3 { | 3 (function() { |
| 4 var lazyModules = []; | |
| 5 var oldLoadResourcePromise = Runtime.loadResourcePromise; | 4 var oldLoadResourcePromise = Runtime.loadResourcePromise; |
| 6 Runtime.loadResourcePromise = function(url) | 5 Runtime.loadResourcePromise = function(url) |
| 7 { | 6 { |
| 8 if (url.startsWith("/")) | 7 if (url.startsWith("/")) |
| 9 return oldLoadResourcePromise(url); | 8 return oldLoadResourcePromise(url); |
| 10 | 9 |
| 11 if (!url.startsWith("http://")) | 10 if (!url.startsWith("http://")) |
| 12 return oldLoadResourcePromise("/inspector-debug/" + url); | 11 return oldLoadResourcePromise("/inspector-debug/" + url); |
| 13 | 12 |
| 14 var parsedURL = new URL(url, location.href); | 13 var parsedURL = new URL(url, location.href); |
| 15 var parsedLocation = new URL(location.href); | |
| 16 | 14 |
| 17 // hosted devtools is confused. | 15 // hosted devtools is confused. |
| 18 parsedURL.pathname = parsedURL.pathname.replace('/inspector-unit/', '/in spector-debug/'); | 16 parsedURL.pathname = parsedURL.pathname.replace('/inspector-unit/', '/in spector-debug/'); |
| 19 return oldLoadResourcePromise(parsedURL.toString()); | 17 return oldLoadResourcePromise(parsedURL.toString()); |
| 20 } | 18 }; |
| 21 | 19 |
| 22 if (window.testRunner) { | 20 if (window.testRunner) { |
| 23 testRunner.dumpAsText(); | 21 testRunner.dumpAsText(); |
| 24 testRunner.waitUntilDone(); | 22 testRunner.waitUntilDone(); |
| 25 } | 23 } |
| 26 | 24 |
| 27 var results = []; | 25 var results = []; |
| 28 UnitTest.completeTest = function() | 26 UnitTest.completeTest = function() |
| 29 { | 27 { |
| 30 if (!window.testRunner) { | 28 if (!window.testRunner) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 resolve.apply(this, arguments); | 97 resolve.apply(this, arguments); |
| 100 } catch (e) { | 98 } catch (e) { |
| 101 reject("Exception in overriden method '" + methodName + "': " + e); | 99 reject("Exception in overriden method '" + methodName + "': " + e); |
| 102 UnitTest.completeTest(); | 100 UnitTest.completeTest(); |
| 103 } | 101 } |
| 104 return result; | 102 return result; |
| 105 }; | 103 }; |
| 106 }); | 104 }); |
| 107 }; | 105 }; |
| 108 | 106 |
| 109 UnitTest.addDependency = function(lazyModule) | 107 UnitTest.loadLazyModules = function (lazyModules) { |
| 110 { | 108 return Promise.all(lazyModules.map(lazyModule => window.runtime.loadModu lePromise(lazyModule))); |
| 111 lazyModules.push(lazyModule); | |
| 112 }; | 109 }; |
| 113 | 110 |
| 114 UnitTest.createKeyEvent = function(key, ctrlKey, altKey, shiftKey, metaKey) | 111 UnitTest.createKeyEvent = function(key, ctrlKey, altKey, shiftKey, metaKey) |
| 115 { | 112 { |
| 116 return new KeyboardEvent("keydown", { key: key, bubbles: true, cancelabl e: true, ctrlKey: ctrlKey, altKey: altKey, shiftKey: shiftKey, metaKey: metaKey }); | 113 return new KeyboardEvent("keydown", { key: key, bubbles: true, cancelabl e: true, ctrlKey: ctrlKey, altKey: altKey, shiftKey: shiftKey, metaKey: metaKey }); |
| 117 }; | 114 }; |
| 118 | 115 |
| 119 function completeTestOnError(message, source, lineno, colno, error) | 116 function completeTestOnError(message, source, lineno, colno, error) |
| 120 { | 117 { |
| 121 UnitTest.addResult("TEST ENDED IN ERROR: " + error.stack); | 118 UnitTest.addResult("TEST ENDED IN ERROR: " + error.stack); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 144 | 141 |
| 145 UI.zoomManager = new UI.ZoomManager(window, InspectorFrontendHost); | 142 UI.zoomManager = new UI.ZoomManager(window, InspectorFrontendHost); |
| 146 UI.inspectorView = UI.InspectorView.instance(); | 143 UI.inspectorView = UI.InspectorView.instance(); |
| 147 UI.ContextMenu.initialize(); | 144 UI.ContextMenu.initialize(); |
| 148 UI.ContextMenu.installHandler(document); | 145 UI.ContextMenu.installHandler(document); |
| 149 UI.Tooltip.installHandler(document); | 146 UI.Tooltip.installHandler(document); |
| 150 | 147 |
| 151 var rootView = new UI.RootView(); | 148 var rootView = new UI.RootView(); |
| 152 UI.inspectorView.show(rootView.element); | 149 UI.inspectorView.show(rootView.element); |
| 153 rootView.attachToDocument(document); | 150 rootView.attachToDocument(document); |
| 154 Promise.all(lazyModules.map(lazyModule => window.runtime.loadModulePromi se(lazyModule))).then(test); | 151 executeTestScript(); |
| 152 } | |
| 153 | |
| 154 function executeTestScript() { | |
| 155 fetch(`/inspector-unit/${Runtime.queryParam('test')}`) | |
| 156 .then((data) => data.text()) | |
|
dgozman
2016/11/22 21:59:05
Let's not .then() synchronous actions.
chenwilliam
2016/11/23 00:27:41
The text() method on the Response object from a fe
| |
| 157 .then((testScript) => eval(testScript)) | |
|
dgozman
2016/11/22 21:59:05
Let's wrap the source in closure to improve isolat
chenwilliam
2016/11/23 00:27:41
Done.
| |
| 158 .catch((error) => { | |
| 159 UnitTest.addResult(`Unable to execute test script because of err or: ${error}`); | |
| 160 UnitTest.completeTest(); | |
| 161 }); | |
| 155 } | 162 } |
| 156 })(); | 163 })(); |
| 157 | 164 |
| OLD | NEW |