forked from mirrors/gecko-dev
		
	 5dec0e0beb
			
		
	
	
		5dec0e0beb
		
	
	
	
	
		
			
			This patch was autogenerated by my decomponents.py
It covers almost every file with the extension js, jsm, html, py,
xhtml, or xul.
It removes blank lines after removed lines, when the removed lines are
preceded by either blank lines or the start of a new block. The "start
of a new block" is defined fairly hackily: either the line starts with
//, ends with */, ends with {, <![CDATA[, """ or '''. The first two
cover comments, the third one covers JS, the fourth covers JS embedded
in XUL, and the final two cover JS embedded in Python. This also
applies if the removed line was the first line of the file.
It covers the pattern matching cases like "var {classes: Cc,
interfaces: Ci, utils: Cu, results: Cr} = Components;". It'll remove
the entire thing if they are all either Ci, Cr, Cc or Cu, or it will
remove the appropriate ones and leave the residue behind. If there's
only one behind, then it will turn it into a normal, non-pattern
matching variable definition. (For instance, "const { classes: Cc,
Constructor: CC, interfaces: Ci, utils: Cu } = Components" becomes
"const CC = Components.Constructor".)
MozReview-Commit-ID: DeSHcClQ7cG
--HG--
extra : rebase_source : d9c41878036c1ef7766ef5e91a7005025bc1d72b
		
	
			
		
			
				
	
	
		
			114 lines
		
	
	
	
		
			3.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			114 lines
		
	
	
	
		
			3.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /* Any copyright is dedicated to the Public Domain.
 | |
|  * http://creativecommons.org/publicdomain/zero/1.0/ */
 | |
| 
 | |
| "use strict";
 | |
| 
 | |
| do_get_profile();
 | |
| 
 | |
| ChromeUtils.import("resource://gre/modules/osfile.jsm");
 | |
|   // OS.File doesn't like to be first imported during shutdown
 | |
| ChromeUtils.import("resource://gre/modules/Sqlite.jsm");
 | |
| ChromeUtils.import("resource://gre/modules/Services.jsm");
 | |
| ChromeUtils.import("resource://gre/modules/AsyncShutdown.jsm");
 | |
| 
 | |
| function getConnection(dbName, extraOptions = {}) {
 | |
|   let path = dbName + ".sqlite";
 | |
|   let options = {path};
 | |
|   for (let [k, v] of Object.entries(extraOptions)) {
 | |
|     options[k] = v;
 | |
|   }
 | |
| 
 | |
|   return Sqlite.openConnection(options);
 | |
| }
 | |
| 
 | |
| async function getDummyDatabase(name, extraOptions = {}) {
 | |
|   const TABLES = {
 | |
|     dirs: "id INTEGER PRIMARY KEY AUTOINCREMENT, path TEXT",
 | |
|     files: "id INTEGER PRIMARY KEY AUTOINCREMENT, dir_id INTEGER, path TEXT",
 | |
|   };
 | |
| 
 | |
|   let c = await getConnection(name, extraOptions);
 | |
|   c._initialStatementCount = 0;
 | |
| 
 | |
|   for (let [k, v] of Object.entries(TABLES)) {
 | |
|     await c.execute("CREATE TABLE " + k + "(" + v + ")");
 | |
|     c._initialStatementCount++;
 | |
|   }
 | |
| 
 | |
|   return c;
 | |
| }
 | |
| 
 | |
| function sleep(ms) {
 | |
|   return new Promise(resolve => {
 | |
| 
 | |
|     let timer = Cc["@mozilla.org/timer;1"]
 | |
|                   .createInstance(Ci.nsITimer);
 | |
| 
 | |
|     timer.initWithCallback({
 | |
|       notify() {
 | |
|         resolve();
 | |
|       },
 | |
|     }, ms, timer.TYPE_ONE_SHOT);
 | |
| 
 | |
|   });
 | |
| }
 | |
| 
 | |
| 
 | |
| //
 | |
| // -----------  Don't add a test after this one, as it shuts down Sqlite.jsm
 | |
| //
 | |
| add_task(async function test_shutdown_clients() {
 | |
|   info("Ensuring that Sqlite.jsm doesn't shutdown before its clients");
 | |
| 
 | |
|   let assertions = [];
 | |
| 
 | |
|   let sleepStarted = false;
 | |
|   let sleepComplete = false;
 | |
|   Sqlite.shutdown.addBlocker("test_sqlite.js shutdown blocker (sleep)",
 | |
|     async function() {
 | |
|       sleepStarted = true;
 | |
|       await sleep(100);
 | |
|       sleepComplete = true;
 | |
|     });
 | |
|   assertions.push({name: "sleepStarted", value: () => sleepStarted});
 | |
|   assertions.push({name: "sleepComplete", value: () => sleepComplete});
 | |
| 
 | |
|   Sqlite.shutdown.addBlocker("test_sqlite.js shutdown blocker (immediate)",
 | |
|     true);
 | |
| 
 | |
|   let dbOpened = false;
 | |
|   let dbClosed = false;
 | |
| 
 | |
|   Sqlite.shutdown.addBlocker("test_sqlite.js shutdown blocker (open a connection during shutdown)",
 | |
|     async function() {
 | |
|       let db = await getDummyDatabase("opened during shutdown");
 | |
|       dbOpened = true;
 | |
|       db.close().then(
 | |
|         () => dbClosed = true
 | |
|       ); // Don't wait for this task to complete, Sqlite.jsm must wait automatically
 | |
|   });
 | |
| 
 | |
|   assertions.push({name: "dbOpened", value: () => dbOpened});
 | |
|   assertions.push({name: "dbClosed", value: () => dbClosed});
 | |
| 
 | |
|   info("Now shutdown Sqlite.jsm synchronously");
 | |
|   Services.prefs.setBoolPref("toolkit.asyncshutdown.testing", true);
 | |
|   AsyncShutdown.profileBeforeChange._trigger();
 | |
|   Services.prefs.clearUserPref("toolkit.asyncshutdown.testing");
 | |
| 
 | |
| 
 | |
|   for (let {name, value} of assertions) {
 | |
|     info("Checking: " + name);
 | |
|     Assert.ok(value());
 | |
|   }
 | |
| 
 | |
|   info("Ensure that we cannot open databases anymore");
 | |
|   let exn;
 | |
|   try {
 | |
|     await getDummyDatabase("opened after shutdown");
 | |
|   } catch (ex) {
 | |
|     exn = ex;
 | |
|   }
 | |
|   Assert.ok(!!exn);
 | |
|   Assert.ok(exn.message.includes("Sqlite.jsm has been shutdown"));
 | |
| });
 |