Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / core / browser_unittest.py
1 # Copyright 2012 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
5 import logging
6
7 from telemetry import benchmark
8 from telemetry.core import gpu_device
9 from telemetry.core import gpu_info
10 from telemetry.core import system_info
11 from telemetry.unittest import browser_test_case
12
13
14 class BrowserTest(browser_test_case.BrowserTestCase):
15   def testBrowserCreation(self):
16     self.assertEquals(1, len(self._browser.tabs))
17
18     # Different browsers boot up to different things.
19     assert self._browser.tabs[0].url
20
21   def testVersionDetection(self):
22     # pylint: disable=W0212
23     v = self._browser._browser_backend.chrome_branch_number
24     self.assertTrue(v > 0)
25
26   @benchmark.Enabled('has tabs')
27   def testNewCloseTab(self):
28     existing_tab = self._browser.tabs[0]
29     self.assertEquals(1, len(self._browser.tabs))
30     existing_tab_url = existing_tab.url
31
32     new_tab = self._browser.tabs.New()
33     self.assertEquals(2, len(self._browser.tabs))
34     self.assertEquals(existing_tab.url, existing_tab_url)
35     self.assertEquals(new_tab.url, 'about:blank')
36
37     new_tab.Close()
38     self.assertEquals(1, len(self._browser.tabs))
39     self.assertEquals(existing_tab.url, existing_tab_url)
40
41   def testMultipleTabCalls(self):
42     self._browser.tabs[0].Navigate(self.UrlOfUnittestFile('blank.html'))
43     self._browser.tabs[0].WaitForDocumentReadyStateToBeInteractiveOrBetter()
44
45   def testTabCallByReference(self):
46     tab = self._browser.tabs[0]
47     tab.Navigate(self.UrlOfUnittestFile('blank.html'))
48     self._browser.tabs[0].WaitForDocumentReadyStateToBeInteractiveOrBetter()
49
50   @benchmark.Enabled('has tabs')
51   @benchmark.Disabled('win')  # crbug.com/321527
52   def testCloseReferencedTab(self):
53     self._browser.tabs.New()
54     tab = self._browser.tabs[0]
55     tab.Navigate(self.UrlOfUnittestFile('blank.html'))
56     tab.Close()
57     self.assertEquals(1, len(self._browser.tabs))
58
59   @benchmark.Enabled('has tabs')
60   def testForegroundTab(self):
61     # Should be only one tab at this stage, so that must be the foreground tab
62     original_tab = self._browser.tabs[0]
63     self.assertEqual(self._browser.foreground_tab, original_tab)
64     new_tab = self._browser.tabs.New()
65     # New tab shouls be foreground tab
66     self.assertEqual(self._browser.foreground_tab, new_tab)
67     # Make sure that activating the background tab makes it the foreground tab
68     original_tab.Activate()
69     self.assertEqual(self._browser.foreground_tab, original_tab)
70     # Closing the current foreground tab should switch the foreground tab to the
71     # other tab
72     original_tab.Close()
73     self.assertEqual(self._browser.foreground_tab, new_tab)
74
75   def testGetSystemInfo(self):
76     if not self._browser.supports_system_info:
77       logging.warning(
78           'Browser does not support getting system info, skipping test.')
79       return
80
81     info = self._browser.GetSystemInfo()
82
83     self.assertTrue(isinstance(info, system_info.SystemInfo))
84     self.assertTrue(hasattr(info, 'model_name'))
85     self.assertTrue(hasattr(info, 'gpu'))
86     self.assertTrue(isinstance(info.gpu, gpu_info.GPUInfo))
87     self.assertTrue(hasattr(info.gpu, 'devices'))
88     self.assertTrue(len(info.gpu.devices) > 0)
89     for g in info.gpu.devices:
90       self.assertTrue(isinstance(g, gpu_device.GPUDevice))
91
92   def testGetSystemInfoNotCachedObject(self):
93     if not self._browser.supports_system_info:
94       logging.warning(
95           'Browser does not support getting system info, skipping test.')
96       return
97
98     info_a = self._browser.GetSystemInfo()
99     info_b = self._browser.GetSystemInfo()
100     self.assertFalse(info_a is info_b)
101
102   def testGetSystemTotalMemory(self):
103     self.assertTrue(self._browser.memory_stats['SystemTotalPhysicalMemory'] > 0)
104
105   def testIsTracingRunning(self):
106     if not self._browser.supports_tracing:
107       return
108     self.assertFalse(self._browser.is_tracing_running)
109     self._browser.StartTracing()
110     self.assertTrue(self._browser.is_tracing_running)
111     self._browser.StopTracing()
112     self.assertFalse(self._browser.is_tracing_running)
113
114
115 class CommandLineBrowserTest(browser_test_case.BrowserTestCase):
116   @classmethod
117   def CustomizeBrowserOptions(cls, options):
118     options.AppendExtraBrowserArgs('--user-agent=telemetry')
119
120   def testCommandLineOverriding(self):
121     # This test starts the browser with --user-agent=telemetry. This tests
122     # whether the user agent is then set.
123     t = self._browser.tabs[0]
124     t.Navigate(self.UrlOfUnittestFile('blank.html'))
125     t.WaitForDocumentReadyStateToBeInteractiveOrBetter()
126     self.assertEquals(t.EvaluateJavaScript('navigator.userAgent'),
127                       'telemetry')
128
129 class DirtyProfileBrowserTest(browser_test_case.BrowserTestCase):
130   @classmethod
131   def CustomizeBrowserOptions(cls, options):
132     options.profile_type = 'small_profile'
133
134   @benchmark.Disabled('chromeos')  # crbug.com/243912
135   def testDirtyProfileCreation(self):
136     self.assertEquals(1, len(self._browser.tabs))