michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Test that the cookie APIs behave sanely after 'profile-before-change'. michael@0: michael@0: let test_generator = do_run_test(); michael@0: michael@0: function run_test() { michael@0: do_test_pending(); michael@0: test_generator.next(); michael@0: } michael@0: michael@0: function finish_test() { michael@0: do_execute_soon(function() { michael@0: test_generator.close(); michael@0: do_test_finished(); michael@0: }); michael@0: } michael@0: michael@0: function do_run_test() { michael@0: // Set up a profile. michael@0: let profile = do_get_profile(); michael@0: michael@0: // Allow all cookies. michael@0: Services.prefs.setIntPref("network.cookie.cookieBehavior", 0); michael@0: michael@0: // Start the cookieservice. michael@0: Services.cookies; michael@0: michael@0: // Set a cookie. michael@0: let uri = NetUtil.newURI("http://foo.com"); michael@0: Services.cookies.setCookieString(uri, null, "oh=hai; max-age=1000", null); michael@0: let enumerator = Services.cookiemgr.enumerator; michael@0: do_check_true(enumerator.hasMoreElements()); michael@0: let cookie = enumerator.getNext(); michael@0: do_check_false(enumerator.hasMoreElements()); michael@0: michael@0: // Fire 'profile-before-change'. michael@0: do_close_profile(); michael@0: michael@0: // Check that the APIs behave appropriately. michael@0: do_check_eq(Services.cookies.getCookieString(uri, null), null); michael@0: do_check_eq(Services.cookies.getCookieStringFromHttp(uri, null, null), null); michael@0: Services.cookies.setCookieString(uri, null, "oh2=hai", null); michael@0: Services.cookies.setCookieStringFromHttp(uri, null, null, "oh3=hai", null, null); michael@0: do_check_eq(Services.cookies.getCookieString(uri, null), null); michael@0: michael@0: do_check_throws(function() { michael@0: Services.cookiemgr.removeAll(); michael@0: }, Cr.NS_ERROR_NOT_AVAILABLE); michael@0: michael@0: do_check_throws(function() { michael@0: Services.cookiemgr.enumerator; michael@0: }, Cr.NS_ERROR_NOT_AVAILABLE); michael@0: michael@0: do_check_throws(function() { michael@0: Services.cookiemgr.add("foo.com", "", "oh4", "hai", false, false, false, 0); michael@0: }, Cr.NS_ERROR_NOT_AVAILABLE); michael@0: michael@0: do_check_throws(function() { michael@0: Services.cookiemgr.remove("foo.com", "", "oh4", false); michael@0: }, Cr.NS_ERROR_NOT_AVAILABLE); michael@0: michael@0: do_check_throws(function() { michael@0: let file = profile.clone(); michael@0: file.append("cookies.txt"); michael@0: Services.cookiemgr.importCookies(file); michael@0: }, Cr.NS_ERROR_NOT_AVAILABLE); michael@0: michael@0: do_check_throws(function() { michael@0: Services.cookiemgr.cookieExists(cookie); michael@0: }, Cr.NS_ERROR_NOT_AVAILABLE); michael@0: michael@0: do_check_throws(function() { michael@0: Services.cookies.countCookiesFromHost("foo.com"); michael@0: }, Cr.NS_ERROR_NOT_AVAILABLE); michael@0: michael@0: do_check_throws(function() { michael@0: Services.cookies.getCookiesFromHost("foo.com"); michael@0: }, Cr.NS_ERROR_NOT_AVAILABLE); michael@0: michael@0: // Wait for the database to finish closing. michael@0: new _observer(test_generator, "cookie-db-closed"); michael@0: yield; michael@0: michael@0: // Load the profile and check that the API is available. michael@0: do_load_profile(); michael@0: do_check_true(Services.cookiemgr.cookieExists(cookie)); michael@0: michael@0: finish_test(); michael@0: } michael@0: