public function setUp()
 {
     $rawTestInfo = array();
     $this->testInfo = TestInfo::fromValues("160628_AB_C", "/test/path", $rawTestInfo);
     $this->xmlInfoDomainBreakdown = array(XmlResultGenerator::INFO_DOMAIN_BREAKDOWN);
     ob_start();
 }
示例#2
0
 /**
  * @return bool True if the step has a breakdown timeline, false otherwise
  */
 public function hasBreakdownTimeline()
 {
     $info = $this->testInfo->getInfoArray();
     if (!isset($info) || empty($info["timeline"])) {
         return false;
     }
     return $this->fileHandler->gzFileExists($this->localPaths->devtoolsFile()) || $this->fileHandler->gzFileExists($this->localPaths->devtoolsTraceFile());
 }
 private function _createErrorRow($run, $cached, $tableColumns)
 {
     $error = $this->testInfo->getRunError($run, $cached);
     $error_str = $error ? htmlspecialchars('Test Error: ' . $error) : "Test Data Missing";
     $cachedLabel = $cached ? "Repeat View" : "First View";
     $out = "<tr id='run{$run}_step1' class='stepResultRow'>";
     $out .= "<td colspan=\"{$tableColumns}\" align=\"left\" valign=\"middle\">{$cachedLabel}: {$error_str}</td></tr>\n";
     return $out;
 }
 /**
  * RunResultHtmlTable constructor.
  * @param TestInfo $testInfo
  * @param TestRunResults $runResults
  * @param TestRunResults $rvRunResults Optional. Run results of the repeat view
  */
 public function __construct($testInfo, $runResults, $rvRunResults = null)
 {
     $this->testInfo = $testInfo;
     $this->runResults = $runResults;
     $this->rvRunResults = $rvRunResults;
     $this->isMultistep = $runResults->isMultistep();
     $this->leftOptionalColumns = array(self::COL_LABEL, self::COL_ABOVE_THE_FOLD, self::COL_USER_TIME, self::COL_DOM_TIME, self::COL_DOM_ELEMENTS, self::COL_SPEED_INDEX, self::COL_VISUAL_COMPLETE, self::COL_RESULT);
     $this->rightOptionalColumns = array(self::COL_COST);
     $this->enabledColumns = array();
     // optional columns default setting based on data
     $this->enabledColumns[self::COL_LABEL] = $this->testInfo->getRuns() > 1 || $this->isMultistep || $this->rvRunResults;
     $this->enabledColumns[self::COL_ABOVE_THE_FOLD] = $testInfo->hasAboveTheFoldTime();
     $this->enabledColumns[self::COL_RESULT] = true;
     $checkByMetric = array(self::COL_USER_TIME, self::COL_DOM_TIME, self::COL_DOM_ELEMENTS, self::COL_SPEED_INDEX, self::COL_VISUAL_COMPLETE);
     foreach ($checkByMetric as $col) {
         $this->enabledColumns[$col] = $runResults->hasValidMetric($col) || $rvRunResults && $rvRunResults->hasValidMetric($col);
     }
 }
