metadata_spec.js 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2017 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. 'use strict';
  23. var _metadata = require('../../display/metadata');
  24. describe('metadata', function () {
  25. it('should handle valid metadata', function () {
  26. var validData = '<x:xmpmeta xmlns:x=\'adobe:ns:meta/\'>' + '<rdf:RDF xmlns:rdf=\'http://www.w3.org/1999/02/22-rdf-syntax-ns#\'>' + '<rdf:Description xmlns:dc=\'http://purl.org/dc/elements/1.1/\'>' + '<dc:title><rdf:Alt><rdf:li xml:lang="x-default">Foo bar baz</rdf:li>' + '</rdf:Alt></dc:title></rdf:Description></rdf:RDF></x:xmpmeta>';
  27. var metadata = new _metadata.Metadata(validData);
  28. expect(metadata.has('dc:title')).toBeTruthy();
  29. expect(metadata.has('dc:qux')).toBeFalsy();
  30. expect(metadata.get('dc:title')).toEqual('Foo bar baz');
  31. expect(metadata.get('dc:qux')).toEqual(null);
  32. expect(metadata.getAll()).toEqual({ 'dc:title': 'Foo bar baz' });
  33. });
  34. it('should repair and handle invalid metadata', function () {
  35. var invalidData = '<x:xmpmeta xmlns:x=\'adobe:ns:meta/\'>' + '<rdf:RDF xmlns:rdf=\'http://www.w3.org/1999/02/22-rdf-syntax-ns#\'>' + '<rdf:Description xmlns:dc=\'http://purl.org/dc/elements/1.1/\'>' + '<dc:title>\\376\\377\\000P\\000D\\000F\\000&</dc:title>' + '</rdf:Description></rdf:RDF></x:xmpmeta>';
  36. var metadata = new _metadata.Metadata(invalidData);
  37. expect(metadata.has('dc:title')).toBeTruthy();
  38. expect(metadata.has('dc:qux')).toBeFalsy();
  39. expect(metadata.get('dc:title')).toEqual('PDF&');
  40. expect(metadata.get('dc:qux')).toEqual(null);
  41. expect(metadata.getAll()).toEqual({ 'dc:title': 'PDF&' });
  42. });
  43. it('should repair and handle invalid metadata (bug 1424938)', function () {
  44. var invalidData = '<x:xmpmeta xmlns:x=\'adobe:ns:meta/\' ' + 'x:xmptk=\'XMP toolkit 2.9.1-13, framework 1.6\'>' + '<rdf:RDF xmlns:rdf=\'http://www.w3.org/1999/02/22-rdf-syntax-ns#\' ' + 'xmlns:iX=\'http://ns.adobe.com/iX/1.0/\'>' + '<rdf:Description rdf:about=\'61652fa7-fc1f-11dd-0000-ce81d41f9ecf\' ' + 'xmlns:pdf=\'http://ns.adobe.com/pdf/1.3/\' ' + 'pdf:Producer=\'GPL Ghostscript 8.63\'/>' + '<rdf:Description rdf:about=\'61652fa7-fc1f-11dd-0000-ce81d41f9ecf\' ' + 'xmlns:xap=\'http://ns.adobe.com/xap/1.0/\' ' + 'xap:ModifyDate=\'2009-02-13T12:42:54+01:00\' ' + 'xap:CreateDate=\'2009-02-13T12:42:54+01:00\'>' + '<xap:CreatorTool>\\376\\377\\000P\\000D\\000F\\000C\\000r\\000e\\000a' + '\\000t\\000o\\000r\\000 \\000V\\000e\\000r\\000s\\000i\\000o\\000n' + '\\000 \\0000\\000.\\0009\\000.\\0006</xap:CreatorTool>' + '</rdf:Description><rdf:Description ' + 'rdf:about=\'61652fa7-fc1f-11dd-0000-ce81d41f9ecf\' ' + 'xmlns:xapMM=\'http://ns.adobe.com/xap/1.0/mm/\' ' + 'xapMM:DocumentID=\'61652fa7-fc1f-11dd-0000-ce81d41f9ecf\'/>' + '<rdf:Description rdf:about=\'61652fa7-fc1f-11dd-0000-ce81d41f9ecf\' ' + 'xmlns:dc=\'http://purl.org/dc/elements/1.1/\' ' + 'dc:format=\'application/pdf\'><dc:title><rdf:Alt>' + '<rdf:li xml:lang=\'x-default\'>\\376\\377\\000L\\000&apos;\\000O\\000d' + '\\000i\\000s\\000s\\000e\\000e\\000 \\000t\\000h\\000\\351\\000m\\000a' + '\\000t\\000i\\000q\\000u\\000e\\000 \\000l\\000o\\000g\\000o\\000 ' + '\\000O\\000d\\000i\\000s\\000s\\000\\351\\000\\351\\000 \\000-\\000 ' + '\\000d\\000\\351\\000c\\000e\\000m\\000b\\000r\\000e\\000 \\0002\\0000' + '\\0000\\0008\\000.\\000p\\000u\\000b</rdf:li></rdf:Alt></dc:title>' + '<dc:creator><rdf:Seq><rdf:li>\\376\\377\\000O\\000D\\000I\\000S' + '</rdf:li></rdf:Seq></dc:creator></rdf:Description></rdf:RDF>' + '</x:xmpmeta>';
  45. var metadata = new _metadata.Metadata(invalidData);
  46. expect(metadata.has('dc:title')).toBeTruthy();
  47. expect(metadata.has('dc:qux')).toBeFalsy();
  48. expect(metadata.get('dc:title')).toEqual('L\'Odissee thématique logo Odisséé - décembre 2008.pub');
  49. expect(metadata.get('dc:qux')).toEqual(null);
  50. expect(metadata.getAll()).toEqual({
  51. 'dc:creator': 'ODIS',
  52. 'dc:title': 'L\'Odissee thématique logo Odisséé - décembre 2008.pub',
  53. 'xap:creatortool': 'PDFCreator Version 0.9.6'
  54. });
  55. });
  56. });