PageRenderTime 18ms CodeModel.GetById 14ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/extensions/cookie/test/unit/test_bug468700.js

http://github.com/zpao/v8monkey
JavaScript | 52 lines | 31 code | 9 blank | 12 comment | 1 complexity | 3970670f99528ed4c67267bf2944ca95 MD5 | raw file
 1/* Any copyright is dedicated to the Public Domain.
 2   http://creativecommons.org/publicdomain/zero/1.0/ */
 3
 4function run_test() {
 5  do_load_manifest("cookieprompt.manifest");
 6
 7  var cs = Cc["@mozilla.org/cookieService;1"].getService(Ci.nsICookieService);
 8  var cm = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager2);
 9  var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
10  var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
11  var pb = null;
12  try {
13    pb = Cc["@mozilla.org/privatebrowsing;1"].getService(Ci.nsIPrivateBrowsingService);
14  } catch (e) {}
15
16  var spec = "http://foo.bar/baz";
17  var uri = ios.newURI(spec, null, null);
18
19  // accept all cookies
20  prefs.setIntPref("network.cookie.lifetimePolicy", 0);
21  // add a test cookie
22  cs.setCookieString(uri, null, "foo=bar", null);
23  do_check_eq(cs.countCookiesFromHost("foo.bar"), 1);
24  // ask all cookies (will result in rejection because the prompt is not available)
25  prefs.setIntPref("network.cookie.lifetimePolicy", 1);
26  // add a test cookie
27  cs.setCookieString(uri, null, "bar=baz", null);
28  do_check_eq(cs.countCookiesFromHost("foo.bar"), 1);
29  cs.removeAll();
30
31  // if private browsing is available
32  if (pb) {
33    prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
34
35    // enter private browsing mode
36    pb.privateBrowsingEnabled = true;
37
38    // accept all cookies
39    prefs.setIntPref("network.cookie.lifetimePolicy", 0);
40    // add a test cookie
41    cs.setCookieString(uri, null, "foobar=bar", null);
42    do_check_eq(cs.countCookiesFromHost("foo.bar"), 1);
43    // ask all cookies (will result in rejection because the prompt is not available)
44    prefs.setIntPref("network.cookie.lifetimePolicy", 1);
45    // add a test cookie
46    cs.setCookieString(uri, null, "foobaz=bar", null);
47    do_check_eq(cs.countCookiesFromHost("foo.bar"), 2);
48
49    prefs.clearUserPref("browser.privatebrowsing.keep_current_session");
50  }
51}
52