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');
15 mimeType: 'image/jpeg',
23 value: 'Manufacture\0'
30 value: 'DeviceModel\0'
37 value: 0 // The value is set by the encoder.
62 var encoder = ImageEncoder.encodeMetadata(metadata, canvas, 1,
63 new Date(2015, 0, 7, 15, 30, 6));
65 // Assert that ExifEncoder is returned.
66 assertTrue(encoder instanceof ExifEncoder);
68 var encodedResult = encoder.encode();
70 // Decode encoded exif data.
71 var exifParser = new ExifParser(this);
73 // Redirect .log and .vlog to console.log for debugging.
74 exifParser.log = function(arg) { console.log(arg); };
75 exifParser.vlog = function(arg) { console.log(arg); };
77 var parsedMetadata = {};
78 var byteReader = new ByteReader(encodedResult);
79 byteReader.readString(2 + 2); // Skip marker and size.
80 exifParser.parseExifSection(parsedMetadata, encodedResult, byteReader);
83 assertEquals(1, parsedMetadata.ifd.image[0x112].value); // Orientation
85 // Since thumbnail is compressed with JPEG, compression must be 6.
86 assertEquals(6, parsedMetadata.ifd.image[0x102].value);
89 assertEquals(1920, parsedMetadata.ifd.exif[0xA002].value); // PixelXDimension
90 assertEquals(1080, parsedMetadata.ifd.exif[0xA003].value); // PixelYDimension
92 // These fields should be copied correctly.
94 assertEquals('Manufacture\0', parsedMetadata.ifd.image[0x10F].value);
96 assertEquals('DeviceModel\0', parsedMetadata.ifd.image[0x110].value);
98 assertEquals('LensModel\0', parsedMetadata.ifd.exif[0xa434].value);
100 assertEquals('N\0', parsedMetadata.ifd.gps[0x1].value);
102 // Software should be set as Gallery.app
103 assertEquals('Chrome OS Gallery App\0',
104 parsedMetadata.ifd.image[0x131].value);
106 // Datetime should be updated.
107 assertEquals('2015:01:07 15:30:06\0', parsedMetadata.ifd.image[0x132].value);
110 assert(parsedMetadata.thumbnailTransform);
111 assert(parsedMetadata.thumbnailURL);