From 33bb7b2d4deb62ca1ff4941b924668ce7eca4bcf Mon Sep 17 00:00:00 2001 From: Martijn Wargers Date: Mon, 16 Sep 2013 17:15:22 +0200 Subject: [PATCH] Bug 913706 - Fix the tests for B2G mochitest that use nsICookiePermission.setAccess. r=honzab.moz --HG-- extra : rebase_source : 54036e1638d9de46d7ee0116d40e527046d0b26d --- .../localstorage/frameQuotaSessionOnly.html | 18 +- .../localstorage/localStorageCommon.js | 3 +- .../mochitest/localstorage/mochitest.ini | 3 +- .../localstorage/test_cookieBlock.html | 14 +- .../test_cookieSession-phase1.html | 46 ----- .../test_cookieSession-phase2.html | 81 --------- .../localstorage/test_cookieSession.html | 132 ++++++++++++++ .../test_localStorageBaseSessionOnly.html | 13 +- .../test_localStorageCookieSettings.html | 52 +++--- .../test_localStorageEnablePref.html | 44 ++--- .../localstorage/test_localStorageQuota.html | 31 +--- .../test_localStorageQuotaSessionOnly.html | 41 +---- .../test_localStorageQuotaSessionOnly2.html | 43 +---- .../test_localStorageReplace.html | 22 +-- .../sessionstorage/test_cookieSession.html | 168 ++++++++++-------- .../test_sessionStorageBaseSessionOnly.html | 41 +++-- testing/mochitest/b2g.json | 26 +-- .../test_SpecialPowersPushPermissions.html | 46 ++++- .../specialpowers/content/specialpowersAPI.js | 6 + 19 files changed, 392 insertions(+), 438 deletions(-) delete mode 100644 dom/tests/mochitest/localstorage/test_cookieSession-phase1.html delete mode 100644 dom/tests/mochitest/localstorage/test_cookieSession-phase2.html create mode 100644 dom/tests/mochitest/localstorage/test_cookieSession.html diff --git a/dom/tests/mochitest/localstorage/frameQuotaSessionOnly.html b/dom/tests/mochitest/localstorage/frameQuotaSessionOnly.html index 36bca89d44e2..a6f69b176258 100644 --- a/dom/tests/mochitest/localstorage/frameQuotaSessionOnly.html +++ b/dom/tests/mochitest/localstorage/frameQuotaSessionOnly.html @@ -6,7 +6,6 @@ - + diff --git a/dom/tests/mochitest/localstorage/localStorageCommon.js b/dom/tests/mochitest/localstorage/localStorageCommon.js index 3c314f1b351f..5ca4140679e9 100644 --- a/dom/tests/mochitest/localstorage/localStorageCommon.js +++ b/dom/tests/mochitest/localstorage/localStorageCommon.js @@ -36,8 +36,7 @@ function localStorageClearDomain(domain) function os() { - return SpecialPowers.Cc["@mozilla.org/observer-service;1"] - .getService(SpecialPowers.Ci.nsIObserverService); + return SpecialPowers.Services.obs; } function notify(top) diff --git a/dom/tests/mochitest/localstorage/mochitest.ini b/dom/tests/mochitest/localstorage/mochitest.ini index 5c0660d5f617..72d30715adef 100644 --- a/dom/tests/mochitest/localstorage/mochitest.ini +++ b/dom/tests/mochitest/localstorage/mochitest.ini @@ -22,8 +22,7 @@ support-files = [test_bug746272-1.html] [test_bug746272-2.html] [test_cookieBlock.html] -[test_cookieSession-phase1.html] -[test_cookieSession-phase2.html] +[test_cookieSession.html] [test_embededNulls.html] [test_keySync.html] [test_localStorageBase.html] diff --git a/dom/tests/mochitest/localstorage/test_cookieBlock.html b/dom/tests/mochitest/localstorage/test_cookieBlock.html index 51549122cf70..c95cbca49784 100644 --- a/dom/tests/mochitest/localstorage/test_cookieBlock.html +++ b/dom/tests/mochitest/localstorage/test_cookieBlock.html @@ -9,14 +9,6 @@ function startTest() { - var io = SpecialPowers.Cc["@mozilla.org/network/io-service;1"] - .getService(SpecialPowers.Ci.nsIIOService); - var uri = io.newURI(window.location, "", null); - var cp = SpecialPowers.Cc["@mozilla.org/cookie/permission;1"] - .getService(SpecialPowers.Ci.nsICookiePermission); - - cp.setAccess(uri, SpecialPowers.Ci.nsICookiePermission.ACCESS_DENY); - try { localStorage.setItem("blocked", "blockedvalue"); ok(false, "Exception for localStorage.setItem, ACCESS_DENY"); @@ -33,18 +25,18 @@ function startTest() ok(true, "Exception for localStorage.getItem, ACCESS_DENY"); } - cp.setAccess(uri, SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT); - SimpleTest.finish(); } SimpleTest.waitForExplicitFinish(); +SpecialPowers.pushPermissions([{'type': 'cookie', 'allow': false, 'context': document}], startTest); + - + diff --git a/dom/tests/mochitest/localstorage/test_cookieSession-phase1.html b/dom/tests/mochitest/localstorage/test_cookieSession-phase1.html deleted file mode 100644 index 26fe2a4eb90e..000000000000 --- a/dom/tests/mochitest/localstorage/test_cookieSession-phase1.html +++ /dev/null @@ -1,46 +0,0 @@ - - -cookie per-session only test - - - - - - - - - - - - diff --git a/dom/tests/mochitest/localstorage/test_cookieSession-phase2.html b/dom/tests/mochitest/localstorage/test_cookieSession-phase2.html deleted file mode 100644 index 798a136ec819..000000000000 --- a/dom/tests/mochitest/localstorage/test_cookieSession-phase2.html +++ /dev/null @@ -1,81 +0,0 @@ - - -cookie per-session only test - - - - - - - - - - - - diff --git a/dom/tests/mochitest/localstorage/test_cookieSession.html b/dom/tests/mochitest/localstorage/test_cookieSession.html new file mode 100644 index 000000000000..1fdd6f4d5656 --- /dev/null +++ b/dom/tests/mochitest/localstorage/test_cookieSession.html @@ -0,0 +1,132 @@ + + +cookie per-session only test + + + + + + + + + + + diff --git a/dom/tests/mochitest/localstorage/test_localStorageBaseSessionOnly.html b/dom/tests/mochitest/localstorage/test_localStorageBaseSessionOnly.html index 6354628f4ad4..a2e11fc6112b 100644 --- a/dom/tests/mochitest/localstorage/test_localStorageBaseSessionOnly.html +++ b/dom/tests/mochitest/localstorage/test_localStorageBaseSessionOnly.html @@ -9,14 +9,10 @@ function startTest() { - var io = SpecialPowers.Cc["@mozilla.org/network/io-service;1"] - .getService(SpecialPowers.Ci.nsIIOService); - var uri = io.newURI(window.location, "", null); - var cp = SpecialPowers.Cc["@mozilla.org/cookie/permission;1"] - .getService(SpecialPowers.Ci.nsICookiePermission); - cp.setAccess(uri, SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION); - + SpecialPowers.pushPermissions([{'type': 'cookie', 'allow': SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION, 'context': document}], test1); +} +function test1() { // Initially check the localStorage is empty is(localStorage.length, 0, "The storage is empty [1]"); is(localStorage.key(0), null, "key() should return null for out-of-bounds access"); @@ -195,9 +191,6 @@ function startTest() localStorage.removeItem("key1"); // Just check there is no exception localStorage.removeItem("key2"); // Just check there is no exception - - cp.setAccess(uri, SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT); - localStorage.clear(); SimpleTest.finish(); } diff --git a/dom/tests/mochitest/localstorage/test_localStorageCookieSettings.html b/dom/tests/mochitest/localstorage/test_localStorageCookieSettings.html index 7298514fc49c..5e3b36b3e519 100644 --- a/dom/tests/mochitest/localstorage/test_localStorageCookieSettings.html +++ b/dom/tests/mochitest/localstorage/test_localStorageCookieSettings.html @@ -7,38 +7,38 @@ diff --git a/dom/tests/mochitest/localstorage/test_localStorageEnablePref.html b/dom/tests/mochitest/localstorage/test_localStorageEnablePref.html index 5533e4abeebb..6c40ca0dc1bf 100644 --- a/dom/tests/mochitest/localstorage/test_localStorageEnablePref.html +++ b/dom/tests/mochitest/localstorage/test_localStorageEnablePref.html @@ -7,13 +7,6 @@ - + diff --git a/dom/tests/mochitest/localstorage/test_localStorageQuotaSessionOnly.html b/dom/tests/mochitest/localstorage/test_localStorageQuotaSessionOnly.html index ae9561925fca..585da7ceb9d9 100644 --- a/dom/tests/mochitest/localstorage/test_localStorageQuotaSessionOnly.html +++ b/dom/tests/mochitest/localstorage/test_localStorageQuotaSessionOnly.html @@ -9,19 +9,6 @@ - + diff --git a/dom/tests/mochitest/localstorage/test_localStorageQuotaSessionOnly2.html b/dom/tests/mochitest/localstorage/test_localStorageQuotaSessionOnly2.html index 661badf758b9..1c1a70537679 100644 --- a/dom/tests/mochitest/localstorage/test_localStorageQuotaSessionOnly2.html +++ b/dom/tests/mochitest/localstorage/test_localStorageQuotaSessionOnly2.html @@ -8,20 +8,7 @@ - + diff --git a/dom/tests/mochitest/localstorage/test_localStorageReplace.html b/dom/tests/mochitest/localstorage/test_localStorageReplace.html index 367400dbdc96..e1412eaef4a2 100644 --- a/dom/tests/mochitest/localstorage/test_localStorageReplace.html +++ b/dom/tests/mochitest/localstorage/test_localStorageReplace.html @@ -17,9 +17,6 @@ var shell; var shellType; var failureRegExp = new RegExp("^FAILURE"); -var origBlockDisplay; -var origBlockActive; - window.addEventListener("message", onMessageReceived, false); @@ -50,7 +47,7 @@ function onMessageReceived(event) case "window": shell.close(); - window.setTimeout(function() {endTest();}, 0); + window.setTimeout(function() {SimpleTest.finish();}, 0); break; } break; @@ -61,25 +58,16 @@ function onMessageReceived(event) } } -function startTest() -{ - origBlockDisplay = SpecialPowers.getBoolPref("security.mixed_content.block_display_content"); - origBlockActive = SpecialPowers.getBoolPref("security.mixed_content.block_active_content"); - SpecialPowers.setBoolPref("security.mixed_content.block_display_content", false); - SpecialPowers.setBoolPref("security.mixed_content.block_active_content", false); +function startTest() { + SpecialPowers.pushPrefEnv({"set": [["security.mixed_content.block_display_content", false], ["security.mixed_content.block_active_content", false]]}, test1); +} +function test1() { shellType = "frame"; shell = frame; shell.location = "http://example.org:80/tests/dom/tests/mochitest/localstorage/frameReplace.html?init&" + shellType; } -function endTest() -{ - SpecialPowers.setBoolPref("security.mixed_content.block_display_content", origBlockDisplay); - SpecialPowers.setBoolPref("security.mixed_content.block_active_content", origBlockActive); - SimpleTest.finish(); -} - SimpleTest.waitForExplicitFinish(); diff --git a/dom/tests/mochitest/sessionstorage/test_cookieSession.html b/dom/tests/mochitest/sessionstorage/test_cookieSession.html index b011adc92a0c..01bd596ee3d7 100644 --- a/dom/tests/mochitest/sessionstorage/test_cookieSession.html +++ b/dom/tests/mochitest/sessionstorage/test_cookieSession.html @@ -14,78 +14,104 @@ storage. */ -function startTest() -{ - var io = SpecialPowers.Cc["@mozilla.org/network/io-service;1"] - .getService(SpecialPowers.Ci.nsIIOService); - var uri = io.newURI(window.location, "", null); - var cp = SpecialPowers.Cc["@mozilla.org/cookie/permission;1"] - .getService(SpecialPowers.Ci.nsICookiePermission); - - // ==================== start of the test ============================ - - cp.setAccess(uri, SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT); - - sessionStorage.setItem("persistent1", "persistent value 1"); - sessionStorage.setItem("persistent2", "persistent value 2"); - - cp.setAccess(uri, SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION); - - sessionStorage.setItem("session only", "session value"); - is(sessionStorage.getItem("session only"), "session value", "Value present when cookies in session-only mode"); - is(sessionStorage.getItem("persistent1"), "persistent value 1", "Persistent value present"); - is(sessionStorage.getItem("persistent2"), "persistent value 2", "Persistent value present"); - - sessionStorage.setItem("persistent1", "changed persistent value 1"); - sessionStorage.removeItem("persistent2"); - - is(sessionStorage.getItem("session only"), "session value", "Value present when cookies in session-only mode"); - is(sessionStorage.getItem("persistent1"), "changed persistent value 1", "Persistent value present"); - is(sessionStorage.getItem("persistent2"), null, "Persistent value removed"); - - // This clear has to delete only changes made in session only mode - sessionStorage.clear(); - - is(sessionStorage.getItem("session only"), null, "Value not present when cookies in session-only mode after delete"); - is(sessionStorage.getItem("persistent1"), null, "Persistent value not present in session only after delete"); - is(sessionStorage.getItem("persistent2"), null, "Persistent value not present in session only after delete"); - - sessionStorage.setItem("session only 2", "must be deleted on drop of session-only cookies permissions"); - - cp.setAccess(uri, SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT); - - is(sessionStorage.getItem("session only"), null, "No value when cookies are in default mode"); - is(sessionStorage.getItem("session only 2"), null, "No value when cookies are in default mode"); - is(sessionStorage.getItem("persistent1"), "persistent value 1", "Persistent value present"); - is(sessionStorage.getItem("persistent2"), "persistent value 2", "Persistent value present"); - - cp.setAccess(uri, SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION); - - is(sessionStorage.getItem("session only"), null, "Value not present when cookies in session-only mode after delete"); - is(sessionStorage.getItem("session only 2"), null, "Value not present when cookies in session-only mode after delete"); - is(sessionStorage.getItem("persistent1"), "persistent value 1", "Persistent value present again"); - is(sessionStorage.getItem("persistent2"), "persistent value 2", "Persistent value present again"); - - cp.setAccess(uri, SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT); - - sessionStorage.clear(); - - is(sessionStorage.getItem("session only"), null, "No value when cookies are in default mode"); - is(sessionStorage.getItem("persistent1"), null, "Persistent value not present after delete"); - is(sessionStorage.getItem("persistent2"), null, "Persistent value not present after delete"); - - cp.setAccess(uri, SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION); - - is(sessionStorage.getItem("session only"), null, "Value not present when cookies in session-only mode after delete"); - is(sessionStorage.getItem("session only 2"), null, "No value when cookies are in default mode"); - is(sessionStorage.getItem("persistent1"), null, "Persistent value not present in session only after delete"); - is(sessionStorage.getItem("persistent2"), null, "Persistent value not present in session only after delete"); - - cp.setAccess(uri, SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT); - - SimpleTest.finish(); +function pushCookie(aValue, aNext) { + SpecialPowers.pushPermissions([{'type': 'cookie', 'allow': aValue, 'context': document}], pushPermissionAndTest); } +function pushPermissionAndTest() { + var test = tests.shift(); + if (test) { + document.getElementById('testframe').onload = test; + /* After every permission change, an iframe has to be reloaded, + otherwise this test causes failures in b2g (oop) mochitest, because + the permission changes don't seem to be always picked up + by the code that excercises it */ + document.getElementById('testframe').contentWindow.location.reload(); + } else { + ok(false, 'should not be reached'); + SimpleTest.finish(); + } +} + +function startTest() { + pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT); +} + +var tests = [ + function test1() { + sessionStorage.setItem("persistent1", "persistent value 1"); + sessionStorage.setItem("persistent2", "persistent value 2"); + + pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION); + }, + + function test2() { + sessionStorage.setItem("session only", "session value"); + is(sessionStorage.getItem("session only"), "session value", "Value present when cookies in session-only mode"); + is(sessionStorage.getItem("persistent1"), "persistent value 1", "Persistent value present"); + is(sessionStorage.getItem("persistent2"), "persistent value 2", "Persistent value present"); + + sessionStorage.setItem("persistent1", "changed persistent value 1"); + sessionStorage.removeItem("persistent2"); + + is(sessionStorage.getItem("session only"), "session value", "Value present when cookies in session-only mode"); + is(sessionStorage.getItem("persistent1"), "changed persistent value 1", "Persistent value present"); + is(sessionStorage.getItem("persistent2"), null, "Persistent value removed"); + + // This clear has to delete only changes made in session only mode + sessionStorage.clear(); + + is(sessionStorage.getItem("session only"), null, "Value not present when cookies in session-only mode after delete"); + is(sessionStorage.getItem("persistent1"), null, "Persistent value not present in session only after delete"); + is(sessionStorage.getItem("persistent2"), null, "Persistent value not present in session only after delete"); + + sessionStorage.setItem("session only 2", "must be deleted on drop of session-only cookies permissions"); + + pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT); + }, + + function test3() { + is(sessionStorage.getItem("session only"), null, "No value when cookies are in default mode"); + is(sessionStorage.getItem("session only 2"), null, "No value when cookies are in default mode"); + is(sessionStorage.getItem("persistent1"), "persistent value 1", "Persistent value present"); + is(sessionStorage.getItem("persistent2"), "persistent value 2", "Persistent value present"); + + pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION); + }, + + function test4() { + is(sessionStorage.getItem("session only"), null, "Value not present when cookies in session-only mode after delete"); + is(sessionStorage.getItem("session only 2"), null, "Value not present when cookies in session-only mode after delete"); + is(sessionStorage.getItem("persistent1"), "persistent value 1", "Persistent value present again"); + is(sessionStorage.getItem("persistent2"), "persistent value 2", "Persistent value present again"); + + pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT); + }, + + function test5() { + sessionStorage.clear(); + + is(sessionStorage.getItem("session only"), null, "No value when cookies are in default mode"); + is(sessionStorage.getItem("persistent1"), null, "Persistent value not present after delete"); + is(sessionStorage.getItem("persistent2"), null, "Persistent value not present after delete"); + + pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION); + }, + + function test6() { + is(sessionStorage.getItem("session only"), null, "Value not present when cookies in session-only mode after delete"); + is(sessionStorage.getItem("session only 2"), null, "No value when cookies are in default mode"); + is(sessionStorage.getItem("persistent1"), null, "Persistent value not present in session only after delete"); + is(sessionStorage.getItem("persistent2"), null, "Persistent value not present in session only after delete"); + + pushCookie(SpecialPowers.Ci.nsICookiePermission.ACCESS_DEFAULT); + }, + + function test7() { + SimpleTest.finish(); + } +]; + SimpleTest.waitForExplicitFinish(); @@ -93,6 +119,6 @@ SimpleTest.waitForExplicitFinish(); - + diff --git a/dom/tests/mochitest/sessionstorage/test_sessionStorageBaseSessionOnly.html b/dom/tests/mochitest/sessionstorage/test_sessionStorageBaseSessionOnly.html index 7048777f7735..76216ea8fb80 100644 --- a/dom/tests/mochitest/sessionstorage/test_sessionStorageBaseSessionOnly.html +++ b/dom/tests/mochitest/sessionstorage/test_sessionStorageBaseSessionOnly.html @@ -7,15 +7,33 @@