|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 Cu.import("resource://gre/modules/Services.jsm", this); |
|
5 Cu.import("resource://gre/modules/osfile.jsm", this); |
|
6 Cu.import("resource://gre/modules/Task.jsm", this); |
|
7 |
|
8 function test() { |
|
9 waitForExplicitFinish(); |
|
10 |
|
11 Task.spawn(function task() { |
|
12 try { |
|
13 // Wait until initialization is complete |
|
14 yield SessionStore.promiseInitialized; |
|
15 |
|
16 const PREF_UPGRADE = "browser.sessionstore.upgradeBackup.latestBuildID"; |
|
17 let buildID = Services.appinfo.platformBuildID; |
|
18 |
|
19 // Write state once before starting the test to |
|
20 // ensure sessionstore.js writes won't happen in between. |
|
21 yield forceSaveState(); |
|
22 |
|
23 // Force backup to take place with a file decided by us |
|
24 Services.prefs.setCharPref(PREF_UPGRADE, ""); |
|
25 let contents = "browser_upgrade_backup.js"; |
|
26 let pathStore = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.js"); |
|
27 yield OS.File.writeAtomic(pathStore, contents, { tmpPath: pathStore + ".tmp" }); |
|
28 yield SessionStore._internal._performUpgradeBackup(); |
|
29 is(Services.prefs.getCharPref(PREF_UPGRADE), buildID, "upgrade backup should be set (again)"); |
|
30 |
|
31 let pathBackup = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.bak-" + Services.appinfo.platformBuildID); |
|
32 is((yield OS.File.exists(pathBackup)), true, "upgrade backup file has been created"); |
|
33 |
|
34 let data = yield OS.File.read(pathBackup); |
|
35 is(new TextDecoder().decode(data), contents, "upgrade backup contains the expected contents"); |
|
36 |
|
37 // Ensure that we don't re-backup by accident |
|
38 yield OS.File.writeAtomic(pathStore, "something else entirely", { tmpPath: pathStore + ".tmp" }); |
|
39 yield SessionStore._internal._performUpgradeBackup(); |
|
40 data = yield OS.File.read(pathBackup); |
|
41 is(new TextDecoder().decode(data), contents, "upgrade backup hasn't changed"); |
|
42 |
|
43 } catch (ex) { |
|
44 ok(false, "Uncaught error: " + ex + " at " + ex.stack); |
|
45 } finally { |
|
46 finish(); |
|
47 } |
|
48 }); |
|
49 } |