tor-browser

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

test_failedOpenConnection_leak.html (1821B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 
      4 <head>
      5  <meta charset="utf-8">
      6  <title>Tests for the BackupSettings component</title>
      7  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
      8  <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
      9  <link rel="stylesheet" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
     10  <script>
     11 
     12    const { Assert } = ChromeUtils.importESModule(
     13      "resource://testing-common/Assert.sys.mjs"
     14    );
     15 
     16    /**
     17     * Tests that failing to open a SQLite connection doesn't leak the SQLite
     18     * structure. sqlite3_close() must always be invoked, even in case of failures.
     19     * This will only fail on asan builds and requires shutdown leaks detection.
     20     */
     21 
     22    add_task(async function test_initWidget() {
     23      let file = Services.dirsvc.get("ProfDS", Ci.nsIFile);
     24      file.append("nonexisting.sqlite");
     25 
     26      try {
     27        file.remove(true);
     28      } catch (ex) { }
     29      await Assert.rejects(
     30        new Promise((resolve, reject) => {
     31          Services.storage.openAsyncDatabase(
     32            file,
     33            Ci.mozIStorageService.OPEN_READONLY,
     34            Ci.mozIStorageService.CONNECTION_DEFAULT,
     35            function (status, db) {
     36              if (Components.isSuccessCode(status)) {
     37                resolve(db.QueryInterface(Ci.mozIStorageAsyncConnection));
     38              } else {
     39                reject(new Components.Exception("Error opening database", status));
     40              }
     41            }
     42          );
     43        }),
     44        /NS_ERROR_FILE_ACCESS_DENIED/,
     45        "Should fail to open non existing database"
     46      );
     47    });
     48 
     49    ok(true, "Must have at least one test");
     50 
     51  </script>
     52 </head>
     53 
     54 <body>
     55  <p id="display"></p>
     56  <div id="content" style="display: none">
     57  </div>
     58  <pre id="test"></pre>
     59 </body>
     60 
     61 </html>