tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug1321912.js (2623B)


      1 do_get_profile();
      2 const dirSvc = Services.dirsvc;
      3 
      4 let dbFile = dirSvc.get("ProfD", Ci.nsIFile);
      5 dbFile.append("cookies.sqlite");
      6 
      7 let storage = Services.storage;
      8 let properties = Cc["@mozilla.org/hash-property-bag;1"].createInstance(
      9  Ci.nsIWritablePropertyBag
     10 );
     11 properties.setProperty("shared", true);
     12 let conn = storage.openDatabase(dbFile);
     13 
     14 // Write the schema v7 to the database.
     15 conn.schemaVersion = 7;
     16 conn.executeSimpleSQL(
     17  "CREATE TABLE moz_cookies (" +
     18    "id INTEGER PRIMARY KEY, " +
     19    "baseDomain TEXT, " +
     20    "originAttributes TEXT NOT NULL DEFAULT '', " +
     21    "name TEXT, " +
     22    "value TEXT, " +
     23    "host TEXT, " +
     24    "path TEXT, " +
     25    "expiry INTEGER, " +
     26    "lastAccessed INTEGER, " +
     27    "creationTime INTEGER, " +
     28    "isSecure INTEGER, " +
     29    "isHttpOnly INTEGER, " +
     30    "appId INTEGER DEFAULT 0, " +
     31    "inBrowserElement INTEGER DEFAULT 0, " +
     32    "CONSTRAINT moz_uniqueid UNIQUE (name, host, path, originAttributes)" +
     33    ")"
     34 );
     35 conn.executeSimpleSQL(
     36  "CREATE INDEX moz_basedomain ON moz_cookies (baseDomain, " +
     37    "originAttributes)"
     38 );
     39 
     40 conn.executeSimpleSQL("PRAGMA synchronous = OFF");
     41 conn.executeSimpleSQL("PRAGMA journal_mode = WAL");
     42 conn.executeSimpleSQL("PRAGMA wal_autocheckpoint = 16");
     43 
     44 let now = Date.now();
     45 conn.executeSimpleSQL(
     46  "INSERT INTO moz_cookies(" +
     47    "baseDomain, host, name, value, path, expiry, " +
     48    "lastAccessed, creationTime, isSecure, isHttpOnly) VALUES (" +
     49    "'foo.com', '.foo.com', 'foo', 'bar=baz', '/', " +
     50    Math.round(now / 1000) +
     51    ", " +
     52    now +
     53    ", " +
     54    now +
     55    ", 1, 1)"
     56 );
     57 
     58 // Now start the cookie service, and then check the fields in the table.
     59 // Get sessionCookies to wait for the initialization in cookie thread
     60 Services.cookies.sessionCookies;
     61 
     62 Assert.greaterOrEqual(conn.schemaVersion, 13);
     63 let stmt = conn.createStatement(
     64  "SELECT sql FROM sqlite_master " +
     65    "WHERE type = 'table' AND " +
     66    "      name = 'moz_cookies'"
     67 );
     68 try {
     69  Assert.ok(stmt.executeStep());
     70  let sql = stmt.getString(0);
     71  Assert.equal(sql.indexOf("appId"), -1);
     72 } finally {
     73  stmt.finalize();
     74 }
     75 
     76 stmt = conn.createStatement(
     77  "SELECT * FROM moz_cookies " +
     78    "WHERE host = '.foo.com' AND " +
     79    "      name = 'foo' AND " +
     80    "      value = 'bar=baz' AND " +
     81    "      path = '/' AND " +
     82    "      expiry = " +
     83    Math.round(now / 1000) * 1000 +
     84    " AND " +
     85    "      lastAccessed = " +
     86    now +
     87    " AND " +
     88    "      creationTime = " +
     89    now +
     90    " AND " +
     91    "      isSecure = 1 AND " +
     92    "      isHttpOnly = 1"
     93 );
     94 try {
     95  Assert.ok(stmt.executeStep());
     96 } finally {
     97  stmt.finalize();
     98 }
     99 conn.close();