Bug 1146304 - Touch slider bar or tap forward button, the video got stuck 1s then...
[gecko.git] / netwerk / test / unit / test_safeoutputstream.js
blob3e41fcbb0266cdb688a9d6a4c42d9101c4e959f5
1 /* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 function write_atomic(file, str) {
7     var stream = Cc["@mozilla.org/network/atomic-file-output-stream;1"]
8                    .createInstance(Ci.nsIFileOutputStream);
9     stream.init(file, -1, -1, 0);
10     do {
11         var written = stream.write(str, str.length);
12         if (written == str.length)
13             break;
14         str = str.substring(written);
15     } while (1);
16     stream.QueryInterface(Ci.nsISafeOutputStream).finish();
17     stream.close();
20 function write(file, str) {
21     var stream = Cc["@mozilla.org/network/safe-file-output-stream;1"]
22                    .createInstance(Ci.nsIFileOutputStream);
23     stream.init(file, -1, -1, 0);
24     do {
25         var written = stream.write(str, str.length);
26         if (written == str.length)
27             break;
28         str = str.substring(written);
29     } while (1);
30     stream.QueryInterface(Ci.nsISafeOutputStream).finish();
31     stream.close();
34 function checkFile(file, str) {
35     var stream = Cc["@mozilla.org/network/file-input-stream;1"]
36                    .createInstance(Ci.nsIFileInputStream);
37     stream.init(file, -1, -1, 0);
39     var scriptStream = Cc["@mozilla.org/scriptableinputstream;1"]
40                          .createInstance(Ci.nsIScriptableInputStream);
41     scriptStream.init(stream);
43     do_check_eq(scriptStream.read(scriptStream.available()), str);
44     scriptStream.close();
47 function run_test()
49     var filename = "\u0913";
50     var file = Cc["@mozilla.org/file/directory_service;1"]
51                  .getService(Ci.nsIProperties)
52                  .get("TmpD", Ci.nsIFile);
53     file.append(filename);
55     write(file, "First write");
56     checkFile(file, "First write");
58     write(file, "Second write");
59     checkFile(file, "Second write");
61     write_atomic(file, "First write: Atomic");
62     checkFile(file, "First write: Atomic");
64     write_atomic(file, "Second write: Atomic");
65     checkFile(file, "Second write: Atomic");