tbb-tests/browser_tor_bug2950.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 // # Regression tests for tor Bug #2950, Make Permissions Manager memory-only
     2 // Ensures that permissions.sqlite file in profile directory is not written to,
     3 // even when we write a value to Firefox's permissions database.
     5 // The requisite test() function.
     6 function test() {
     8 // Needed because of asynchronous part later in the test.
     9 waitForExplicitFinish();
    11 // Shortcut
    12 let Ci = Components.interfaces;
    14 // ## utility functions
    16 // __uri(spec)__.
    17 // Creates an nsIURI instance from a spec
    18 // (string address such as "http://torproject.org").
    19 let uri = spec => Services.io.newURI(spec, null, null);
    21 // __setPermission(spec, key, value)__.
    22 // Sets the site permission of type key to value, for the site located at address spec.
    23 let setPermission = (spec, key, value) => SitePermissions.set(uri(spec), key, value);
    25 // __getPermission(spec, key)__.
    26 // Reads the site permission value for permission type key, for the site
    27 // located at address spec.
    28 let getPermission = (spec, key) => SitePermissions.get(uri(spec), key);
    30 // __profileDirPath__.
    31 // The Firefox Profile directory. Expected location of various persistent files.
    32 let profileDirPath = Services.dirsvc.get("ProfD", Components.interfaces.nsIFile).path;
    34 // __fileInProfile(fileName)__.
    35 // Returns an nsIFile instance corresponding to a file in the Profile directory.
    36 let fileInProfile = fileName => FileUtils.File(profileDirPath + "/" + fileName);
    38 // ## Now let's run the test.
    40 let SITE = "http://torproject.org",
    41     KEY = "popup";
    43 let permissionsFile = fileInProfile("permissions.sqlite"),
    44                       lastModifiedTime = null,
    45                       newModifiedTime = null;
    46 if (permissionsFile.exists()) {
    47   lastModifiedTime = permissionsFile.lastModifiedTime;
    48 }
    49 // Read the original value of the permission.
    50 let originalValue = getPermission(SITE, KEY);
    52 // We need to delay by at least 1000 ms, because that's the granularity
    53 // of file time stamps, it seems.
    54 window.setTimeout(
    55   function () {
    56     // Set the permission to a new value.
    57     setPermission(SITE, KEY, (originalValue === 0) ? 1 : 0);
    58     // Now read back the permission value again.
    59     let newReadValue = getPermission(SITE, KEY);
    60     // Compare to confirm that the permission
    61     // value was successfully changed.
    62     isnot(newReadValue, originalValue, "Set a value in permissions db (perhaps in memory).");;
    63     // If file existed or now exists, get the current time stamp.
    64     if (permissionsFile.exists()) {
    65     	newModifiedTime = permissionsFile.lastModifiedTime;
    66     }
    67     // If file was created or modified since we began this test,
    68     // then permissions db is not memory only. Complain!
    69     is(lastModifiedTime, newModifiedTime, "Don't write to permissions.sqlite file on disk.");
    70     // We are done with the test.
    71     finish();
    72   }, 1100);
    74 } // test()

mercurial