Uploaded Test files

This commit is contained in:
Batuhan Berk Başoğlu 2020-11-12 11:05:57 -05:00
parent f584ad9d97
commit 2e81cb7d99
16627 changed files with 2065359 additions and 102444 deletions

View file

@ -0,0 +1,58 @@
casper.notebook_test(function () {
this.on('remote.callback', function(data){
if(data.error_expected){
that.test.assertEquals(
data.error,
true,
"!highlight: " + data.provided + " errors"
);
}else{
that.test.assertEquals(
data.observed,
data.expected,
"highlight: " + data.provided + " as " + data.expected
);
}
});
var that = this;
// syntax highlighting
[
{to: "gfm"},
{to: "python"},
{to: "ipython"},
{to: "ipythongfm"},
{to: "text/x-markdown", from: [".md"]},
{to: "text/x-python", from: [".py", "Python"]},
{to: "application/json", from: ["json", "JSON"]},
{to: "text/x-ruby", from: [".rb", "ruby", "Ruby"]},
{to: "application/ld+json", from: ["json-ld", "JSON-LD"]},
{from: [".pyc"], error: true},
{from: ["../"], error: true},
{from: ["//"], error: true},
].map(function (mode) {
(mode.from || []).concat(mode.to || []).map(function(from){
casper.evaluate(function(from, expected, error_expected){
IPython.utils.requireCodeMirrorMode(from, function(observed){
window.callPhantom({
provided: from,
expected: expected,
observed: observed,
error_expected: error_expected
});
}, function(error){
window.callPhantom({
provided: from,
expected: expected,
error: true,
error_expected: error_expected
});
});
}, {
from: from,
expected: mode.to,
error_expected: mode.error
});
});
});
});

View file

@ -0,0 +1,95 @@
var normalized_shortcuts = [
'ctrl-shift-m',
'alt-meta-p',
];
var to_normalize = [
['shift-%', 'shift-5'],
['ShiFT-MeTa-CtRl-AlT-m', 'alt-ctrl-meta-shift-m'],
];
var unshifted = "` 1 2 3 4 5 6 7 8 9 0 - = q w e r t y u i o p [ ] \\ a s d f g h j k l ; ' z x c v b n m , . /";
// shifted = '~ ! @ # $ % ^ & * ( ) _ + Q W E R T Y U I O P { } | A S D F G H J K L : " Z X C V B N M < > ?';
var ambiguous_expect = function(ch){
// `-` is ambiguous in shortcut context as a separator, so map it to `minus`
if(ch === '-'){
return 'minus';
}
return ch;
};
casper.notebook_test(function () {
var that = this;
this.then(function () {
this.each(unshifted.split(' '), function (self, item) {
var result = this.evaluate(function (sc) {
var e = IPython.keyboard.shortcut_to_event(sc);
var sc2 = IPython.keyboard.event_to_shortcut(e);
return sc2;
}, item);
this.test.assertEquals(result, ambiguous_expect(item), 'Shortcut to event roundtrip: '+item);
});
});
this.then(function () {
this.each(to_normalize, function (self, item) {
var result = this.evaluate(function (pair) {
return IPython.keyboard.normalize_shortcut(pair[0]);
}, item);
this.test.assertEquals(result, item[1], 'Normalize shortcut: '+item[0]);
});
});
this.then(function () {
this.each(normalized_shortcuts, function (self, item) {
var result = this.evaluate(function (sc) {
var e = IPython.keyboard.shortcut_to_event(sc);
var sc2 = IPython.keyboard.event_to_shortcut(e);
return sc2;
}, item);
this.test.assertEquals(result, item, 'Shortcut to event roundtrip: '+item);
});
});
this.then(function(){
var shortcuts_test = {
'i,e,e,e,e,e' : '[[5E]]',
'i,d,d,q,d' : '[[TEST1]]',
'i,d,d' : '[[TEST1 WILL BE SHADOWED]]',
'i,d,k' : '[[SHOULD SHADOW TEST2]]',
'i,d,k,r,q' : '[[TEST2 NOT SHADOWED]]',
';,up,down,up,down,left,right,left,right,b,a' : '[[KONAMI]]',
'ctrl-x,meta-c,meta-b,u,t,t,e,r,f,l,y' : '[[XKCD]]'
};
that.msgs = [];
that.on('remote.message', function(msg) {
that.msgs.push(msg);
});
that.evaluate(function (obj) {
for(var k in obj){
if ({}.hasOwnProperty.call(obj, k)) {
IPython.keyboard_manager.command_shortcuts.add_shortcut(k, function(){console.log(obj[k]);});
}
}
}, shortcuts_test);
var longer_first = false;
var longer_last = false;
for(var m in that.msgs){
if ({}.hasOwnProperty.call(that.msgs, m)) {
longer_first = longer_first||(that.msgs[m].match(/you are overriting/)!= null);
longer_last = longer_last ||(that.msgs[m].match(/will be shadowed/) != null);
}
}
this.test.assert(longer_first, 'no warning if registering shorter shortcut');
this.test.assert(longer_last , 'no warning if registering longer shortcut');
});
});

