| OLD | NEW |
| 1 var UnitTest = {}; | 1 var UnitTest = {}; |
| 2 (function() | 2 (function() |
| 3 { | 3 { |
| 4 var lazyModules = []; |
| 4 var oldLoadResourcePromise = Runtime.loadResourcePromise; | 5 var oldLoadResourcePromise = Runtime.loadResourcePromise; |
| 5 Runtime.loadResourcePromise = function(url) | 6 Runtime.loadResourcePromise = function(url) |
| 6 { | 7 { |
| 7 if (url.startsWith("/")) | 8 if (url.startsWith("/")) |
| 8 return oldLoadResourcePromise(url); | 9 return oldLoadResourcePromise(url); |
| 9 | 10 |
| 10 if (!url.startsWith("http://")) | 11 if (!url.startsWith("http://")) |
| 11 return oldLoadResourcePromise("/inspector-debug/" + url); | 12 return oldLoadResourcePromise("/inspector-debug/" + url); |
| 12 | 13 |
| 13 var parsedURL = new URL(url, location.href); | 14 var parsedURL = new URL(url, location.href); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 39 outputElement.style.height = "10px"; | 40 outputElement.style.height = "10px"; |
| 40 outputElement.style.overflow = "hidden"; | 41 outputElement.style.overflow = "hidden"; |
| 41 } | 42 } |
| 42 document.documentElement.appendChild(outputElement); | 43 document.documentElement.appendChild(outputElement); |
| 43 for (var i = 0; i < results.length; i++) { | 44 for (var i = 0; i < results.length; i++) { |
| 44 outputElement.appendChild(document.createTextNode(results[i])); | 45 outputElement.appendChild(document.createTextNode(results[i])); |
| 45 outputElement.appendChild(document.createElement("br")); | 46 outputElement.appendChild(document.createElement("br")); |
| 46 } | 47 } |
| 47 results = []; | 48 results = []; |
| 48 testRunner.notifyDone(); | 49 testRunner.notifyDone(); |
| 49 } | 50 }; |
| 50 | 51 |
| 51 UnitTest.addResult = function(text) | 52 UnitTest.addResult = function(text) |
| 52 { | 53 { |
| 53 if (window.testRunner) | 54 if (window.testRunner) |
| 54 results.push(String(text)); | 55 results.push(String(text)); |
| 55 else | 56 else |
| 56 console.log(text); | 57 console.log(text); |
| 57 } | 58 }; |
| 58 | 59 |
| 59 UnitTest.runTests = function(tests) | 60 UnitTest.runTests = function(tests) |
| 60 { | 61 { |
| 61 nextTest(); | 62 nextTest(); |
| 62 | 63 |
| 63 function nextTest() | 64 function nextTest() |
| 64 { | 65 { |
| 65 var test = tests.shift(); | 66 var test = tests.shift(); |
| 66 if (!test) { | 67 if (!test) { |
| 67 UnitTest.completeTest(); | 68 UnitTest.completeTest(); |
| 68 return; | 69 return; |
| 69 } | 70 } |
| 70 UnitTest.addResult("\ntest: " + test.name); | 71 UnitTest.addResult("\ntest: " + test.name); |
| 71 var testPromise = test(); | 72 var testPromise = test(); |
| 72 if (!(testPromise instanceof Promise)) | 73 if (!(testPromise instanceof Promise)) |
| 73 testPromise = Promise.resolve(); | 74 testPromise = Promise.resolve(); |
| 74 testPromise.then(nextTest); | 75 testPromise.then(nextTest); |
| 75 } | 76 } |
| 76 } | 77 }; |
| 78 |
| 79 UnitTest.addSniffer = function(receiver, methodName) |
| 80 { |
| 81 return new Promise(function(resolve, reject) |
| 82 { |
| 83 var original = receiver[methodName]; |
| 84 if (typeof original !== "function") { |
| 85 reject("Cannot find method to override: " + methodName); |
| 86 return; |
| 87 } |
| 88 |
| 89 receiver[methodName] = function(var_args) |
| 90 { |
| 91 try { |
| 92 var result = original.apply(this, arguments); |
| 93 } finally { |
| 94 receiver[methodName] = original; |
| 95 } |
| 96 // In case of exception the override won't be called. |
| 97 try { |
| 98 Array.prototype.push.call(arguments, result); |
| 99 resolve.apply(this, arguments); |
| 100 } catch (e) { |
| 101 reject("Exception in overriden method '" + methodName + "':
" + e); |
| 102 UnitTest.completeTest(); |
| 103 } |
| 104 return result; |
| 105 }; |
| 106 }); |
| 107 }; |
| 108 |
| 109 UnitTest.addDependency = function(lazyModule) |
| 110 { |
| 111 lazyModules.push(lazyModule); |
| 112 }; |
| 113 |
| 114 UnitTest.createKeyEvent = function(key, ctrlKey, altKey, shiftKey, metaKey) |
| 115 { |
| 116 return new KeyboardEvent("keydown", { key: key, bubbles: true, cancelabl
e: true, ctrlKey: ctrlKey, altKey: altKey, shiftKey: shiftKey, metaKey: metaKey
}); |
| 117 }; |
| 77 | 118 |
| 78 function completeTestOnError(message, source, lineno, colno, error) | 119 function completeTestOnError(message, source, lineno, colno, error) |
| 79 { | 120 { |
| 80 UnitTest.addResult("TEST ENDED IN ERROR: " + error.stack); | 121 UnitTest.addResult("TEST ENDED IN ERROR: " + error.stack); |
| 81 UnitTest.completeTest(); | 122 UnitTest.completeTest(); |
| 82 } | 123 } |
| 83 window.onerror = completeTestOnError; | 124 window.onerror = completeTestOnError; |
| 84 | 125 |
| 85 Runtime.startApplication("/inspector-unit/inspector-unit-test").then(runTest
); | 126 Runtime.startApplication("/inspector-unit/inspector-unit-test").then(runTest
); |
| 86 | 127 |
| 87 function runTest() | 128 function runTest() |
| 88 { | 129 { |
| 89 var description = document.body.textContent.trim(); | 130 var description = document.body.textContent.trim(); |
| 90 if (description) | 131 if (description) |
| 91 UnitTest.addResult(description); | 132 UnitTest.addResult(description); |
| 92 | 133 |
| 93 WebInspector.settings = new WebInspector.Settings(new WebInspector.Setti
ngsStorage( | 134 WebInspector.settings = new WebInspector.Settings(new WebInspector.Setti
ngsStorage( |
| 94 {}, | 135 {}, |
| 95 InspectorFrontendHost.setPreference, | 136 InspectorFrontendHost.setPreference, |
| 96 InspectorFrontendHost.removePreference, | 137 InspectorFrontendHost.removePreference, |
| 97 InspectorFrontendHost.clearPreferences)); | 138 InspectorFrontendHost.clearPreferences)); |
| 98 | 139 |
| 140 |
| 99 WebInspector.viewManager = new WebInspector.ViewManager(); | 141 WebInspector.viewManager = new WebInspector.ViewManager(); |
| 100 WebInspector.initializeUIUtils(document, WebInspector.settings.createSet
ting("uiTheme", "default")); | 142 WebInspector.initializeUIUtils(document, WebInspector.settings.createSet
ting("uiTheme", "default")); |
| 143 WebInspector.installComponentRootStyles(document.body); |
| 101 | 144 |
| 102 WebInspector.zoomManager = new WebInspector.ZoomManager(window, Inspecto
rFrontendHost); | 145 WebInspector.zoomManager = new WebInspector.ZoomManager(window, Inspecto
rFrontendHost); |
| 103 WebInspector.inspectorView = WebInspector.InspectorView.instance(); | 146 WebInspector.inspectorView = WebInspector.InspectorView.instance(); |
| 104 WebInspector.ContextMenu.initialize(); | 147 WebInspector.ContextMenu.initialize(); |
| 105 WebInspector.ContextMenu.installHandler(document); | 148 WebInspector.ContextMenu.installHandler(document); |
| 106 WebInspector.Tooltip.installHandler(document); | 149 WebInspector.Tooltip.installHandler(document); |
| 107 | 150 |
| 108 var rootView = new WebInspector.RootView(); | 151 var rootView = new WebInspector.RootView(); |
| 109 WebInspector.inspectorView.show(rootView.element); | 152 WebInspector.inspectorView.show(rootView.element); |
| 110 rootView.attachToDocument(document); | 153 rootView.attachToDocument(document); |
| 111 | 154 Promise.all(lazyModules.map(lazyModule => window.runtime.loadModulePromi
se(lazyModule))).then(test); |
| 112 test(); | |
| 113 } | 155 } |
| 114 })(); | 156 })(); |
| 157 |
| OLD | NEW |