示例#5
0
 /**
  * @param string[] $keywords Keywords to use for the check
  * @return bool True if the checked site is an adult site, false otherwise
  */
 public function isAdultSite($keywords)
 {
     if ($this->testInfo->isAdultSite($keywords)) {
         return true;
     }
     foreach ($this->stepResults as $step) {
         if ($step->isAdultSite($keywords)) {
             return true;
         }
     }
     return false;
 }
 private function getTestResultsFromPageData()
 {
     $run1 = array('result' => 0, 'TTFB' => 300, 'loadTime' => 6000);
     $run2 = array('result' => 404, 'TTFB' => 200, 'loadTime' => 3000);
     $run3 = array('result' => 0, 'TTFB' => 100, 'loadTime' => 2000);
     $run4 = array('result' => 99999, 'TTFB' => 500, 'loadTime' => 1000);
     $run5 = array('result' => 0, 'TTFB' => 400, 'loadTime' => 5000);
     $pageData = array(1 => array($run1), 2 => array($run2, $run4), 3 => array($run3, $run1), 4 => array($run4, $run5));
     foreach (array_keys($pageData) as $key) {
         $pageData[$key][0]["cached"] = 0;
         if (isset($pageData[$key][1])) {
             $pageData[$key][1]["cached"] = 1;
         }
     }
     $testinfo = array();
     return TestResults::fromPageData(TestInfo::fromValues("testId", "/test/path", $testinfo), $pageData);
 }
 public function testJsonResultArrayGeneration()
 {
     global $SINGLESTEP_JSON_RESULT_ARRAY;
     $this->tempDir = TestUtil::extractToTemp(__DIR__ . '/data/singlestepResults.zip');
     $testInfo = TestInfo::fromFiles($this->tempDir . '/singlestepResults');
     $imitatedPath = $this->imitatedResultPath($testInfo->getId());
     // we need to move the results to a directory structure that equal to the real one.
     // Then, we can go into the parent directory, so the relatece "testRoot" is the same as it would be in production
     // This is important, as during XML generation, some URLs contain the test path
     mkdir($this->tempDir . $imitatedPath, 0777, true);
     rename($this->tempDir . '/singlestepResults', $this->tempDir . $imitatedPath);
     $this->orgDir = getcwd();
     chdir($this->tempDir);
     $testRoot = "." . $imitatedPath;
     $testInfo = TestInfo::fromFiles($testRoot);
     $testResults = TestResults::fromFiles($testInfo);
     $jsonGenerator = new JsonResultGenerator($testInfo, "http://wpt-test-vm", new FileHandler());
     $resultArray = $jsonGenerator->resultDataArray($testResults, "loadTime");
     $this->assertThat($resultArray, new IsArraySubsetConstraint($SINGLESTEP_JSON_RESULT_ARRAY));
 }
 public function testCompleteXmlGeneration()
 {
     $this->tempDir = TestUtil::extractToTemp(__DIR__ . '/data/singlestepResults.zip');
     $testInfo = TestInfo::fromFiles($this->tempDir . '/singlestepResults');
     $imitatedPath = $this->imitatedResultPath($testInfo->getId());
     // we need to move the results to a directory structure that equal to the real one.
     // Then, we can go into the parent directory, so the relatece "testRoot" is the same as it would be in production
     // This is important, as during XML generation, some URLs contain the test path
     mkdir($this->tempDir . $imitatedPath, 0777, true);
     rename($this->tempDir . '/singlestepResults', $this->tempDir . $imitatedPath);
     $this->orgDir = getcwd();
     chdir($this->tempDir);
     $testRoot = "." . $imitatedPath;
     $testInfo = TestInfo::fromFiles($testRoot);
     $expectedXmlFile = __DIR__ . '/data/singlestepXmlResult.xml.gz';
     $testResults = TestResults::fromFiles($testInfo);
     $xmlGenerator = new XmlResultGenerator($testInfo, "http://wpt-test-vm", new FileHandler(), $this->allAdditionalInfo, true);
     $xmlGenerator->printAllResults($testResults, "loadTime", null);
     $this->assertThat(ob_get_contents(), IsCompatibleXMLConstraint::fromFile($expectedXmlFile));
 }
示例#9
0
 /**
  * Constructs a TestResults object by loading the information from result files
  * @param TestInfo $testInfo Test information used to load the data
  * @param FileHandler $fileHandler FileHandler to use
  * @param array $options Options to load the TestRunResults
  * @return TestResults The new instance
  */
 public static function fromFiles($testInfo, $fileHandler = null, $options = null)
 {
     $runResults = array();
     $numRuns = $testInfo->getRuns();
     $firstViewOnly = $testInfo->isFirstViewOnly();
     $testComplete = $testInfo->isComplete();
     for ($runNumber = 1; $runNumber <= $numRuns; $runNumber++) {
         if (!$testComplete && !$testInfo->isRunComplete($runNumber)) {
             continue;
         }
         $firstView = TestRunResults::fromFiles($testInfo, $runNumber, false, $fileHandler, $options);
         $repeatView = $firstViewOnly ? null : TestRunResults::fromFiles($testInfo, $runNumber, true, $fileHandler, $options);
         $runResults[] = array($firstView, $repeatView);
     }
     return new self($testInfo, $runResults, $fileHandler);
 }
