Add cross origin test cases

This commit is contained in:
Alex Dima 2016-06-24 12:06:32 +02:00
parent 0abdd95fe1
commit e61cf2c079
9 changed files with 102 additions and 18 deletions

View file

@ -6,6 +6,7 @@ var path = require('path');
var fs = require('fs');
var rimraf = require('rimraf');
var cp = require('child_process');
var httpServer = require('http-server');
var SAMPLES_MDOC_PATH = path.join(__dirname, 'website/playground/playground.mdoc');
var WEBSITE_GENERATED_PATH = path.join(__dirname, 'website/playground/samples');
@ -339,4 +340,10 @@ 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');
});

View file

@ -6,7 +6,7 @@
"author": "Microsoft Corporation",
"license": "MIT",
"scripts": {
"simpleserver": "http-server -c-1 ../",
"simpleserver": "gulp simpleserver",
"release": "gulp release",
"website": "gulp website"
},

View 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>

View 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>

View file

@ -0,0 +1,4 @@
self.GlobalEnvironment = {
baseUrl: 'http://localhost:8088/vscode/out/'
};
importScripts('http://localhost:8088/vscode/out/vs/base/worker/workerMain.js');

View 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');

View file

@ -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

View file

@ -20,6 +20,10 @@
<a href="./mouse-scrollable-body.html">[scrollable body]</a>
&nbsp;|&nbsp;
<a href="./mouse-scrollable-element.html">[scrollable element]</a>
&nbsp;|&nbsp;
<a href="./cross-origin-broken.html">[cross origin broken]</a>
&nbsp;|&nbsp;
<a href="./cross-origin-good.html">[cross origin good]</a>
<br/><br/>
<div id="bar" style="margin-bottom: 6px;"></div>

View file

@ -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>