| 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..2904d9b9b2b4f30f13aa6cbae65a6b774514bd4c
|
| --- /dev/null
|
| +++ b/tools/perf/measurements/v8_detached_context_age_in_gc_unittest.py
|
| @@ -0,0 +1,84 @@
|
| +# 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
|
| +
|
| +
|
| +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 "{}"
|
| +
|
| + def CollectGarbage(self):
|
| + pass
|
| +
|
| +
|
| +def _MeasureFakePage(histograms):
|
| + results = page_test_results.PageTestResults()
|
| + page = FakePage("file://blank.html")
|
| + 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.units, v.value))
|
| + for v in results.all_page_specific_values
|
| + ))
|
| +
|
| +
|
| +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)
|
| + expected = {'V8_DetachedContextAgeInGC': ('garbage_collections', 0) }
|
| + self._AssertResultsEqual(expected, _ActualValues(results))
|
| +
|
| + def testWithData(self):
|
| + 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)
|
| + expected = {'V8_DetachedContextAgeInGC': ('garbage_collections', 2) }
|
| + self._AssertResultsEqual(expected, _ActualValues(results))
|
| +
|
| + def _AssertResultsEqual(self, expected, actual):
|
| + for key in expected.iterkeys():
|
| + self.assertIn(key, actual.keys())
|
| + self.assertEqual(expected[key], actual[key],
|
| + 'Result for [' + key + '] - expected ' + str(expected[key]) +
|
| + ' but got ' + str(actual[key]))
|
|
|