示例#10
0
 public function testHasVideo()
 {
     $testInfo = TestInfo::fromValues("test", "/test/root", array());
     $this->assertFalse($testInfo->hasVideo());
     $testInfo = TestInfo::fromValues("test", "/test/root", array("test" => array("video" => false)));
     $this->assertFalse($testInfo->hasVideo());
     $testInfo = TestInfo::fromValues("test", "/test/root", array("test" => array("video" => true)));
     $this->assertTrue($testInfo->hasVideo());
     $testInfo = TestInfo::fromValues("test", "/test/root", array("test" => array("Video" => true)));
     $this->assertTrue($testInfo->hasVideo());
     $testInfo = TestInfo::fromValues("test", "/test/root", array("test" => array("Capture Video" => true)));
     $this->assertTrue($testInfo->hasVideo());
 }
 public function testIsAdultSite()
 {
     $stepAdult = TestStepResult::fromPageData($this->testInfo, array("title" => "myadUltPage"), 2, false, 1);
     $stepNonAdult = TestStepResult::fromPageData($this->testInfo, array("title" => "normalSite"), 2, false, 2);
     $runResults = TestRunResults::fromStepResults($this->testInfo, 2, false, array($stepAdult, $stepNonAdult));
     $this->assertTrue($runResults->isAdultSite(array("adult", "foo")));
     $this->assertFalse($runResults->isAdultSite(array("bar", "foo")));
     $runResults = TestRunResults::fromStepResults($this->testInfo, 2, false, array($stepNonAdult, $stepNonAdult));
     $this->assertFalse($runResults->isAdultSite(array("adult", "foo")));
     $this->assertFalse($runResults->isAdultSite(array("bar", "foo")));
     $runResults = TestRunResults::fromStepResults($this->testInfo, 2, false, array($stepNonAdult, $stepNonAdult));
     $this->assertFalse($runResults->isAdultSite(array("adult", "foo")));
     $this->assertFalse($runResults->isAdultSite(array("bar", "foo")));
     $testInfo = TestInfo::fromValues("testId", "/test/path", array("testinfo" => array("url" => "adultSite")));
     $runResults = TestRunResults::fromStepResults($testInfo, 2, false, array($stepNonAdult, $stepNonAdult));
     $this->assertTrue($runResults->isAdultSite(array("adult", "foo")));
     $this->assertFalse($runResults->isAdultSite(array("bar", "foo")));
 }
