Show More
@@ -1,65 +1,48 | |||
|
1 | 1 | // Test image class |
|
2 | 2 | casper.notebook_test(function () { |
|
3 | 3 | index = this.append_cell( |
|
4 | 4 | 'from IPython.html import widgets\n' + |
|
5 | 5 | 'from IPython.display import display, clear_output\n' + |
|
6 | 6 | 'print("Success")'); |
|
7 | 7 | this.execute_cell_then(index); |
|
8 | 8 | |
|
9 | 9 | // Get the temporary directory that the test server is running in. |
|
10 | 10 | var cwd = ''; |
|
11 | 11 | index = this.append_cell('!echo $(pwd)'); |
|
12 | 12 | this.execute_cell_then(index, function(index){ |
|
13 | 13 | cwd = this.get_output_cell(index).text.trim(); |
|
14 | 14 | }); |
|
15 | 15 | |
|
16 | test_jpg = '/9j/4AAQSkZJRgABAQEASABIAAD//gATQ3JlYXRlZCB3aXRoIEdJTVD/2wBDACAWGBwYFCAcGhwkIiAmMFA0MCwsMGJGSjpQdGZ6eHJmcG6AkLicgIiuim5woNqirr7EztDOfJri8uDI8LjKzsb/2wBDASIkJDAqMF40NF7GhHCExsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsb/wgARCAABAAEDAREAAhEBAxEB/8QAFAABAAAAAAAAAAAAAAAAAAAAA//EABUBAQEAAAAAAAAAAAAAAAAAAAME/9oADAMBAAIQAxAAAAECv//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAQUCf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Bf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Bf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEABj8Cf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAT8hf//aAAwDAQACAAMAAAAQn//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Qf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Qf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAT8Qf//Z'; | |
|
17 | ||
|
18 | // It has been verified that both of the following are the correct image. | |
|
19 | // Unfortunately, SlimerJS and PhantomJS disagree on a byte by byte level. | |
|
20 | test_results_phantom = '/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAyADIDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDi6KKK+ZP3EKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//Z'; | |
|
21 | test_results_slimer = '/9j/4AAQSkZJRg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F7GhHCExsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsb/wgARCAABAAEDAREAAhEBAxEB/8QAFAABAAAAAAAAAAAAAAAAAAAAA//EABUBAQEAAAAAAAAAAAAAAAAAAAME/9oADAMBAAIQAxAAAAECv//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAQUCf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Bf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Bf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEABj8Cf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAT8hf//aAAwDAQACAAMAAAAQn//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Qf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Qf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAT8Qf//Z'; | |
|
22 | 17 | |
|
23 | 18 | var image_index = this.append_cell( |
|
24 | 19 | 'import base64\n' + |
|
25 | 20 | 'data = base64.b64decode("' + test_jpg + '")\n' + |
|
26 | 21 | 'image = widgets.ImageWidget()\n' + |
|
27 | 22 | 'image.format = "jpeg"\n' + |
|
28 | 23 | 'image.value = data\n' + |
|
29 | 24 | 'image.width = "50px"\n' + |
|
30 | 25 | 'image.height = "50px"\n' + |
|
31 | 26 | // Set css that will make the image render within the PhantomJS visible |
|
32 | 27 | // window. If we don't do this, the captured image will be black. |
|
33 | 28 | 'image.set_css({"background": "blue", "z-index": "9999", "position": "fixed", "top": "0px", "left": "0px"})\n' + |
|
34 | 29 | 'display(image)\n' + |
|
35 | 30 | 'image.add_class("my-test-image")\n' + |
|
36 | 31 | 'print("Success")\n'); |
|
37 | 32 | this.execute_cell_then(image_index, function(index){ |
|
38 | 33 | |
|
39 | 34 | this.test.assertEquals(this.get_output_cell(index).text, 'Success\n', |
|
40 | 35 | 'Create image executed with correct output.'); |
|
41 | 36 | |
|
42 | 37 | this.test.assert(this.cell_element_exists(index, |
|
43 | 38 | '.widget-area .widget-subarea'), |
|
44 | 39 | 'Widget subarea exists.'); |
|
45 | 40 | |
|
46 | this.test.assert(this.cell_element_exists(index, | |
|
47 | '.widget-area .widget-subarea img'), | |
|
48 | 'Image exists.'); | |
|
49 | ||
|
50 | // Capture a screenshot of the img element as a base64 string. | |
|
51 | var fs = require('fs'); | |
|
52 | capture_filename = cwd + fs.separator + 'captured.jpg'; | |
|
53 | this.captureSelector(capture_filename, '.my-test-image'); | |
|
54 | var stream = fs.open(capture_filename, 'rb'); | |
|
55 | var captured = btoa(stream.read()); | |
|
56 | stream.close(); | |
|
57 | fs.remove(capture_filename); | |
|
58 | ||
|
59 | // Uncomment line below to output captured image data to a text file. | |
|
60 | // fs.write('./captured.txt', captured, 'w'); | |
|
41 | var img_sel = '.widget-area .widget-subarea img'; | |
|
42 | this.test.assert(this.cell_element_exists(index, img_sel), 'Image exists.'); | |
|
61 | 43 | |
|
62 | var match = captured == test_results_phantom || captured == test_results_slimer; | |
|
63 | this.test.assert(match, "Red image data displayed correctly."); | |
|
44 | // Verify that the image's base64 data has made it into the DOM. | |
|
45 | var img_src = this.cell_element_function(image_index, img_sel, 'attr', ['src']); | |
|
46 | this.test.assert(img_src.indexOf(test_jpg) > -1, 'Image src data exists.'); | |
|
64 | 47 | }); |
|
65 | 48 | }); No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now