Chromium Code Reviews| Index: tools/perf/measurements/v8_detached_context_age_in_gc_unittest.py |
| diff --git a/tools/perf/measurements/v8_detached_context_age_in_gc_unittest.py b/tools/perf/measurements/v8_detached_context_age_in_gc_unittest.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1364d61f3511ea16ba1ed455b40cdfcfe2e987fd |
| --- /dev/null |
| +++ b/tools/perf/measurements/v8_detached_context_age_in_gc_unittest.py |
| @@ -0,0 +1,77 @@ |
| +# Copyright 2015 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +from measurements import v8_detached_context_age_in_gc |
| +from telemetry.core import wpr_modes |
| +from telemetry.page import page_test |
| +from telemetry.results import page_test_results |
| +from telemetry.unittest_util import options_for_unittests |
| +from telemetry.unittest_util import page_test_test_case |
| +from telemetry.value import skip |
| + |
| + |
| +class FakePage(object): |
| + def __init__(self, url): |
| + self.url = url |
| + self.is_file = url.startswith('file://') |
| + |
| + |
| +class FakeTab(object): |
| + def __init__(self, histograms): |
| + self.histograms = histograms |
| + self.current_histogram_index = 0 |
| + |
| + def EvaluateJavaScript(self, script): |
| + if 'V8.DetachedContextAgeInGC' in script: |
| + self.current_histogram_index += 1 |
| + return self.histograms[self.current_histogram_index - 1] |
| + return "{}" |
|
Sami
2015/02/18 15:30:26
nit: single quotes
ulan
2015/02/18 15:58:41
Done.
|
| + |
| + def CollectGarbage(self): |
| + pass |
| + |
| + |
| +def _MeasureFakePage(histograms): |
| + results = page_test_results.PageTestResults() |
| + page = FakePage("file://blank.html") |
|
Sami
2015/02/18 15:30:26
ditto
ulan
2015/02/18 15:58:41
Done.
|
| + tab = FakeTab(histograms) |
| + metric = v8_detached_context_age_in_gc.V8DetachedContextAgeInGC() |
| + results.WillRunPage(page) |
| + metric.DidNavigateToPage(page, tab) |
| + metric.ValidateAndMeasurePage(page, tab, results) |
| + results.DidRunPage(page) |
| + return results |
| + |
| + |
| +def _ActualValues(results): |
| + return dict(list((v.name, v)) for v in results.all_page_specific_values) |
|
Sami
2015/02/18 15:30:27
nit: "list()" is redundant
ulan
2015/02/18 15:58:41
Done.
|
| + |
| + |
| +class V8DetachedContextAgeInGCTests(page_test_test_case.PageTestTestCase): |
| + |
| + def setUp(self): |
| + self._options = options_for_unittests.GetCopy() |
| + self._options.browser_options.wpr_mode = wpr_modes.WPR_OFF |
| + |
| + def testWithNoData(self): |
| + histograms = [ |
| + """{"count": 0, "buckets": []}""", |
| + """{"count": 0, "buckets": []}""" |
| + ] |
| + results = _MeasureFakePage(histograms) |
| + actual = _ActualValues(results) |
| + self.assertTrue('skip' in actual) |
| + self.assertFalse('V8_DetachedContextAgeInGC' in actual) |
| + |
| + def testWithData(self): |
|
Sami
2015/02/18 15:30:26
Could we write this test in a way that uses the re
ulan
2015/02/18 15:58:41
Do you mean: create a real html page, let the brow
Sami
2015/02/18 16:20:56
Breaking a unit test instead triggering a perf reg
|
| + histograms = [ |
| + """{"count": 3, "buckets": [{"low": 1, "high": 2, "count": 1}, |
| + {"low": 2, "high": 3, "count": 2}]}""", |
| + """{"count": 4, "buckets": [{"low": 1, "high": 2, "count": 2}, |
| + {"low": 2, "high": 3, "count": 2}]}""", |
| + ] |
| + results = _MeasureFakePage(histograms) |
| + actual = _ActualValues(results)['V8_DetachedContextAgeInGC'] |
| + self.assertEqual(2, actual.value) |
| + self.assertEqual('garbage_collections', actual.units) |