Chromium Code Reviews| Index: tools/telemetry/telemetry/page/test_expectations_unittest.py |
| diff --git a/tools/telemetry/telemetry/page/test_expectations_unittest.py b/tools/telemetry/telemetry/page/test_expectations_unittest.py |
| index ee4a1b82d1b0249a6924a61ffcf0d07263b5892a..6d98a8f30fd4b61ad195a4f0b8de5560f8a2f681 100644 |
| --- a/tools/telemetry/telemetry/page/test_expectations_unittest.py |
| +++ b/tools/telemetry/telemetry/page/test_expectations_unittest.py |
| @@ -18,6 +18,39 @@ class StubPlatform(object): |
| def GetOSVersionName(self): |
| return self.os_version_name |
| +class StubGpu(object): |
| + def __init__(self, vendor_string): |
| + self.vendor_string = vendor_string |
| + self.vendor_id = 0 |
|
Ken Russell (switch to Gerrit)
2013/08/15 19:25:28
Rather than defining StubGpu, StubGpuInfo and Stub
|
| + |
| +class StubGpuInfo(object): |
| + def __init__(self, gpu): |
| + self.devices = [gpu] |
| + |
| +class StubSystemInfo(object): |
| + def __init__(self, gpu): |
| + self.gpu_info = StubGpuInfo(gpu) |
| + |
| + @property |
| + def gpu(self): |
| + return self.gpu_info |
| + |
| +class StubBrowser(object): |
| + def __init__(self, platform, gpu): |
| + self.platform = platform |
| + self.system_info = StubSystemInfo(gpu) if gpu else None |
| + |
| + @property |
| + def supports_system_info(self): |
| + return False if not self.system_info else True |
| + |
| + def GetSystemInfo(self): |
| + return self.system_info |
| + |
| +class StubState(object): |
| + def __init__(self, platform=None, gpu=None): |
| + self.browser = StubBrowser(platform, gpu) |
| + |
| class SampleTestExpectations(test_expectations.TestExpectations): |
| def SetExpectations(self): |
| self.Fail('page1.html', ['win', 'mac'], bug=123) |
| @@ -25,54 +58,57 @@ class SampleTestExpectations(test_expectations.TestExpectations): |
| self.Fail('page3.html', bug=123) |
| self.Fail('page4.*', bug=123) |
| self.Fail('http://test.com/page5.html', bug=123) |
| + self.Fail('page6.html', ['nvidia', 'intel'], bug=123) |
| + self.Fail('page7.html', ['win', 'amd'], bug=123) |
| class TestExpectationsTest(unittest.TestCase): |
| def setUp(self): |
| self.expectations = SampleTestExpectations() |
| - def assertExpectationEquals(self, expected, platform, page): |
| - result = self.expectations.GetExpectationForPage(platform, page) |
| + def assertExpectationEquals(self, expected, page, platform=None, gpu=None): |
| + result = self.expectations.GetExpectationForPage(StubState(platform, gpu), |
| + page) |
| self.assertEquals(expected, result) |
| # Pages with no expectations should always return 'pass' |
| def testNoExpectations(self): |
| ps = page_set.PageSet() |
| page = page_module.Page('http://test.com/page0.html', ps) |
| - self.assertExpectationEquals('pass', StubPlatform('win'), page) |
| + self.assertExpectationEquals('pass', page, StubPlatform('win')) |
| # Pages with expectations for an OS should only return them when running on |
| # that OS |
| def testOSExpectations(self): |
| ps = page_set.PageSet() |
| page = page_module.Page('http://test.com/page1.html', ps) |
| - self.assertExpectationEquals('fail', StubPlatform('win'), page) |
| - self.assertExpectationEquals('fail', StubPlatform('mac'), page) |
| - self.assertExpectationEquals('pass', StubPlatform('linux'), page) |
| + self.assertExpectationEquals('fail', page, StubPlatform('win')) |
| + self.assertExpectationEquals('fail', page, StubPlatform('mac')) |
| + self.assertExpectationEquals('pass', page, StubPlatform('linux')) |
| # Pages with expectations for an OS version should only return them when |
| # running on that OS version |
| def testOSVersionExpectations(self): |
| ps = page_set.PageSet() |
| page = page_module.Page('http://test.com/page2.html', ps) |
| - self.assertExpectationEquals('fail', StubPlatform('win', 'vista'), page) |
| - self.assertExpectationEquals('pass', StubPlatform('win', 'win7'), page) |
| + self.assertExpectationEquals('fail', page, StubPlatform('win', 'vista')) |
| + self.assertExpectationEquals('pass', page, StubPlatform('win', 'win7')) |
| # Pages with non-conditional expectations should always return that |
| # expectation regardless of OS or OS version |
| def testConditionlessExpectations(self): |
| ps = page_set.PageSet() |
| page = page_module.Page('http://test.com/page3.html', ps) |
| - self.assertExpectationEquals('fail', StubPlatform('win'), page) |
| - self.assertExpectationEquals('fail', StubPlatform('mac', 'lion'), page) |
| - self.assertExpectationEquals('fail', StubPlatform('linux'), page) |
| + self.assertExpectationEquals('fail', page, StubPlatform('win')) |
| + self.assertExpectationEquals('fail', page, StubPlatform('mac', 'lion')) |
| + self.assertExpectationEquals('fail', page, StubPlatform('linux')) |
| # Expectations with wildcard characters should return for matching patterns |
| def testWildcardExpectations(self): |
| ps = page_set.PageSet() |
| page = page_module.Page('http://test.com/page4.html', ps) |
| page_js = page_module.Page('http://test.com/page4.html', ps) |
| - self.assertExpectationEquals('fail', StubPlatform('win'), page) |
| - self.assertExpectationEquals('fail', StubPlatform('win'), page_js) |
| + self.assertExpectationEquals('fail', page, StubPlatform('win')) |
| + self.assertExpectationEquals('fail', page_js, StubPlatform('win')) |
| # Expectations with absolute paths should match the entire path |
| def testAbsoluteExpectations(self): |
| @@ -80,6 +116,27 @@ class TestExpectationsTest(unittest.TestCase): |
| page = page_module.Page('http://test.com/page5.html', ps) |
| page_org = page_module.Page('http://test.org/page5.html', ps) |
| page_https = page_module.Page('https://test.com/page5.html', ps) |
| - self.assertExpectationEquals('fail', StubPlatform('win'), page) |
| - self.assertExpectationEquals('pass', StubPlatform('win'), page_org) |
| - self.assertExpectationEquals('pass', StubPlatform('win'), page_https) |
| + self.assertExpectationEquals('fail', page, StubPlatform('win')) |
| + self.assertExpectationEquals('pass', page_org, StubPlatform('win')) |
| + self.assertExpectationEquals('pass', page_https, StubPlatform('win')) |
| + |
| + # Pages with expectations for a GPU should only return them when running with |
| + # that GPU |
| + def testGpuExpectations(self): |
| + ps = page_set.PageSet() |
| + page = page_module.Page('http://test.com/page6.html', ps) |
| + self.assertExpectationEquals('fail', page, gpu=StubGpu('nvidia')) |
| + self.assertExpectationEquals('fail', page, gpu=StubGpu('intel')) |
| + self.assertExpectationEquals('pass', page, gpu=StubGpu('amd')) |
| + |
| + # Pages with expectations for an OS/GPU combo should only return them when |
| + # running with both that OS and GPU |
| + def testOSAndGpuExpectations(self): |
|
Ken Russell (switch to Gerrit)
2013/08/15 19:25:28
The new tests look good, but assuming the PCI ID i
|
| + ps = page_set.PageSet() |
| + page = page_module.Page('http://test.com/page7.html', ps) |
| + self.assertExpectationEquals('fail', page, |
| + StubPlatform('win'), StubGpu('amd')) |
| + self.assertExpectationEquals('pass', page, |
| + StubPlatform('win'), StubGpu('nvidia')) |
| + self.assertExpectationEquals('pass', page, |
| + StubPlatform('mac'), StubGpu('amd')) |