summaryrefslogtreecommitdiffstats
path: root/netwerk/cookie/test/unit/test_bug1321912.js
blob: fd24f15bbf78640f87fb579a243430983ea48fa3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
do_get_profile();
const dirSvc = Services.dirsvc;

let dbFile = dirSvc.get("ProfD", Ci.nsIFile);
dbFile.append("cookies.sqlite");

let storage = Services.storage;
let properties = Cc["@mozilla.org/hash-property-bag;1"].createInstance(
  Ci.nsIWritablePropertyBag
);
properties.setProperty("shared", true);
let conn = storage.openDatabase(dbFile);

// Write the schema v7 to the database.
conn.schemaVersion = 7;
conn.executeSimpleSQL(
  "CREATE TABLE moz_cookies (" +
    "id INTEGER PRIMARY KEY, " +
    "baseDomain TEXT, " +
    "originAttributes TEXT NOT NULL DEFAULT '', " +
    "name TEXT, " +
    "value TEXT, " +
    "host TEXT, " +
    "path TEXT, " +
    "expiry INTEGER, " +
    "lastAccessed INTEGER, " +
    "creationTime INTEGER, " +
    "isSecure INTEGER, " +
    "isHttpOnly INTEGER, " +
    "appId INTEGER DEFAULT 0, " +
    "inBrowserElement INTEGER DEFAULT 0, " +
    "CONSTRAINT moz_uniqueid UNIQUE (name, host, path, originAttributes)" +
    ")"
);
conn.executeSimpleSQL(
  "CREATE INDEX moz_basedomain ON moz_cookies (baseDomain, " +
    "originAttributes)"
);

conn.executeSimpleSQL("PRAGMA synchronous = OFF");
conn.executeSimpleSQL("PRAGMA journal_mode = WAL");
conn.executeSimpleSQL("PRAGMA wal_autocheckpoint = 16");

let now = Date.now();
conn.executeSimpleSQL(
  "INSERT INTO moz_cookies(" +
    "baseDomain, host, name, value, path, expiry, " +
    "lastAccessed, creationTime, isSecure, isHttpOnly) VALUES (" +
    "'foo.com', '.foo.com', 'foo', 'bar=baz', '/', " +
    now +
    ", " +
    now +
    ", " +
    now +
    ", 1, 1)"
);

// Now start the cookie service, and then check the fields in the table.
// Get sessionCookies to wait for the initialization in cookie thread
Services.cookies.sessionCookies;

Assert.equal(conn.schemaVersion, 13);
let stmt = conn.createStatement(
  "SELECT sql FROM sqlite_master " +
    "WHERE type = 'table' AND " +
    "      name = 'moz_cookies'"
);
try {
  Assert.ok(stmt.executeStep());
  let sql = stmt.getString(0);
  Assert.equal(sql.indexOf("appId"), -1);
} finally {
  stmt.finalize();
}

stmt = conn.createStatement(
  "SELECT * FROM moz_cookies " +
    "WHERE host = '.foo.com' AND " +
    "      name = 'foo' AND " +
    "      value = 'bar=baz' AND " +
    "      path = '/' AND " +
    "      expiry = " +
    now +
    " AND " +
    "      lastAccessed = " +
    now +
    " AND " +
    "      creationTime = " +
    now +
    " AND " +
    "      isSecure = 1 AND " +
    "      isHttpOnly = 1"
);
try {
  Assert.ok(stmt.executeStep());
} finally {
  stmt.finalize();
}
conn.close();