|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 // Test that the cookie APIs behave sanely after 'profile-before-change'. |
|
5 |
|
6 let test_generator = do_run_test(); |
|
7 |
|
8 function run_test() { |
|
9 do_test_pending(); |
|
10 test_generator.next(); |
|
11 } |
|
12 |
|
13 function finish_test() { |
|
14 do_execute_soon(function() { |
|
15 test_generator.close(); |
|
16 do_test_finished(); |
|
17 }); |
|
18 } |
|
19 |
|
20 function do_run_test() { |
|
21 // Set up a profile. |
|
22 let profile = do_get_profile(); |
|
23 |
|
24 // Allow all cookies. |
|
25 Services.prefs.setIntPref("network.cookie.cookieBehavior", 0); |
|
26 |
|
27 // Start the cookieservice. |
|
28 Services.cookies; |
|
29 |
|
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()); |
|
37 |
|
38 // Fire 'profile-before-change'. |
|
39 do_close_profile(); |
|
40 |
|
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); |
|
47 |
|
48 do_check_throws(function() { |
|
49 Services.cookiemgr.removeAll(); |
|
50 }, Cr.NS_ERROR_NOT_AVAILABLE); |
|
51 |
|
52 do_check_throws(function() { |
|
53 Services.cookiemgr.enumerator; |
|
54 }, Cr.NS_ERROR_NOT_AVAILABLE); |
|
55 |
|
56 do_check_throws(function() { |
|
57 Services.cookiemgr.add("foo.com", "", "oh4", "hai", false, false, false, 0); |
|
58 }, Cr.NS_ERROR_NOT_AVAILABLE); |
|
59 |
|
60 do_check_throws(function() { |
|
61 Services.cookiemgr.remove("foo.com", "", "oh4", false); |
|
62 }, Cr.NS_ERROR_NOT_AVAILABLE); |
|
63 |
|
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); |
|
69 |
|
70 do_check_throws(function() { |
|
71 Services.cookiemgr.cookieExists(cookie); |
|
72 }, Cr.NS_ERROR_NOT_AVAILABLE); |
|
73 |
|
74 do_check_throws(function() { |
|
75 Services.cookies.countCookiesFromHost("foo.com"); |
|
76 }, Cr.NS_ERROR_NOT_AVAILABLE); |
|
77 |
|
78 do_check_throws(function() { |
|
79 Services.cookies.getCookiesFromHost("foo.com"); |
|
80 }, Cr.NS_ERROR_NOT_AVAILABLE); |
|
81 |
|
82 // Wait for the database to finish closing. |
|
83 new _observer(test_generator, "cookie-db-closed"); |
|
84 yield; |
|
85 |
|
86 // Load the profile and check that the API is available. |
|
87 do_load_profile(); |
|
88 do_check_true(Services.cookiemgr.cookieExists(cookie)); |
|
89 |
|
90 finish_test(); |
|
91 } |
|
92 |