OLD | NEW |
---|---|
(Empty) | |
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 | |
3 # found in the LICENSE file. | |
4 | |
5 from measurements import v8_detached_context_age_in_gc | |
6 from telemetry.core import wpr_modes | |
7 from telemetry.page import page_test | |
8 from telemetry.results import page_test_results | |
9 from telemetry.unittest_util import options_for_unittests | |
10 from telemetry.unittest_util import page_test_test_case | |
11 from telemetry.value import skip | |
12 | |
13 | |
14 class FakePage(object): | |
15 def __init__(self, url): | |
16 self.url = url | |
17 self.is_file = url.startswith('file://') | |
18 | |
19 | |
20 class FakeTab(object): | |
21 def __init__(self, histograms): | |
22 self.histograms = histograms | |
23 self.current_histogram_index = 0 | |
24 | |
25 def EvaluateJavaScript(self, script): | |
26 if 'V8.DetachedContextAgeInGC' in script: | |
27 self.current_histogram_index += 1 | |
28 return self.histograms[self.current_histogram_index - 1] | |
29 return "{}" | |
Sami
2015/02/18 15:30:26
nit: single quotes
ulan
2015/02/18 15:58:41
Done.
| |
30 | |
31 def CollectGarbage(self): | |
32 pass | |
33 | |
34 | |
35 def _MeasureFakePage(histograms): | |
36 results = page_test_results.PageTestResults() | |
37 page = FakePage("file://blank.html") | |
Sami
2015/02/18 15:30:26
ditto
ulan
2015/02/18 15:58:41
Done.
| |
38 tab = FakeTab(histograms) | |
39 metric = v8_detached_context_age_in_gc.V8DetachedContextAgeInGC() | |
40 results.WillRunPage(page) | |
41 metric.DidNavigateToPage(page, tab) | |
42 metric.ValidateAndMeasurePage(page, tab, results) | |
43 results.DidRunPage(page) | |
44 return results | |
45 | |
46 | |
47 def _ActualValues(results): | |
48 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.
| |
49 | |
50 | |
51 class V8DetachedContextAgeInGCTests(page_test_test_case.PageTestTestCase): | |
52 | |
53 def setUp(self): | |
54 self._options = options_for_unittests.GetCopy() | |
55 self._options.browser_options.wpr_mode = wpr_modes.WPR_OFF | |
56 | |
57 def testWithNoData(self): | |
58 histograms = [ | |
59 """{"count": 0, "buckets": []}""", | |
60 """{"count": 0, "buckets": []}""" | |
61 ] | |
62 results = _MeasureFakePage(histograms) | |
63 actual = _ActualValues(results) | |
64 self.assertTrue('skip' in actual) | |
65 self.assertFalse('V8_DetachedContextAgeInGC' in actual) | |
66 | |
67 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
| |
68 histograms = [ | |
69 """{"count": 3, "buckets": [{"low": 1, "high": 2, "count": 1}, | |
70 {"low": 2, "high": 3, "count": 2}]}""", | |
71 """{"count": 4, "buckets": [{"low": 1, "high": 2, "count": 2}, | |
72 {"low": 2, "high": 3, "count": 2}]}""", | |
73 ] | |
74 results = _MeasureFakePage(histograms) | |
75 actual = _ActualValues(results)['V8_DetachedContextAgeInGC'] | |
76 self.assertEqual(2, actual.value) | |
77 self.assertEqual('garbage_collections', actual.units) | |
OLD | NEW |