- add sources.
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / page / test_expectations_unittest.py
1 # Copyright 2013 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 import unittest
5
6 from telemetry.core import system_info
7 from telemetry.page import page as page_module
8 from telemetry.page import page_set
9 from telemetry.page import test_expectations
10
11 VENDOR_NVIDIA = 0x10DE
12 VENDOR_AMD = 0x1002
13 VENDOR_INTEL = 0x8086
14
15 VENDOR_STRING_IMAGINATION = 'Imagination Technologies'
16 DEVICE_STRING_SGX = 'PowerVR SGX 554'
17
18 class StubPlatform(object):
19   def __init__(self, os_name, os_version_name=None):
20     self.os_name = os_name
21     self.os_version_name = os_version_name
22
23   def GetOSName(self):
24     return self.os_name
25
26   def GetOSVersionName(self):
27     return self.os_version_name
28
29 class StubBrowser(object):
30   def __init__(self, platform, gpu, device, vendor_string, device_string):
31     self.platform = platform
32     self.system_info = system_info.SystemInfo.FromDict({
33       'model_name': '',
34       'gpu': {
35         'devices': [
36           { 'vendor_id': gpu, 'device_id': device,
37             'vendor_string': vendor_string, 'device_string': device_string },
38         ]
39       }
40     })
41
42   @property
43   def supports_system_info(self):
44     return False if not self.system_info else True
45
46   def GetSystemInfo(self):
47     return self.system_info
48
49 class SampleTestExpectations(test_expectations.TestExpectations):
50   def SetExpectations(self):
51     self.Fail('page1.html', ['win', 'mac'], bug=123)
52     self.Fail('page2.html', ['vista'], bug=123)
53     self.Fail('page3.html', bug=123)
54     self.Fail('page4.*', bug=123)
55     self.Fail('http://test.com/page5.html', bug=123)
56     self.Fail('page6.html', ['nvidia', 'intel'], bug=123)
57     self.Fail('page7.html', [('nvidia', 0x1001), ('nvidia', 0x1002)], bug=123)
58     self.Fail('page8.html', ['win', 'intel', ('amd', 0x1001)], bug=123)
59     self.Fail('page9.html', ['imagination'])
60     self.Fail('page10.html', [('imagination', 'PowerVR SGX 554')])
61     self.Fail('Pages.page_11')
62
63 class TestExpectationsTest(unittest.TestCase):
64   def setUp(self):
65     self.expectations = SampleTestExpectations()
66
67   def assertExpectationEquals(self, expected, page, platform='', gpu=0,
68       device=0, vendor_string='', device_string=''):
69     result = self.expectations.GetExpectationForPage(StubBrowser(platform, gpu,
70         device, vendor_string, device_string), page)
71     self.assertEquals(expected, result)
72
73   # Pages with no expectations should always return 'pass'
74   def testNoExpectations(self):
75     ps = page_set.PageSet()
76     page = page_module.Page('http://test.com/page0.html', ps)
77     self.assertExpectationEquals('pass', page, StubPlatform('win'))
78
79   # Pages with expectations for an OS should only return them when running on
80   # that OS
81   def testOSExpectations(self):
82     ps = page_set.PageSet()
83     page = page_module.Page('http://test.com/page1.html', ps)
84     self.assertExpectationEquals('fail', page, StubPlatform('win'))
85     self.assertExpectationEquals('fail', page, StubPlatform('mac'))
86     self.assertExpectationEquals('pass', page, StubPlatform('linux'))
87
88   # Pages with expectations for an OS version should only return them when
89   # running on that OS version
90   def testOSVersionExpectations(self):
91     ps = page_set.PageSet()
92     page = page_module.Page('http://test.com/page2.html', ps)
93     self.assertExpectationEquals('fail', page, StubPlatform('win', 'vista'))
94     self.assertExpectationEquals('pass', page, StubPlatform('win', 'win7'))
95
96   # Pages with non-conditional expectations should always return that
97   # expectation regardless of OS or OS version
98   def testConditionlessExpectations(self):
99     ps = page_set.PageSet()
100     page = page_module.Page('http://test.com/page3.html', ps)
101     self.assertExpectationEquals('fail', page, StubPlatform('win'))
102     self.assertExpectationEquals('fail', page, StubPlatform('mac', 'lion'))
103     self.assertExpectationEquals('fail', page, StubPlatform('linux'))
104
105   # Expectations with wildcard characters should return for matching patterns
106   def testWildcardExpectations(self):
107     ps = page_set.PageSet()
108     page = page_module.Page('http://test.com/page4.html', ps)
109     page_js = page_module.Page('http://test.com/page4.html', ps)
110     self.assertExpectationEquals('fail', page, StubPlatform('win'))
111     self.assertExpectationEquals('fail', page_js, StubPlatform('win'))
112
113   # Expectations with absolute paths should match the entire path
114   def testAbsoluteExpectations(self):
115     ps = page_set.PageSet()
116     page = page_module.Page('http://test.com/page5.html', ps)
117     page_org = page_module.Page('http://test.org/page5.html', ps)
118     page_https = page_module.Page('https://test.com/page5.html', ps)
119     self.assertExpectationEquals('fail', page, StubPlatform('win'))
120     self.assertExpectationEquals('pass', page_org, StubPlatform('win'))
121     self.assertExpectationEquals('pass', page_https, StubPlatform('win'))
122
123   # Pages with expectations for a GPU should only return them when running with
124   # that GPU
125   def testGpuExpectations(self):
126     ps = page_set.PageSet()
127     page = page_module.Page('http://test.com/page6.html', ps)
128     self.assertExpectationEquals('fail', page, gpu=VENDOR_NVIDIA)
129     self.assertExpectationEquals('fail', page, gpu=VENDOR_INTEL)
130     self.assertExpectationEquals('pass', page, gpu=VENDOR_AMD)
131
132   # Pages with expectations for a GPU should only return them when running with
133   # that GPU
134   def testGpuDeviceIdExpectations(self):
135     ps = page_set.PageSet()
136     page = page_module.Page('http://test.com/page7.html', ps)
137     self.assertExpectationEquals('fail', page, gpu=VENDOR_NVIDIA, device=0x1001)
138     self.assertExpectationEquals('fail', page, gpu=VENDOR_NVIDIA, device=0x1002)
139     self.assertExpectationEquals('pass', page, gpu=VENDOR_NVIDIA, device=0x1003)
140     self.assertExpectationEquals('pass', page, gpu=VENDOR_AMD, device=0x1001)
141
142   # Pages with multiple expectations should only return them when all criteria
143   # is met
144   def testMultipleExpectations(self):
145     ps = page_set.PageSet()
146     page = page_module.Page('http://test.com/page8.html', ps)
147     self.assertExpectationEquals('fail', page,
148         StubPlatform('win'), VENDOR_AMD, 0x1001)
149     self.assertExpectationEquals('fail', page,
150         StubPlatform('win'), VENDOR_INTEL, 0x1002)
151     self.assertExpectationEquals('pass', page,
152         StubPlatform('win'), VENDOR_NVIDIA, 0x1001)
153     self.assertExpectationEquals('pass', page,
154         StubPlatform('mac'), VENDOR_AMD, 0x1001)
155     self.assertExpectationEquals('pass', page,
156         StubPlatform('win'), VENDOR_AMD, 0x1002)
157
158   # Pages with expectations based on GPU vendor string.
159   def testGpuVendorStringExpectations(self):
160     ps = page_set.PageSet()
161     page = page_module.Page('http://test.com/page9.html', ps)
162     self.assertExpectationEquals('fail', page,
163                                  vendor_string=VENDOR_STRING_IMAGINATION,
164                                  device_string=DEVICE_STRING_SGX)
165     self.assertExpectationEquals('fail', page,
166                                  vendor_string=VENDOR_STRING_IMAGINATION,
167                                  device_string='Triangle Monster 3000')
168     self.assertExpectationEquals('pass', page,
169                                  vendor_string='Acme',
170                                  device_string=DEVICE_STRING_SGX)
171
172   # Pages with expectations based on GPU vendor and renderer string pairs.
173   def testGpuDeviceStringExpectations(self):
174     ps = page_set.PageSet()
175     page = page_module.Page('http://test.com/page10.html', ps)
176     self.assertExpectationEquals('fail', page,
177                                  vendor_string=VENDOR_STRING_IMAGINATION,
178                                  device_string=DEVICE_STRING_SGX)
179     self.assertExpectationEquals('pass', page,
180                                  vendor_string=VENDOR_STRING_IMAGINATION,
181                                  device_string='Triangle Monster 3000')
182     self.assertExpectationEquals('pass', page,
183                                  vendor_string='Acme',
184                                  device_string=DEVICE_STRING_SGX)
185
186   # Expectations can be set against page names as well as urls
187   def testPageNameExpectations(self):
188     ps = page_set.PageSet()
189     page = page_module.Page('http://test.com/page11.html', ps)
190     page.name = "Pages.page_11"
191     self.assertExpectationEquals('fail', page)