File: browser_833286_atomic_backup.js

package info (click to toggle)
icedove 31.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 1,007,612 kB
  • sloc: cpp: 3,959,977; ansic: 1,866,528; java: 219,720; python: 200,664; xml: 142,383; asm: 133,557; sh: 75,814; makefile: 27,028; perl: 26,849; objc: 4,014; yacc: 1,995; pascal: 1,024; lex: 950; exp: 449; lisp: 228; awk: 211; php: 113; sed: 43; csh: 31; ada: 16; ruby: 3
file content (99 lines) | stat: -rw-r--r-- 3,434 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// This tests are for a sessionstore.js atomic backup.
// Each test will wait for a write to the Session Store
// before executing.

let tmp = {};
Cu.import("resource://gre/modules/osfile.jsm", tmp);
Cu.import("resource:///modules/sessionstore/SessionFile.jsm", tmp);

const {OS, SessionFile} = tmp;

const PREF_SS_INTERVAL = "browser.sessionstore.interval";
// Full paths for sessionstore.js and sessionstore.bak.
const path = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.js");
const backupPath = OS.Path.join(OS.Constants.Path.profileDir,
  "sessionstore.bak");

// A text decoder.
let gDecoder = new TextDecoder();
// Global variables that contain sessionstore.js and sessionstore.bak data for
// comparison between tests.
let gSSData;
let gSSBakData;



add_task(function* testAfterFirstWrite() {
  // Ensure sessionstore.bak is not created. We start with a clean
  // profile so there was nothing to move to sessionstore.bak before
  // initially writing sessionstore.js
  let ssExists = yield OS.File.exists(path);
  let ssBackupExists = yield OS.File.exists(backupPath);
  ok(ssExists, "sessionstore.js should exist.");
  ok(!ssBackupExists, "sessionstore.bak should not have been created, yet");

  // Save sessionstore.js data to compare to the sessionstore.bak data in the
  // next test.
  let array = yield OS.File.read(path);
  gSSData = gDecoder.decode(array);

  // Manually move to the backup since the first write has already happened
  // and a backup would not be triggered again.
  yield OS.File.move(path, backupPath);

  yield forceSaveState();
});

add_task(function* testReadBackup() {
  // Ensure sessionstore.bak is finally created.
  let ssExists = yield OS.File.exists(path);
  let ssBackupExists = yield OS.File.exists(backupPath);
  ok(ssExists, "sessionstore.js exists.");
  ok(ssBackupExists, "sessionstore.bak should now be created.");

  // Read sessionstore.bak data.
  let array = yield OS.File.read(backupPath);
  gSSBakData = gDecoder.decode(array);

  // Make sure that the sessionstore.bak is identical to the last
  // sessionstore.js.
  is(gSSBakData, gSSData, "sessionstore.js is backed up correctly.");

  // Read latest sessionstore.js.
  array = yield OS.File.read(path);
  gSSData = gDecoder.decode(array);

  // Read sessionstore.js with SessionFile.read.
  let ssDataRead = yield SessionFile.read();
  is(ssDataRead, gSSData, "SessionFile.read read sessionstore.js correctly.");

  // Remove sessionstore.js to test fallback onto sessionstore.bak.
  yield OS.File.remove(path);
  ssExists = yield OS.File.exists(path);
  ok(!ssExists, "sessionstore.js should be removed now.");

  // Read sessionstore.bak with SessionFile.read.
  ssDataRead = yield SessionFile.read();
  is(ssDataRead, gSSBakData,
    "SessionFile.read read sessionstore.bak correctly.");

  yield forceSaveState();
});

add_task(function* testBackupUnchanged() {
  // Ensure sessionstore.bak is backed up only once.

  // Read sessionstore.bak data.
  let array = yield OS.File.read(backupPath);
  let ssBakData = gDecoder.decode(array);
  // Ensure the sessionstore.bak did not change.
  is(ssBakData, gSSBakData, "sessionstore.bak is unchanged.");
});

add_task(function* cleanup() {
  // Cleaning up after the test: removing the sessionstore.bak file.
  yield OS.File.remove(backupPath);
});