From d1783d364c2201c7e3d619cb6966bbafe5792ad8 Mon Sep 17 00:00:00 2001 From: Leonardo Bartoli Date: Wed, 12 Feb 2025 15:56:59 +0100 Subject: [PATCH] Handle fp url param --- www/common.inc | 11 +- www/include/UrlGenerator.php | 186 +++++----- www/result.inc | 681 +++++++++++++++++------------------ 3 files changed, 446 insertions(+), 432 deletions(-) diff --git a/www/common.inc b/www/common.inc index ca891d11ce..67c3b24c6d 100644 --- a/www/common.inc +++ b/www/common.inc @@ -42,7 +42,7 @@ if (Util::getSetting('cp_auth')) { error_log($e->getMessage()); $route = "/"; $message = "There was a problem with you account. Please reach out to customer service." . - "Error number: 2000"; + "Error number: 2000"; $host = Util::getSetting('host'); if (Util::getSetting('php_sessions')) { @@ -65,7 +65,7 @@ if (Util::getSetting('cp_auth')) { $message = ""; if (is_a($e, PortalException::class)) { $message = "There was a problem with you account. Please reach out to customer service." . - "Error number: {$e->getErrorNumber()}"; + "Error number: {$e->getErrorNumber()}"; } else { $message = $e->getMessage(); } @@ -375,7 +375,7 @@ if ($supportsAuth && $supportsCPAuth) { require_once INCLUDES_PATH . '/common/AttachUser.php'; require_once INCLUDES_PATH . '/common/AttachSignupClient.php'; require_once INCLUDES_PATH . '/common/AttachBannerMessageManager.php'; -// require_once INCLUDES_PATH . '/common/CheckCSRF.php'; + // require_once INCLUDES_PATH . '/common/CheckCSRF.php'; } // Load the test-specific data @@ -531,7 +531,7 @@ if (strlen($id)) { $controlTestUrlGenerator = UrlGenerator::create(FRIENDLY_URLS, "", $metaInfo['experiment']['control_id'], 0, 0); $controlTestHref = $controlTestUrlGenerator->resultSummary(); - $experimentResultsHref = "/video/compare.php?tests=" . $id . ',' . $metaInfo['experiment']['control_id']; + $experimentResultsHref = "/video/compare.php?tests=" . $id . ',' . $metaInfo['experiment']['control_id'] . ($req_fp ? "&fp=1" : ''); $experimentTestHref = "/result/" . $id; $experimentOptsUrlGenerator = UrlGenerator::create(FRIENDLY_URLS, "", $id, 0, 0); @@ -567,5 +567,6 @@ if (is_file(SETTINGS_PATH . '/custom_common.inc.php')) { require_once INCLUDES_PATH . '/experiments/user_access.inc'; $request_context->setReadOnly( - !is_null($request_context->getUser()) && $request_context->getUser() && $request_context->getUser()->newPortalExperience() + isset($req_fp) || + !is_null($request_context->getUser()) && $request_context->getUser() && $request_context->getUser()->newPortalExperience() ); diff --git a/www/include/UrlGenerator.php b/www/include/UrlGenerator.php index 5050eed1eb..4b3eac4026 100644 --- a/www/include/UrlGenerator.php +++ b/www/include/UrlGenerator.php @@ -14,25 +14,29 @@ abstract class UrlGenerator protected $step; protected $baseUrl; protected $testId; + protected $fp; protected function __construct($baseUrl, $testId, $run, $cached, $step = 1) { + global $req_fp; + $this->baseUrl = rtrim(strval($baseUrl), "/"); $this->testId = $testId; $this->run = intval($run); $this->cached = $cached ? true : false; $this->step = $step; + $this->fp = $req_fp; } - /** - * @param bool $friendlyUrls If the URL should be friendly (via mod_rewrite) or standard - * @param string $baseUrl URL base for the server (like http://my.wpt.server) - * @param string $testId ID of the test - * @param int $run Run number - * @param bool $cached True if cached run, false otherwise - * @param int $step The step number (1 by default) - * @return FriendlyUrlGenerator|StandardUrlGenerator A UrlGenerator for friendly or standard URLs - */ + /** + * @param bool $friendlyUrls If the URL should be friendly (via mod_rewrite) or standard + * @param string $baseUrl URL base for the server (like http://my.wpt.server) + * @param string $testId ID of the test + * @param int $run Run number + * @param bool $cached True if cached run, false otherwise + * @param int $step The step number (1 by default) + * @return FriendlyUrlGenerator|StandardUrlGenerator A UrlGenerator for friendly or standard URLs + */ public static function create($friendlyUrls, $baseUrl, $testId, $run, $cached, $step = 1) { if ($friendlyUrls) { @@ -42,49 +46,49 @@ public static function create($friendlyUrls, $baseUrl, $testId, $run, $cached, $ } } - /** - * @param string $page Result page to generate the URL for - * @param string $extraParams|null Extra parameters to append (without '?' or '&' at start) - * @return string The generated URL - */ + /** + * @param string $page Result page to generate the URL for + * @param string $extraParams|null Extra parameters to append (without '?' or '&' at start) + * @return string The generated URL + */ abstract public function resultPage($page, $extraParams = null); - /** - * @param string $image Image name to generate the thumbnail URL for - * @return string The generated URL - */ + /** + * @param string $image Image name to generate the thumbnail URL for + * @return string The generated URL + */ abstract public function thumbnail($image); - /** - * @param string $image Generated image name to generate the URL for - * @return string The generated URL - */ + /** + * @param string $image Generated image name to generate the URL for + * @return string The generated URL + */ abstract public function generatedImage($image); - /** - * @param bool $connectionView True for a connection view waterfall, false for the normal one. - * @param int $width Width of the generated image - * @param bool $withMime True if MIME data should be generated, false otherwise - * @return string The generated URL - */ + /** + * @param bool $connectionView True for a connection view waterfall, false for the normal one. + * @param int $width Width of the generated image + * @param bool $withMime True if MIME data should be generated, false otherwise + * @return string The generated URL + */ abstract public function waterfallImage($connectionView, $width, $withMime); - /** - * @param string $extraParams|null Extra parameters to append (without '?' or '&' at start) - * @return string The generated URL - */ + /** + * @param string $extraParams|null Extra parameters to append (without '?' or '&' at start) + * @return string The generated URL + */ abstract public function resultSummary($extraParams = null); - /** - * @return string The generated URL - */ + /** + * @return string The generated URL + */ abstract public function optimizationChecklistImage(); - /** - * @param string $file The name of the file to get with the URL - * @param string $video If it's a video-related file, this can be set to the corresponding video directory name - * @return string The generated URL - */ + /** + * @param string $file The name of the file to get with the URL + * @param string $video If it's a video-related file, this can be set to the corresponding video directory name + * @return string The generated URL + */ public function getFile($file, $video = "") { $videoParam = $video ? "&video=" . $video : ""; @@ -92,10 +96,10 @@ public function getFile($file, $video = "") return $url; } - /** - * @param string $file The name of the file to get with the URL - * @return string The generated URL - */ + /** + * @param string $file The name of the file to get with the URL + * @return string The generated URL + */ public function getGZip($file) { $compressedParam = (substr($file, -3) == ".gz") ? "&compressed=1" : ""; @@ -103,66 +107,71 @@ public function getGZip($file) return $url; } - /** - * @param string|int $requestNumber The request number to identify the response body - * @return string The generated URL - */ + /** + * @param string|int $requestNumber The request number to identify the response body + * @return string The generated URL + */ public function responseBodyWithRequestNumber($requestNumber) { - return $this->baseUrl . "/response_body.php?" . $this->urlParams() . "&request=" . strval($requestNumber); + $fpParam = $this->fp ? "&fp=$this->fp" : ""; + return $this->baseUrl . "/response_body.php?" . $this->urlParams() . "&request=" . strval($requestNumber) . $fpParam; } - /** - * @param int $bodyId The body ID to identify the response body - * @return string The generated URL - */ + /** + * @param int $bodyId The body ID to identify the response body + * @return string The generated URL + */ public function responseBodyWithBodyId($bodyId) { - return $this->baseUrl . "/response_body.php?" . $this->urlParams() . "&bodyid=" . strval($bodyId); + $fpParam = $this->fp ? "&fp=$this->fp" : ""; + return $this->baseUrl . "/response_body.php?" . $this->urlParams() . "&bodyid=" . strval($bodyId) . $fpParam; } - /** - * @param string $end Optional. A specific "end" to use for video creation - * @return string The generated URL to create a video - */ + /** + * @param string $end Optional. A specific "end" to use for video creation + * @return string The generated URL to create a video + */ public function createVideo($end = null) { $tests = $this->testId . "-r:" . $this->run . "-c:" . ($this->cached ? 1 : 0); $tests .= ($this->step > 1) ? ("-s:" . $this->step) : ""; $tests .= $end ? "-e:$end" : ""; + $tests .= $this->fp ? "&fp=$this->fp" : ""; return $this->baseUrl . "/video/view.php?tests=" . $tests; } - /** - * @param string $end Optional. A specific "end" to use for filmstrip view - * @return string The generated URL for the filmstrip view - */ + /** + * @param string $end Optional. A specific "end" to use for filmstrip view + * @return string The generated URL for the filmstrip view + */ public function filmstripView($end = null) { $tests = $this->testId . "-r:" . $this->run . "-c:" . ($this->cached ? 1 : 0); $tests .= ($this->step > 1) ? ("-s:" . $this->step) : ""; $tests .= $end ? "-e:$end" : ""; + $tests .= $this->fp ? "&fp=$this->fp" : ""; return $this->baseUrl . "/video/compare.php?tests=" . $tests; } - /** - * @param string $end Optional. A specific "end" to use for filmstrip view - * @return string The generated URL for the filmstrip view - */ + /** + * @param string $end Optional. A specific "end" to use for filmstrip view + * @return string The generated URL for the filmstrip view + */ public function filmstripImage($end = null) { $tests = $this->testId . "-r:" . $this->run . "-c:" . ($this->cached ? 1 : 0); $tests .= ($this->step > 1) ? ("-s:" . $this->step) : ""; $tests .= $end ? "-e:$end" : ""; + $tests .= $this->fp ? "&fp=$this->fp" : ""; return $this->baseUrl . "/video/filmstrip.php?tests=" . $tests; } - /** - * @param string $frame The thumbnail name - * @param int $fit Maximum size of the thumbnail - * @return string The URL for a thumbnail of the video frame - */ + /** + * @param string $frame The thumbnail name + * @param int $fit Maximum size of the thumbnail + * @return string The URL for a thumbnail of the video frame + */ public function videoFrameThumbnail($frame, $fit, $options = null) { $file = "video_" . rtrim(strtolower($this->underscorePrefix()), "_") . "/" . $frame; @@ -173,19 +182,19 @@ public function videoFrameThumbnail($frame, $fit, $options = null) return $url; } - /** - * @return string The generated URL to download all video frames - */ + /** + * @return string The generated URL to download all video frames + */ public function downloadVideoFrames() { return $this->baseUrl . "/video/downloadFrames.php?" . $this->urlParams(); } - /** - * @param string $page Step-independent Result page to generate the URL for - * @param string $extraParams|null Extra parameters to append (without '?' or '&' at start) - * @return string The generated URL - */ + /** + * @param string $page Step-independent Result page to generate the URL for + * @param string $extraParams|null Extra parameters to append (without '?' or '&' at start) + * @return string The generated URL + */ public function stepDetailPage($page, $extraParams = null) { $extraParams = $extraParams ? ("&" . $extraParams) : ""; @@ -201,7 +210,8 @@ protected function underscorePrefix() protected function urlParams() { $stepParam = $this->step > 1 ? ("&step=" . $this->step) : ""; - return "test=" . $this->testId . "&run=" . $this->run . ($this->cached ? "&cached=1" : "") . $stepParam; + $fpParam = $this->fp ? "&fp=$this->fp" : ""; + return "test=" . $this->testId . "&run=" . $this->run . ($this->cached ? "&cached=1" : "") . $stepParam . $fpParam; } } @@ -213,6 +223,7 @@ public function resultPage($page, $extraParams = null) if ($this->cached) { $url .= "cached/"; } + $extraParams = $this->prepareExtraParams($extraParams); if ($extraParams != null) { $url .= "?" . $extraParams; } @@ -241,7 +252,7 @@ public function generatedImage($image) { $parts = explode("_", $this->testId); $testPath = substr($parts[0], 0, 2) . "/" . substr($parts[0], 2, 2) . "/" . substr($parts[0], 4, 2) . - "/" . $parts[1]; + "/" . $parts[1]; if (sizeof($parts) > 2) { $testPath .= "/" . $parts[2]; } @@ -251,6 +262,7 @@ public function generatedImage($image) public function resultSummary($extraParams = null) { $url = $this->baseUrl . "/result/" . $this->testId . "/"; + $extraParams = $this->prepareExtraParams($extraParams); if ($extraParams != null) { $url .= "?" . $extraParams; } @@ -269,6 +281,17 @@ public function optimizationChecklistImage() { return $this->generatedImage("optimization"); } + + private function prepareExtraParams($extraParams = null) + { + if (!$this->fp) { + return $extraParams; + } + + return $extraParams + ? ("fp=$this->fp&" . $extraParams) + : "fp=$this->fp"; + } } class StandardUrlGenerator extends UrlGenerator @@ -298,6 +321,7 @@ public function generatedImage($image) public function resultSummary($extraParams = null) { $extraParams = $extraParams ? ("&" . $extraParams) : ""; + $extraParams .= $this->fp ? "&fp=$this->fp" : ""; return $this->baseUrl . "/results.php?test=" . $this->testId . $extraParams; } diff --git a/www/result.inc b/www/result.inc index 388843f1e8..32cb818061 100644 --- a/www/result.inc +++ b/www/result.inc @@ -40,398 +40,387 @@ foreach ($requests as $request) { } } - - - -$page_keywords = array('Results','WebPageTest','Website Speed Test','Page Speed'); +$page_keywords = array('Results', 'WebPageTest', 'Website Speed Test', 'Page Speed'); $page_description = "Website performance test result$testLabel."; ?> - - <?php echo "$page_title - WebPageTest Result"; ?> - - - - - - - - - - + + <?php echo "$page_title - WebPageTest Result"; ?> + + + + + + + + + + + + + +
- -

\n"; - } else { - echo "URL: $url
\n"; - } - echo "From: {$test['test']['location']}
\n"; - echo GetTestInfoHtml(); + if (!$testComplete) { ?> +

+ \n"; + } else { + echo "URL: $url
\n"; + } + echo "From: {$test['test']['location']}
\n"; + echo GetTestInfoHtml(); + ?>

- countRuns(); echo "

Test is partially complete ($available of $expected tests).
This page will refresh as tests complete.

"; echo "\n"; - } else { + } else { ?> - - - -
- - - - - -
-

Performance Summary

-
- - - - -

You have Free Experiments Available! - Try them now!'; - } - ?>

- +
+
+

Performance Summary

+
+ + +

You have Free Experiments Available! + Try them now!'; + } + ?>

+ +
+
- - - -
- -
- - - - - -
- - - -
- isTestError(); - $fvRunResults = $testResults->getRunResult($fvMedian, false); - $rvRunResults = $rvMedian ? $testResults->getRunResult($rvMedian, true) : null; - - if ($fvMedian) { - echo '

Page Performance Metrics '; - $medianMetrics = array( - "chromeUserTiming.CumulativeLayoutShift" => "Cumulative Layout Shift", - "firstContentfulPaint" => "First Contentful Paint", - "chromeUserTiming.LargestContentfulPaint" => "Largest Contentful Paint", - "fullyLoaded" => "Load Time", - "SpeedIndex" => "Speed Index", - "render" => "Start Render", - "TTFB" => "Time to First Byte", - "TotalBlockingTime" => "Total Blocking Time" - ); - if ($medianMetrics[$median_metric]) { - $friendlyMedianMetric = $medianMetrics[$median_metric]; - } else { - $friendlyMedianMetric = htmlspecialchars($median_metric); - } - if ($testResults->countRuns() > 1) { - echo '(Based on Median Run by: +
+
+ isTestError(); + $fvRunResults = $testResults->getRunResult($fvMedian, false); + $rvRunResults = $rvMedian ? $testResults->getRunResult($rvMedian, true) : null; + + if ($fvMedian) { + echo '

Page Performance Metrics '; + $medianMetrics = array( + "chromeUserTiming.CumulativeLayoutShift" => "Cumulative Layout Shift", + "firstContentfulPaint" => "First Contentful Paint", + "chromeUserTiming.LargestContentfulPaint" => "Largest Contentful Paint", + "fullyLoaded" => "Load Time", + "SpeedIndex" => "Speed Index", + "render" => "Start Render", + "TTFB" => "Time to First Byte", + "TotalBlockingTime" => "Total Blocking Time" + ); + if ($medianMetrics[$median_metric]) { + $friendlyMedianMetric = $medianMetrics[$median_metric]; + } else { + $friendlyMedianMetric = htmlspecialchars($median_metric); + } + if ($testResults->countRuns() > 1) { + echo '(Based on Median Run by:
' . $friendlyMedianMetric . ''; - echo "
    "; + echo "
      "; - $url = strtok($_SERVER["REQUEST_URI"], '?'); - foreach ($medianMetrics as $key => $value) { - if ($pageData[$run][$cached][$key]) { - echo "
    • " . $value . "
    • "; - } - } - echo "
    "; + $url = strtok($_SERVER["REQUEST_URI"], '?'); + foreach ($medianMetrics as $key => $value) { + if ($pageData[$run][$cached][$key]) { + echo "
  • " . $value . "
  • "; + } + } + echo "
"; - echo '
)
'; - } - echo '

'; + echo ')
'; + } + echo '

'; - echo '
+ echo '
Note: Metric availability will vary

Please note: Availability of metrics will vary based on the browser being tested. Also, the way a site performs in some conditions may not predict how well it will perform in others, so we encourage testing in a variety of browsers, devices, & locations.

'; - $resultTable = new RunResultHtmlTable($testInfo, $fvRunResults, $rvRunResults, false, true); - $resultTable->useLabelLinks(true); - $resultTable->disableColumns(array( - RunResultHtmlTable::COL_VISUAL_COMPLETE, - RunResultHtmlTable::COL_COST, - RunResultHtmlTable::COL_FULLYLOADED, - RunResultHtmlTable::COL_REQUESTS, - RunResultHtmlTable::COL_RESULT, - )); - $resultTable->disableCustomMetrics(); - if (GetSetting('show_cost')) { - //$resultTable->enableColumns(array(RunResultHtmlTable::COL_COST)); - } - echo $resultTable->create(true); - - if ($testResults->countRuns() > 1) { - $link = '/video/compare.php?tests='; - $repeatlink = '/video/compare.php?tests='; - $cnt = 1; - do { - $link .= $id . '-r:' . $cnt; - $repeatlink .= $id . '-r:' . $cnt . '-c:1'; - if ($tests[0]['step']) { - $link .= '-s:' . $test['step']; - $repeatlink .= '-s:' . $test['step']; + $resultTable = new RunResultHtmlTable($testInfo, $fvRunResults, $rvRunResults, false, true); + $resultTable->useLabelLinks(true); + $resultTable->disableColumns(array( + RunResultHtmlTable::COL_VISUAL_COMPLETE, + RunResultHtmlTable::COL_COST, + RunResultHtmlTable::COL_FULLYLOADED, + RunResultHtmlTable::COL_REQUESTS, + RunResultHtmlTable::COL_RESULT, + )); + $resultTable->disableCustomMetrics(); + if (GetSetting('show_cost')) { + //$resultTable->enableColumns(array(RunResultHtmlTable::COL_COST)); } - $link .= ','; - $repeatlink .= ','; - $cnt++; - } while ($cnt <= $testResults->countRuns()); - echo "Compare First Views"; - if ($rvRunResults) { - echo "Compare Repeat Views"; - } - echo "Plot Full Results"; - } - ?> - create(true); + + if ($testResults->countRuns() > 1) { + $link = '/video/compare.php?tests='; + $repeatlink = '/video/compare.php?tests='; + $cnt = 1; + do { + $link .= $id . '-r:' . $cnt; + $repeatlink .= $id . '-r:' . $cnt . '-c:1'; + if ($tests[0]['step']) { + $link .= '-s:' . $test['step']; + $repeatlink .= '-s:' . $test['step']; + } + $link .= ','; + $repeatlink .= ','; + $cnt++; + } while ($cnt <= $testResults->countRuns()); + $link = substr($link, 0, -1) . ($req_fp ? "&fp=$req_fp" : ''); + $repeatlink = substr($repeatlink, 0, -1) . ($req_fp ? "&fp=$req_fp" : ''); + echo "Compare First Views"; + if ($rvRunResults) { + echo "Compare Repeat Views"; + } + $graphLink = "graph_page_data.php?tests=$id&medianMetric=$median_metric" . ($req_fp ? "&fp=$req_fp" : ''); + + echo "Plot Full Results"; + } + ?> + ' . htmlspecialchars($error) . ''; + } + if (isset($detail)) { + echo '

' . htmlspecialchars($detail) . '

'; + } } - } - if (!$fvMedian) { - echo '

' . htmlspecialchars($error) . '

'; - } - if (isset($detail)) { - echo '

' . htmlspecialchars($detail) . '

'; - } - } - ?> -
- + ?> +
- - '; - require_once(INCLUDES_PATH . '/include/CrUX.php'); - InsertCruxHTML($fvRunResults); - echo '
'; - } - ?> - - - - -
-

Individual Runs

- - - - create(); - ?> -
-
- -
- - + '; + require_once(INCLUDES_PATH . '/include/CrUX.php'); + InsertCruxHTML($fvRunResults); + echo ''; + } + ?> + +
+

Individual Runs

+ create(); + ?> +
+ + - + + + + + + getBreakdown(); + if ($breakdown) { + ?> + - getBreakdown(); - if ($breakdown) { - ?> - - - \n"; - echo "var testId = '$id';\n"; - ?> - // polyfill performance.now - if ("performance" in window == false) { - window.performance = {}; + function RGBtoHex(R, G, B) { + return toHex(R) + toHex(G) + toHex(B) } - Date.now = (Date.now || function () { // thanks IE8 - return new Date().getTime(); - }); - if ("now" in window.performance == false){ - var nowOffset = Date.now(); - if (performance.timing && performance.timing.navigationStart){ - nowOffset = performance.timing.navigationStart - } - window.performance.now = function now(){ - return Date.now() - nowOffset; - } + + function toHex(N) { + if (N == null) return "00"; + N = parseInt(N); + if (N == 0 || isNaN(N)) return "00"; + N = Math.max(0, N); + N = Math.min(N, 255); + N = Math.round(N); + return "0123456789ABCDEF".charAt((N - N % 16) / 16) + + "0123456789ABCDEF".charAt(N % 16); } - var lastUpdate = window.performance.now(); - function UpdateStatus(){ - var now = window.performance.now(); - var elapsed = now - lastUpdate; - lastUpdate = now; - if (elapsed < 0 || elapsed > 10000) { - try { - var xhr = new XMLHttpRequest(); - xhr.open('GET', '/testStatus.php?f=json&pos=1&test=' + testId, true); - xhr.onreadystatechange = function() { - if (xhr.readyState != 4) - return; - var reload = false; - if (xhr.status == 200) { - var response = JSON.parse(xhr.responseText); - if (response['statusCode'] != undefined) { - if (response['statusCode'] == 100) { - if (response['data'] != undefined && - availableTests != undefined && - response.data['testsCompleted'] != undefined && - response.data['testsCompleted'] > availableTests) - reload = true; - } else - reload = true; - } - } - if (reload) { - window.location.reload(true); - } else { - setTimeout('UpdateStatus()', 15000); - } + + function drawCharts() { + for (index in wptBreakdown) { + var bytes = new google.visualization.DataTable(); + bytes.addColumn('string', 'Content Type'); + bytes.addColumn('number', 'Bytes'); + var bytesColors = new Array(); + for (i in wptBreakdown[index].data) { + bytes.addRow([i, wptBreakdown[index].data[i].bytes]); + var color = RGBtoHex(wptBreakdown[index].data[i].color[0], wptBreakdown[index].data[i].color[1], wptBreakdown[index].data[i].color[2]); + bytesColors.push('#' + color); + } + var bytesOptions = { + width: 370, + height: 200, + title: 'Bytes', + colors: bytesColors }; - xhr.onerror = function() { - setTimeout('UpdateStatus()', 15000); + var bytesChart = new google.visualization.PieChart(document.getElementById('bytes_' + wptBreakdown[index].run)); + bytesChart.draw(bytes, bytesOptions); + + var requests = new google.visualization.DataTable(); + requests.addColumn('string', 'Content Type'); + requests.addColumn('number', 'Requests'); + var requestsColors = new Array(); + for (i in wptBreakdown[index].data) { + requests.addRow([i, wptBreakdown[index].data[i].requests]); + var color = RGBtoHex(wptBreakdown[index].data[i].color[0], wptBreakdown[index].data[i].color[1], wptBreakdown[index].data[i].color[2]); + requestsColors.push('#' + color); + } + var requestsOptions = { + width: 370, + height: 200, + title: 'Requests', + colors: requestsColors }; - xhr.send(); - } catch (err) { - setTimeout('UpdateStatus()', 15000); - } - } else { - setTimeout('UpdateStatus()', 15000); + var requestsChart = new google.visualization.PieChart(document.getElementById('requests_' + wptBreakdown[index].run)); + requestsChart.draw(requests, requestsOptions); } } - setTimeout('UpdateStatus()', 15000); - - + \n"; + echo "var testId = '$id';\n"; + ?> + // polyfill performance.now + if ("performance" in window == false) { + window.performance = {}; + } + Date.now = (Date.now || function () { // thanks IE8 + return new Date().getTime(); + }); + if ("now" in window.performance == false){ + var nowOffset = Date.now(); + if (performance.timing && performance.timing.navigationStart){ + nowOffset = performance.timing.navigationStart + } + window.performance.now = function now(){ + return Date.now() - nowOffset; + } } + var lastUpdate = window.performance.now(); + function UpdateStatus(){ + var now = window.performance.now(); + var elapsed = now - lastUpdate; + lastUpdate = now; + if (elapsed < 0 || elapsed> 10000) { + try { + var xhr = new XMLHttpRequest(); + xhr.open('GET', '/testStatus.php?f=json&pos=1&test=' + testId, true); + xhr.onreadystatechange = function() { + if (xhr.readyState != 4) + return; + var reload = false; + if (xhr.status == 200) { + var response = JSON.parse(xhr.responseText); + if (response['statusCode'] != undefined) { + if (response['statusCode'] == 100) { + if (response['data'] != undefined && + availableTests != undefined && + response.data['testsCompleted'] != undefined && + response.data['testsCompleted'] > availableTests) + reload = true; + } else + reload = true; + } + } + if (reload) { + window.location.reload(true); + } else { + setTimeout('UpdateStatus()', 15000); + } + }; + xhr.onerror = function() { + setTimeout('UpdateStatus()', 15000); + }; + xhr.send(); + } catch (err) { + setTimeout('UpdateStatus()', 15000); + } + } else { + setTimeout('UpdateStatus()', 15000); + } + } + setTimeout('UpdateStatus()', 15000); + + - - + + + \ No newline at end of file