tor-browser

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

test_schema_17_migration.js (1839B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Test cookie database schema 17
      5 "use strict";
      6 
      7 add_task(async function test_schema_17_migration() {
      8  // Set up a profile.
      9  let profile = do_get_profile();
     10 
     11  // Start the cookieservice, to force creation of a database.
     12  Services.cookies.sessionCookies;
     13 
     14  // Close the profile.
     15  await promise_close_profile();
     16 
     17  // Remove the cookie file in order to create another database file.
     18  do_get_cookie_file(profile).remove(false);
     19 
     20  // Create a schema 16 database.
     21  let schema16db = new CookieDatabaseConnection(
     22    do_get_cookie_file(profile),
     23    16
     24  );
     25 
     26  let nowInUSec = Date.now() * 1000;
     27  let futureInMSec = Date.now() + 60 * 60 * 24 * 1000;
     28 
     29  schema16db.insertCookie(
     30    new Cookie(
     31      "test1",
     32      "Some data",
     33      "foo.com",
     34      "/",
     35      futureInMSec,
     36      nowInUSec,
     37      nowInUSec,
     38      false,
     39      false,
     40      false,
     41      false,
     42      {},
     43      Ci.nsICookie.SAMESITE_NONE,
     44      Ci.nsICookie.SCHEME_UNSET
     45    )
     46  );
     47 
     48  schema16db.close();
     49  schema16db = null;
     50 
     51  // Reload profile.
     52  await promise_load_profile();
     53 
     54  // Assert inserted cookies are in the db and correctly handled by services.
     55  Assert.equal(Services.cookies.countCookiesFromHost("foo.com"), 1);
     56 
     57  // Check if the time was reset
     58  {
     59    const dbConnection = Services.storage.openDatabase(
     60      do_get_cookie_file(profile)
     61    );
     62    const stmt = dbConnection.createStatement(
     63      "SELECT updateTime FROM moz_cookies"
     64    );
     65 
     66    const results = [];
     67    while (stmt.executeStep()) {
     68      results.push(stmt.getInt64(0));
     69    }
     70 
     71    Assert.equal(results.length, 1);
     72    Assert.greater(results[0], 0);
     73 
     74    stmt.finalize();
     75    dbConnection.close();
     76  }
     77 
     78  // Cleanup
     79  Services.cookies.removeAll();
     80  do_close_profile();
     81 });