Show More
@@ -213,11 +213,11 b' define([' | |||||
213 | json.text = content.text; |
|
213 | json.text = content.text; | |
214 | json.name = content.name; |
|
214 | json.name = content.name; | |
215 | } else if (msg_type === "display_data") { |
|
215 | } else if (msg_type === "display_data") { | |
216 | json = content.data; |
|
216 | json.data = content.data; | |
217 | json.output_type = msg_type; |
|
217 | json.output_type = msg_type; | |
218 | json.metadata = content.metadata; |
|
218 | json.metadata = content.metadata; | |
219 | } else if (msg_type === "execute_result") { |
|
219 | } else if (msg_type === "execute_result") { | |
220 | json = content.data; |
|
220 | json.data = content.data; | |
221 | json.output_type = msg_type; |
|
221 | json.output_type = msg_type; | |
222 | json.metadata = content.metadata; |
|
222 | json.metadata = content.metadata; | |
223 | json.execution_count = content.execution_count; |
|
223 | json.execution_count = content.execution_count; | |
@@ -258,15 +258,14 b' define([' | |||||
258 |
|
258 | |||
259 | OutputArea.prototype.validate_output = function (json) { |
|
259 | OutputArea.prototype.validate_output = function (json) { | |
260 | // scrub invalid outputs |
|
260 | // scrub invalid outputs | |
261 | // TODO: right now everything is a string, but JSON really shouldn't be. |
|
261 | var data = json.data; | |
262 | // nbformat 4 will fix that. |
|
|||
263 | $.map(OutputArea.output_types, function(key){ |
|
262 | $.map(OutputArea.output_types, function(key){ | |
264 | if (key !== 'application/json' && |
|
263 | if (key !== 'application/json' && | |
265 |
|
|
264 | data[key] !== undefined && | |
266 |
typeof |
|
265 | typeof data[key] !== 'string' | |
267 | ) { |
|
266 | ) { | |
268 |
console.log("Invalid type for " + key, |
|
267 | console.log("Invalid type for " + key, data[key]); | |
269 |
delete |
|
268 | delete data[key]; | |
270 | } |
|
269 | } | |
271 | }); |
|
270 | }); | |
272 | return json; |
|
271 | return json; | |
@@ -276,7 +275,9 b' define([' | |||||
276 | this.expand(); |
|
275 | this.expand(); | |
277 |
|
276 | |||
278 | // validate output data types |
|
277 | // validate output data types | |
279 | json = this.validate_output(json); |
|
278 | if (json.data) { | |
|
279 | json = this.validate_output(json); | |||
|
280 | } | |||
280 |
|
281 | |||
281 | // Clear the output if clear is queued. |
|
282 | // Clear the output if clear is queued. | |
282 | var needs_height_reset = false; |
|
283 | var needs_height_reset = false; | |
@@ -517,8 +518,8 b' define([' | |||||
517 | for (var i=0; i < OutputArea.display_order.length; i++) { |
|
518 | for (var i=0; i < OutputArea.display_order.length; i++) { | |
518 | var type = OutputArea.display_order[i]; |
|
519 | var type = OutputArea.display_order[i]; | |
519 | var append = OutputArea.append_map[type]; |
|
520 | var append = OutputArea.append_map[type]; | |
520 | if ((json[type] !== undefined) && append) { |
|
521 | if ((json.data[type] !== undefined) && append) { | |
521 | var value = json[type]; |
|
522 | var value = json.data[type]; | |
522 | if (!this.trusted && !OutputArea.safe_outputs[type]) { |
|
523 | if (!this.trusted && !OutputArea.safe_outputs[type]) { | |
523 | // not trusted, sanitize HTML |
|
524 | // not trusted, sanitize HTML | |
524 | if (type==='text/html' || type==='text/svg') { |
|
525 | if (type==='text/html' || type==='text/svg') { | |
@@ -804,7 +805,7 b' define([' | |||||
804 | // replace with plaintext version in stdout |
|
805 | // replace with plaintext version in stdout | |
805 | this.append_output(content, false); |
|
806 | this.append_output(content, false); | |
806 | this.events.trigger('send_input_reply.Kernel', value); |
|
807 | this.events.trigger('send_input_reply.Kernel', value); | |
807 | } |
|
808 | }; | |
808 |
|
809 | |||
809 |
|
810 | |||
810 | OutputArea.prototype.handle_clear_output = function (msg) { |
|
811 | OutputArea.prototype.handle_clear_output = function (msg) { |
@@ -24,13 +24,13 b' var svg = "\\"<svg width=\'1cm\' height=\'1cm\' viewBox=\'0 0 1000 500\'><defs><style>r' | |||||
24 | // name, and that fromJSON also gets its long mimetype name |
|
24 | // name, and that fromJSON also gets its long mimetype name | |
25 | function assert_has(short_name, json, result, result2) { |
|
25 | function assert_has(short_name, json, result, result2) { | |
26 | long_name = mime[short_name]; |
|
26 | long_name = mime[short_name]; | |
27 | this.test.assertFalse(json[0].hasOwnProperty(short_name), |
|
27 | this.test.assertFalse(json[0].data.hasOwnProperty(short_name), | |
28 | "toJSON() representation doesn't use " + short_name); |
|
28 | "toJSON() representation doesn't use " + short_name); | |
29 | this.test.assertTrue(json[0].hasOwnProperty(long_name), |
|
29 | this.test.assertTrue(json[0].data.hasOwnProperty(long_name), | |
30 | 'toJSON() representation uses ' + long_name); |
|
30 | 'toJSON() representation uses ' + long_name); | |
31 | this.test.assertTrue(result.hasOwnProperty(long_name), |
|
31 | this.test.assertTrue(result.data.hasOwnProperty(long_name), | |
32 | 'toJSON() original embedded JSON keeps ' + long_name); |
|
32 | 'toJSON() original embedded JSON keeps ' + long_name); | |
33 | this.test.assertTrue(result2.hasOwnProperty(long_name), |
|
33 | this.test.assertTrue(result2.data.hasOwnProperty(long_name), | |
34 | 'fromJSON() embedded ' + short_name + ' gets mime key ' + long_name); |
|
34 | 'fromJSON() embedded ' + short_name + ' gets mime key ' + long_name); | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
@@ -71,7 +71,7 b' function clear_and_execute(that, code) {' | |||||
71 | that.execute_cell(0); |
|
71 | that.execute_cell(0); | |
72 | that.wait_for_idle(); |
|
72 | that.wait_for_idle(); | |
73 | }); |
|
73 | }); | |
74 |
} |
|
74 | } | |
75 |
|
75 | |||
76 | casper.notebook_test(function () { |
|
76 | casper.notebook_test(function () { | |
77 | this.evaluate(function () { |
|
77 | this.evaluate(function () { | |
@@ -88,7 +88,7 b' casper.notebook_test(function () {' | |||||
88 | var result = this.get_output_cell(0); |
|
88 | var result = this.get_output_cell(0); | |
89 | var num_cells = this.get_cells_length(); |
|
89 | var num_cells = this.get_cells_length(); | |
90 | this.test.assertEquals(num_cells, 2, '%%javascript magic works'); |
|
90 | this.test.assertEquals(num_cells, 2, '%%javascript magic works'); | |
91 | this.test.assertTrue(result.hasOwnProperty('application/javascript'), |
|
91 | this.test.assertTrue(result.data.hasOwnProperty('application/javascript'), | |
92 | 'testing JS embedded with mime key'); |
|
92 | 'testing JS embedded with mime key'); | |
93 | }); |
|
93 | }); | |
94 |
|
94 | |||
@@ -236,10 +236,10 b' casper.notebook_test(function () {' | |||||
236 | this.then(function () { |
|
236 | this.then(function () { | |
237 | var long_name = 'text/superfancymimetype'; |
|
237 | var long_name = 'text/superfancymimetype'; | |
238 | var result = this.get_output_cell(0); |
|
238 | var result = this.get_output_cell(0); | |
239 | this.test.assertTrue(result.hasOwnProperty(long_name), |
|
239 | this.test.assertTrue(result.data.hasOwnProperty(long_name), | |
240 | 'display_data custom mimetype ' + long_name); |
|
240 | 'display_data custom mimetype ' + long_name); | |
241 |
|
|
241 | result = this.get_output_cell(0, 1); | |
242 | this.test.assertTrue(result.hasOwnProperty(long_name), |
|
242 | this.test.assertTrue(result.data.hasOwnProperty(long_name), | |
243 | 'execute_result custom mimetype ' + long_name); |
|
243 | 'execute_result custom mimetype ' + long_name); | |
244 |
|
244 | |||
245 | }); |
|
245 | }); |
@@ -26,7 +26,7 b' casper.notebook_test(function () {' | |||||
26 | var output = this.get_output_cell(0); |
|
26 | var output = this.get_output_cell(0); | |
27 | this.test.assert(messages.length > 0, "Captured log message"); |
|
27 | this.test.assert(messages.length > 0, "Captured log message"); | |
28 | this.test.assertEquals(messages[messages.length-1].substr(0,26), "Invalid type for image/png", "Logged Invalid type message"); |
|
28 | this.test.assertEquals(messages[messages.length-1].substr(0,26), "Invalid type for image/png", "Logged Invalid type message"); | |
29 | this.test.assertEquals(output['image/png'], undefined, "Non-string png data was stripped"); |
|
29 | this.test.assertEquals(output.data['image/png'], undefined, "Non-string png data was stripped"); | |
30 | this.test.assertEquals(output['text/plain'], '5', "text data is fine"); |
|
30 | this.test.assertEquals(output.data['text/plain'], '5', "text data is fine"); | |
31 | }); |
|
31 | }); | |
32 | }); |
|
32 | }); |
@@ -170,7 +170,7 b' casper.notebook_test(function () {' | |||||
170 | this.test.assert(outputs.length <= 5, 'Messages throttled.'); |
|
170 | this.test.assert(outputs.length <= 5, 'Messages throttled.'); | |
171 |
|
171 | |||
172 | // We also need to verify that the last state sent was correct. |
|
172 | // We also need to verify that the last state sent was correct. | |
173 | var last_state = outputs[outputs.length-1]['text/plain']; |
|
173 | var last_state = outputs[outputs.length-1].data['text/plain']; | |
174 | this.test.assertEquals(last_state, "20", "Last state sent when throttling."); |
|
174 | this.test.assertEquals(last_state, "20", "Last state sent when throttling."); | |
175 | }); |
|
175 | }); | |
176 | }); |
|
176 | }); |
@@ -37,7 +37,7 b' casper.notebook_test(function () {' | |||||
37 | this.wait_for_output(button_index, 1); |
|
37 | this.wait_for_output(button_index, 1); | |
38 |
|
38 | |||
39 | this.then(function () { |
|
39 | this.then(function () { | |
40 | this.test.assertEquals(this.get_output_cell(button_index, 1)['text/plain'], "'Clicked'", |
|
40 | this.test.assertEquals(this.get_output_cell(button_index, 1).data['text/plain'], "'Clicked'", | |
41 | 'Button click event fires.'); |
|
41 | 'Button click event fires.'); | |
42 | }); |
|
42 | }); | |
43 | }); No newline at end of file |
|
43 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now