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.
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
14 class BrowserTest(browser_test_case.BrowserTestCase):
15 def testBrowserCreation(self):
16 self.assertEquals(1, len(self._browser.tabs))
18 # Different browsers boot up to different things.
19 assert self._browser.tabs[0].url
21 def testVersionDetection(self):
22 # pylint: disable=W0212
23 v = self._browser._browser_backend.chrome_branch_number
24 self.assertTrue(v > 0)
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
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')
38 self.assertEquals(1, len(self._browser.tabs))
39 self.assertEquals(existing_tab.url, existing_tab_url)
41 def testMultipleTabCalls(self):
42 self._browser.tabs[0].Navigate(self.UrlOfUnittestFile('blank.html'))
43 self._browser.tabs[0].WaitForDocumentReadyStateToBeInteractiveOrBetter()
45 def testTabCallByReference(self):
46 tab = self._browser.tabs[0]
47 tab.Navigate(self.UrlOfUnittestFile('blank.html'))
48 self._browser.tabs[0].WaitForDocumentReadyStateToBeInteractiveOrBetter()
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'))
57 self.assertEquals(1, len(self._browser.tabs))
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
73 self.assertEqual(self._browser.foreground_tab, new_tab)
75 def testGetSystemInfo(self):
76 if not self._browser.supports_system_info:
78 'Browser does not support getting system info, skipping test.')
81 info = self._browser.GetSystemInfo()
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))
92 def testGetSystemInfoNotCachedObject(self):
93 if not self._browser.supports_system_info:
95 'Browser does not support getting system info, skipping test.')
98 info_a = self._browser.GetSystemInfo()
99 info_b = self._browser.GetSystemInfo()
100 self.assertFalse(info_a is info_b)
102 def testGetSystemTotalMemory(self):
103 self.assertTrue(self._browser.memory_stats['SystemTotalPhysicalMemory'] > 0)
105 def testIsTracingRunning(self):
106 if not self._browser.supports_tracing:
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)
115 class CommandLineBrowserTest(browser_test_case.BrowserTestCase):
117 def CustomizeBrowserOptions(cls, options):
118 options.AppendExtraBrowserArgs('--user-agent=telemetry')
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'),
129 class DirtyProfileBrowserTest(browser_test_case.BrowserTestCase):
131 def CustomizeBrowserOptions(cls, options):
132 options.profile_type = 'small_profile'
134 @benchmark.Disabled('chromeos') # crbug.com/243912
135 def testDirtyProfileCreation(self):
136 self.assertEquals(1, len(self._browser.tabs))