DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (d5c3254b3e56)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
#!/usr/bin/perl -w
# -*- mode: cperl; c-basic-offset: 8; indent-tabs-mode: nil; -*-

# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Litmus.
#
# The Initial Developer of the Original Code is
# the Mozilla Corporation.
# Portions created by the Initial Developer are Copyright (C) 2006
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#   Chris Cooper <ccooper@deadsquid.com>
#   Zach Lipton <zach@zachlipton.com>
#
# ***** END LICENSE BLOCK *****

use strict;

use Time::HiRes qw( gettimeofday tv_interval );
our $t0 = [gettimeofday];

use Litmus;
use Litmus::Error;
use Litmus::FormWidget;
use Litmus::DB::Product;
use Litmus::UserAgentDetect;
use Litmus::SysConfig;
use Litmus::Auth;

use CGI;
use JSON -convert_blessed_universally;

Litmus->init();

our $title = "Run Tests";

our $c = Litmus->cgi(); 

if ($c->param) {
  if ($c->param("testgroup")) {
    &displayTestcases();
  } elsif ($c->param("criterion") or
           $c->param("continuetesting")) { 
    &displayGroupSelection();
  } elsif ($c->param("test_run_id")) {
    &displaySysConfig();
  } else { 
    &displayAllTestRuns();
  }
} else {
  &displayAllTestRuns();
}

if ($Litmus::Config::DEBUG) {
  my $elapsed = tv_interval ( $t0 );
  printf  "<div id='pageload'>Page took %f seconds to load.</div>", $elapsed;
}

exit 0;

# END

#########################################################################
sub displaySysConfig() {
  Litmus::Auth::requireLogin("run_tests.cgi");
  
  my $test_run_id = $c->param("test_run_id");

  if (!$test_run_id) {
    &displayAllTestRuns();
  }

  print $c->header();

  my $test_run = Litmus::DB::TestRun->getTestRunWithRefs($test_run_id);
  
  my $title = "Run Tests - Your Chosen Test Run";

  my $platforms = Litmus::FormWidget->getPlatforms();
  my $opsyses = Litmus::FormWidget->getOpsyses();
  my $locales = Litmus::FormWidget->getLocales();

  my $json = new JSON;
  my $test_run_js = $json->allow_unknown->convert_blessed->encode($test_run);
  my $platforms_js = $json->allow_unknown->convert_blessed->encode($platforms);
  my $opsyses_js = $json->allow_unknown->convert_blessed->encode($opsyses);

  my $vars = {
              title        => $title,
              user         => Litmus::Auth::getCurrentUser(),
              test_run     => [$test_run],
              test_run_js  => $test_run_js,
              platforms_js => $platforms_js,
              opsyses_js   => $opsyses_js,
              locales      => $locales,
             };
  
  my $cookie =  Litmus::Auth::getCookie();
  $vars->{"defaultemail"} = $cookie;
  $vars->{"show_admin"} = Litmus::Auth::istrusted($cookie);
  
  Litmus->template()->process("runtests/sysconfig.html.tmpl", $vars) || 
    internalError(Litmus->template()->error());
  
}

#########################################################################
sub displayGroupSelection() {
  Litmus::Auth::requireLogin("run_tests.cgi");
  
  my $test_run_id = $c->param("test_run_id");
  my $default_testgroup = $c->param("defaulttestgroup");

  if (!$test_run_id) {
    &displayAllTestRuns();
    return;
  }

  my $test_run = Litmus::DB::TestRun->getTestRunWithRefs($test_run_id);
  my $sysconfig;
  if ($c->param("continuetesting")) {
    # Check that we have config info for this test run already.
    $sysconfig = Litmus::SysConfig->getCookieByTestRunId($test_run_id);
  } else {
    $sysconfig = &verifySysConfig($test_run);
  }
 
  if (!$sysconfig) {
    &displaySysConfig();
    return;
  };

  $c->storeCookie($sysconfig->setCookie());
  
  $test_run->flagCriteriaInUse($sysconfig);

  print $c->header();
  
  my $user =  Litmus::Auth::getCookie();
  my @testgroups;
  if (Litmus::Auth::istrusted($user)) {
    @testgroups = Litmus::DB::Testgroup->search_ByTestRun($test_run_id);
  } else {
    @testgroups = Litmus::DB::Testgroup->search_EnabledByTestRun($test_run_id);
  }
  
  # all possible subgroups per group:
  my %subgroups; 
  foreach my $testgroup (@testgroups) {
    my @component_subgroups;
    if (Litmus::Auth::istrusted($user)) {
      @component_subgroups = Litmus::DB::Subgroup->search_ByTestgroup($testgroup->testgroup_id());
    } else {
      @component_subgroups = Litmus::DB::Subgroup->search_EnabledByTestgroup($testgroup->testgroup_id());
    }
    $subgroups{$testgroup->testgroup_id()} = \@component_subgroups;
  }
  
  my $defaultgroup = "";
  if ($c->param("defaulttestgroup")) {
    $defaultgroup = Litmus::DB::Testgroup->
      retrieve($c->param("defaulttestgroup"));
  }

  my $vars = {
              title            => $title,
              user             => Litmus::Auth::getCurrentUser(),
              test_runs        => [$test_run],
              testgroups       => \@testgroups,
              subgroups        => \%subgroups,
              defaulttestgroup => $default_testgroup,
              defaultemail     => $user,
              show_admin       => Litmus::Auth::istrusted($user),
              sysconfig        => $sysconfig,
             };

  Litmus->template()->process("runtests/selectgroupsubgroup.html.tmpl", 
                              $vars) or 
    internalError(Litmus->template()->error());
}

