Bug 1293067 - Implement a cookie limit warning - tests, r=mayhemer
☠☠ backed out by 0577d24b6ca5 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 25 Mar 2020 10:39:03 +0000
changeset 520345 5df9d39b0b98eb17eecad01752b736a28c316cc6
parent 520344 8ed41aa3ed4f2611ed2efd0bf835542874155071
child 520346 0577d24b6ca5be503767d9e82536d431bcabe575
push id37248
push userbtara@mozilla.com
push dateWed, 25 Mar 2020 16:40:49 +0000
treeherdermozilla-central@c5112a7573ac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1293067
milestone76.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1293067 - Implement a cookie limit warning - tests, r=mayhemer Differential Revision: https://phabricator.services.mozilla.com/D67330
netwerk/cookie/test/browser/browser.ini
netwerk/cookie/test/browser/browser_oversize.js
netwerk/cookie/test/browser/oversize.sjs
--- a/netwerk/cookie/test/browser/browser.ini
+++ b/netwerk/cookie/test/browser/browser.ini
@@ -11,8 +11,10 @@ support-files = server.sjs
 [browser_indexedDB.js]
 [browser_originattributes.js]
 [browser_storage.js]
 [browser_serviceWorker.js]
 [browser_sharedWorker.js]
 skip-if = fission #Bug 1582318
 [browser_sameSiteConsole.js]
 support-files = sameSite.sjs
+[browser_oversize.js]
+support-files = oversize.sjs
new file mode 100644
--- /dev/null
+++ b/netwerk/cookie/test/browser/browser_oversize.js
@@ -0,0 +1,94 @@
+const OVERSIZE_DOMAIN = "http://example.com/";
+const OVERSIZE_PATH = "browser/netwerk/cookie/test/browser/";
+const OVERSIZE_TOP_PAGE = OVERSIZE_DOMAIN + OVERSIZE_PATH + "oversize.sjs";
+
+add_task(async _ => {
+  const expected = [];
+
+  const consoleListener = {
+    observe(what) {
+      if (!(what instanceof Ci.nsIConsoleMessage)) {
+        return;
+      }
+
+      info("Console Listener: " + what);
+      for (let i = expected.length - 1; i >= 0; --i) {
+        const e = expected[i];
+
+        if (what.message.includes(e.match)) {
+          ok(true, "Message received: " + e.match);
+          expected.splice(i, 1);
+          e.resolve();
+        }
+      }
+    },
+  };
+
+  Services.console.registerListener(consoleListener);
+
+  registerCleanupFunction(() =>
+    Services.console.unregisterListener(consoleListener)
+  );
+
+  const netPromises = [
+    new Promise(resolve => {
+      expected.push({
+        resolve,
+        match:
+          "Cookie “a” is invalid because its size is too big. Max size is 4096 bytes.",
+      });
+    }),
+
+    new Promise(resolve => {
+      expected.push({
+        resolve,
+        match:
+          "Cookie “b” is invalid because its path size is too big. Max size is 1024 bytes.",
+      });
+    }),
+  ];
+
+  // Let's open our tab.
+  const tab = BrowserTestUtils.addTab(gBrowser, OVERSIZE_TOP_PAGE);
+  gBrowser.selectedTab = tab;
+
+  const browser = gBrowser.getBrowserForTab(tab);
+  await BrowserTestUtils.browserLoaded(browser);
+
+  // Let's wait for the first set of console events.
+  await Promise.all(netPromises);
+
+  // the DOM list of events.
+  const domPromises = [
+    new Promise(resolve => {
+      expected.push({
+        resolve,
+        match:
+          "Cookie “d” is invalid because its size is too big. Max size is 4096 bytes.",
+      });
+    }),
+
+    new Promise(resolve => {
+      expected.push({
+        resolve,
+        match:
+          "Cookie “e” is invalid because its path size is too big. Max size is 1024 bytes.",
+      });
+    }),
+  ];
+
+  // Let's use document.cookie
+  SpecialPowers.spawn(browser, [], () => {
+    const maxBytesPerCookie = 4096;
+    const maxBytesPerCookiePath = 1024;
+    content.document.cookie = "d=" + Array(maxBytesPerCookie + 1).join("x");
+    content.document.cookie =
+      "e=f; path=/" + Array(maxBytesPerCookiePath + 1).join("x");
+  });
+
+  // Let's wait for the dom events.
+  await Promise.all(domPromises);
+
+  // Let's close the tab.
+  BrowserTestUtils.removeTab(tab);
+});
new file mode 100644
--- /dev/null
+++ b/netwerk/cookie/test/browser/oversize.sjs
@@ -0,0 +1,9 @@
+function handleRequest(aRequest, aResponse) {
+  aResponse.setStatusLine(aRequest.httpVersion, 200);
+
+  const maxBytesPerCookie = 4096;
+  const maxBytesPerCookiePath = 1024;
+
+  aResponse.setHeader("Set-Cookie", "a=" + Array(maxBytesPerCookie + 1).join('x'), true);
+  aResponse.setHeader("Set-Cookie", "b=c; path=/" + Array(maxBytesPerCookiePath + 1).join('x'), true);
+}