View file

@ -0,0 +1,45 @@
//
// Miscellaneous javascript tests
//
casper.notebook_test(function () {
var jsver = this.evaluate(function () {
var cell = IPython.notebook.get_cell(0);
cell.set_text('import notebook; print(notebook.__version__)');
cell.execute();
return IPython.version;
});
this.wait_for_output(0);
// refactor this into just a get_output(0)
this.then(function () {
var result = this.get_output_cell(0);
this.test.assertEquals(result.text.trim(), jsver, 'IPython.version in JS matches server-side.');
});
// verify that requirejs loads the same CodeCell prototype at runtime as build time
this.thenEvaluate(function () {
require(['notebook/js/codecell'], function (codecell) {
codecell.CodeCell.prototype.test = function () {
return 'ok';
}
window._waitForMe = true;
})
})
this.waitFor(function () {
return this.evaluate(function () {
return window._waitForMe;
});
})
this.then(function () {
var result = this.evaluate(function () {
var cell = Jupyter.notebook.get_cell(0);
return cell.test();
});
this.test.assertEquals(result, 'ok', "runtime-requirejs loads the same modules")
})
});

View file

@ -0,0 +1,57 @@
safe_tests = [
"<p>Hi there</p>",
'<h1 class="foo">Hi There!</h1>',
'<a data-cite="foo">citation</a>',
'<div><span>Hi There</span></div>',
];
unsafe_tests = [
"<script>alert(999);</script>",
'<a onmouseover="alert(999)">999</a>',
'<a onmouseover=alert(999)>999</a>',
'<IMG """><SCRIPT>alert("XSS")</SCRIPT>">',
'<IMG SRC=# onmouseover="alert(999)">',
'<<SCRIPT>alert(999);//<</SCRIPT>',
'<SCRIPT SRC=http://ha.ckers.org/xss.js?< B >',
'<META HTTP-EQUIV="refresh" CONTENT="0;url=data:text/html base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K">',
'<META HTTP-EQUIV="refresh" CONTENT="0; URL=http://;URL=javascript:alert(999);">',
'<IFRAME SRC="javascript:alert(999);"></IFRAME>',
'<IFRAME SRC=# onmouseover="alert(document.cookie)"></IFRAME>',
'<EMBED SRC="data:image/svg+xml;base64,PHN2ZyB4bWxuczpzdmc9Imh0dH A6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcv MjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hs aW5rIiB2ZXJzaW9uPSIxLjAiIHg9IjAiIHk9IjAiIHdpZHRoPSIxOTQiIGhlaWdodD0iMjAw IiBpZD0ieHNzIj48c2NyaXB0IHR5cGU9InRleHQvZWNtYXNjcmlwdCI+YWxlcnQoIlh TUyIpOzwvc2NyaXB0Pjwvc3ZnPg==" type="image/svg+xml" AllowScriptAccess="always"></EMBED>',
// CSS is scrubbed
'<style src="http://untrusted/style.css"></style>',
'<style>div#notebook { background-color: alert-red; }</style>',
'<div style="background-color: alert-red;"></div>',
];
var truncate = function (s, n) {
// truncate a string with an ellipsis
if (s.length > n) {
return s.substr(0, n-3) + '...';
} else {
return s;
}
};
casper.notebook_test(function () {
this.each(safe_tests, function (self, item) {
var sanitized = self.evaluate(function (item) {
return IPython.security.sanitize_html(item);
}, item);
// string equality may be too strict, but it works for now
this.test.assertEquals(sanitized, item, "Safe: '" + truncate(item, 32) + "'");
});
this.each(unsafe_tests, function (self, item) {
var sanitized = self.evaluate(function (item) {
return IPython.security.sanitize_html(item);
}, item);
this.test.assertNotEquals(sanitized, item,
"Sanitized: '" + truncate(item, 32) +
"' => '" + truncate(sanitized, 32) + "'"
);
this.test.assertEquals(sanitized.indexOf("alert"), -1, "alert removed");
});
});

