From e61cf2c079e8b7003bae2d70b2b694c2991a9607 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Fri, 24 Jun 2016 12:06:32 +0200 Subject: [PATCH] Add cross origin test cases --- gulpfile.js | 9 ++++++- package.json | 2 +- test/cross-origin-broken.html | 28 +++++++++++++++++++++ test/cross-origin-good.html | 35 +++++++++++++++++++++++++++ test/cross-origin-worker-proxy-dev.js | 4 +++ test/cross-origin-worker-proxy.js | 4 +++ test/dev-setup.js | 24 ++++++++++++------ test/index.html | 4 +++ test/mouse-fixed.html | 10 ++------ 9 files changed, 102 insertions(+), 18 deletions(-) create mode 100644 test/cross-origin-broken.html create mode 100644 test/cross-origin-good.html create mode 100644 test/cross-origin-worker-proxy-dev.js create mode 100644 test/cross-origin-worker-proxy.js diff --git a/gulpfile.js b/gulpfile.js index e7b017d9..d0c5bc42 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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() { })) ); -}); \ No newline at end of file +}); + +gulp.task('simpleserver', function(cb) { + httpServer.createServer({ root: '../' }).listen(8080); + httpServer.createServer({ root: '../' }).listen(8088); + console.log('LISTENING on 8080 and 8088'); +}); diff --git a/package.json b/package.json index b196dbef..6f431e7f 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "author": "Microsoft Corporation", "license": "MIT", "scripts": { - "simpleserver": "http-server -c-1 ../", + "simpleserver": "gulp simpleserver", "release": "gulp release", "website": "gulp website" }, diff --git a/test/cross-origin-broken.html b/test/cross-origin-broken.html new file mode 100644 index 00000000..252c1988 --- /dev/null +++ b/test/cross-origin-broken.html @@ -0,0 +1,28 @@ + + + + + + + + +

Monaco Editor wrong cross origin

+ +
+
+
+ + + + + + + + \ No newline at end of file diff --git a/test/cross-origin-good.html b/test/cross-origin-good.html new file mode 100644 index 00000000..c4849d62 --- /dev/null +++ b/test/cross-origin-good.html @@ -0,0 +1,35 @@ + + + + + + + + +

Monaco Editor cross origin correct

+ +
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/test/cross-origin-worker-proxy-dev.js b/test/cross-origin-worker-proxy-dev.js new file mode 100644 index 00000000..94db2d65 --- /dev/null +++ b/test/cross-origin-worker-proxy-dev.js @@ -0,0 +1,4 @@ +self.GlobalEnvironment = { + baseUrl: 'http://localhost:8088/vscode/out/' +}; +importScripts('http://localhost:8088/vscode/out/vs/base/worker/workerMain.js'); \ No newline at end of file diff --git a/test/cross-origin-worker-proxy.js b/test/cross-origin-worker-proxy.js new file mode 100644 index 00000000..d0669c27 --- /dev/null +++ b/test/cross-origin-worker-proxy.js @@ -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'); \ No newline at end of file diff --git a/test/dev-setup.js b/test/dev-setup.js index d2af3b56..11b4b568 100644 --- a/test/dev-setup.js +++ b/test/dev-setup.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 diff --git a/test/index.html b/test/index.html index 6ae9a623..3bb72444 100644 --- a/test/index.html +++ b/test/index.html @@ -20,6 +20,10 @@ [scrollable body]  |  [scrollable element] + |  +[cross origin broken] + |  +[cross origin good]

diff --git a/test/mouse-fixed.html b/test/mouse-fixed.html index 9e6d5f08..a5a801af 100644 --- a/test/mouse-fixed.html +++ b/test/mouse-fixed.html @@ -15,16 +15,10 @@