示例#12
0
 global $testPath, $run, $cached, $step;
 // from common.inc
 $file = $_GET['file'];
 // make sure nobody is trying to use us to pull down external images from somewhere else
 if (strpos($file, ':') === FALSE && strpos($file, '//') === FALSE && strpos($file, '\\') === FALSE) {
     $fileParts = explode('.', $file);
     $parts = pathinfo($file);
     $type = $parts['extension'];
     $fit = max(min(@$_REQUEST['fit'], 1000), 0);
     $newWidth = 250;
     $w = @$_REQUEST['width'];
     if ($w && $w > 20 && $w < 1000) {
         $newWidth = $w;
     }
     $img = null;
     $testStepResult = TestStepResult::fromFiles(TestInfo::fromFiles($testPath), $run, $cached, $step);
     // see if it is a waterfall image
     if (strstr($parts['basename'], 'waterfall') !== false) {
         tbnDrawWaterfall($testStepResult, $img);
     } elseif (strstr($parts['basename'], 'optimization') !== false) {
         tbnDrawChecklist($testStepResult, $img);
     } else {
         if (!is_file("{$testPath}/{$file}")) {
             $file = str_ireplace('.jpg', '.png', $file);
             $parts = pathinfo($file);
             $type = $parts['extension'];
         }
         if (is_file("{$testPath}/{$file}")) {
             if (!strcasecmp($type, 'jpg')) {
                 $img = imagecreatefromjpeg("{$testPath}/{$file}");
             } elseif (!strcasecmp($type, 'gif')) {
 public function testHasBreakdownTimeline()
 {
     $fileHandlerExists = $this->getMock("FileHandler");
     $fileHandlerExists->method("gzFileExists")->willReturn(true);
     $fileHandlerDoesntExists = $this->getMock("FileHandler");
     $fileHandlerDoesntExists->method("gzFileExists")->willReturn(false);
     $testInfoWithTimeline = TestInfo::fromValues("testId", "/root/path", array("testinfo" => array("timeline" => "1")));
     $testInfoWithoutTimeline = TestInfo::fromValues("testId", "/root/path", array("testinfo" => array()));
     $step = TestStepResult::fromPageData($testInfoWithTimeline, array(), 1, 1, 1, $fileHandlerExists);
     $this->assertTrue($step->hasBreakdownTimeline());
     $step = TestStepResult::fromPageData($testInfoWithTimeline, array(), 1, 1, 1, $fileHandlerDoesntExists);
     $this->assertFalse($step->hasBreakdownTimeline());
     $step = TestStepResult::fromPageData($testInfoWithoutTimeline, array(), 1, 1, 1, $fileHandlerExists);
     $this->assertFalse($step->hasBreakdownTimeline());
     $step = TestStepResult::fromPageData($testInfoWithoutTimeline, array(), 1, 1, 1, $fileHandlerDoesntExists);
     $this->assertFalse($step->hasBreakdownTimeline());
 }
 public function setUp()
 {
     $rawTestInfo = array();
     $this->testInfo = TestInfo::fromValues("160628_AB_C", "/tmp", $rawTestInfo);
 }
示例#15
0
<?php

include __DIR__ . '/common.inc';
require_once __DIR__ . '/object_detail.inc';
require_once __DIR__ . '/page_data.inc';
require_once __DIR__ . '/include/TestInfo.php';
require_once __DIR__ . '/include/TestPaths.php';
require_once __DIR__ . '/include/TestStepResult.php';
require_once __DIR__ . '/include/UrlGenerator.php';
global $testPath, $id, $run, $cached, $step;
// defined in common.inc
$secure = false;
$haveLocations = false;
$testInfo = TestInfo::fromFiles($testPath);
$localPaths = new TestPaths($testPath, $run, $cached, $step);
$urlGenerator = UrlGenerator::create(false, "", $id, $run, $cached, $step);
$requests = getRequestsForStep($localPaths, $urlGenerator, $secure, $haveLocations, true);
$page_keywords = array('Images', 'Webpagetest', 'Website Speed Test', 'Page Speed');
$page_description = "Website speed test images{$testLabel}.";
$userImages = true;
?>
<!DOCTYPE html>
<html>
  <head>
    <title>WebPagetest Page Images<?php 
echo $testLabel;
?>
</title>
    <?php 
$gaTemplate = 'Page Images';
include 'head.inc';
示例#16
0
// see if we are sending abbreviated results
$pagespeed = 0;
if (array_key_exists('pagespeed', $_REQUEST)) {
    $pagespeed = (int) $_REQUEST['pagespeed'];
}
if (isset($test['test']) && $test['test']['batch']) {
    BatchResult($id, $testPath);
} else {
    // see if the test is actually finished
    $status = GetTestStatus($id);
    if (isset($test['test']['completeTime'])) {
        $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || isset($_SERVER['HTTP_SSL']) && $_SERVER['HTTP_SSL'] == 'On' ? 'https' : 'http';
        $host = $_SERVER['HTTP_HOST'];
        $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
        $path = substr($testPath, 1);
        $testInfo = TestInfo::fromValues($id, $testPath, $test);
        $testResults = TestResults::fromFiles($testInfo);
        $msLoad = microtime(true);
        // if we don't have an url, try to get it from the page results
        if (!strlen($url)) {
            $url = $testResults->getUrlFromRun();
        }
        $additionalInfo = array();
        if ($pagespeed) {
            $additionalInfo[] = XmlResultGenerator::INFO_PAGESPEED;
        }
        if (array_key_exists("requests", $_REQUEST) && $_REQUEST["requests"]) {
            $additionalInfo[] = XmlResultGenerator::INFO_MEDIAN_REQUESTS;
            if ($_REQUEST["requests"] != "median") {
                $additionalInfo[] = XmlResultGenerator::INFO_REQUESTS;
            }
示例#17
0
     if (array_key_exists('discard', $info) && $info['discard'] >= 1 && array_key_exists('priority', $info) && $info['priority'] >= 1) {
         $defaultInterval = 100;
     }
     $test['url'] = $info['url'];
     if (isset($info['medianMetric'])) {
         $test_median_metric = $info['medianMetric'];
     }
 }
 $testInfo = parse_ini_file("./{$test['path']}/testinfo.ini", true);
 if ($testInfo !== FALSE) {
     if (array_key_exists('test', $testInfo) && array_key_exists('location', $testInfo['test'])) {
         $test['location'] = $testInfo['test']['location'];
     }
     if (isset($testInfo['test']) && isset($testInfo['test']['completeTime'])) {
         $test['done'] = true;
         $testInfoObject = TestInfo::fromFiles("./" . $test['path']);
         if (!array_key_exists('run', $test) || !$test['run']) {
             $testResults = TestResults::fromFiles($testInfoObject);
             $test['run'] = $testResults->getMedianRunNumber($test_median_metric, $test['cached']);
             $runResults = $testResults->getRunResult($test['run'], $test['cached']);
             $stepResult = $runResults->getStepResult($test['step']);
         } else {
             $stepResult = TestStepResult::fromFiles($testInfoObject, $test['run'], $test['cached'], $test['step']);
         }
         $test['stepResult'] = $stepResult;
         $test['aft'] = (int) $stepResult->getMetric('aft');
         $loadTime = $stepResult->getMetric('fullyLoaded');
         if (isset($loadTime) && (!isset($fastest) || $loadTime < $fastest)) {
             $fastest = $loadTime;
         }
         // figure out the real end time (in ms)
示例#18
0
/**
 * @param FileHandler $fileHandler FileHandler to use
 * @param TestInfo $testInfo Information about the test
 * @param TestStepResult $testStepResult Results of the specific test
 * @param bool $useQuicklinks True if quicklinks are used, false otherwise
 */
function printStep($fileHandler, $testInfo, $testStepResult, $useQuicklinks)
{
    $pageRunData = $testStepResult->getRawResults();
    $localPaths = $testStepResult->createTestPaths();
    $urlPaths = $testStepResult->createTestPaths(substr($testInfo->getRootDirectory(), 1));
    $urlGenerator = $testStepResult->createUrlGenerator("", FRIENDLY_URLS);
    echo "<a name=\"step_" . $testStepResult->getStepNumber() . "\">";
    echo "<h1 class='stepName'>" . $testStepResult->readableIdentifier() . "</h1>";
    echo "</a>";
    if ($fileHandler->dirExists($localPaths->videoDir())) {
        echo "<a href=\"" . $urlGenerator->createVideo() . "\">Create Video</a> &#8226; ";
        echo "<a href=\"" . $urlGenerator->downloadVideoFrames() . "\">Download Video Frames</a>";
        if ($useQuicklinks) {
            echo " &#8226; ";
        }
    }
    if ($useQuicklinks) {
        echo '<a href="#quicklinks">Back to Quicklinks</a>';
    }
    $screenShotUrl = null;
    if ($fileHandler->fileExists($localPaths->screenShotPngFile())) {
        $screenShotUrl = $urlPaths->screenShotPngFile();
    } else {
        if ($fileHandler->fileExists($localPaths->screenShotFile())) {
            $screenShotUrl = $urlPaths->screenShotFile();
        }
    }
    if ($screenShotUrl) {
        echo '<h2>Fully Loaded</h2>';
        echo '<a href="' . $screenShotUrl . '">';
        echo '<img class="center" alt="Screen Shot" style="max-width:930px; -ms-interpolation-mode: bicubic;" src="' . $screenShotUrl . '">';
        echo '</a>';
    }
    // display the last status message if we have one
    $messages = $testStepResult->getStatusMessages();
    if (count($messages)) {
        $lastMessage = end($messages);
        if (strlen($lastMessage['message'])) {
            echo "\n<br>Last Status Message: \"{$lastMessage['message']}\"\n";
        }
    }
    $stepNumber = $testStepResult->getStepNumber();
    $linkSuffix = $stepNumber > 1 ? "_" . $stepNumber : "";
    if ($fileHandler->fileExists($localPaths->additionalScreenShotFile("render"))) {
        echo '<br><br><a name="start_render' . $linkSuffix . '"><h2>Start Render';
        if (isset($pageRunData) && isset($pageRunData['render'])) {
            echo ' (' . number_format($pageRunData['render'] / 1000.0, 3) . '  sec)';
        }
        echo '</h2></a>';
        echo '<img class="center" alt="Start Render Screen Shot" src="' . $urlPaths->additionalScreenShotFile("render") . '">';
    }
    if ($fileHandler->fileExists($localPaths->additionalScreenShotFile("dom"))) {
        echo '<br><br><a name="dom_element' . $linkSuffix . '"><h2>DOM Element';
        if (isset($pageRunData) && isset($pageRunData['domTime'])) {
            echo ' (' . number_format($pageRunData['domTime'] / 1000.0, 3) . '  sec)';
        }
        echo '</h2></a>';
        echo '<img class="center" alt="DOM Element Screen Shot" src="' . $urlPaths->additionalScreenShotFile("dom") . '">';
    }
    if ($fileHandler->fileExists($localPaths->additionalScreenShotFile("doc"))) {
        echo '<br><br><a name="doc_complete' . $linkSuffix . '"><h2>Document Complete';
        if (isset($pageRunData) && isset($pageRunData['docTime'])) {
            echo ' (' . number_format($pageRunData['docTime'] / 1000.0, 3) . '  sec)';
        }
        echo '</h2></a>';
        echo '<img class="center" alt="Document Complete Screen Shot" src="' . $urlPaths->additionalScreenShotFile("doc") . '">';
    }
    if ($fileHandler->fileExists($localPaths->aftDiagnosticImageFile())) {
        echo '<br><br><a name="aft' . $linkSuffix . '"><h2>AFT Details';
        if (isset($pageRunData) && isset($pageRunData['aft'])) {
            echo ' (' . number_format($pageRunData['aft'] / 1000.0, 3) . '  sec)';
        }
        echo '</h2></a>';
        echo 'White = Stabilized Early, Blue = Dynamic, Red = Late Static (failed AFT), Green = AFT<br>';
        echo '<img class="center" alt="AFT Diagnostic image" src="' . $urlPaths->aftDiagnosticImageFile() . '">';
    }
    if ($fileHandler->fileExists($localPaths->additionalScreenShotFile("responsive"))) {
        echo '<br><br><h2 id="responsive">Responsive Site Check</h2>';
        echo '<img class="center" alt="Responsive Site Check image" src="' . $urlPaths->additionalScreenShotFile("responsive") . '">';
    }
    // display all of the status messages
    if (count($messages)) {
        echo "\n<br><br><a name=\"status_messages" . $linkSuffix . "\"><h2>Status Messages</h2></a>\n";
        echo "<table id=\"messages\" class=\"translucent\"><tr><th>Time</th><th>Message</th></tr>\n";
        foreach ($messages as $message) {
            $time = $message['time'] / 1000.0;
            if ($time > 0.0) {
                echo "<tr><td class=\"time\">{$time} sec.</td><td>{$message['message']}</td></tr>";
            }
        }
        echo "</table>\n";
    }
    $row = 0;
    $console_log = $testStepResult->getConsoleLog();
    if (isset($console_log) && count($console_log)) {
        echo "\n<br><br><a name=\"console-log" . $linkSuffix . "\"><h2>Console Log</h2></a>\n";
        echo "<table id=\"console-log\" class=\"translucent\"><tr><th>Source</th><th>Level</th><th>Message</th><th>URL</th><th>Line</th></tr>\n";
        foreach ($console_log as &$log_entry) {
            $row++;
            $rowClass = '';
            if ($row % 2 == 0) {
                $rowClass = ' class="even"';
            }
            echo "<tr{$rowClass}><td class=\"source\">" . htmlspecialchars($log_entry['source']) . "</td><td class=\"level\">" . htmlspecialchars($log_entry['level']) . "</td><td class=\"message\"><div>" . htmlspecialchars($log_entry['text']) . "</div></td><td class=\"url\"><div><a href=\"" . htmlspecialchars($log_entry['url']) . "\">" . htmlspecialchars($log_entry['url']) . "</a></div></td><td class=\"line\">" . htmlspecialchars($log_entry['line']) . "</td></tr>\n";
        }
        echo "</table>\n";
    }
}