extensions/cookie/test/unit/test_cookies_profile_close.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 // Test that the cookie APIs behave sanely after 'profile-before-change'.
michael@0 5
michael@0 6 let test_generator = do_run_test();
michael@0 7
michael@0 8 function run_test() {
michael@0 9 do_test_pending();
michael@0 10 test_generator.next();
michael@0 11 }
michael@0 12
michael@0 13 function finish_test() {
michael@0 14 do_execute_soon(function() {
michael@0 15 test_generator.close();
michael@0 16 do_test_finished();
michael@0 17 });
michael@0 18 }
michael@0 19
michael@0 20 function do_run_test() {
michael@0 21 // Set up a profile.
michael@0 22 let profile = do_get_profile();
michael@0 23
michael@0 24 // Allow all cookies.
michael@0 25 Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
michael@0 26
michael@0 27 // Start the cookieservice.
michael@0 28 Services.cookies;
michael@0 29
michael@0 30 // Set a cookie.
michael@0 31 let uri = NetUtil.newURI("http://foo.com");
michael@0 32 Services.cookies.setCookieString(uri, null, "oh=hai; max-age=1000", null);
michael@0 33 let enumerator = Services.cookiemgr.enumerator;
michael@0 34 do_check_true(enumerator.hasMoreElements());
michael@0 35 let cookie = enumerator.getNext();
michael@0 36 do_check_false(enumerator.hasMoreElements());
michael@0 37
michael@0 38 // Fire 'profile-before-change'.
michael@0 39 do_close_profile();
michael@0 40
michael@0 41 // Check that the APIs behave appropriately.
michael@0 42 do_check_eq(Services.cookies.getCookieString(uri, null), null);
michael@0 43 do_check_eq(Services.cookies.getCookieStringFromHttp(uri, null, null), null);
michael@0 44 Services.cookies.setCookieString(uri, null, "oh2=hai", null);
michael@0 45 Services.cookies.setCookieStringFromHttp(uri, null, null, "oh3=hai", null, null);
michael@0 46 do_check_eq(Services.cookies.getCookieString(uri, null), null);
michael@0 47
michael@0 48 do_check_throws(function() {
michael@0 49 Services.cookiemgr.removeAll();
michael@0 50 }, Cr.NS_ERROR_NOT_AVAILABLE);
michael@0 51
michael@0 52 do_check_throws(function() {
michael@0 53 Services.cookiemgr.enumerator;
michael@0 54 }, Cr.NS_ERROR_NOT_AVAILABLE);
michael@0 55
michael@0 56 do_check_throws(function() {
michael@0 57 Services.cookiemgr.add("foo.com", "", "oh4", "hai", false, false, false, 0);
michael@0 58 }, Cr.NS_ERROR_NOT_AVAILABLE);
michael@0 59
michael@0 60 do_check_throws(function() {
michael@0 61 Services.cookiemgr.remove("foo.com", "", "oh4", false);
michael@0 62 }, Cr.NS_ERROR_NOT_AVAILABLE);
michael@0 63
michael@0 64 do_check_throws(function() {
michael@0 65 let file = profile.clone();
michael@0 66 file.append("cookies.txt");
michael@0 67 Services.cookiemgr.importCookies(file);
michael@0 68 }, Cr.NS_ERROR_NOT_AVAILABLE);
michael@0 69
michael@0 70 do_check_throws(function() {
michael@0 71 Services.cookiemgr.cookieExists(cookie);
michael@0 72 }, Cr.NS_ERROR_NOT_AVAILABLE);
michael@0 73
michael@0 74 do_check_throws(function() {
michael@0 75 Services.cookies.countCookiesFromHost("foo.com");
michael@0 76 }, Cr.NS_ERROR_NOT_AVAILABLE);
michael@0 77
michael@0 78 do_check_throws(function() {
michael@0 79 Services.cookies.getCookiesFromHost("foo.com");
michael@0 80 }, Cr.NS_ERROR_NOT_AVAILABLE);
michael@0 81
michael@0 82 // Wait for the database to finish closing.
michael@0 83 new _observer(test_generator, "cookie-db-closed");
michael@0 84 yield;
michael@0 85
michael@0 86 // Load the profile and check that the API is available.
michael@0 87 do_load_profile();
michael@0 88 do_check_true(Services.cookiemgr.cookieExists(cookie));
michael@0 89
michael@0 90 finish_test();
michael@0 91 }
michael@0 92

mercurial