| Index: tools/telemetry/telemetry/page/page_runner_unittest.py
|
| diff --git a/tools/telemetry/telemetry/page/page_runner_unittest.py b/tools/telemetry/telemetry/page/page_runner_unittest.py
|
| index 09384781338866becec3c52810af3c9762d72a59..51bd95c31f811a0214032c2f5d5f3bb80f524e27 100644
|
| --- a/tools/telemetry/telemetry/page/page_runner_unittest.py
|
| +++ b/tools/telemetry/telemetry/page/page_runner_unittest.py
|
| @@ -2,12 +2,12 @@
|
| # Use of this source code is governed by a BSD-style license that can be
|
| # found in the LICENSE file.
|
|
|
| -import logging
|
| import os
|
| import tempfile
|
| import unittest
|
| import StringIO
|
| import sys
|
| +import tempfile
|
|
|
| from telemetry import benchmark
|
| from telemetry import decorators
|
| @@ -37,6 +37,9 @@ SIMPLE_CREDENTIALS_STRING = """
|
| }
|
| }
|
| """
|
| +class DummyTest(page_test.PageTest):
|
| + def ValidatePage(self, *_):
|
| + pass
|
|
|
|
|
| def SetUpPageRunnerArguments(options):
|
| @@ -160,16 +163,12 @@ class PageRunnerTests(unittest.TestCase):
|
| page1 = page_module.Page('chrome://crash', ps)
|
| ps.pages.append(page1)
|
|
|
| - class Test(page_test.PageTest):
|
| - def ValidatePage(self, *_):
|
| - pass
|
| -
|
| options = options_for_unittests.GetCopy()
|
| options.output_formats = ['none']
|
| options.suppress_gtest_report = True
|
| SetUpPageRunnerArguments(options)
|
| results = results_options.CreateResults(EmptyMetadataForTest(), options)
|
| - page_runner.Run(Test(), ps, expectations, options, results)
|
| + page_runner.Run(DummyTest(), ps, expectations, options, results)
|
| self.assertEquals(1, len(GetSuccessfulPageRuns(results)))
|
| self.assertEquals(0, len(results.failures))
|
|
|
| @@ -561,61 +560,6 @@ class PageRunnerTests(unittest.TestCase):
|
| self.assertEquals(0, len(GetSuccessfulPageRuns(results)))
|
| self.assertEquals(0, len(results.failures))
|
|
|
| - def TestUseLiveSitesFlag(self, options, expect_from_archive):
|
| - ps = page_set.PageSet(
|
| - file_path=util.GetUnittestDataDir(),
|
| - archive_data_file='data/archive_blank.json')
|
| - ps.pages.append(page_module.Page(
|
| - 'file://blank.html', ps, base_dir=ps.base_dir))
|
| - expectations = test_expectations.TestExpectations()
|
| -
|
| - class ArchiveTest(page_test.PageTest):
|
| - def __init__(self):
|
| - super(ArchiveTest, self).__init__()
|
| - self.is_page_from_archive = False
|
| - self.archive_path_exist = True
|
| -
|
| - def WillStartBrowser(self, platform):
|
| - self.is_page_from_archive = (
|
| - self.options.browser_options.wpr_mode != wpr_modes.WPR_OFF)
|
| -
|
| - def WillNavigateToPage(self, page, tab):
|
| - self.archive_path_exist = (page.archive_path
|
| - and os.path.isfile(page.archive_path))
|
| -
|
| - def ValidateAndMeasurePage(self, _, __, results):
|
| - pass
|
| -
|
| - test = ArchiveTest()
|
| - results = results_options.CreateResults(EmptyMetadataForTest(), options)
|
| - try:
|
| - page_runner.Run(test, ps, expectations, options, results)
|
| - if expect_from_archive and not test.archive_path_exist:
|
| - logging.warning('archive path did not exist, asserting that page '
|
| - 'is from archive is skipped.')
|
| - return
|
| - self.assertEquals(expect_from_archive, test.is_page_from_archive)
|
| - finally:
|
| - for p in ps:
|
| - if os.path.isfile(p.archive_path):
|
| - os.remove(p.archive_path)
|
| -
|
| -
|
| - def testUseLiveSitesFlagSet(self):
|
| - options = options_for_unittests.GetCopy()
|
| - options.output_formats = ['none']
|
| - options.suppress_gtest_report = True
|
| - options.use_live_sites = True
|
| - SetUpPageRunnerArguments(options)
|
| - self.TestUseLiveSitesFlag(options, expect_from_archive=False)
|
| -
|
| - def testUseLiveSitesFlagUnset(self):
|
| - options = options_for_unittests.GetCopy()
|
| - options.output_formats = ['none']
|
| - options.suppress_gtest_report = True
|
| - SetUpPageRunnerArguments(options)
|
| - self.TestUseLiveSitesFlag(options, expect_from_archive=True)
|
| -
|
| def _testMaxFailuresOptionIsRespectedAndOverridable(self, max_failures=None):
|
| self.SuppressExceptionFormatting()
|
| class TestPage(page_module.Page):
|
| @@ -664,3 +608,41 @@ class PageRunnerTests(unittest.TestCase):
|
|
|
| def testMaxFailuresOptionIsOverridable(self):
|
| self._testMaxFailuresOptionIsRespectedAndOverridable(1)
|
| +
|
| +
|
| +class FakeNetworkController(object):
|
| + def __init__(self):
|
| + self.archive_path = None
|
| + self.wpr_mode = None
|
| +
|
| + def SetReplayArgs(self, archive_path, wpr_mode, _netsim, _extra_wpr_args,
|
| + _make_javascript_deterministic=False):
|
| + self.archive_path = archive_path
|
| + self.wpr_mode = wpr_mode
|
| +
|
| +
|
| +class RunStateTest(unittest.TestCase):
|
| +
|
| + # pylint: disable=W0212
|
| + def TestUseLiveSitesFlag(self, options, expected_wpr_mode):
|
| + with tempfile.NamedTemporaryFile() as f:
|
| + run_state = page_runner._RunState(DummyTest())
|
| + fake_network_controller = FakeNetworkController()
|
| + run_state._PrepareWpr(options, fake_network_controller, f.name, None)
|
| + self.assertEquals(fake_network_controller.wpr_mode, expected_wpr_mode)
|
| + self.assertEquals(fake_network_controller.archive_path, f.name)
|
| +
|
| + def testUseLiveSitesFlagSet(self):
|
| + options = options_for_unittests.GetCopy()
|
| + options.output_formats = ['none']
|
| + options.suppress_gtest_report = True
|
| + options.use_live_sites = True
|
| + SetUpPageRunnerArguments(options)
|
| + self.TestUseLiveSitesFlag(options, expected_wpr_mode=wpr_modes.WPR_OFF)
|
| +
|
| + def testUseLiveSitesFlagUnset(self):
|
| + options = options_for_unittests.GetCopy()
|
| + options.output_formats = ['none']
|
| + options.suppress_gtest_report = True
|
| + SetUpPageRunnerArguments(options)
|
| + self.TestUseLiveSitesFlag(options, expected_wpr_mode=wpr_modes.WPR_REPLAY)
|
|
|