michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: let {OS: {File, Path, Constants}} = Components.utils.import("resource://gre/modules/osfile.jsm", {}); michael@0: Components.utils.import("resource://gre/modules/Task.jsm"); michael@0: michael@0: function run_test() { michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_task(function* testFileError_with_writeAtomic() { michael@0: let DEFAULT_CONTENTS = "default contents" + Math.random(); michael@0: let path = Path.join(Constants.Path.tmpDir, michael@0: "testFileError.tmp"); michael@0: yield File.remove(path); michael@0: yield File.writeAtomic(path, DEFAULT_CONTENTS); michael@0: let exception; michael@0: try { michael@0: yield File.writeAtomic(path, DEFAULT_CONTENTS, { noOverwrite: true }); michael@0: } catch (ex) { michael@0: exception = ex; michael@0: } michael@0: do_check_true(exception instanceof File.Error); michael@0: do_check_true(exception.path == path); michael@0: }); michael@0: michael@0: add_task(function* testFileError_with_makeDir() { michael@0: let path = Path.join(Constants.Path.tmpDir, michael@0: "directory"); michael@0: yield File.removeDir(path); michael@0: yield File.makeDir(path); michael@0: let exception; michael@0: try { michael@0: yield File.makeDir(path, { ignoreExisting: false }); michael@0: } catch (ex) { michael@0: exception = ex; michael@0: } michael@0: do_check_true(exception instanceof File.Error); michael@0: do_check_true(exception.path == path); michael@0: }); michael@0: michael@0: add_task(function* testFileError_with_move() { michael@0: let DEFAULT_CONTENTS = "default contents" + Math.random(); michael@0: let sourcePath = Path.join(Constants.Path.tmpDir, michael@0: "src.tmp"); michael@0: let destPath = Path.join(Constants.Path.tmpDir, michael@0: "dest.tmp"); michael@0: yield File.remove(sourcePath); michael@0: yield File.remove(destPath); michael@0: yield File.writeAtomic(sourcePath, DEFAULT_CONTENTS); michael@0: yield File.writeAtomic(destPath, DEFAULT_CONTENTS); michael@0: let exception; michael@0: try { michael@0: yield File.move(sourcePath, destPath, { noOverwrite: true }); michael@0: } catch (ex) { michael@0: exception = ex; michael@0: } michael@0: do_print(exception); michael@0: do_check_true(exception instanceof File.Error); michael@0: do_check_true(exception.path == sourcePath); michael@0: });