Bug 1357676 - Modify failed tests r=jdm
authorKershaw Chang <kershaw@mozilla.com>
Thu, 30 Aug 2018 15:41:37 +0000
changeset 482491 513621c77f125e2c2198e7e71d064ebb3f13bb74
parent 482490 575e3ec6db41089f80734bf872b63c9bfe354c08
child 482492 c14b6edd88634fe65402dbf3d5b404ed1c83fc4c
push id232
push userfmarier@mozilla.com
push dateWed, 05 Sep 2018 20:45:54 +0000
reviewersjdm
bugs1357676
milestone63.0a1
Bug 1357676 - Modify failed tests r=jdm We've introduced a new pref network.cookie.quotaPerHost and also a rule that the value of network.cookie.maxPerHost should always be bigger than network.cookie.quotaPerHost. So, before changing the value of network.cookie.maxPerHost, we have to set network.cookie.quotaPerHost first. This patch only sets network.cookie.quotaPerHost equal to network.cookie.maxPerHost - 1 in all failed tests. Differential Revision: https://phabricator.services.mozilla.com/D4346
extensions/cookie/test/unit/test_domain_eviction.js
netwerk/test/TestCookie.cpp
toolkit/components/extensions/test/mochitest/test_ext_cookies_permissions_bad.html
toolkit/components/extensions/test/mochitest/test_ext_cookies_permissions_good.html
--- a/extensions/cookie/test/unit/test_domain_eviction.js
+++ b/extensions/cookie/test/unit/test_domain_eviction.js
@@ -14,16 +14,19 @@ function run_test()
 
 function continue_test()
 {
   do_run_generator(test_generator);
 }
 
 function* do_run_test()
 {
+  // Set quotaPerHost to maxPerHost - 1, so there is only one cookie
+  // will be evicted everytime.
+  Services.prefs.setIntPref("network.cookie.quotaPerHost", 49);
   // Set the base domain limit to 50 so we have a known value.
   Services.prefs.setIntPref("network.cookie.maxPerHost", 50);
 
   let futureExpiry = Math.floor(Date.now() / 1000 + 1000);
 
   // test eviction under the 50 cookies per base domain limit. this means
   // that cookies for foo.com and bar.foo.com should count toward this limit,
   // while cookies for baz.com should not. there are several tests we perform
--- a/netwerk/test/TestCookie.cpp
+++ b/netwerk/test/TestCookie.cpp
@@ -25,16 +25,17 @@
 
 using mozilla::Unused;
 
 static NS_DEFINE_CID(kCookieServiceCID, NS_COOKIESERVICE_CID);
 static NS_DEFINE_CID(kPrefServiceCID,   NS_PREFSERVICE_CID);
 
 // various pref strings
 static const char kCookiesPermissions[] = "network.cookie.cookieBehavior";
+static const char kPrefCookieQuotaPerHost[] = "network.cookie.quotaPerHost";
 static const char kCookiesMaxPerHost[] = "network.cookie.maxPerHost";
 static const char kCookieLeaveSecurityAlone[] = "network.cookie.leave-secure-alone";
 
 #define OFFSET_ONE_WEEK int64_t(604800) * PR_USEC_PER_SEC
 #define OFFSET_ONE_DAY int64_t(86400) * PR_USEC_PER_SEC
 
 //Set server time or expiry time
 void
@@ -174,16 +175,19 @@ CheckResult(const char *aLhs, uint32_t a
 void
 InitPrefs(nsIPrefBranch *aPrefBranch)
 {
     // init some relevant prefs, so the tests don't go awry.
     // we use the most restrictive set of prefs we can;
     // however, we don't test third party blocking here.
     aPrefBranch->SetIntPref(kCookiesPermissions, 0); // accept all
     aPrefBranch->SetBoolPref(kCookieLeaveSecurityAlone, true);
+    // Set quotaPerHost to maxPerHost - 1, so there is only one cookie
+    // will be evicted everytime.
+    aPrefBranch->SetIntPref(kPrefCookieQuotaPerHost, 49);
     // Set the base domain limit to 50 so we have a known value.
     aPrefBranch->SetIntPref(kCookiesMaxPerHost, 50);
 }
 
 
 TEST(TestCookie,TestCookieMain)
 {
     nsresult rv0;
--- a/toolkit/components/extensions/test/mochitest/test_ext_cookies_permissions_bad.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_cookies_permissions_bad.html
@@ -12,18 +12,23 @@
 <body>
 
 <script type="text/javascript">
 "use strict";
 
 add_task(async function init() {
   // We need to trigger a cookie eviction in order to test our batch delete
   // observer.
+
+  // Set quotaPerHost to maxPerHost - 1, so there is only one cookie
+  // will be evicted everytime.
+  SpecialPowers.setIntPref("network.cookie.quotaPerHost", 2);
   SpecialPowers.setIntPref("network.cookie.maxPerHost", 3);
   SimpleTest.registerCleanupFunction(() => {
+    SpecialPowers.clearUserPref("network.cookie.quotaPerHost");
     SpecialPowers.clearUserPref("network.cookie.maxPerHost");
   });
 });
 
 add_task(async function test_bad_cookie_permissions() {
   info("Test non-matching, non-secure domain with non-secure cookie");
   await testCookies({
     permissions: ["http://example.com/", "cookies"],
--- a/toolkit/components/extensions/test/mochitest/test_ext_cookies_permissions_good.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_cookies_permissions_good.html
@@ -12,18 +12,23 @@
 <body>
 
 <script type="text/javascript">
 "use strict";
 
 add_task(async function init() {
   // We need to trigger a cookie eviction in order to test our batch delete
   // observer.
+
+  // Set quotaPerHost to maxPerHost - 1, so there is only one cookie
+  // will be evicted everytime.
+  SpecialPowers.setIntPref("network.cookie.quotaPerHost", 2);
   SpecialPowers.setIntPref("network.cookie.maxPerHost", 3);
   SimpleTest.registerCleanupFunction(() => {
+    SpecialPowers.clearUserPref("network.cookie.quotaPerHost");
     SpecialPowers.clearUserPref("network.cookie.maxPerHost");
   });
 });
 
 add_task(async function test_good_cookie_permissions() {
   info("Test matching, non-secure domain with non-secure cookie");
   await testCookies({
     permissions: ["http://example.com/", "cookies"],