blob: 2805fc1b7bf440d10a1768760285f86d67bc6fd3 [file] [log] [blame]
# Copyright 2012 Google Inc. All Rights Reserved.
# Author: (Jeff Kaufman)
# Runs all Apache-specific experiment framework tests that don't depend on
# Google Analytics.
# See automatic/ for usage.
# Not intended to be run stand-alone. Should be run only by
# apache_experiment_no_ge_test and apache_experiment_ga_test.
this_dir="$( dirname "${BASH_SOURCE[0]}" )"
if [ ! -e "$PAGESPEED_CODE_DIR" ] ; then
source "$PAGESPEED_CODE_DIR/automatic/" || exit 1
echo Testing whether or not the experiment framework is working.
start_test PageSpeedExperiment cookie is set.
check_from "$OUT" fgrep "PageSpeedExperiment="
start_test PageSpeedFilters query param should disable experiments.
OUT=$($WGET_DUMP "$EXTEND_CACHE?PageSpeed=on&PageSpeedFilters=rewrite_css")
check_not_from "$OUT" fgrep 'PageSpeedExperiment='
start_test ModPagespeedFilters query param should also disable experiments.
check_not_from "$OUT" fgrep 'PageSpeedExperiment='
start_test experiment assignment can be forced
check_from "$OUT" fgrep 'PageSpeedExperiment=2'
start_test experiment assignment can be forced to a 0% experiment
check_from "$OUT" fgrep 'PageSpeedExperiment=3'
start_test experiment assignment can be forced even if already assigned
OUT=$($WGET_DUMP --header Cookie:PageSpeedExperiment=7 \
check_from "$OUT" fgrep 'PageSpeedExperiment=2'
start_test If the user is already assigned, no need to assign them again.
OUT=$($WGET_DUMP --header='Cookie: PageSpeedExperiment=2' $EXTEND_CACHE)
check_not_from "$OUT" fgrep 'PageSpeedExperiment='
start_test The beacon should include the experiment id.
OUT=$($WGET_DUMP --header='Cookie: PageSpeedExperiment=2' $EXTEND_CACHE)
check_from "$OUT" grep "pagespeed.addInstrumentationInit('/mod_pagespeed_beacon', 'load', '&exptid=2', 'http://localhost[:0-9]*/mod_pagespeed_example/extend_cache.html');"
OUT=$($WGET_DUMP --header='Cookie: PageSpeedExperiment=7' $EXTEND_CACHE)
check_from "$OUT" grep "pagespeed.addInstrumentationInit('/mod_pagespeed_beacon', 'load', '&exptid=7', 'http://localhost[:0-9]*/mod_pagespeed_example/extend_cache.html');"
start_test The no-experiment group beacon should not include an experiment id.
OUT=$($WGET_DUMP --header='Cookie: PageSpeedExperiment=0' $EXTEND_CACHE)
check_not_from "$OUT" grep 'mod_pagespeed_beacon.*exptid'
# We expect id=7 to be index=a and id=2 to be index=b because that's the
# order they're defined in the config file.
start_test Resource urls are rewritten to include experiment indexes.
WGET_ARGS="--header Cookie:PageSpeedExperiment=7" fetch_until $EXTEND_CACHE \
"fgrep -c .pagespeed.a.ic." 1
WGET_ARGS="--header Cookie:PageSpeedExperiment=2" fetch_until $EXTEND_CACHE \
"fgrep -c .pagespeed.b.ic." 1
OUT=$($WGET_DUMP --header='Cookie: PageSpeedExperiment=7' $EXTEND_CACHE)
check_from "$OUT" fgrep ".pagespeed.a.ic."
OUT=$($WGET_DUMP --header='Cookie: PageSpeedExperiment=2' $EXTEND_CACHE)
check_from "$OUT" fgrep ".pagespeed.b.ic."
start_test Options are respected.
# For id 2 ARIS is on. First fetch until normal.js is rewritten, after which
# we expect introspective.js would be rewritten if it were going to be.
WGET_ARGS="--header Cookie:PageSpeedExperiment=2" fetch_until -save $ARIS \
'grep -c "src=\"normal.js\""' 0
check [ $(grep -c "src=\"introspection.js\"" $FETCH_UNTIL_OUTFILE) = 1 ]
# For id 7 ARIS is off. Repeat this test, expecting it to get renamed.
WGET_ARGS="--header Cookie:PageSpeedExperiment=7" fetch_until -save $ARIS \
'grep -c "src=\"normal.js\""' 0
check [ $(grep -c "src=\"introspection.js\"" $FETCH_UNTIL_OUTFILE) = 0 ]
start_test Images are different when the url specifies different experiments.
# While the images are the same, image B should be smaller because in the config
# file we enable convert_jpeg_to_progressive only for id=2 (side B). Ideally we
# would check that it was actually progressive, by checking whether "identify
# -verbose filename" produced "Interlace: JPEG" or "Interlace: None", but that
# would introduce a dependency on imagemagick. This is just as accurate, but
# more brittle (because changes to our compression code would change the
# computed file sizes).
fetch_until $IMG_A 'wc -c' 102902 "" -le
fetch_until $IMG_B 'wc -c' 98276 "" -le