Chromium Code Reviews| 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); | |
|
lushnikov
2016/11/01 22:35:32
let's end test?
| |
| 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 } | |
| 103 return result; | |
| 104 }; | |
| 105 }); | |
| 106 }; | |
| 107 | |
| 108 UnitTest.addDependency = function(lazyModule) | |
| 109 { | |
| 110 lazyModules.push(lazyModule); | |
| 111 }; | |
| 112 | |
| 113 UnitTest.createKeyEvent = function(key, ctrlKey, altKey, shiftKey, metaKey) | |
| 114 { | |
| 115 return new KeyboardEvent("keydown", { key: key, bubbles: true, cancelabl e: true, ctrlKey: ctrlKey, altKey: altKey, shiftKey: shiftKey, metaKey: metaKey }); | |
| 116 }; | |
| 77 | 117 |
| 78 function completeTestOnError(message, source, lineno, colno, error) | 118 function completeTestOnError(message, source, lineno, colno, error) |
| 79 { | 119 { |
| 80 UnitTest.addResult("TEST ENDED IN ERROR: " + error.stack); | 120 UnitTest.addResult("TEST ENDED IN ERROR: " + error.stack); |
| 81 UnitTest.completeTest(); | 121 UnitTest.completeTest(); |
| 82 } | 122 } |
| 83 window.onerror = completeTestOnError; | 123 window.onerror = completeTestOnError; |
| 84 | 124 |
| 85 Runtime.startApplication("/inspector-unit/inspector-unit-test").then(runTest ); | 125 Runtime.startApplication("/inspector-unit/inspector-unit-test").then(runTest ); |
| 86 | 126 |
| 87 function runTest() | 127 function runTest() |
| 88 { | 128 { |
| 89 var description = document.body.textContent.trim(); | 129 var description = document.body.textContent.trim(); |
| 90 if (description) | 130 if (description) |
| 91 UnitTest.addResult(description); | 131 UnitTest.addResult(description); |
| 92 | 132 |
| 93 WebInspector.settings = new WebInspector.Settings(new WebInspector.Setti ngsStorage( | 133 WebInspector.settings = new WebInspector.Settings(new WebInspector.Setti ngsStorage( |
| 94 {}, | 134 {}, |
| 95 InspectorFrontendHost.setPreference, | 135 InspectorFrontendHost.setPreference, |
| 96 InspectorFrontendHost.removePreference, | 136 InspectorFrontendHost.removePreference, |
| 97 InspectorFrontendHost.clearPreferences)); | 137 InspectorFrontendHost.clearPreferences)); |
| 98 | 138 |
| 139 | |
| 99 WebInspector.viewManager = new WebInspector.ViewManager(); | 140 WebInspector.viewManager = new WebInspector.ViewManager(); |
| 100 WebInspector.initializeUIUtils(document, WebInspector.settings.createSet ting("uiTheme", "default")); | 141 WebInspector.initializeUIUtils(document, WebInspector.settings.createSet ting("uiTheme", "default")); |
| 142 WebInspector.installComponentRootStyles(document.body); | |
| 101 | 143 |
| 102 WebInspector.zoomManager = new WebInspector.ZoomManager(window, Inspecto rFrontendHost); | 144 WebInspector.zoomManager = new WebInspector.ZoomManager(window, Inspecto rFrontendHost); |
| 103 WebInspector.inspectorView = WebInspector.InspectorView.instance(); | 145 WebInspector.inspectorView = WebInspector.InspectorView.instance(); |
| 104 WebInspector.ContextMenu.initialize(); | 146 WebInspector.ContextMenu.initialize(); |
| 105 WebInspector.ContextMenu.installHandler(document); | 147 WebInspector.ContextMenu.installHandler(document); |
| 106 WebInspector.Tooltip.installHandler(document); | 148 WebInspector.Tooltip.installHandler(document); |
| 107 | 149 |
| 108 var rootView = new WebInspector.RootView(); | 150 var rootView = new WebInspector.RootView(); |
| 109 WebInspector.inspectorView.show(rootView.element); | 151 WebInspector.inspectorView.show(rootView.element); |
| 110 rootView.attachToDocument(document); | 152 rootView.attachToDocument(document); |
| 111 | 153 Promise.all(lazyModules.map(lazyModule => window.runtime.loadModulePromi se(lazyModule))).then(test); |
| 112 test(); | |
| 113 } | 154 } |
| 114 })(); | 155 })(); |
| OLD | NEW |