1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 * Test case for ordinal exif encoding and decoding.
9 function testExifEncodeAndDecode() {
10 var canvas = getSampleCanvas();
11 var data = canvas.toDataURL('image/jpeg');
14 mediaMimeType: 'image/jpeg',
15 modificationTime: new Date(2015, 0, 7, 15, 30, 6),
23 value: 'Manufacture\0'
30 value: 'DeviceModel\0'
37 value: 0 // The value is set by the encoder.
61 var encoder = ImageEncoder.encodeMetadata(metadata, canvas, 1);
63 // Assert that ExifEncoder is returned.
64 assertTrue(encoder instanceof ExifEncoder);
66 var encodedResult = encoder.encode();
68 // Decode encoded exif data.
69 var exifParser = new ExifParser(this);
71 // Redirect .log and .vlog to console.log for debugging.
72 exifParser.log = function(arg) { console.log(arg); };
73 exifParser.vlog = function(arg) { console.log(arg); };
75 var parsedMetadata = {};
76 var byteReader = new ByteReader(encodedResult);
77 byteReader.readString(2 + 2); // Skip marker and size.
78 exifParser.parseExifSection(parsedMetadata, encodedResult, byteReader);
81 assertEquals(1, parsedMetadata.ifd.image[0x112].value); // Orientation
83 // Since thumbnail is compressed with JPEG, compression must be 6.
84 assertEquals(6, parsedMetadata.ifd.image[0x102].value);
87 assertEquals(1920, parsedMetadata.ifd.exif[0xA002].value); // PixelXDimension
88 assertEquals(1080, parsedMetadata.ifd.exif[0xA003].value); // PixelYDimension
90 // These fields should be copied correctly.
92 assertEquals('Manufacture\0', parsedMetadata.ifd.image[0x10F].value);
94 assertEquals('DeviceModel\0', parsedMetadata.ifd.image[0x110].value);
96 assertEquals('LensModel\0', parsedMetadata.ifd.exif[0xa434].value);
98 assertEquals('N\0', parsedMetadata.ifd.gps[0x1].value);
100 // Software should be set as Gallery.app
101 assertEquals('Chrome OS Gallery App\0',
102 parsedMetadata.ifd.image[0x131].value);
104 // Datetime should be updated.
105 assertEquals('2015:01:07 15:30:06\0', parsedMetadata.ifd.image[0x132].value);
108 assertTrue(!!parsedMetadata.thumbnailTransform);
109 assertTrue(!!parsedMetadata.thumbnailURL);