| 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 import contextlib | 5 import contextlib |
| 6 from telemetry.internal.results import page_test_results | 6 from telemetry.internal.results import page_test_results |
| 7 from telemetry.testing import page_test_test_case | 7 from telemetry.testing import page_test_test_case |
| 8 | 8 |
| 9 from measurements import tab_switching | 9 from measurements import tab_switching |
| 10 | 10 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 browser = BrowserForTest() | 58 browser = BrowserForTest() |
| 59 tab_0 = self.MakeTabForTest() | 59 tab_0 = self.MakeTabForTest() |
| 60 browser.AddTab(tab_0) | 60 browser.AddTab(tab_0) |
| 61 tab_1 = self.MakeTabForTest() | 61 tab_1 = self.MakeTabForTest() |
| 62 browser.AddTab(tab_1) | 62 browser.AddTab(tab_1) |
| 63 | 63 |
| 64 # Mock histogram result to test _IsDone really works. | 64 # Mock histogram result to test _IsDone really works. |
| 65 expected_histogram = [ | 65 expected_histogram = [ |
| 66 # To get first_histogram for last tab (tab_1). | 66 # To get first_histogram for last tab (tab_1). |
| 67 '{"count": 0, "buckets": []}', | 67 '{"count": 0, "buckets": []}', |
| 68 # First _IsDone check for tab_0. Retry. | |
| 69 '{"count": 0, "buckets": []}', | |
| 70 # Second _IsDone check for tab_0. Retry. | |
| 71 '{"count": 0, "buckets": []}', | |
| 72 # Third _IsDone check for tab_0. Pass. | |
| 73 '{"count": 1, "buckets": [{"low": 1, "high": 2, "count": 1}]}', | |
| 74 # To get prev_histogram. End of tab_0 loop. | |
| 75 '{"count": 1, "buckets": [{"low": 1, "high": 2, "count": 1}]}', | |
| 76 # First _IsDone check for tab_1. Retry. | |
| 77 '{"count": 1, "buckets": [{"low": 1, "high": 2, "count": 1}]}', | |
| 78 # Second _IsDone check for tab_1. Pass. | |
| 79 '{"count": 2, "buckets": [{"low": 1, "high": 2, "count": 1},' | |
| 80 '{"low": 2, "high": 3, "count": 1}]}', | |
| 81 # To get prev_histogram. End of tab_1 loop. | 68 # To get prev_histogram. End of tab_1 loop. |
| 82 '{"count": 2, "buckets": [{"low": 1, "high": 2, "count": 1},' | 69 '{"count": 2, "buckets": [{"low": 1, "high": 2, "count": 1},' |
| 83 '{"low": 2, "high": 3, "count": 1}]}', | 70 '{"low": 2, "high": 3, "count": 1}]}', |
| 84 ] | 71 ] |
| 85 mock_get_histogram = mock.MagicMock(side_effect=expected_histogram) | 72 mock_get_histogram = mock.MagicMock(side_effect=expected_histogram) |
| 86 | 73 |
| 87 with contextlib.nested( | 74 with contextlib.nested( |
| 88 mock.patch('telemetry.value.histogram_util.GetHistogram', | 75 mock.patch('telemetry.value.histogram_util.GetHistogram', |
| 89 mock_get_histogram), | 76 mock_get_histogram), |
| 90 mock.patch('metrics.keychain_metric.KeychainMetric')): | 77 mock.patch('metrics.keychain_metric.KeychainMetric')): |
| 78 measure.DidNavigateToPage(story_set.stories[0], browser.tabs[-1]) |
| 91 measure.ValidateAndMeasurePage(story_set.stories[0], browser.tabs[-1], | 79 measure.ValidateAndMeasurePage(story_set.stories[0], browser.tabs[-1], |
| 92 page_test_results.PageTestResults()) | 80 page_test_results.PageTestResults()) |
| 93 self.assertEqual(len(expected_histogram), | 81 self.assertEqual(len(expected_histogram), |
| 94 len(mock_get_histogram.mock_calls)) | 82 len(mock_get_histogram.mock_calls)) |
| 95 expected_calls = [mock.call(mock.ANY, mock.ANY, t) for t in | 83 expected_calls = [mock.call(mock.ANY, mock.ANY, t) for t in |
| 96 [tab_1] + [tab_0] * 4 + [tab_1] * 3] | 84 [tab_1] + [tab_1]] |
| 97 self.assertEqual(expected_calls, mock_get_histogram.mock_calls) | 85 self.assertEqual(expected_calls, mock_get_histogram.mock_calls) |
| OLD | NEW |