mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 10:25:42 +01:00
Add cross origin test cases
This commit is contained in:
parent
0abdd95fe1
commit
e61cf2c079
9 changed files with 102 additions and 18 deletions
28
test/cross-origin-broken.html
Normal file
28
test/cross-origin-broken.html
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h2>Monaco Editor wrong cross origin</h2>
|
||||
|
||||
<div style="clear:both"></div>
|
||||
<div id="container" style="float:left;width:800px;height:450px;border: 1px solid grey"></div>
|
||||
<div style="clear:both"></div>
|
||||
|
||||
<script src="../metadata.js"></script>
|
||||
<script src="dev-setup.js"></script>
|
||||
<script>document.write('<script src="http://localhost:8088' + METADATA.CORE.path + '/loader.js"><'+'/script>');</script>
|
||||
<script>
|
||||
loadEditor(function() {
|
||||
monaco.editor.create(document.getElementById('container'), {
|
||||
value: document.documentElement.innerHTML,
|
||||
language: 'xml'
|
||||
});
|
||||
}, 'http://localhost:8088');
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
35
test/cross-origin-good.html
Normal file
35
test/cross-origin-good.html
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h2>Monaco Editor cross origin correct</h2>
|
||||
|
||||
<div style="clear:both"></div>
|
||||
<div id="container" style="float:left;width:800px;height:450px;border: 1px solid grey"></div>
|
||||
<div style="clear:both"></div>
|
||||
|
||||
<script src="../metadata.js"></script>
|
||||
<script src="dev-setup.js"></script>
|
||||
<script>
|
||||
window.GlobalEnvironment = {
|
||||
getWorkerUrl: function() {
|
||||
return loadDevEditor() ? 'cross-origin-worker-proxy-dev.js' : 'cross-origin-worker-proxy.js';
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<script>document.write('<script src="http://localhost:8088' + METADATA.CORE.path + '/loader.js"><'+'/script>');</script>
|
||||
<script>
|
||||
loadEditor(function() {
|
||||
monaco.editor.create(document.getElementById('container'), {
|
||||
value: document.documentElement.innerHTML,
|
||||
language: 'xml'
|
||||
});
|
||||
}, 'http://localhost:8088');
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
4
test/cross-origin-worker-proxy-dev.js
Normal file
4
test/cross-origin-worker-proxy-dev.js
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
self.GlobalEnvironment = {
|
||||
baseUrl: 'http://localhost:8088/vscode/out/'
|
||||
};
|
||||
importScripts('http://localhost:8088/vscode/out/vs/base/worker/workerMain.js');
|
||||
4
test/cross-origin-worker-proxy.js
Normal file
4
test/cross-origin-worker-proxy.js
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
self.GlobalEnvironment = {
|
||||
baseUrl: 'http://localhost:8088/monaco-editor/node_modules/monaco-editor-core/min/'
|
||||
};
|
||||
importScripts('http://localhost:8088/monaco-editor/node_modules/monaco-editor-core/min/vs/base/worker/workerMain.js');
|
||||
|
|
@ -1,11 +1,16 @@
|
|||
(function() {
|
||||
function getQueryStringValue (key) {
|
||||
return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
|
||||
}
|
||||
|
||||
function loadDevEditor() {
|
||||
return (getQueryStringValue('editor') === 'dev');
|
||||
}
|
||||
|
||||
function getQueryStringValue (key) {
|
||||
return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
|
||||
}
|
||||
|
||||
(function() {
|
||||
// Resolve paths
|
||||
// should run the editor and/or plugins from source? (or from the node module)
|
||||
if (getQueryStringValue('editor') === 'dev') {
|
||||
if (loadDevEditor()) {
|
||||
METADATA.CORE.path = METADATA.CORE.srcPath;
|
||||
} else {
|
||||
METADATA.CORE.path = '/monaco-editor/' + METADATA.CORE.path;
|
||||
|
|
@ -20,12 +25,15 @@
|
|||
});
|
||||
})();
|
||||
|
||||
function loadEditor(callback) {
|
||||
function loadEditor(callback, PATH_PREFIX) {
|
||||
PATH_PREFIX = PATH_PREFIX || '';
|
||||
var pathsConfig = {};
|
||||
METADATA.PLUGINS.forEach(function(plugin) {
|
||||
pathsConfig[plugin.modulePrefix] = plugin.path;
|
||||
pathsConfig[plugin.modulePrefix] = PATH_PREFIX + plugin.path;
|
||||
});
|
||||
pathsConfig['vs'] = METADATA.CORE.path;
|
||||
pathsConfig['vs'] = PATH_PREFIX + METADATA.CORE.path;
|
||||
|
||||
// console.log(JSON.stringify(pathsConfig, null, '\t'));
|
||||
|
||||
require.config({
|
||||
paths: pathsConfig
|
||||
|
|
|
|||
|
|
@ -20,6 +20,10 @@
|
|||
<a href="./mouse-scrollable-body.html">[scrollable body]</a>
|
||||
|
|
||||
<a href="./mouse-scrollable-element.html">[scrollable element]</a>
|
||||
|
|
||||
<a href="./cross-origin-broken.html">[cross origin broken]</a>
|
||||
|
|
||||
<a href="./cross-origin-good.html">[cross origin good]</a>
|
||||
<br/><br/>
|
||||
|
||||
<div id="bar" style="margin-bottom: 6px;"></div>
|
||||
|
|
|
|||
|
|
@ -15,16 +15,10 @@
|
|||
<script>document.write('<script src="' + METADATA.CORE.path + '/loader.js"><'+'/script>');</script>
|
||||
<script>
|
||||
loadEditor(function() {
|
||||
var ed =monaco.editor.create(document.getElementById('Editor'), {
|
||||
value: document.documentElement.innerHTML.split(/\n|></).join('\n'),
|
||||
monaco.editor.create(document.getElementById('Editor'), {
|
||||
value: document.documentElement.innerHTML,
|
||||
language: 'xml'
|
||||
});
|
||||
ed.deltaDecorations([], [{
|
||||
range: { startLineNumber:1, startColumn:1, endLineNumber:Number.MAX_VALUE, endColumn:Number.MAX_VALUE },
|
||||
options: {
|
||||
hoverMessage: 'come on'
|
||||
}
|
||||
}])
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue