Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from telemetry.internal.results import page_test_results | 5 from telemetry.internal.results import page_test_results |
| 6 from telemetry.page import page as page_module | 6 from telemetry.page import page as page_module |
| 7 from telemetry.testing import options_for_unittests | 7 from telemetry.testing import options_for_unittests |
| 8 from telemetry.testing import page_test_test_case | 8 from telemetry.testing import page_test_test_case |
| 9 from telemetry.util import wpr_modes | 9 from telemetry.util import wpr_modes |
| 10 | 10 |
| 11 from measurements import v8_detached_context_age_in_gc | 11 from measurements import v8_detached_context_age_in_gc |
| 12 | 12 |
| 13 | 13 |
| 14 class FakePage(page_module.Page): | 14 class FakePage(page_module.Page): |
| 15 | 15 |
| 16 def __init__(self, url): | 16 def __init__(self, url): |
| 17 super(FakePage, self).__init__(url=url) | 17 super(FakePage, self).__init__(url=url) |
| 18 | 18 |
| 19 @property | 19 @property |
| 20 def is_file(self): | 20 def is_file(self): |
| 21 return self._url.startswith('file://') | 21 return self._url.startswith('file://') |
| 22 | 22 |
| 23 | 23 |
| 24 class FakeTab(object): | 24 class FakeTab(object): |
| 25 | 25 |
| 26 def __init__(self, histograms): | 26 def __init__(self, histograms): |
| 27 self.histograms = histograms | 27 self.histograms = histograms |
| 28 self.current_histogram_index = 0 | 28 self.current_histogram_index = 0 |
| 29 | 29 |
| 30 def EvaluateJavaScript(self, script): | 30 def EvaluateJavaScript(self, script, **kwargs): |
| 31 if 'V8.DetachedContextAgeInGC' in script: | 31 histogram_name = 'V8.DetachedContextAgeInGC' |
| 32 if kwargs.get('name') == histogram_name or histogram_name in script: | |
|
perezju
2017/02/14 11:42:04
Tweaked to work both before and after applying the
| |
| 32 self.current_histogram_index += 1 | 33 self.current_histogram_index += 1 |
| 33 return self.histograms[self.current_histogram_index - 1] | 34 return self.histograms[self.current_histogram_index - 1] |
| 34 return '{}' | 35 return '{}' |
| 35 | 36 |
| 37 # TODO(catapult:3028): Remove after migration to new JS API completed. | |
| 38 def EvaluateJavaScript2(self, script, **kwargs): | |
| 39 return self.EvaluateJavaScript(script, **kwargs) | |
| 40 | |
| 36 def CollectGarbage(self): | 41 def CollectGarbage(self): |
| 37 pass | 42 pass |
| 38 | 43 |
| 39 | 44 |
| 40 def _MeasureFakePage(histograms): | 45 def _MeasureFakePage(histograms): |
| 41 results = page_test_results.PageTestResults() | 46 results = page_test_results.PageTestResults() |
| 42 page = FakePage('file://blank.html') | 47 page = FakePage('file://blank.html') |
| 43 tab = FakeTab(histograms) | 48 tab = FakeTab(histograms) |
| 44 metric = v8_detached_context_age_in_gc.V8DetachedContextAgeInGC() | 49 metric = v8_detached_context_age_in_gc.V8DetachedContextAgeInGC() |
| 45 results.WillRunPage(page) | 50 results.WillRunPage(page) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 def testWithSimplePage(self): | 100 def testWithSimplePage(self): |
| 96 page_set = self.CreateEmptyPageSet() | 101 page_set = self.CreateEmptyPageSet() |
| 97 page = SimplePage(page_set) | 102 page = SimplePage(page_set) |
| 98 page_set.AddStory(page) | 103 page_set.AddStory(page) |
| 99 metric = v8_detached_context_age_in_gc.V8DetachedContextAgeInGC() | 104 metric = v8_detached_context_age_in_gc.V8DetachedContextAgeInGC() |
| 100 results = self.RunMeasurement(metric, page_set, options=self._options) | 105 results = self.RunMeasurement(metric, page_set, options=self._options) |
| 101 self.assertEquals(0, len(results.failures), msg=str(results.failures)) | 106 self.assertEquals(0, len(results.failures), msg=str(results.failures)) |
| 102 actual = _ActualValues(results)['V8_DetachedContextAgeInGC'] | 107 actual = _ActualValues(results)['V8_DetachedContextAgeInGC'] |
| 103 self.assertLessEqual(0, actual.value) | 108 self.assertLessEqual(0, actual.value) |
| 104 self.assertEqual('garbage_collections', actual.units) | 109 self.assertEqual('garbage_collections', actual.units) |
| OLD | NEW |