test-tmp-file.js 939 B

123456789101112131415161718192021222324252627
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. const tmp = require("sdk/test/tmp-file");
  6. const file = require("sdk/io/file");
  7. const testFolderURL = module.uri.split('test-tmp-file.js')[0];
  8. exports.testCreateFromString = function (assert) {
  9. let expectedContent = "foo";
  10. let path = tmp.createFromString(expectedContent);
  11. let content = file.read(path);
  12. assert.equal(content, expectedContent,
  13. "Temporary file contains the expected content");
  14. }
  15. exports.testCreateFromURL = function (assert) {
  16. let url = testFolderURL + "test-tmp-file.txt";
  17. let path = tmp.createFromURL(url);
  18. let content = file.read(path);
  19. assert.equal(content, "foo",
  20. "Temporary file contains the expected content");
  21. }
  22. require("sdk/test").run(exports);