diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /toolkit/profile/test | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/profile/test')
-rw-r--r-- | toolkit/profile/test/.eslintrc.js | 5 | ||||
-rw-r--r-- | toolkit/profile/test/chrome.ini | 3 | ||||
-rw-r--r-- | toolkit/profile/test/test_create_profile.xhtml | 123 |
3 files changed, 131 insertions, 0 deletions
diff --git a/toolkit/profile/test/.eslintrc.js b/toolkit/profile/test/.eslintrc.js new file mode 100644 index 0000000000..f667a57bf5 --- /dev/null +++ b/toolkit/profile/test/.eslintrc.js @@ -0,0 +1,5 @@ +"use strict"; + +module.exports = { + extends: ["plugin:mozilla/chrome-test"], +}; diff --git a/toolkit/profile/test/chrome.ini b/toolkit/profile/test/chrome.ini new file mode 100644 index 0000000000..9d27de238e --- /dev/null +++ b/toolkit/profile/test/chrome.ini @@ -0,0 +1,3 @@ +[DEFAULT] + +[test_create_profile.xhtml] diff --git a/toolkit/profile/test/test_create_profile.xhtml b/toolkit/profile/test/test_create_profile.xhtml new file mode 100644 index 0000000000..99b82f15f9 --- /dev/null +++ b/toolkit/profile/test/test_create_profile.xhtml @@ -0,0 +1,123 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=543854 +--> +<window title="Mozilla Bug 543854" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=543854" + target="_blank">Mozilla Bug 543854</a> + </body> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + + /** Test for Bug 543854 **/ + + SimpleTest.waitForExplicitFinish(); + + const ASCIIName = "myprofile"; + const UnicodeName = "\u09A0\u09BE\u0995\u09C1\u09B0"; // A Bengali name + + var gDirService = SpecialPowers.Services.dirsvc; + var gIOService = SpecialPowers.Services.io; + var gProfileService; + var gDefaultLocalProfileParent; + + gProfileService = Cc["@mozilla.org/toolkit/profile-service;1"]. + getService(Ci.nsIToolkitProfileService); + + gDefaultLocalProfileParent = gDirService.get("DefProfLRt", Ci.nsIFile); + + createProfile(ASCIIName); + createProfile(UnicodeName); + SimpleTest.finish(); + +/** + * Read the contents of an nsIFile. Throws on error. + + * @param file an nsIFile instance. + * @return string contents. + */ +function readFile(file) { + let fstream = Cc["@mozilla.org/network/file-input-stream;1"]. + createInstance(Ci.nsIFileInputStream); + let sstream = Cc["@mozilla.org/scriptableinputstream;1"]. + createInstance(Ci.nsIScriptableInputStream); + + const RO = 0x01; + const READ_OTHERS = 4; + + fstream.init(file, RO, READ_OTHERS, 0); + sstream.init(fstream); + let out = sstream.read(sstream.available()); + sstream.close(); + fstream.close(); + return out; +} + +function checkBounds(lowerBound, value, upperBound) { + ok(lowerBound <= value, "value " + value + + " is above lower bound " + lowerBound); + ok(upperBound >= value, "value " + value + + " is within upper bound " + upperBound); +} + +function createProfile(profileName) { + // Filesystem precision is lower than Date precision. + let lowerBound = Date.now() - 1000; + + let profile = gProfileService.createProfile(null, profileName); + + // check that the directory was created + isnot(profile, null, "Profile " + profileName + " created"); + + let profileDir = profile.rootDir; + + ok(profileDir.exists(), "Profile dir created"); + ok(profileDir.isDirectory(), "Profile dir is a directory"); + + let profileDirPath = profileDir.path; + + is(profileDirPath.substr(profileDirPath.length - profileName.length), + profileName, "Profile dir has expected name"); + + // Ensure that our timestamp file was created. + let jsonFile = profileDir.clone(); + jsonFile.append("times.json"); + ok(jsonFile.path, "Path is " + jsonFile.path); + ok(jsonFile.exists(), "Times file was created"); + ok(jsonFile.isFile(), "Times file is a file"); + let json = JSON.parse(readFile(jsonFile)); + + let upperBound = Date.now() + 1000; + + let created = json.created; + ok(created, "created is set"); + + // Check against real clock time. + checkBounds(lowerBound, created, upperBound); + + // Clean up the profile before local profile test. + profile.remove(true); + + // Create with non-null aRootDir + profile = gProfileService.createProfile(profileDir, profileName); + + let localProfileDir = profile.localDir; + ok(gDefaultLocalProfileParent.contains(localProfileDir, false), + "Local profile dir created in DefProfLRt"); + + // Clean up the profile. + profile.remove(true); +} + + ]]> + </script> +</window> |