michael@0: // # Regression tests for tor Bug #2950, Make Permissions Manager memory-only michael@0: // Ensures that permissions.sqlite file in profile directory is not written to, michael@0: // even when we write a value to Firefox's permissions database. michael@0: michael@0: // The requisite test() function. michael@0: function test() { michael@0: michael@0: // Needed because of asynchronous part later in the test. michael@0: waitForExplicitFinish(); michael@0: michael@0: // Shortcut michael@0: let Ci = Components.interfaces; michael@0: michael@0: // ## utility functions michael@0: michael@0: // __uri(spec)__. michael@0: // Creates an nsIURI instance from a spec michael@0: // (string address such as "http://torproject.org"). michael@0: let uri = spec => Services.io.newURI(spec, null, null); michael@0: michael@0: // __setPermission(spec, key, value)__. michael@0: // Sets the site permission of type key to value, for the site located at address spec. michael@0: let setPermission = (spec, key, value) => SitePermissions.set(uri(spec), key, value); michael@0: michael@0: // __getPermission(spec, key)__. michael@0: // Reads the site permission value for permission type key, for the site michael@0: // located at address spec. michael@0: let getPermission = (spec, key) => SitePermissions.get(uri(spec), key); michael@0: michael@0: // __profileDirPath__. michael@0: // The Firefox Profile directory. Expected location of various persistent files. michael@0: let profileDirPath = Services.dirsvc.get("ProfD", Components.interfaces.nsIFile).path; michael@0: michael@0: // __fileInProfile(fileName)__. michael@0: // Returns an nsIFile instance corresponding to a file in the Profile directory. michael@0: let fileInProfile = fileName => FileUtils.File(profileDirPath + "/" + fileName); michael@0: michael@0: // ## Now let's run the test. michael@0: michael@0: let SITE = "http://torproject.org", michael@0: KEY = "popup"; michael@0: michael@0: let permissionsFile = fileInProfile("permissions.sqlite"), michael@0: lastModifiedTime = null, michael@0: newModifiedTime = null; michael@0: if (permissionsFile.exists()) { michael@0: lastModifiedTime = permissionsFile.lastModifiedTime; michael@0: } michael@0: // Read the original value of the permission. michael@0: let originalValue = getPermission(SITE, KEY); michael@0: michael@0: // We need to delay by at least 1000 ms, because that's the granularity michael@0: // of file time stamps, it seems. michael@0: window.setTimeout( michael@0: function () { michael@0: // Set the permission to a new value. michael@0: setPermission(SITE, KEY, (originalValue === 0) ? 1 : 0); michael@0: // Now read back the permission value again. michael@0: let newReadValue = getPermission(SITE, KEY); michael@0: // Compare to confirm that the permission michael@0: // value was successfully changed. michael@0: isnot(newReadValue, originalValue, "Set a value in permissions db (perhaps in memory).");; michael@0: // If file existed or now exists, get the current time stamp. michael@0: if (permissionsFile.exists()) { michael@0: newModifiedTime = permissionsFile.lastModifiedTime; michael@0: } michael@0: // If file was created or modified since we began this test, michael@0: // then permissions db is not memory only. Complain! michael@0: is(lastModifiedTime, newModifiedTime, "Don't write to permissions.sqlite file on disk."); michael@0: // We are done with the test. michael@0: finish(); michael@0: }, 1100); michael@0: michael@0: } // test()