Skip to content

Commit

Permalink
initial functional pass at a edit html response body experiment. #2471
Browse files Browse the repository at this point in the history
  • Loading branch information
scottjehl committed Jan 12, 2023
1 parent cf01013 commit b3a9cf2
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 3 deletions.
13 changes: 13 additions & 0 deletions www/assets/css/pagestyle2.css
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ h4.experiments_list_hed-recs {
}
.experiments_list > li:target {
background: #f8f7e0;
scroll-padding-top: 4rem;
}

.experiment_description code {
Expand Down Expand Up @@ -2211,6 +2212,18 @@ footer ul {
}
}

.experiment_description_go > label.experiment_pair_value textarea[data-fullscreenfocus=true]:focus {
position: fixed;
top: 10vh;
left: 10vw;
right: 10vw;
bottom: 10vh;
z-index: 999999;
box-shadow: 0 0 0 11vw rgba(0,0,0,.3);
height: 80vh;
width: 80vw;
}

@media (max-width: 50em) {
.grade_header,
.experiments_foot {
Expand Down
6 changes: 4 additions & 2 deletions www/experiments.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,13 @@ function observationHTML($parts)
} elseif ($exp->expvar && !$exp->expval && $textinput) {
if ($experimentEnabled) {
$placeholderEncodedVal = htmlentities('<script src="https://example.com/test.js"></script>');
$textinputvalue = $exp->textinputvalue ? $exp->textinputvalue : "";
$fullscreenfocus = $exp->fullscreenfocus ? "true" : "false";
$out .= <<<EOT
</div>
<div class="experiment_description_go experiment_description_go-multi">
<label class="experiment_pair_check"><input type="checkbox" name="recipes[]" value="{$expNum}-{$exp->expvar}">Run this Experiment with:</label>
<label class="experiment_pair_value"><span>Value: </span><textarea name="{$expNum}-{$exp->expvar}[]" placeholder="{$placeholderEncodedVal}"></textarea></label>
<label class="experiment_pair_value"><span>Value: </span><textarea id="experiment-{$exp->id}-textarea" data-fullscreenfocus="{$fullscreenfocus}" name="{$expNum}-{$exp->expvar}[]">{$textinputvalue}</textarea></label>
</div>
EOT;
Expand Down Expand Up @@ -582,7 +584,7 @@ function refreshExperimentFormState(){
}
}
}
if( input && !(keyval[1] === 'on' && form.querySelectorAll("[type=checkbox][name='" + keyval[0] + "']")) ){
if( input && !(keyval[1] === 'on' && form.querySelectorAll("[type=checkbox][name='" + keyval[0] + "']")) && keyval[1] !== "" ){
input.value = keyval[1];
input.setAttribute('data-hydrated', 'true');
}
Expand Down
24 changes: 24 additions & 0 deletions www/experiments/custom.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php



$requests = $testStepResult->getRequests();

$category = "Custom";
$assessment[$category]["opportunities"][] = array(
"title" => "Add HTML to document",
Expand Down Expand Up @@ -68,6 +72,26 @@ $assessment[$category]["opportunities"][] = array(
"inputttext" => true
);

if( $requests[0]['body_url'] ){
$assessment[$category]["opportunities"][] = array(
"title" => "Edit Response HTML",
"desc" => "This experiment allows you to freely edit the text of the initial HTML response",
"examples" => array(),
"experiments" => array(
(object) [
'id' => '054',
'title' => 'Edit Response HTML',
"desc" => '<p>This experiment will replace the initial HTML with the submitted value as if it was served that way initially.</p>',
"expvar" => 'editresponsehtml',
'textinputvalue' => htmlentities(file_get_contents("https://next.webpagetest.org" . $requests[0]['body_url'])),
"fullscreenfocus" => true
]
),
"good" => null,
"inputttext" => true
);
}


$assessment[$category]["opportunities"][] = array(
"title" => "Delivery Optimizations",
Expand Down
19 changes: 19 additions & 0 deletions www/experiments/getExperimentHTML.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
require_once '../common.inc';
use WebPageTest\Util;
require_once '../include/TestInfo.php';
$testInfo = json_decode(gz_file_get_contents("../$testPath/testinfo.json.gz"));

if($testInfo && $testInfo->metadata){
$recipes = json_decode($testInfo->metadata)->experiment->recipes;
$html = "";

foreach($recipes as $recipe){
if( $recipe->{'054'} ){
$html = $recipe->{'054'}[0];
}

}
}

echo $html;
6 changes: 5 additions & 1 deletion www/runtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,10 @@ function buildSelfHost($hosts)
}
$ingredients = implode(",", $ingredients);
}
if($recipeSansId === "editresponsehtml"){
// striking out the ingredients here because it's too much to send in a cookie
$ingredients = "";
}
// these recipes need encoded values. they all do afterwards! TODO
if (
$recipeSansId === "insertheadstart"
Expand Down Expand Up @@ -1109,7 +1113,7 @@ function buildSelfHost($hosts)


//replace last step with last step plus recipes
$test['script'] = str_replace($scriptNavigate, "setCookie\t" . $originToUse . "\twpt-experiments=" . urlencode($recipeScript) . "\r\n" . $scriptNavigate, $test['script']);
$test['script'] = str_replace($scriptNavigate, "setCookie\t" . $originToUse . "\twpt-experiments=" . urlencode($recipeScript) . "\r\n" . "setCookie\t" . $originToUse . "\twpt-testid=" . urlencode($id) . "\r\n" . $scriptNavigate, $test['script']);


$id = CreateTest($test, $test['url']);
Expand Down

0 comments on commit b3a9cf2

Please sign in to comment.