OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 import copy | 5 import copy |
6 import unittest | 6 import unittest |
7 | 7 |
8 import metrics | 8 import metrics |
9 import request_track | 9 import request_track |
10 import test_utils | 10 import test_utils |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 self._BODY_SIZE + self._RESPONSE_HEADERS_SIZE + cache_control_length, | 65 self._BODY_SIZE + self._RESPONSE_HEADERS_SIZE + cache_control_length, |
66 downloaded) | 66 downloaded) |
67 | 67 |
68 def testTransferSize(self): | 68 def testTransferSize(self): |
69 trace = self._MakeTrace() | 69 trace = self._MakeTrace() |
70 r = trace.request_track.GetEvents()[0] | 70 r = trace.request_track.GetEvents()[0] |
71 (_, downloaded) = metrics.TransferSize([r]) | 71 (_, downloaded) = metrics.TransferSize([r]) |
72 self.assertEqual(self._BODY_SIZE + self._RESPONSE_HEADERS_SIZE, | 72 self.assertEqual(self._BODY_SIZE + self._RESPONSE_HEADERS_SIZE, |
73 downloaded) | 73 downloaded) |
74 | 74 |
| 75 def testDnsRequestsAndCost(self): |
| 76 trace = self._MakeTrace() |
| 77 (count, cost) = metrics.DnsRequestsAndCost(trace) |
| 78 self.assertEqual(0, count) |
| 79 self.assertEqual(0, cost) |
| 80 r = trace.request_track.GetEvents()[0] |
| 81 r.timing.dns_end = 12 |
| 82 r.timing.dns_start = 4 |
| 83 (count, cost) = metrics.DnsRequestsAndCost(trace) |
| 84 self.assertEqual(1, count) |
| 85 self.assertEqual(8, cost) |
| 86 |
75 @classmethod | 87 @classmethod |
76 def _MakeTrace(cls): | 88 def _MakeTrace(cls): |
77 request = request_track.Request.FromJsonDict(copy.deepcopy(cls._REQUEST)) | 89 request = request_track.Request.FromJsonDict(copy.deepcopy(cls._REQUEST)) |
78 return test_utils.LoadingTraceFromEvents([request]) | 90 return test_utils.LoadingTraceFromEvents([request]) |
79 | 91 |
80 | 92 |
81 if __name__ == '__main__': | 93 if __name__ == '__main__': |
82 unittest.main() | 94 unittest.main() |
OLD | NEW |