forked from mirrors/gecko-dev
		
	Initializing OSCrypto can lead to a useless macOS Keychain prompt when there are no logins to import. Differential Revision: https://phabricator.services.mozilla.com/D46616 --HG-- rename : browser/components/migration/tests/unit/AppData/Local/Google/Chrome/User Data/Default/Login Data => browser/components/migration/tests/unit/AppData/LocalWithNoData/Google/Chrome/User Data/Default/Login Data rename : browser/components/migration/tests/unit/Library/Application Support/Google/Chrome/Default/Login Data => browser/components/migration/tests/unit/LibraryWithNoData/Application Support/Google/Chrome/Default/Login Data rename : browser/components/migration/tests/unit/Library/Application Support/Google/Chrome/Local State => browser/components/migration/tests/unit/LibraryWithNoData/Application Support/Google/Chrome/Local State rename : browser/components/migration/tests/unit/test_Chrome_passwords.js => browser/components/migration/tests/unit/test_Chrome_passwords_emptySource.js extra : moz-landing-system : lando
		
			
				
	
	
		
			109 lines
		
	
	
	
		
			2.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			109 lines
		
	
	
	
		
			2.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
"use strict";
 | 
						|
 | 
						|
var { MigrationUtils, MigratorPrototype } = ChromeUtils.import(
 | 
						|
  "resource:///modules/MigrationUtils.jsm"
 | 
						|
);
 | 
						|
var { LoginHelper } = ChromeUtils.import(
 | 
						|
  "resource://gre/modules/LoginHelper.jsm"
 | 
						|
);
 | 
						|
var { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
 | 
						|
var { PlacesUtils } = ChromeUtils.import(
 | 
						|
  "resource://gre/modules/PlacesUtils.jsm"
 | 
						|
);
 | 
						|
var { Preferences } = ChromeUtils.import(
 | 
						|
  "resource://gre/modules/Preferences.jsm"
 | 
						|
);
 | 
						|
var { PromiseUtils } = ChromeUtils.import(
 | 
						|
  "resource://gre/modules/PromiseUtils.jsm"
 | 
						|
);
 | 
						|
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 | 
						|
var { XPCOMUtils } = ChromeUtils.import(
 | 
						|
  "resource://gre/modules/XPCOMUtils.jsm"
 | 
						|
);
 | 
						|
var { TestUtils } = ChromeUtils.import(
 | 
						|
  "resource://testing-common/TestUtils.jsm"
 | 
						|
);
 | 
						|
var { PlacesTestUtils } = ChromeUtils.import(
 | 
						|
  "resource://testing-common/PlacesTestUtils.jsm"
 | 
						|
);
 | 
						|
 | 
						|
XPCOMUtils.defineLazyGlobalGetters(this, ["URL"]);
 | 
						|
 | 
						|
ChromeUtils.defineModuleGetter(
 | 
						|
  this,
 | 
						|
  "FileUtils",
 | 
						|
  "resource://gre/modules/FileUtils.jsm"
 | 
						|
);
 | 
						|
ChromeUtils.defineModuleGetter(
 | 
						|
  this,
 | 
						|
  "Sqlite",
 | 
						|
  "resource://gre/modules/Sqlite.jsm"
 | 
						|
);
 | 
						|
 | 
						|
// Initialize profile.
 | 
						|
var gProfD = do_get_profile();
 | 
						|
 | 
						|
var { getAppInfo, newAppInfo, updateAppInfo } = ChromeUtils.import(
 | 
						|
  "resource://testing-common/AppInfo.jsm"
 | 
						|
);
 | 
						|
updateAppInfo();
 | 
						|
 | 
						|
/**
 | 
						|
 * Migrates the requested resource and waits for the migration to be complete.
 | 
						|
 */
 | 
						|
async function promiseMigration(
 | 
						|
  migrator,
 | 
						|
  resourceType,
 | 
						|
  aProfile = null,
 | 
						|
  succeeds = null
 | 
						|
) {
 | 
						|
  // Ensure resource migration is available.
 | 
						|
  let availableSources = await migrator.getMigrateData(aProfile, false);
 | 
						|
  Assert.ok(
 | 
						|
    (availableSources & resourceType) > 0,
 | 
						|
    "Resource supported by migrator"
 | 
						|
  );
 | 
						|
  let promises = [TestUtils.topicObserved("Migration:Ended")];
 | 
						|
 | 
						|
  if (succeeds !== null) {
 | 
						|
    // Check that the specific resource type succeeded
 | 
						|
    promises.push(
 | 
						|
      TestUtils.topicObserved(
 | 
						|
        succeeds ? "Migration:ItemAfterMigrate" : "Migration:ItemError",
 | 
						|
        (_, data) => data == resourceType
 | 
						|
      )
 | 
						|
    );
 | 
						|
  }
 | 
						|
 | 
						|
  // Start the migration.
 | 
						|
  migrator.migrate(resourceType, null, aProfile);
 | 
						|
 | 
						|
  return Promise.all(promises);
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
 * Replaces a directory service entry with a given nsIFile.
 | 
						|
 */
 | 
						|
function registerFakePath(key, file) {
 | 
						|
  let dirsvc = Services.dirsvc.QueryInterface(Ci.nsIProperties);
 | 
						|
  let originalFile;
 | 
						|
  try {
 | 
						|
    // If a file is already provided save it and undefine, otherwise set will
 | 
						|
    // throw for persistent entries (ones that are cached).
 | 
						|
    originalFile = dirsvc.get(key, Ci.nsIFile);
 | 
						|
    dirsvc.undefine(key);
 | 
						|
  } catch (e) {
 | 
						|
    // dirsvc.get will throw if nothing provides for the key and dirsvc.undefine
 | 
						|
    // will throw if it's not a persistent entry, in either case we don't want
 | 
						|
    // to set the original file in cleanup.
 | 
						|
    originalFile = undefined;
 | 
						|
  }
 | 
						|
 | 
						|
  dirsvc.set(key, file);
 | 
						|
  registerCleanupFunction(() => {
 | 
						|
    dirsvc.undefine(key);
 | 
						|
    if (originalFile) {
 | 
						|
      dirsvc.set(key, originalFile);
 | 
						|
    }
 | 
						|
  });
 | 
						|
}
 |