Test bustage fix by using specific event listener.
[wine-gecko.git] / testing / tinderbox-standalone-tests / Util / Prefs.pm
blob5b37b1c9850adfce81da613ccbba8721a257a595
1 package Prefs;
3 sub set_pref {
4 my ($pref_file, $pref, $value) = @_;
5 # Make sure we get rid of whatever value was there,
6 # to allow for resetting prefs
7 system ("\\grep -v \\\"$pref\\\" '$pref_file' > '$pref_file.new'");
8 File::Copy::move("$pref_file.new", "$pref_file") or die("move: $!\n");
10 Util::print_log("Setting $pref to $value\n");
11 open PREFS, ">>$pref_file" or die "can't open $pref_file ($?)\n";
12 print PREFS "user_pref(\"$pref\", $value);\n";
13 close PREFS;
16 sub get_prefs_file {
17 my ($pref_file, $profile_dir);
19 if ($Settings::UseMozillaProfile) {
20 # Profile directory. This lives in way-different places
21 # depending on the OS.
23 my $profiledir = get_profile_dir($build_dir);
26 # Make sure we have a profile to run tests. This is assumed to be called
27 # $Settings::MozProfileName and will live in $build_dir/.mozilla.
28 # Also assuming only one profile here.
30 my $cp_result = 0;
32 unless (-d "$profiledir") {
33 Util::print_log("No profile found, creating profile.\n");
34 $cp_result = create_profile($build_dir, $binary_dir, $binary);
35 } else {
36 Util::print_log("Found profile.\n");
38 # Recreate profile if we have $Settings::CleanProfile set.
39 if ($Settings::CleanProfile) {
40 my $deletedir = $profiledir;
42 Util::print_log("Creating clean profile ...\n");
43 Util::print_log("Deleting $deletedir ...\n");
44 File::Path::rmtree([$deletedir], 0, 0);
45 if (-e "$deletedir") {
46 Util::print_log("Error: rmtree([$deletedir], 0, 0) failed.\n");
48 $cp_result = create_profile($build_dir, $binary_dir, $binary);
52 # Set status, in case create profile failed.
53 if ($cp_result) {
54 # We should check $cp_result->{exit_value} too, except
55 # semi-single-profile landing made 0 the success value (which is
56 # good), so we now have inconsistent expected results.
57 if (not $cp_result->{timed_out}) {
58 $test_result = "success";
59 } else {
60 Util::print_log("cp_result failed\n");
61 $test_result = "testfailed";
62 Util::print_log("Error: create profile failed.\n");
66 # Call get_profile_dir again, so it can find the extension-salted
67 # profile directory under the profile root.
69 $profiledir = get_profile_dir($build_dir);
72 # Find the prefs file, remember we have that random string now
73 # e.g. <build-dir>/.mozilla/default/uldx6pyb.slt/prefs.js
74 # so File::Path::find will find the prefs.js file.
76 ($pref_file, $profile_dir) = find_pref_file($profiledir);
78 #XXX this is ugly and hacky
79 $test_result = 'testfailed' unless $pref_file;;
80 if (!$pref_file) { Util::print_log("no pref file found\n"); }
82 } elsif($Settings::BinaryName eq "TestGtkEmbed") {
83 Util::print_log("Using TestGtkEmbed profile\n");
85 $pref_file = "$build_dir/.TestGtkEmbed/TestGtkEmbed/prefs.js";
86 $profile_dir = "$build_dir";
88 # Create empty prefs file if needed
89 #unless (-e $pref_file) {
90 # system("mkdir -p $build_dir/.TestGtkEmbed/TestGtkEmbed");
91 # system("touch $pref_file");
94 # Run TestGtkEmbed to generate proper pref file.
95 # This should only need to be run the first time for a given tree.
96 unless (-e $pref_file) {
97 $test_result = AliveTest("EmbedAliveTest_profile", $build_dir,
98 ["$embed_binary_dir/$embed_binary_basename"],
99 $Settings::EmbedTestTimeout);
102 return $pref_file;
106 # Given profile directory, find pref file hidden in salt directory.
107 # profile $Settings::MozProfileName must exist before calling this sub.
109 sub find_pref_file {
110 my $profile_dir = shift;
112 # default to *nix
113 my $pref_file = "prefs.js";
115 unless (-e $profile_dir) {
116 print_log "ERROR: profile $profile_dir does not exist\n";
117 #XXX should make 'run_all_tests' throw a 'testfailed' exception
118 # and just skip all the continual checking for $test_result
119 return; # empty list
122 my $found = undef;
123 my $sub = sub {$pref_file = $File::Find::name, $found++ if $pref_file eq $_};
124 File::Find::find($sub, $profile_dir);
125 unless ($found) {
126 print_log "ERROR: couldn't find prefs.js in $profile_dir\n";
127 return; # empty list
130 # Find full profile_dir while we're at it.
131 $profile_dir = File::Basename::dirname($pref_file);
133 print_log "profile dir = $profile_dir\n";
134 print_log "prefs.js = $pref_file\n";
136 return ($pref_file, $profile_dir);