mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 15:05:39 +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
|
|
@ -6,6 +6,7 @@ var path = require('path');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var rimraf = require('rimraf');
|
var rimraf = require('rimraf');
|
||||||
var cp = require('child_process');
|
var cp = require('child_process');
|
||||||
|
var httpServer = require('http-server');
|
||||||
|
|
||||||
var SAMPLES_MDOC_PATH = path.join(__dirname, 'website/playground/playground.mdoc');
|
var SAMPLES_MDOC_PATH = path.join(__dirname, 'website/playground/playground.mdoc');
|
||||||
var WEBSITE_GENERATED_PATH = path.join(__dirname, 'website/playground/samples');
|
var WEBSITE_GENERATED_PATH = path.join(__dirname, 'website/playground/samples');
|
||||||
|
|
@ -340,3 +341,9 @@ gulp.task('website', ['clean-website', 'playground-samples'], function() {
|
||||||
);
|
);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
gulp.task('simpleserver', function(cb) {
|
||||||
|
httpServer.createServer({ root: '../' }).listen(8080);
|
||||||
|
httpServer.createServer({ root: '../' }).listen(8088);
|
||||||
|
console.log('LISTENING on 8080 and 8088');
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
"author": "Microsoft Corporation",
|
"author": "Microsoft Corporation",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"simpleserver": "http-server -c-1 ../",
|
"simpleserver": "gulp simpleserver",
|
||||||
"release": "gulp release",
|
"release": "gulp release",
|
||||||
"website": "gulp website"
|
"website": "gulp website"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
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 loadDevEditor() {
|
||||||
|
return (getQueryStringValue('editor') === 'dev');
|
||||||
|
}
|
||||||
|
|
||||||
function getQueryStringValue (key) {
|
function getQueryStringValue (key) {
|
||||||
return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
|
return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(function() {
|
||||||
// Resolve paths
|
// Resolve paths
|
||||||
// should run the editor and/or plugins from source? (or from the node module)
|
// 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;
|
METADATA.CORE.path = METADATA.CORE.srcPath;
|
||||||
} else {
|
} else {
|
||||||
METADATA.CORE.path = '/monaco-editor/' + METADATA.CORE.path;
|
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 = {};
|
var pathsConfig = {};
|
||||||
METADATA.PLUGINS.forEach(function(plugin) {
|
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({
|
require.config({
|
||||||
paths: pathsConfig
|
paths: pathsConfig
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,10 @@
|
||||||
<a href="./mouse-scrollable-body.html">[scrollable body]</a>
|
<a href="./mouse-scrollable-body.html">[scrollable body]</a>
|
||||||
|
|
|
|
||||||
<a href="./mouse-scrollable-element.html">[scrollable element]</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/>
|
<br/><br/>
|
||||||
|
|
||||||
<div id="bar" style="margin-bottom: 6px;"></div>
|
<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>document.write('<script src="' + METADATA.CORE.path + '/loader.js"><'+'/script>');</script>
|
||||||
<script>
|
<script>
|
||||||
loadEditor(function() {
|
loadEditor(function() {
|
||||||
var ed =monaco.editor.create(document.getElementById('Editor'), {
|
monaco.editor.create(document.getElementById('Editor'), {
|
||||||
value: document.documentElement.innerHTML.split(/\n|></).join('\n'),
|
value: document.documentElement.innerHTML,
|
||||||
language: 'xml'
|
language: 'xml'
|
||||||
});
|
});
|
||||||
ed.deltaDecorations([], [{
|
|
||||||
range: { startLineNumber:1, startColumn:1, endLineNumber:Number.MAX_VALUE, endColumn:Number.MAX_VALUE },
|
|
||||||
options: {
|
|
||||||
hoverMessage: 'come on'
|
|
||||||
}
|
|
||||||
}])
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue