Commit 5c4fa4dd authored by chrishenry@google.com's avatar chrishenry@google.com

Modify all usage of PageMeasurement to use PageTest in tools/telemetry.

Also modify MeasurePage -> ValidateAndMeasurePage.

BUG=383635

Review URL: https://codereview.chromium.org/449963002

Cr-Commit-Position: refs/heads/master@{#288510}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288510 0039d316-1c4b-4281-b951-d872f2087c98
parent e77e2715
...@@ -21,7 +21,6 @@ from telemetry.core.browser import Browser ...@@ -21,7 +21,6 @@ from telemetry.core.browser import Browser
from telemetry.core.browser_options import BrowserFinderOptions from telemetry.core.browser_options import BrowserFinderOptions
from telemetry.core.tab import Tab from telemetry.core.tab import Tab
from telemetry.page.page_measurement import PageMeasurement
from telemetry.page.page_runner import Run as RunPage from telemetry.page.page_runner import Run as RunPage
......
...@@ -36,7 +36,7 @@ class BenchmarkMetadata(object): ...@@ -36,7 +36,7 @@ class BenchmarkMetadata(object):
class Benchmark(command_line.Command): class Benchmark(command_line.Command):
"""Base class for a Telemetry benchmark. """Base class for a Telemetry benchmark.
A test packages a PageTest/PageMeasurement and a PageSet together. A test packages a PageTest and a PageSet together.
""" """
options = {} options = {}
......
...@@ -14,7 +14,6 @@ from telemetry.core import exceptions ...@@ -14,7 +14,6 @@ from telemetry.core import exceptions
from telemetry.core import user_agent from telemetry.core import user_agent
from telemetry.core import util from telemetry.core import util
from telemetry.page import page as page_module from telemetry.page import page as page_module
from telemetry.page import page_measurement
from telemetry.page import page_set from telemetry.page import page_set
from telemetry.page import page_test from telemetry.page import page_test
from telemetry.page import page_runner from telemetry.page import page_runner
...@@ -69,7 +68,7 @@ def GetSuccessfulPageRuns(results): ...@@ -69,7 +68,7 @@ def GetSuccessfulPageRuns(results):
class PageRunnerTests(unittest.TestCase): class PageRunnerTests(unittest.TestCase):
# TODO(nduca): Move the basic "test failed, test succeeded" tests from # TODO(nduca): Move the basic "test failed, test succeeded" tests from
# page_measurement_unittest to here. # page_test_unittest to here.
def testHandlingOfCrashedTab(self): def testHandlingOfCrashedTab(self):
ps = page_set.PageSet() ps = page_set.PageSet()
...@@ -148,9 +147,9 @@ class PageRunnerTests(unittest.TestCase): ...@@ -148,9 +147,9 @@ class PageRunnerTests(unittest.TestCase):
ps.pages.append(page_module.Page( ps.pages.append(page_module.Page(
'file://blank.html', ps, base_dir=util.GetUnittestDataDir())) 'file://blank.html', ps, base_dir=util.GetUnittestDataDir()))
class CrashyMeasurement(page_measurement.PageMeasurement): class CrashyMeasurement(page_test.PageTest):
has_crashed = False has_crashed = False
def MeasurePage(self, page, tab, results): def ValidateAndMeasurePage(self, page, tab, results):
# This value should be discarded on the first run when the # This value should be discarded on the first run when the
# browser crashed. # browser crashed.
results.AddValue( results.AddValue(
...@@ -182,12 +181,12 @@ class PageRunnerTests(unittest.TestCase): ...@@ -182,12 +181,12 @@ class PageRunnerTests(unittest.TestCase):
ps.pages.append(page_module.Page( ps.pages.append(page_module.Page(
'file://blank.html', ps, base_dir=util.GetUnittestDataDir())) 'file://blank.html', ps, base_dir=util.GetUnittestDataDir()))
class Measurement(page_measurement.PageMeasurement): class Measurement(page_test.PageTest):
@property @property
def discard_first_result(self): def discard_first_result(self):
return True return True
def MeasurePage(self, page, _, results): def ValidateAndMeasurePage(self, page, _, results):
results.AddValue(string.StringValue(page, 'test', 't', page.url)) results.AddValue(string.StringValue(page, 'test', 't', page.url))
options = options_for_unittests.GetCopy() options = options_for_unittests.GetCopy()
...@@ -244,9 +243,9 @@ class PageRunnerTests(unittest.TestCase): ...@@ -244,9 +243,9 @@ class PageRunnerTests(unittest.TestCase):
ps.pages.append(page_module.Page( ps.pages.append(page_module.Page(
'file://green_rect.html', ps, base_dir=util.GetUnittestDataDir())) 'file://green_rect.html', ps, base_dir=util.GetUnittestDataDir()))
class Measurement(page_measurement.PageMeasurement): class Measurement(page_test.PageTest):
i = 0 i = 0
def MeasurePage(self, page, _, results): def ValidateAndMeasurePage(self, page, _, results):
self.i += 1 self.i += 1
results.AddValue(scalar.ScalarValue( results.AddValue(scalar.ScalarValue(
page, 'metric', 'unit', self.i)) page, 'metric', 'unit', self.i))
...@@ -435,7 +434,7 @@ class PageRunnerTests(unittest.TestCase): ...@@ -435,7 +434,7 @@ class PageRunnerTests(unittest.TestCase):
page.startup_url = 'about:blank' page.startup_url = 'about:blank'
ps.pages.append(page) ps.pages.append(page)
class Measurement(page_measurement.PageMeasurement): class Measurement(page_test.PageTest):
def __init__(self): def __init__(self):
super(Measurement, self).__init__() super(Measurement, self).__init__()
self.browser_restarted = False self.browser_restarted = False
...@@ -444,7 +443,7 @@ class PageRunnerTests(unittest.TestCase): ...@@ -444,7 +443,7 @@ class PageRunnerTests(unittest.TestCase):
self.browser_restarted = True self.browser_restarted = True
super(Measurement, self).CustomizeBrowserOptionsForSinglePage(ps, super(Measurement, self).CustomizeBrowserOptionsForSinglePage(ps,
options) options)
def MeasurePage(self, page, tab, results): def ValidateAndMeasurePage(self, page, tab, results):
pass pass
options = options_for_unittests.GetCopy() options = options_for_unittests.GetCopy()
...@@ -537,7 +536,7 @@ class PageRunnerTests(unittest.TestCase): ...@@ -537,7 +536,7 @@ class PageRunnerTests(unittest.TestCase):
'file://blank.html', ps, base_dir=ps.base_dir)) 'file://blank.html', ps, base_dir=ps.base_dir))
expectations = test_expectations.TestExpectations() expectations = test_expectations.TestExpectations()
class ArchiveTest(page_measurement.PageMeasurement): class ArchiveTest(page_test.PageTest):
def __init__(self): def __init__(self):
super(ArchiveTest, self).__init__() super(ArchiveTest, self).__init__()
self.is_page_from_archive = False self.is_page_from_archive = False
...@@ -549,7 +548,7 @@ class PageRunnerTests(unittest.TestCase): ...@@ -549,7 +548,7 @@ class PageRunnerTests(unittest.TestCase):
self.is_page_from_archive = ( self.is_page_from_archive = (
tab.browser._wpr_server is not None) # pylint: disable=W0212 tab.browser._wpr_server is not None) # pylint: disable=W0212
def MeasurePage(self, _, __, results): def ValidateAndMeasurePage(self, _, __, results):
pass pass
test = ArchiveTest() test = ArchiveTest()
......
...@@ -9,7 +9,7 @@ from telemetry.page.actions import action_runner as action_runner_module ...@@ -9,7 +9,7 @@ from telemetry.page.actions import action_runner as action_runner_module
class Failure(Exception): class Failure(Exception):
"""Exception that can be thrown from PageMeasurement to indicate an """Exception that can be thrown from PageTest to indicate an
undesired but designed-for problem.""" undesired but designed-for problem."""
......
...@@ -18,7 +18,7 @@ from telemetry.value import scalar ...@@ -18,7 +18,7 @@ from telemetry.value import scalar
class PageTestThatFails(page_test.PageTest): class PageTestThatFails(page_test.PageTest):
def MeasurePage(self, page, tab, results): def ValidateAndMeasurePage(self, page, tab, results):
raise exceptions.IntentionalException raise exceptions.IntentionalException
...@@ -26,7 +26,7 @@ class PageTestThatHasDefaults(page_test.PageTest): ...@@ -26,7 +26,7 @@ class PageTestThatHasDefaults(page_test.PageTest):
def AddCommandLineArgs(self, parser): def AddCommandLineArgs(self, parser):
parser.add_option('-x', dest='x', default=3) parser.add_option('-x', dest='x', default=3)
def MeasurePage(self, page, tab, results): def ValidateAndMeasurePage(self, page, tab, results):
if not hasattr(self.options, 'x'): if not hasattr(self.options, 'x'):
raise page_test.MeasurementFailure('Default option was not set.') raise page_test.MeasurementFailure('Default option was not set.')
if self.options.x != 3: if self.options.x != 3:
...@@ -36,7 +36,7 @@ class PageTestThatHasDefaults(page_test.PageTest): ...@@ -36,7 +36,7 @@ class PageTestThatHasDefaults(page_test.PageTest):
class PageTestForBlank(page_test.PageTest): class PageTestForBlank(page_test.PageTest):
def MeasurePage(self, page, tab, results): def ValidateAndMeasurePage(self, page, tab, results):
contents = tab.EvaluateJavaScript('document.body.textContent') contents = tab.EvaluateJavaScript('document.body.textContent')
if contents.strip() != 'Hello world': if contents.strip() != 'Hello world':
raise page_test.MeasurementFailure( raise page_test.MeasurementFailure(
...@@ -44,7 +44,7 @@ class PageTestForBlank(page_test.PageTest): ...@@ -44,7 +44,7 @@ class PageTestForBlank(page_test.PageTest):
class PageTestForReplay(page_test.PageTest): class PageTestForReplay(page_test.PageTest):
def MeasurePage(self, page, tab, results): def ValidateAndMeasurePage(self, page, tab, results):
# Web Page Replay returns '404 Not found' if a page is not in the archive. # Web Page Replay returns '404 Not found' if a page is not in the archive.
contents = tab.EvaluateJavaScript('document.body.textContent') contents = tab.EvaluateJavaScript('document.body.textContent')
if '404 Not Found' in contents.strip(): if '404 Not Found' in contents.strip():
...@@ -52,7 +52,7 @@ class PageTestForReplay(page_test.PageTest): ...@@ -52,7 +52,7 @@ class PageTestForReplay(page_test.PageTest):
class PageTestQueryParams(page_test.PageTest): class PageTestQueryParams(page_test.PageTest):
def MeasurePage(self, page, tab, results): def ValidateAndMeasurePage(self, page, tab, results):
query = tab.EvaluateJavaScript('window.location.search') query = tab.EvaluateJavaScript('window.location.search')
expected = '?foo=1' expected = '?foo=1'
if query.strip() != expected: if query.strip() != expected:
...@@ -64,7 +64,7 @@ class PageTestWithAction(page_test.PageTest): ...@@ -64,7 +64,7 @@ class PageTestWithAction(page_test.PageTest):
def __init__(self): def __init__(self):
super(PageTestWithAction, self).__init__('RunTestAction') super(PageTestWithAction, self).__init__('RunTestAction')
def MeasurePage(self, page, tab, results): def ValidateAndMeasurePage(self, page, tab, results):
pass pass
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
from telemetry.page import page_measurement from telemetry.page import page_test
class ProfileCreator(page_measurement.PageMeasurement): class ProfileCreator(page_test.PageTest):
"""Base class for an object that constructs a Chrome profile.""" """Base class for an object that constructs a Chrome profile."""
def __init__(self): def __init__(self):
...@@ -15,5 +15,5 @@ class ProfileCreator(page_measurement.PageMeasurement): ...@@ -15,5 +15,5 @@ class ProfileCreator(page_measurement.PageMeasurement):
def page_set(self): def page_set(self):
return self._page_set return self._page_set
def MeasurePage(self, _, tab, results): def ValidateAndMeasurePage(self, _, tab, results):
pass pass
\ No newline at end of file
...@@ -10,7 +10,6 @@ from telemetry import benchmark ...@@ -10,7 +10,6 @@ from telemetry import benchmark
from telemetry.core import browser_options from telemetry.core import browser_options
from telemetry.core import discover from telemetry.core import discover
from telemetry.core import wpr_modes from telemetry.core import wpr_modes
from telemetry.page import page_measurement
from telemetry.page import page_runner from telemetry.page import page_runner
from telemetry.page import page_set from telemetry.page import page_set
from telemetry.page import page_test from telemetry.page import page_test
...@@ -47,9 +46,9 @@ class RecorderPageTest(page_test.PageTest): # pylint: disable=W0223 ...@@ -47,9 +46,9 @@ class RecorderPageTest(page_test.PageTest): # pylint: disable=W0223
if self.page_test: if self.page_test:
self.page_test.DidRunActions(page, tab) self.page_test.DidRunActions(page, tab)
def ValidatePage(self, page, tab, results): def ValidateAndMeasurePage(self, page, tab, results):
if self.page_test: if self.page_test:
self.page_test.ValidatePage(page, tab, results) self.page_test.ValidateAndMeasurePage(page, tab, results)
def RunPage(self, page, tab, results): def RunPage(self, page, tab, results):
tab.WaitForDocumentReadyStateToBeComplete() tab.WaitForDocumentReadyStateToBeComplete()
...@@ -89,9 +88,9 @@ class RecorderPageTest(page_test.PageTest): # pylint: disable=W0223 ...@@ -89,9 +88,9 @@ class RecorderPageTest(page_test.PageTest): # pylint: disable=W0223
def FindAllActionNames(base_dir): def FindAllActionNames(base_dir):
"""Returns a set of of all action names used in our measurements.""" """Returns a set of of all action names used in our measurements."""
action_names = set() action_names = set()
# Get all PageMeasurements except for ProfileCreators (see crbug.com/319573) # Get all PageTests except for ProfileCreators (see crbug.com/319573)
for _, cls in discover.DiscoverClasses( for _, cls in discover.DiscoverClasses(
base_dir, base_dir, page_measurement.PageMeasurement).items(): base_dir, base_dir, page_test.PageTest).items():
if not issubclass(cls, profile_creator.ProfileCreator): if not issubclass(cls, profile_creator.ProfileCreator):
action_name = cls().action_name_to_run action_name = cls().action_name_to_run
if action_name: if action_name:
......
...@@ -87,7 +87,7 @@ class MockBenchmark(benchmark.Benchmark): ...@@ -87,7 +87,7 @@ class MockBenchmark(benchmark.Benchmark):
class RecordWprUnitTests(tab_test_case.TabTestCase): class RecordWprUnitTests(tab_test_case.TabTestCase):
_base_dir = util.GetUnittestDataDir() _base_dir = util.GetUnittestDataDir()
_test_data_dir = os.path.join(util.GetUnittestDataDir(), 'page_measurements') _test_data_dir = os.path.join(util.GetUnittestDataDir(), 'page_tests')
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
...@@ -183,7 +183,7 @@ class RecordWprUnitTests(tab_test_case.TabTestCase): ...@@ -183,7 +183,7 @@ class RecordWprUnitTests(tab_test_case.TabTestCase):
wpr_recorder.options.browser_options.wpr_mode) wpr_recorder.options.browser_options.wpr_mode)
def testFindAllActionNames(self): def testFindAllActionNames(self):
# The src/tools/telemetry/unittest_data/page_measurements/ has been # The src/tools/telemetry/unittest_data/page_tests/ has been
# populated with three simple Page Measurement classes, the first two of # populated with three simple Page Measurement classes, the first two of
# which have action_name_to_run defined. # which have action_name_to_run defined.
action_names_to_run = record_wpr.FindAllActionNames(self._test_data_dir) action_names_to_run = record_wpr.FindAllActionNames(self._test_data_dir)
......
...@@ -13,7 +13,7 @@ from telemetry.web_perf import timeline_interaction_record as tir_module ...@@ -13,7 +13,7 @@ from telemetry.web_perf import timeline_interaction_record as tir_module
from telemetry.web_perf.metrics import fast_metric from telemetry.web_perf.metrics import fast_metric
from telemetry.web_perf.metrics import responsiveness_metric from telemetry.web_perf.metrics import responsiveness_metric
from telemetry.web_perf.metrics import smoothness from telemetry.web_perf.metrics import smoothness
from telemetry.page import page_measurement from telemetry.page import page_test
from telemetry.value import string as string_value_module from telemetry.value import string as string_value_module
...@@ -112,7 +112,7 @@ class _TimelineBasedMetrics(object): ...@@ -112,7 +112,7 @@ class _TimelineBasedMetrics(object):
interactions, wrapped_results) interactions, wrapped_results)
class TimelineBasedMeasurement(page_measurement.PageMeasurement): class TimelineBasedMeasurement(page_test.PageTest):
"""Collects multiple metrics pages based on their interaction records. """Collects multiple metrics pages based on their interaction records.
A timeline measurement shifts the burden of what metrics to collect onto the A timeline measurement shifts the burden of what metrics to collect onto the
...@@ -167,7 +167,7 @@ class TimelineBasedMeasurement(page_measurement.PageMeasurement): ...@@ -167,7 +167,7 @@ class TimelineBasedMeasurement(page_measurement.PageMeasurement):
tab.browser.StartTracing(category_filter) tab.browser.StartTracing(category_filter)
def MeasurePage(self, page, tab, results): def ValidateAndMeasurePage(self, page, tab, results):
""" Collect all possible metrics and added them to results. """ """ Collect all possible metrics and added them to results. """
trace_result = tab.browser.StopTracing() trace_result = tab.browser.StopTracing()
trace_dir = self.options.trace_dir trace_dir = self.options.trace_dir
......
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
"""A simple PageMeasurement used by page/record_wpr.py's unit tests.""" """A simple PageTest used by page/record_wpr.py's unit tests."""
from telemetry.page import page_measurement from telemetry.page import page_test
class MockPageMeasurementOne(page_measurement.PageMeasurement): class MockPageTestOne(page_test.PageTest):
def __init__(self): def __init__(self):
super(MockPageMeasurementOne, self).__init__(action_name_to_run="RunFoo") super(MockPageTestOne, self).__init__(action_name_to_run="RunFoo")
def MeasurePage(self, page, tab, results): def ValidateAndMeasurePage(self, page, tab, results):
pass pass
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
"""A simple PageMeasurement used by page/record_wpr.py's unit tests.""" """A simple PageTest used by page/record_wpr.py's unit tests."""
from telemetry.page import page_measurement from telemetry.page import page_test
class MockPageMeasurementTwo(page_measurement.PageMeasurement): class MockPageTestTwo(page_test.PageTest):
def __init__(self): def __init__(self):
super(MockPageMeasurementTwo, self).__init__(action_name_to_run="RunBar") super(MockPageTestTwo, self).__init__(action_name_to_run="RunBar")
def MeasurePage(self, page, tab, results): def ValidateAndMeasurePage(self, page, tab, results):
pass pass
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
"""A simple PageMeasurement used by page/record_wpr.py's unit tests.""" """A simple PageTest used by page/record_wpr.py's unit tests."""
from telemetry.page import page_measurement from telemetry.page import page_test
class MockPageMeasurementThree(page_measurement.PageMeasurement): class MockPageTestThree(page_test.PageTest):
def __init__(self): def __init__(self):
super(MockPageMeasurementThree, self).__init__(action_name_to_run=None) super(MockPageTestThree, self).__init__(action_name_to_run=None)
def MeasurePage(self, page, tab, results): def ValidateAndMeasurePage(self, page, tab, results):
pass pass
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment