#!/usr/bin/perl
use File::Path;

$app = "/Applications/Firefox.app/Contents/MacOS/firefox-bin";
$profile = "dhtml_test_profile";
$profile_dir = "/tmp/$profile";
$pref_content = <<PREFEND;
user_pref("capability.principal.codebase.p1.granted", "UniversalXPConnect");
user_pref("capability.principal.codebase.p1.id", "http://localhost");
user_pref("capability.principal.codebase.p1.subjectName", "");
user_pref("signed.applets.codebase_principal_support", true);
PREFEND

$ENV{'MOZ_NO_REMOTE'} = '1';
$ENV{'NO_EM_RESTART'} = '1';

mkdir($profile_dir);

# first create our profile
@args = ($app, '-CreateProfile', "$profile $profile_dir");
$rc = 0xffff & system @args;
if ($rc != 0) {
  print "Creating profile failed!\n";
} else {
  print "Creating profile succeeded\n";
}

# append magic prefs to user.js
open(PREFOUTFILE, ">>$profile_dir/user.js") || die ("Could not open prefs.js file $!");
print PREFOUTFILE ($pref_content);
close(PREFOUTFILE);

# now run with the profile we created
@runargs = ($app, '-P', "$profile");
$rc = 0xffff & system @runargs;

# remove the profile we created
rmtree($profile_dir, 0, 0);

# log that we made it through
print "test complete\n";