1# Copyright 2014 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
5from telemetry.internal.results import page_test_results
6from telemetry.page import page as page_module
7from telemetry.value import list_of_scalar_values
8from telemetry.value import scalar
9
10
11class TestPageTestResults(
12    page_test_results.PageTestResults):
13  def __init__(self, test):
14    super(TestPageTestResults, self).__init__()
15    self.test = test
16    page = page_module.Page("http://www.google.com", {})
17    self.WillRunPage(page)
18
19  def GetPageSpecificValueNamed(self, name):
20    values = [value for value in self.all_page_specific_values
21         if value.name == name]
22    assert len(values) == 1, 'Could not find value named %s' % name
23    return values[0]
24
25  def AssertHasPageSpecificScalarValue(self, name, units, expected_value):
26    value = self.GetPageSpecificValueNamed(name)
27    self.test.assertEquals(units, value.units)
28    self.test.assertTrue(isinstance(value, scalar.ScalarValue))
29    self.test.assertEquals(expected_value, value.value)
30
31  def AssertHasPageSpecificListOfScalarValues(self, name, units,
32                                              expected_values):
33    value = self.GetPageSpecificValueNamed(name)
34    self.test.assertEquals(units, value.units)
35    self.test.assertTrue(
36        isinstance(value, list_of_scalar_values.ListOfScalarValues))
37    self.test.assertItemsEqual(expected_values, value.values)
38
39  def __str__(self):
40    return '\n'.join([repr(x) for x in self.all_page_specific_values])
41