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