summaryrefslogtreecommitdiffstats
path: root/devtools/client/storage/test/browser_storage_cookies_add.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /devtools/client/storage/test/browser_storage_cookies_add.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/storage/test/browser_storage_cookies_add.js')
-rw-r--r--devtools/client/storage/test/browser_storage_cookies_add.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/devtools/client/storage/test/browser_storage_cookies_add.js b/devtools/client/storage/test/browser_storage_cookies_add.js
new file mode 100644
index 0000000000..a4eda3cd0e
--- /dev/null
+++ b/devtools/client/storage/test/browser_storage_cookies_add.js
@@ -0,0 +1,59 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// Basic test to check the adding of cookies.
+
+"use strict";
+
+add_task(async function () {
+ const TEST_URL = MAIN_DOMAIN + "storage-cookies.html";
+ await openTabAndSetupStorage(TEST_URL);
+ showAllColumns(true);
+
+ const rowId = await performAdd(["cookies", "http://test1.example.org"]);
+ checkCookieData(rowId);
+
+ await performAdd(["cookies", "http://test1.example.org"]);
+ await performAdd(["cookies", "http://test1.example.org"]);
+ await performAdd(["cookies", "http://test1.example.org"]);
+ await performAdd(["cookies", "http://test1.example.org"]);
+
+ info("Check it does work in private tabs too");
+ const privateWindow = await BrowserTestUtils.openNewBrowserWindow({
+ private: true,
+ });
+ ok(PrivateBrowsingUtils.isWindowPrivate(privateWindow), "window is private");
+ const privateTab = await addTab(TEST_URL, { window: privateWindow });
+ await openStoragePanel({ tab: privateTab });
+ const privateTabRowId = await performAdd([
+ "cookies",
+ "http://test1.example.org",
+ ]);
+ checkCookieData(privateTabRowId);
+
+ await performAdd(["cookies", "http://test1.example.org"]);
+ privateWindow.close();
+});
+
+function checkCookieData(rowId) {
+ is(getCellValue(rowId, "value"), "value", "value is correct");
+ is(getCellValue(rowId, "host"), "test1.example.org", "host is correct");
+ is(getCellValue(rowId, "path"), "/", "path is correct");
+ const actualExpiry = Math.floor(
+ new Date(getCellValue(rowId, "expires")) / 1000
+ );
+ const ONE_DAY_IN_SECONDS = 60 * 60 * 24;
+ const time = Math.floor(new Date(getCellValue(rowId, "creationTime")) / 1000);
+ const expectedExpiry = time + ONE_DAY_IN_SECONDS;
+ Assert.lessOrEqual(
+ actualExpiry - expectedExpiry,
+ 2,
+ "expiry is in expected range"
+ );
+ is(getCellValue(rowId, "size"), "43", "size is correct");
+ is(getCellValue(rowId, "isHttpOnly"), "false", "httpOnly is not set");
+ is(getCellValue(rowId, "isSecure"), "false", "secure is not set");
+ is(getCellValue(rowId, "sameSite"), "Lax", "sameSite is Lax");
+ is(getCellValue(rowId, "hostOnly"), "true", "hostOnly is not set");
+}