metadata_spec.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. 'use strict';
  16. var _metadata = require('../../display/metadata');
  17. describe('metadata', function () {
  18. it('should handle valid metadata', function () {
  19. 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>';
  20. var metadata = new _metadata.Metadata(validData);
  21. expect(metadata.has('dc:title')).toBeTruthy();
  22. expect(metadata.has('dc:qux')).toBeFalsy();
  23. expect(metadata.get('dc:title')).toEqual('Foo bar baz');
  24. expect(metadata.get('dc:qux')).toEqual(null);
  25. expect(metadata.getAll()).toEqual({ 'dc:title': 'Foo bar baz' });
  26. });
  27. it('should repair and handle invalid metadata', function () {
  28. 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>';
  29. var metadata = new _metadata.Metadata(invalidData);
  30. expect(metadata.has('dc:title')).toBeTruthy();
  31. expect(metadata.has('dc:qux')).toBeFalsy();
  32. expect(metadata.get('dc:title')).toEqual('PDF&');
  33. expect(metadata.get('dc:qux')).toEqual(null);
  34. expect(metadata.getAll()).toEqual({ 'dc:title': 'PDF&' });
  35. });
  36. });