mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add support for Page.getResourceTree
Unfortunately we don't yet have a way to walk into imports, so this only is the first-level of the source tree, but this is a huge step forward. You can now click to set breakpoints, however setting breakpoints crashes sky. I had to fix Console.log to flush stdout so that I could actually debug my timing-out test. Also had to fix Chai to dump differences for deepEqual. R=esprehn@chromium.org, abarth@chromium.org, esprhen@chromium.org Review URL: https://codereview.chromium.org/732413004
This commit is contained in:
parent
593c8f8de3
commit
0ca1069cd4
@ -249,6 +249,7 @@ void ChromeClientImpl::addMessageToConsole(LocalFrame* localFrame, MessageSource
|
||||
printf("ERROR: %s \nSOURCE: %s:%u\n", message.utf8().data(), sourceID.utf8().data(), lineNumber);
|
||||
else
|
||||
printf("CONSOLE: %s: %s\n", messageLevelAsString(level).utf8().data(), message.utf8().data());
|
||||
fflush(stdout);
|
||||
|
||||
WebLocalFrameImpl* frame = WebLocalFrameImpl::fromFrame(localFrame);
|
||||
if (frame && frame->client()) {
|
||||
|
||||
@ -19,13 +19,13 @@ Page.prototype.canEmulate = function() {
|
||||
};
|
||||
};
|
||||
|
||||
Page.prototype.getResourceContent = function(params, message_id) {
|
||||
Page.prototype.getResourceContent = function(params, messageId) {
|
||||
var request = new XMLHttpRequest;
|
||||
request.onload = function() {
|
||||
var message = {
|
||||
'content' : request.responseText,
|
||||
};
|
||||
this.delegate_.sendResponse(message_id, message);
|
||||
this.delegate_.sendResponse(messageId, message);
|
||||
}.bind(this);
|
||||
request.open("GET", params.url);
|
||||
request.send();
|
||||
@ -33,6 +33,57 @@ Page.prototype.getResourceContent = function(params, message_id) {
|
||||
return this.delegate_.ASYNC_RESPONSE;
|
||||
};
|
||||
|
||||
// FIXME: ES6 has Array.from which theoretically does this.
|
||||
function arrayFromIterator(iterator) {
|
||||
var a = [];
|
||||
for (var e of iterator)
|
||||
a.push(e);
|
||||
return a;
|
||||
}
|
||||
|
||||
// FIXME: NodeList will soon inherit from array.
|
||||
function forEachInNodeList(array, callback, scope) {
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
callback.call(scope, array[i]);
|
||||
}
|
||||
};
|
||||
|
||||
function addResource(map, url, type, mimeType) {
|
||||
// Be sure to string the url object since has(new Object)
|
||||
// will always return false.
|
||||
var absoluteURL = String(new URL(url, document.URL));
|
||||
if (map.has(absoluteURL))
|
||||
return;
|
||||
map.set(absoluteURL, {
|
||||
'url': String(absoluteURL),
|
||||
'type': type,
|
||||
'mimeType': mimeType,
|
||||
})
|
||||
}
|
||||
|
||||
function resourcesMapForSubtree(root_doc) {
|
||||
var map = new Map;
|
||||
var roots = [root_doc];
|
||||
while (roots.length) {
|
||||
var root = roots.pop();
|
||||
var elements = root.querySelectorAll('*');
|
||||
forEachInNodeList(elements, function(element) {
|
||||
if (element.tagName == "import") {
|
||||
// FIXME: It's no longer possible to walk into an import. :(
|
||||
// roots.push(element.import);
|
||||
addResource(map, element.getAttribute('src'), 'Document', 'text/html');
|
||||
} else if (element.tagName == "img") {
|
||||
// FIXME: Can't determine the type of an image from the DOM.
|
||||
addResource(map, element.getAttribute('src'), 'Image', 'image/unknown');
|
||||
}
|
||||
if (element.shadowRoot) {
|
||||
roots.push(element.shadowRoot);
|
||||
}
|
||||
});
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
Page.prototype.getResourceTree = function() {
|
||||
// Unclear if this is all needed, but if we don't return something here
|
||||
// the inspector hits an exception in WebInspector.ResourceTreeModel.
|
||||
@ -41,11 +92,11 @@ Page.prototype.getResourceTree = function() {
|
||||
"frame": {
|
||||
"id": "1",
|
||||
"loaderId": "1",
|
||||
"url": document.URL,
|
||||
"url": String(document.URL),
|
||||
"mimeType": "text/html",
|
||||
"securityOrigin": document.URL,
|
||||
"securityOrigin": String(document.URL),
|
||||
},
|
||||
"resources": [], // FIXME
|
||||
"resources": arrayFromIterator(resourcesMapForSubtree(document).values()),
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
Running 1 tests
|
||||
ok 1 PageAgent.getResourceTree should dump the current resource tree
|
||||
1 tests
|
||||
1 pass
|
||||
0 fail
|
||||
43
tests/inspector/page-agent-get-resource-tree.sky
Normal file
43
tests/inspector/page-agent-get-resource-tree.sky
Normal file
@ -0,0 +1,43 @@
|
||||
<html>
|
||||
<import src="/sky/tests/resources/chai.sky" />
|
||||
<import src="/sky/tests/resources/mocha.sky" />
|
||||
<import src="/sky/framework/inspector/page-agent.sky" as="PageAgent" />
|
||||
<img src='does_not_exist.jpg' />
|
||||
<script>
|
||||
describe('PageAgent.getResourceTree', function() {
|
||||
it('should dump the current resource tree', function() {
|
||||
var pageAgent = new PageAgent();
|
||||
pageAgent.enable();
|
||||
var resourceTree = pageAgent.getResourceTree();
|
||||
assert.deepEqual(resourceTree, {
|
||||
"frameTree": {
|
||||
"frame": {
|
||||
"id": "1",
|
||||
"loaderId": "1",
|
||||
"url": "http://127.0.0.1:8000/sky/tests/inspector/page-agent-get-resource-tree.sky",
|
||||
"mimeType": "text/html",
|
||||
"securityOrigin": "http://127.0.0.1:8000/sky/tests/inspector/page-agent-get-resource-tree.sky"
|
||||
},
|
||||
"resources": [{
|
||||
"url": "http://127.0.0.1:8000/sky/tests/resources/chai.sky",
|
||||
"type": "Document",
|
||||
"mimeType": "text/html"
|
||||
}, {
|
||||
"url": "http://127.0.0.1:8000/sky/tests/resources/mocha.sky",
|
||||
"type": "Document",
|
||||
"mimeType": "text/html"
|
||||
}, {
|
||||
"url": "http://127.0.0.1:8000/sky/framework/inspector/page-agent.sky",
|
||||
"type": "Document",
|
||||
"mimeType": "text/html"
|
||||
}, {
|
||||
"url": "http://127.0.0.1:8000/sky/tests/inspector/does_not_exist.jpg",
|
||||
"type": "Image",
|
||||
"mimeType": "image/unknown"
|
||||
}]
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</html>
|
||||
@ -967,7 +967,7 @@ module.exports = {
|
||||
* @api public
|
||||
*/
|
||||
|
||||
includeStack: false,
|
||||
includeStack: true,
|
||||
|
||||
/**
|
||||
* ### config.showDiff
|
||||
@ -999,7 +999,7 @@ module.exports = {
|
||||
* @api public
|
||||
*/
|
||||
|
||||
truncateThreshold: 40
|
||||
truncateThreshold: 0
|
||||
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user