##// END OF EJS Templates
Fix #4777 and #7887...
Fix #4777 and #7887 The function in charge of actually converting cursor offset to CodeMirror line number and character number was actually crashing when the cursor was at the last character (loop until undefined, then access length of variable, which is undefined). This was hiding a bug in which when you would completer to a single completion pressing tab after as-you-type filtering, the completion would be completed twice. The logic that was supposed to detect whether or not all completions had a common prefix was actually faulty as the common prefix used to be a string but was then changed to an object. Hence the logic to check whether or not there was actually a common prefix was always true, even for empty string, leading to the deletion of the line (replace by '') in some cases.

File last commit:

r19808:df27872a
r20538:ae7f6d6a
Show More
display_image.js
63 lines | 3.3 KiB | application/javascript | JavascriptLexer
//
// Test display of images
//
// The effect of shape metadata is validated,
// using Image(retina=True)
//
// 2x2 black square in b64 jpeg and png
b64_image_data = {
"image/png" : "b'iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAC0lEQVR4nGNgQAYAAA4AAamRc7EA\\nAAAASUVORK5CYII='",
"image/jpeg" : "b'/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a\\nHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIy\\nMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAACAAIDASIA\\nAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA\\nAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3\\nODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm\\np6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA\\nAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx\\nBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK\\nU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3\\nuLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD5/ooo\\noA//2Q=='"
}
casper.notebook_test(function () {
this.test_img_shape = function(fmt, retina) {
this.thenEvaluate(function (b64data, retina) {
IPython.notebook.insert_cell_at_index("code", 0);
var cell = IPython.notebook.get_cell(0);
cell.set_text([
"import base64",
"from IPython.display import display, Image",
"data = base64.decodestring(" + b64data + ")",
"retina = bool(" + retina + ")",
"display(Image(data, retina=retina))"
].join("\n"));
cell.execute();
}, {b64data : b64_image_data[fmt], retina : retina ? 1:0 });
this.wait_for_output(0);
this.then(function() {
var img = this.evaluate(function() {
// get a summary of the image that was just displayed
var cell = IPython.notebook.get_cell(0);
var img = $(cell.output_area.element.find("img")[0]);
return {
src : img.attr("src"),
width : img.width(),
height : img.height(),
width_attr : img.attr("width"),
height_attr : img.attr("height")
};
});
var prefix = "Image('" + fmt + "', retina=" + retina + ") ";
this.test.assertType(img, "object", prefix + "img was displayed");
this.test.assertEquals(img.src.split(',')[0], "data:" + fmt + ";base64",
prefix + "data-uri prefix"
);
var sz = retina ? 1 : 2;
var sz_attr = retina ? "1" : undefined;
this.test.assertEquals(img.height, sz, prefix + "measured height");
this.test.assertEquals(img.width, sz, prefix + "measured width");
this.test.assertEquals(img.height_attr, sz_attr, prefix + "height attr");
this.test.assertEquals(img.width_attr, sz_attr, prefix + "width attr");
});
};
this.test_img_shape("image/png", false);
this.test_img_shape("image/png", true);
this.test_img_shape("image/jpeg", false);
this.test_img_shape("image/jpeg", true);
});