Files
2018-02-02 04:16:08 -05:00

310 lines
8.3 KiB
HTML

<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<!DOCTYPE HTML>
<html>
<!--
Test the formatting of the file name, line and columns are correct in frame components,
with optional columns, unknown and non-URL sources.
-->
<head>
<meta charset="utf-8">
<title>Frame component test</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
</head>
<body>
<pre id="test">
<script src="head.js" type="application/javascript;version=1.8"></script>
<script type="application/javascript;version=1.8">
window.onload = Task.async(function* () {
try {
let ReactDOM = browserRequire("devtools/client/shared/vendor/react-dom");
let React = browserRequire("devtools/client/shared/vendor/react");
let Frame = React.createFactory(browserRequire("devtools/client/shared/components/frame"));
ok(Frame, "Should get Frame");
// Check when there's a column
yield checkFrameComponent({
frame: {
source: "http://myfile.com/mahscripts.js",
line: 55,
column: 10,
}
}, {
file: "mahscripts.js",
line: 55,
column: 10,
shouldLink: true,
tooltip: "View source in Debugger → http://myfile.com/mahscripts.js:55:10",
});
// Check when there's no column
yield checkFrameComponent({
frame: {
source: "http://myfile.com/mahscripts.js",
line: 55,
}
}, {
file: "mahscripts.js",
line: 55,
shouldLink: true,
tooltip: "View source in Debugger → http://myfile.com/mahscripts.js:55",
});
// Check when column === 0
yield checkFrameComponent({
frame: {
source: "http://myfile.com/mahscripts.js",
line: 55,
column: 0,
}
}, {
file: "mahscripts.js",
line: 55,
shouldLink: true,
tooltip: "View source in Debugger → http://myfile.com/mahscripts.js:55",
});
// Check when there's no parseable URL source;
// should not link but should render line/columns
yield checkFrameComponent({
frame: {
source: "self-hosted",
line: 1,
}
}, {
file: "self-hosted",
line: "1",
shouldLink: false,
tooltip: "self-hosted:1",
});
yield checkFrameComponent({
frame: {
source: "self-hosted",
line: 1,
column: 10,
}
}, {
file: "self-hosted",
line: "1",
column: "10",
shouldLink: false,
tooltip: "self-hosted:1:10",
});
// Check when there's no source;
// should not link but should render line/columns
yield checkFrameComponent({
frame: {
line: 1,
}
}, {
file: "(unknown)",
line: "1",
shouldLink: false,
tooltip: "(unknown):1",
});
yield checkFrameComponent({
frame: {
line: 1,
column: 10,
}
}, {
file: "(unknown)",
line: "1",
column: "10",
shouldLink: false,
tooltip: "(unknown):1:10",
});
// Check when there's a column, but no line;
// no line/column info should render
yield checkFrameComponent({
frame: {
source: "http://myfile.com/mahscripts.js",
column: 55,
}
}, {
file: "mahscripts.js",
shouldLink: true,
tooltip: "View source in Debugger → http://myfile.com/mahscripts.js",
});
// Check when line is 0; this should be an invalid
// line option, so don't render line/column
yield checkFrameComponent({
frame: {
source: "http://myfile.com/mahscripts.js",
line: 0,
column: 55,
}
}, {
file: "mahscripts.js",
shouldLink: true,
tooltip: "View source in Debugger → http://myfile.com/mahscripts.js",
});
// Check when source is via Scratchpad; we should render out the
// lines and columns as this is linkable.
yield checkFrameComponent({
frame: {
source: "Scratchpad/1",
line: 10,
column: 50,
}
}, {
file: "Scratchpad/1",
line: 10,
column: 50,
shouldLink: true,
tooltip: "View source in Debugger → Scratchpad/1:10:50",
});
// Check that line and column can be strings
yield checkFrameComponent({
frame: {
source: "http://myfile.com/mahscripts.js",
line: "10",
column: "55",
}
}, {
file: "mahscripts.js",
line: 10,
column: 55,
shouldLink: true,
tooltip: "View source in Debugger → http://myfile.com/mahscripts.js:10:55",
});
// Check that line and column can be strings,
// and that the `0` rendering rules apply when they are strings as well
yield checkFrameComponent({
frame: {
source: "http://myfile.com/mahscripts.js",
line: "0",
column: "55",
}
}, {
file: "mahscripts.js",
shouldLink: true,
tooltip: "View source in Debugger → http://myfile.com/mahscripts.js",
});
// Check that the showFullSourceUrl option works correctly
yield checkFrameComponent({
frame: {
source: "http://myfile.com/mahscripts.js",
line: 0,
},
showFullSourceUrl: true
}, {
file: "http://myfile.com/mahscripts.js",
shouldLink: true,
tooltip: "View source in Debugger → http://myfile.com/mahscripts.js",
});
// Check that the showFunctionName option works correctly
yield checkFrameComponent({
frame: {
functionDisplayName: "myfun",
source: "http://myfile.com/mahscripts.js",
line: 0,
}
}, {
functionName: null,
file: "mahscripts.js",
shouldLink: true,
tooltip: "View source in Debugger → http://myfile.com/mahscripts.js",
});
yield checkFrameComponent({
frame: {
functionDisplayName: "myfun",
source: "http://myfile.com/mahscripts.js",
line: 0,
},
showFunctionName: true
}, {
functionName: "myfun",
file: "mahscripts.js",
shouldLink: true,
tooltip: "View source in Debugger → http://myfile.com/mahscripts.js",
});
// Check that anonymous function name is not displayed unless explicitly enabled
yield checkFrameComponent({
frame: {
source: "http://myfile.com/mahscripts.js",
line: 0,
},
showFunctionName: true
}, {
functionName: null,
file: "mahscripts.js",
shouldLink: true,
tooltip: "View source in Debugger → http://myfile.com/mahscripts.js",
});
yield checkFrameComponent({
frame: {
source: "http://myfile.com/mahscripts.js",
line: 0,
},
showFunctionName: true,
showAnonymousFunctionName: true
}, {
functionName: "<anonymous>",
file: "mahscripts.js",
shouldLink: true,
tooltip: "View source in Debugger → http://myfile.com/mahscripts.js",
});
// Check if file is rendered with "/" for root documents when showEmptyPathAsHost is false
yield checkFrameComponent({
frame: {
source: "http://www.cnn.com/",
line: "1",
},
showEmptyPathAsHost: false,
}, {
file: "/",
line: "1",
shouldLink: true,
tooltip: "View source in Debugger → http://www.cnn.com/:1",
});
// Check if file is rendered with hostname for root documents when showEmptyPathAsHost is true
yield checkFrameComponent({
frame: {
source: "http://www.cnn.com/",
line: "1",
},
showEmptyPathAsHost: true,
}, {
file: "www.cnn.com",
line: "1",
shouldLink: true,
tooltip: "View source in Debugger → http://www.cnn.com/:1",
});
function* checkFrameComponent(input, expected) {
let props = Object.assign({ onClick: () => {} }, input);
let frame = ReactDOM.render(Frame(props), window.document.body);
yield forceRender(frame);
let el = frame.getDOMNode();
let { source } = input.frame;
checkFrameString(Object.assign({ el, source }, expected));
}
} catch (e) {
ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e));
} finally {
SimpleTest.finish();
}
});
</script>
</pre>
</body>
</html>