#########################################################################
sub displayTestcases() {
  Litmus::Auth::requireLogin("run_tests.cgi");
  
  my $test_run_id = $c->param("test_run_id");

  if (!$test_run_id) {
    &displayAllTestRuns();
  }

  my $test_run = Litmus::DB::TestRun->getTestRunWithRefs($test_run_id);
  my $sysconfig = Litmus::SysConfig->getCookieByTestRunId($test_run_id);
 
  if (!$sysconfig) {
    &displaySysConfig();
    return;
  };

  $c->storeCookie($sysconfig->setCookie());
  
  $test_run->flagCriteriaInUse($sysconfig);

  print $c->header();
#  use Data::Dumper;
#  print Dumper $sysconfig;
#  print Dumper $test_run->{'criteria'};

  # the form has a subgroup radio button set for each possible group, named
  # subgroup_n where n is the group id number. We get the correct
  # subgroup based on whatever group the user selected: 
  my $testgroup_id = $c->param("testgroup");
  my $subgroup_id = $c->param("subgroup_".$testgroup_id);

  my $cookie =  Litmus::Auth::getCookie();
  my $show_admin = Litmus::Auth::istrusted($cookie);
  
  # get the tests to display:
  my @tests;
  if ($show_admin) {
    @tests = Litmus::DB::Testcase->search_EnabledBySubgroup($subgroup_id,$testgroup_id);
  } else {
    @tests = Litmus::DB::Testcase->search_CommunityEnabledBySubgroup($subgroup_id,$testgroup_id);
  }
  
  my $vars = {
              title        => $title,
              test_runs    => [$test_run],
              testgroup    => Litmus::DB::Testgroup->retrieve($testgroup_id),
              subgroup     => Litmus::DB::Subgroup->retrieve($subgroup_id),
              tests        => \@tests,
              defaultemail => $cookie,
              show_admin   => $show_admin,
              istrusted    => $show_admin,
              sysconfig    => $sysconfig,
             };
  
  Litmus->template()->process("runtests/testdisplay.html.tmpl", $vars) ||
    internalError(Litmus->template()->error());
}

#########################################################################
sub displayAllTestRuns() {
  print $c->header();

  my @recommended_test_runs = Litmus::DB::TestRun->getTestRuns(1,'true',0);
  my @remaining_test_runs = Litmus::DB::TestRun->getTestRuns(1,'false',0);

  my $title = "Active Test Runs - All";

  my $vars = {
              title        => $title,
              user         => Litmus::Auth::getCurrentUser(),
              recommended_test_runs => \@recommended_test_runs,
              remaining_test_runs => \@remaining_test_runs,
             };
  
  my $cookie =  Litmus::Auth::getCookie();
  $vars->{"defaultemail"} = $cookie;
  $vars->{"show_admin"} = Litmus::Auth::istrusted($cookie);
  
  Litmus->template()->process("runtests/all_test_runs.tmpl", 
                              $vars) || 
                                internalError(Litmus->template()->error());
}

#########################################################################
sub verifySysConfig() {
  my ($test_run) = @_;
  
  # Use the criterion value as the basis for our check, since disabled form
  # controls don't dubmit their values anyway.
  my ($row_num,$build_id,$platform_id,$opsys_id);
  if ($c->param("criterion")) {
    ($row_num,$build_id,$platform_id,$opsys_id) = split(/\|/,$c->param("criterion"),4);
    if (!$build_id) {
      $build_id = $c->param("build_id_${row_num}");
    }
    if (!$platform_id) {
      $platform_id = $c->param("platform_${row_num}");
    }
    if (!$opsys_id) {
      $opsys_id = $c->param("opsys_${row_num}");
    }
  }
  my $locale = $c->param("locale");

  # Make sure we have a complete set of criteria.
  if (!$build_id or
      !$platform_id or
      !$opsys_id or
      !$locale) {
    return undef;
  }
  
  # Compare the provided criteria with any required criteria.
  my $found_match = 0;
  if ($test_run->criteria and scalar(@{$test_run->criteria}) > 0) {
    foreach my $criterion (@{$test_run->criteria}) {
      # Build ID alone is the smallest possible criteria set.
      if ($criterion->{'build_id'} == $build_id) {
        if ($criterion->{'platform_id'}) {
          if ($criterion->{'platform_id'} == $platform_id) {
            if ($criterion->{'opsys_id'}) {
              if ($criterion->{'opsys_id'} == $opsys_id) {
                # Matches build ID, platform ID, and opsys ID
                $found_match = 1;
                last;
              }
              next;
            }
            # Matches build ID and platform ID
            $found_match = 1;
            last;
          }
          next;
        }
        # Matches build ID.
        $found_match = 1;
        last;
      }
      next;
    }    
  } else {
    # No criteria associated with this test run, so any complete set of
    # criteria will do.
    $found_match = 1;
  }

  if (!$found_match) {
    return undef;
  }

  my $sysconfig = Litmus::SysConfig::new(
                                         $test_run->{'test_run_id'},
                                         $build_id,
                                         $platform_id,
                                         $opsys_id,
                                         $locale
                                         );
  return $sysconfig;
}