fs_test.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2011 The Closure Library Authors. All Rights Reserved.
  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. goog.provide('goog.testing.fsTest');
  15. goog.setTestOnly('goog.testing.fsTest');
  16. goog.require('goog.testing.fs');
  17. goog.require('goog.testing.fs.Blob');
  18. goog.require('goog.testing.jsunit');
  19. function testObjectUrls() {
  20. var blob = goog.testing.fs.getBlob('foo');
  21. var url = goog.testing.fs.createObjectUrl(blob);
  22. assertTrue(goog.testing.fs.isObjectUrlGranted(blob));
  23. goog.testing.fs.revokeObjectUrl(url);
  24. assertFalse(goog.testing.fs.isObjectUrlGranted(blob));
  25. }
  26. function testGetBlob() {
  27. assertEquals(
  28. new goog.testing.fs.Blob('foobarbaz').toString(),
  29. goog.testing.fs.getBlob('foo', 'bar', 'baz').toString());
  30. assertEquals(
  31. new goog.testing.fs.Blob('foobarbaz').toString(),
  32. goog.testing.fs.getBlob('foo', new goog.testing.fs.Blob('bar'), 'baz')
  33. .toString());
  34. }
  35. function testBlobToString() {
  36. return goog.testing.fs.blobToString(new goog.testing.fs.Blob('foobarbaz'))
  37. .then(function(result) { assertEquals('foobarbaz', result); });
  38. }
  39. function testGetBlobWithProperties() {
  40. assertEquals(
  41. 'data:spam/eggs;base64,Zm9vYmFy',
  42. new goog.testing.fs
  43. .getBlobWithProperties(
  44. ['foo', new goog.testing.fs.Blob('bar')], 'spam/eggs')
  45. .toDataUrl());
  46. }
  47. function testSliceBlob() {
  48. myBlob = new goog.testing.fs.Blob('0123456789');
  49. actual = new goog.testing.fs.sliceBlob(myBlob, 1, 3);
  50. expected = new goog.testing.fs.Blob('12');
  51. assertEquals(expected.toString(), actual.toString());
  52. myBlob = new goog.testing.fs.Blob('0123456789');
  53. actual = new goog.testing.fs.sliceBlob(myBlob, 0, -1);
  54. expected = new goog.testing.fs.Blob('012345678');
  55. assertEquals(expected.toString(), actual.toString());
  56. }