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.core.platform import tracing_category_filter
12 from telemetry.core.platform import tracing_options
13 from telemetry.unittest import browser_test_case
16 class BrowserTest(browser_test_case.BrowserTestCase):
17 def testBrowserCreation(self):
18 self.assertEquals(1, len(self._browser.tabs))
20 # Different browsers boot up to different things.
21 assert self._browser.tabs[0].url
23 def testVersionDetection(self):
24 # pylint: disable=W0212
25 v = self._browser._browser_backend.chrome_branch_number
26 self.assertTrue(v > 0)
28 @benchmark.Enabled('has tabs')
29 def testNewCloseTab(self):
30 existing_tab = self._browser.tabs[0]
31 self.assertEquals(1, len(self._browser.tabs))
32 existing_tab_url = existing_tab.url
34 new_tab = self._browser.tabs.New()
35 self.assertEquals(2, len(self._browser.tabs))
36 self.assertEquals(existing_tab.url, existing_tab_url)
37 self.assertEquals(new_tab.url, 'about:blank')
40 self.assertEquals(1, len(self._browser.tabs))
41 self.assertEquals(existing_tab.url, existing_tab_url)
43 def testMultipleTabCalls(self):
44 self._browser.tabs[0].Navigate(self.UrlOfUnittestFile('blank.html'))
45 self._browser.tabs[0].WaitForDocumentReadyStateToBeInteractiveOrBetter()
47 def testTabCallByReference(self):
48 tab = self._browser.tabs[0]
49 tab.Navigate(self.UrlOfUnittestFile('blank.html'))
50 self._browser.tabs[0].WaitForDocumentReadyStateToBeInteractiveOrBetter()
52 @benchmark.Enabled('has tabs')
53 @benchmark.Disabled('win') # crbug.com/321527
54 def testCloseReferencedTab(self):
55 self._browser.tabs.New()
56 tab = self._browser.tabs[0]
57 tab.Navigate(self.UrlOfUnittestFile('blank.html'))
59 self.assertEquals(1, len(self._browser.tabs))
61 @benchmark.Enabled('has tabs')
62 def testForegroundTab(self):
63 # Should be only one tab at this stage, so that must be the foreground tab
64 original_tab = self._browser.tabs[0]
65 self.assertEqual(self._browser.foreground_tab, original_tab)
66 new_tab = self._browser.tabs.New()
67 # New tab shouls be foreground tab
68 self.assertEqual(self._browser.foreground_tab, new_tab)
69 # Make sure that activating the background tab makes it the foreground tab
70 original_tab.Activate()
71 self.assertEqual(self._browser.foreground_tab, original_tab)
72 # Closing the current foreground tab should switch the foreground tab to the
75 self.assertEqual(self._browser.foreground_tab, new_tab)
77 def testGetSystemInfo(self):
78 if not self._browser.supports_system_info:
80 'Browser does not support getting system info, skipping test.')
83 info = self._browser.GetSystemInfo()
85 self.assertTrue(isinstance(info, system_info.SystemInfo))
86 self.assertTrue(hasattr(info, 'model_name'))
87 self.assertTrue(hasattr(info, 'gpu'))
88 self.assertTrue(isinstance(info.gpu, gpu_info.GPUInfo))
89 self.assertTrue(hasattr(info.gpu, 'devices'))
90 self.assertTrue(len(info.gpu.devices) > 0)
91 for g in info.gpu.devices:
92 self.assertTrue(isinstance(g, gpu_device.GPUDevice))
94 def testGetSystemInfoNotCachedObject(self):
95 if not self._browser.supports_system_info:
97 'Browser does not support getting system info, skipping test.')
100 info_a = self._browser.GetSystemInfo()
101 info_b = self._browser.GetSystemInfo()
102 self.assertFalse(info_a is info_b)
104 def testGetSystemTotalMemory(self):
105 self.assertTrue(self._browser.memory_stats['SystemTotalPhysicalMemory'] > 0)
107 @benchmark.Disabled('chromeos') # crbug.com/412713.
108 def testIsTracingRunning(self):
109 tracing_controller = self._browser.platform.tracing_controller
110 if not tracing_controller.IsChromeTracingSupported(self._browser):
112 self.assertFalse(tracing_controller.is_tracing_running)
113 options = tracing_options.TracingOptions()
114 options.enable_chrome_trace = True
115 category_filter = tracing_category_filter.TracingCategoryFilter()
116 tracing_controller.Start(options, category_filter)
117 self.assertTrue(tracing_controller.is_tracing_running)
118 tracing_controller.Stop()
119 self.assertFalse(tracing_controller.is_tracing_running)
122 class CommandLineBrowserTest(browser_test_case.BrowserTestCase):
124 def CustomizeBrowserOptions(cls, options):
125 options.AppendExtraBrowserArgs('--user-agent=telemetry')
127 def testCommandLineOverriding(self):
128 # This test starts the browser with --user-agent=telemetry. This tests
129 # whether the user agent is then set.
130 t = self._browser.tabs[0]
131 t.Navigate(self.UrlOfUnittestFile('blank.html'))
132 t.WaitForDocumentReadyStateToBeInteractiveOrBetter()
133 self.assertEquals(t.EvaluateJavaScript('navigator.userAgent'),
136 class DirtyProfileBrowserTest(browser_test_case.BrowserTestCase):
138 def CustomizeBrowserOptions(cls, options):
139 options.profile_type = 'small_profile'
141 @benchmark.Disabled('chromeos') # crbug.com/243912
142 def testDirtyProfileCreation(self):
143 self.assertEquals(1, len(self._browser.tabs))