Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
<!-- 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
<!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>
<link
rel="stylesheet"
type="text/css"
/>
</head>
<body>
<pre id="test">
<script src="head.js" type="application/javascript"></script>
<script type="application/javascript">
'use strict'
window.onload = async function () {
try {
const ReactDOM = browserRequire("devtools/client/shared/vendor/react-dom");
const React = browserRequire("devtools/client/shared/vendor/react");
const Frame = React.createFactory(browserRequire("devtools/client/shared/components/Frame"));
ok(Frame, "Should get Frame");
// Check when there's a column
await checkFrameComponent({
}
}, {
file: "mahscripts.js",
line: 55,
column: 10,
shouldLink: true,
});
// Check when there's no column
await checkFrameComponent({
}
}, {
file: "mahscripts.js",
line: 55,
shouldLink: true,
});
// Check when column === 0
await checkFrameComponent({
}
}, {
file: "mahscripts.js",
line: 55,
shouldLink: true,
});
// Check when there's an error in CSS (View source in Style Editor)
await checkFrameComponent({
},
messageSource: "css",
}, {
file: "cafebabe.css",
line: 13,
shouldLink: true,
});
// Check when there's no parseable URL source;
// should not link but should render line/columns
await checkFrameComponent({
frame: {
source: "self-hosted",
line: 1,
}
}, {
file: "self-hosted",
line: "1",
shouldLink: false,
tooltip: "self-hosted:1",
});
await 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
await checkFrameComponent({
frame: {
line: 1,
}
}, {
file: "(unknown)",
line: "1",
shouldLink: false,
tooltip: "(unknown):1",
});
await 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
await checkFrameComponent({
}
}, {
file: "mahscripts.js",
shouldLink: true,
});
// Check when line is 0; this should be an invalid
// line option, so don't render line/column
await checkFrameComponent({
}
}, {
file: "mahscripts.js",
shouldLink: true,
});
// Check that line and column can be strings
await checkFrameComponent({
}
}, {
file: "mahscripts.js",
line: 10,
column: 55,
shouldLink: true,
});
// Check that line and column can be strings,
// and that the `0` rendering rules apply when they are strings as well
await checkFrameComponent({
}
}, {
file: "mahscripts.js",
shouldLink: true,
});
// Check that the showFullSourceUrl option works correctly
await checkFrameComponent({
},
showFullSourceUrl: true
}, {
shouldLink: true,
});
// Check that the showFunctionName option works correctly
await checkFrameComponent({
}
}, {
functionName: null,
file: "mahscripts.js",
shouldLink: true,
});
await checkFrameComponent({
},
showFunctionName: true
}, {
functionName: "myfun",
file: "mahscripts.js",
shouldLink: true,
});
// Check that anonymous function name is not displayed unless explicitly enabled
await checkFrameComponent({
},
showFunctionName: true
}, {
functionName: null,
file: "mahscripts.js",
shouldLink: true,
});
await checkFrameComponent({
},
showFunctionName: true,
showAnonymousFunctionName: true
}, {
functionName: "<anonymous>",
file: "mahscripts.js",
shouldLink: true,
});
// Check if file is rendered with "/" for root documents when showEmptyPathAsHost is false
await checkFrameComponent({
},
showEmptyPathAsHost: false,
}, {
file: "/",
line: "1",
shouldLink: true,
});
// Check if file is rendered with hostname for root documents when showEmptyPathAsHost is true
await checkFrameComponent({
},
showEmptyPathAsHost: true,
}, {
file: "www.cnn.com",
line: "1",
shouldLink: true,
});
const resolvedLocation = {
sourceId: "whatever",
line: 23,
};
const mockSourceMapURLService = {
subscribeByLocation (loc, callback) {
// Resolve immediately.
callback({
url: resolvedLocation.sourceUrl,
line: resolvedLocation.line,
column: undefined,
});
return () => {};
},
};
await checkFrameComponent({
},
sourceMapURLService: mockSourceMapURLService,
}, {
file: "original.js",
line: resolvedLocation.line,
shouldLink: true,
});
// Check when a message comes from a logPoint,
// a prefix should render before source
await checkFrameComponent({
frame: {
line: 55,
column: 10,
options: { logPoint: true },
}
}, {
file: "mahscripts.js",
line: 55,
column: 10,
shouldLink: true,
});
function checkFrameComponent(input, expected) {
const props = Object.assign({ onClick: () => {} }, input);
const frame = ReactDOM.render(Frame(props), window.document.body);
const el = ReactDOM.findDOMNode(frame);
const { source } = input.frame;
checkFrameString(Object.assign({ el, source }, expected));
ReactDOM.unmountComponentAtNode(window.document.body);
}
} catch (e) {
ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e));
} finally {
SimpleTest.finish();
}
};
</script>
</pre>
</body>
</html>