From 3a958eaecbfdab273149eccfd5485f81a8aea889 Mon Sep 17 00:00:00 2001 From: Amy Chung Date: Thu, 3 Aug 2017 19:02:06 +0800 Subject: [PATCH] Bug 1331680 - Part 4: Tests for document.cookie behaving synchronously and reflecting changes from the parent process. r=jdm * * * Bug 1331680 - modification part5 -- fixed try server errors. r=jdm --- .../browserElement_CookiesNotThirdParty.js | 3 +- netwerk/test/mochitests/file_1331680.js | 23 +++++ .../file_iframe_allow_same_origin.html | 8 ++ .../mochitests/file_iframe_allow_scripts.html | 6 ++ netwerk/test/mochitests/mochitest.ini | 7 ++ netwerk/test/mochitests/set_cookie_xhr.sjs | 13 +++ netwerk/test/mochitests/test_1331680.html | 80 +++++++++++++++++ .../test/mochitests/test_1331680_iframe.html | 67 ++++++++++++++ netwerk/test/mochitests/test_1331680_xhr.html | 89 +++++++++++++++++++ netwerk/test/unit_ipc/test_bug528292_wrap.js | 3 +- .../test/unit_ipc/test_cookie_header_wrap.js | 1 + .../test_multipart_streamconv_wrap.js | 2 + 12 files changed, 300 insertions(+), 2 deletions(-) create mode 100644 netwerk/test/mochitests/file_1331680.js create mode 100644 netwerk/test/mochitests/file_iframe_allow_same_origin.html create mode 100644 netwerk/test/mochitests/file_iframe_allow_scripts.html create mode 100644 netwerk/test/mochitests/set_cookie_xhr.sjs create mode 100644 netwerk/test/mochitests/test_1331680.html create mode 100644 netwerk/test/mochitests/test_1331680_iframe.html create mode 100644 netwerk/test/mochitests/test_1331680_xhr.html diff --git a/dom/browser-element/mochitest/browserElement_CookiesNotThirdParty.js b/dom/browser-element/mochitest/browserElement_CookiesNotThirdParty.js index 32f877786cf8..92330798c946 100644 --- a/dom/browser-element/mochitest/browserElement_CookiesNotThirdParty.js +++ b/dom/browser-element/mochitest/browserElement_CookiesNotThirdParty.js @@ -47,5 +47,6 @@ function runTest() { // Disable third-party cookies for this test. addEventListener('testready', function() { - SpecialPowers.pushPrefEnv({'set': [['network.cookie.cookieBehavior', 1]]}, runTest); + SpecialPowers.pushPrefEnv({'set': [['network.cookie.cookieBehavior', 1], + ['network.cookie.ipc.sync', true]]}, runTest); }); diff --git a/netwerk/test/mochitests/file_1331680.js b/netwerk/test/mochitests/file_1331680.js new file mode 100644 index 000000000000..5525a11efe0d --- /dev/null +++ b/netwerk/test/mochitests/file_1331680.js @@ -0,0 +1,23 @@ +let {utils: Cu, classes: Cc, interfaces: Ci } = Components; + +Cu.import("resource://gre/modules/Services.jsm"); +let cs = Cc["@mozilla.org/cookieService;1"].getService(Ci.nsICookieService); + +var observer = { + observe: function(subject, topic, data) { + if (topic == "cookie-changed") { + let cookie = subject.QueryInterface(Ci.nsICookie2); + sendAsyncMessage("cookieName", cookie.name + "=" + cookie.value); + } + } +}; + +addMessageListener("createObserver" , function(e) { + Services.obs.addObserver(observer, "cookie-changed"); + sendAsyncMessage("createObserver:return"); +}); + +addMessageListener("removeObserver" , function(e) { + Services.obs.removeObserver(observer, "cookie-changed"); + sendAsyncMessage("removeObserver:return"); +}); diff --git a/netwerk/test/mochitests/file_iframe_allow_same_origin.html b/netwerk/test/mochitests/file_iframe_allow_same_origin.html new file mode 100644 index 000000000000..c34187bb0ad9 --- /dev/null +++ b/netwerk/test/mochitests/file_iframe_allow_same_origin.html @@ -0,0 +1,8 @@ + + + + diff --git a/netwerk/test/mochitests/file_iframe_allow_scripts.html b/netwerk/test/mochitests/file_iframe_allow_scripts.html new file mode 100644 index 000000000000..01504841a10f --- /dev/null +++ b/netwerk/test/mochitests/file_iframe_allow_scripts.html @@ -0,0 +1,6 @@ + + + + diff --git a/netwerk/test/mochitests/mochitest.ini b/netwerk/test/mochitests/mochitest.ini index 98d406c8039b..f7c5feeb6f9e 100644 --- a/netwerk/test/mochitests/mochitest.ini +++ b/netwerk/test/mochitests/mochitest.ini @@ -5,8 +5,12 @@ support-files = rel_preconnect.sjs user_agent.sjs user_agent_update.sjs + set_cookie_xhr.sjs web_packaged_app.sjs file_loadinfo_redirectchain.sjs + file_1331680.js + file_iframe_allow_scripts.html + file_iframe_allow_same_origin.html redirect_idn.html^headers^ redirect_idn.html empty.html @@ -24,3 +28,6 @@ support-files = [test_user_agent_updates_reset.html] [test_viewsource_unlinkable.html] [test_xhr_method_case.html] +[test_1331680.html] +[test_1331680_iframe.html] +[test_1331680_xhr.html] diff --git a/netwerk/test/mochitests/set_cookie_xhr.sjs b/netwerk/test/mochitests/set_cookie_xhr.sjs new file mode 100644 index 000000000000..8a32f95df7c3 --- /dev/null +++ b/netwerk/test/mochitests/set_cookie_xhr.sjs @@ -0,0 +1,13 @@ + +function handleRequest(request, response) +{ + var queryString = request.queryString; + switch (queryString) { + case "xhr1": + response.setHeader("Set-Cookie", "xhr1=xhr_val1; path=/", false); + break; + case "xhr2": + response.setHeader("Set-Cookie", "xhr2=xhr_val2; path=/; HttpOnly", false); + break; + } +} diff --git a/netwerk/test/mochitests/test_1331680.html b/netwerk/test/mochitests/test_1331680.html new file mode 100644 index 000000000000..0a9ffee5dea9 --- /dev/null +++ b/netwerk/test/mochitests/test_1331680.html @@ -0,0 +1,80 @@ + + + + + Cookies set in content processes update immediately. + + + + +Mozilla Bug 1331680 +

+ +
+
+ + diff --git a/netwerk/test/mochitests/test_1331680_iframe.html b/netwerk/test/mochitests/test_1331680_iframe.html new file mode 100644 index 000000000000..0828f843f349 --- /dev/null +++ b/netwerk/test/mochitests/test_1331680_iframe.html @@ -0,0 +1,67 @@ + + + + + Cookies set from iframe in content process + + + + +Mozilla Bug 1331680 +

+ +
+
+ + diff --git a/netwerk/test/mochitests/test_1331680_xhr.html b/netwerk/test/mochitests/test_1331680_xhr.html new file mode 100644 index 000000000000..e0760a974bb4 --- /dev/null +++ b/netwerk/test/mochitests/test_1331680_xhr.html @@ -0,0 +1,89 @@ + + + + + Cookie changes from XHR requests are observed in content processes. + + + + + + +

+ +
+
+ + + diff --git a/netwerk/test/unit_ipc/test_bug528292_wrap.js b/netwerk/test/unit_ipc/test_bug528292_wrap.js index 117ada7484de..c83cc93be8dc 100644 --- a/netwerk/test/unit_ipc/test_bug528292_wrap.js +++ b/netwerk/test/unit_ipc/test_bug528292_wrap.js @@ -1,6 +1,7 @@ Cu.import("resource://gre/modules/Services.jsm"); function run_test() { + Services.prefs.setBoolPref("network.cookie.ipc.sync", true); Services.prefs.setIntPref("network.cookie.cookieBehavior", 1); run_test_in_child("../unit/test_bug528292.js"); -} \ No newline at end of file +} diff --git a/netwerk/test/unit_ipc/test_cookie_header_wrap.js b/netwerk/test/unit_ipc/test_cookie_header_wrap.js index 3a071a6c15cb..02d346ca86a1 100644 --- a/netwerk/test/unit_ipc/test_cookie_header_wrap.js +++ b/netwerk/test/unit_ipc/test_cookie_header_wrap.js @@ -7,5 +7,6 @@ Cu.import("resource://gre/modules/Services.jsm"); function run_test() { // Allow all cookies. Services.prefs.setIntPref("network.cookie.cookieBehavior", 0); + Services.prefs.setBoolPref("network.cookie.ipc.sync", true); run_test_in_child("../unit/test_cookie_header.js"); } diff --git a/netwerk/test/unit_ipc/test_multipart_streamconv_wrap.js b/netwerk/test/unit_ipc/test_multipart_streamconv_wrap.js index b116f095ba57..6068b3694660 100644 --- a/netwerk/test/unit_ipc/test_multipart_streamconv_wrap.js +++ b/netwerk/test/unit_ipc/test_multipart_streamconv_wrap.js @@ -1,3 +1,5 @@ +Cu.import("resource://gre/modules/Services.jsm"); function run_test() { + Services.prefs.setBoolPref("network.cookie.ipc.sync", true); run_test_in_child("../unit/test_multipart_streamconv.js"); }