View file

@ -0,0 +1,93 @@
casper.notebook_test(function () {
// Test fixConsole
// Note, \u001b is the unicode notation of octal \033 which is not officially in js
var input = [
"\u001b[0m[\u001b[0minfo\u001b[0m] \u001b[0mtext\u001b[0m",
"\u001b[0m[\u001b[33mwarn\u001b[0m] \u001b[0m\tmore text\u001b[0m",
"\u001b[0m[\u001b[33mwarn\u001b[0m] \u001b[0m https://some/url/to/a/file.ext\u001b[0m",
"\u001b[0m[\u001b[31merror\u001b[0m] \u001b[0m\u001b[0m",
"\u001b[0m[\u001b[31merror\u001b[0m] \u001b[0m\teven more text\u001b[0m",
"\u001b[?25hBuilding wheels for collected packages: scipy",
"\x1b[38;5;28;01mtry\x1b[39;00m",
"\u001b[0m[\u001b[31merror\u001b[0m] \u001b[0m\t\tand more more text\u001b[0m",
"normal\x1b[43myellowbg\x1b[35mmagentafg\x1b[1mbold\x1b[49mdefaultbg\x1b[39mdefaultfg\x1b[22mnormal",
].join("\n");
var output = [
"[info] text",
'[<span class="ansi-yellow-fg">warn</span>] \tmore text',
'[<span class="ansi-yellow-fg">warn</span>] https://some/url/to/a/file.ext',
'[<span class="ansi-red-fg">error</span>] ',
'[<span class="ansi-red-fg">error</span>] \teven more text',
"Building wheels for collected packages: scipy",
'<span class="ansi-bold" style="color: rgb(0,135,0)">try</span>',
'[<span class="ansi-red-fg">error</span>] \t\tand more more text',
'normal<span class="ansi-yellow-bg">yellowbg</span><span class="ansi-magenta-fg ansi-yellow-bg">magentafg</span><span class="ansi-magenta-intense-fg ansi-yellow-bg ansi-bold">bold</span><span class="ansi-magenta-intense-fg ansi-bold">defaultbg</span><span class="ansi-bold">defaultfg</span>normal',
].join("\n");
var result = this.evaluate(function (input) {
return IPython.utils.fixConsole(input);
}, input);
this.test.assertEquals(result, output, "IPython.utils.fixConsole() handles [0m correctly");
// Test fixOverwrittenChars
var overwriting_test_cases = [
{input: "ABC\rDEF", result: "DEF"},
{input: "ABC\r\nDEF", result: "ABC\nDEF"},
{input: "123\b456", result: "12456"},
{input: "123\n\b456", result: "123\n\b456"},
{input: "\b456", result: "\b456"}
];
var that = this;
overwriting_test_cases.forEach(function(testcase){
var result = that.evaluate(function (input) {
return IPython.utils.fixOverwrittenChars(input);
}, testcase.input);
that.test.assertEquals(result, testcase.result, "Overwriting characters processed");
});
var input = [
'hasrn\r\n',
'hasn\n',
'\n',
'abcdef\r',
'hello\n',
'ab3\r',
'x2\r\r',
'1\r',
].join('');
var output = [
'hasrn\n',
'hasn\n',
'\n',
'hellof\n',
'123\r'
].join('');
var result = this.evaluate(function (input) {
return IPython.utils.fixCarriageReturn(input);
}, input);
this.test.assertEquals(result, output, "IPython.utils.fixCarriageReturns works");
// Test load_extensions
this.thenEvaluate(function() {
define('nbextensions/a', [], function() { window.a = true; });
define('nbextensions/c', [], function() { window.c = true; });
require(['base/js/utils'], function(utils) {
utils.load_extensions('a', 'b', 'c');
});
}).then(function() {
this.waitFor(function() {
return this.evaluate(function() { return window.a; });
});
this.waitFor(function() {
return this.evaluate(function() { return window.a; });
});
});
});