Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: chrome/test/functional/process_count.py

Issue 7976016: New pyauto automation hook to get browser process information. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import os 6 import os
7 import pprint
7 8
8 import pyauto_functional 9 import pyauto_functional
9 import pyauto 10 import pyauto
10 11
11 12
12 class ProcessCountTest(pyauto.PyUITest): 13 class ProcessCountTest(pyauto.PyUITest):
13 """Tests to ensure the number of Chrome-related processes is as expected.""" 14 """Tests to ensure the number of Chrome-related processes is as expected."""
14 15
15 def _VerifyProcessCount(self, expected_count): 16 FRESH_PROFILE_PROC_COUNT = {
17 'win': 2, # Processes: browser, tab.
18 'mac': 2, # Processes: browser, tab.
19 'linux': 4, # Processes: browser, tab, sandbox helper, zygote.
20 'chromeos': 5, # Processes: browser, tab, sandbox helper, zygote, GPU.
21 }
22
23 CHROME_PROCESS_NAME = {
24 'win': 'chrome.exe',
25 'mac': 'Chromium',
26 'linux': 'chrome',
27 'chromeos': 'chrome',
28 }
29
30 def setUp(self):
31 self.proc_count_fresh_profile = 0
32 self.chrome_proc_name = ''
33 if self.IsChromeOS():
34 self.proc_count_fresh_profile = self.FRESH_PROFILE_PROC_COUNT['chromeos']
35 self.chrome_proc_name = self.CHROME_PROCESS_NAME['chromeos']
36 elif self.IsWin():
37 self.proc_count_fresh_profile = self.FRESH_PROFILE_PROC_COUNT['win']
38 self.chrome_proc_name = self.CHROME_PROCESS_NAME['win']
39 elif self.IsMac():
40 self.proc_count_fresh_profile = self.FRESH_PROFILE_PROC_COUNT['mac']
41 self.chrome_proc_name = self.CHROME_PROCESS_NAME['mac']
42 elif self.IsLinux():
43 self.proc_count_fresh_profile = self.FRESH_PROFILE_PROC_COUNT['linux']
44 self.chrome_proc_name = self.CHROME_PROCESS_NAME['linux']
45
46 self.pp = pprint.PrettyPrinter(indent=2)
Nirnimesh 2011/09/21 22:42:35 I think it would be nice to make the pretty printe
dennis_jeffrey 2011/09/22 18:25:35 Good idea. There are a lot of places throughout t
Nirnimesh 2011/09/22 19:35:26 Yes. In another CL yes
dennis_jeffrey 2011/09/22 19:54:02 Ok, I'll take care of it in another CL.
47 pyauto.PyUITest.setUp(self)
48
49 def _VerifyProcessCount(self, num_expected):
16 """Verifies the number of Chrome-related processes is as expected. 50 """Verifies the number of Chrome-related processes is as expected.
17 51
18 Args: 52 Args:
19 expected_count: An integer representing the expected number of Chrome- 53 num_expected: An integer representing the expected number of Chrome-
20 related processes that should currently exist. 54 related processes that should currently exist.
21 """ 55 """
22 # Compute the actual number of Chrome-related processes that exist. 56 proc_info = self.GetProcessInfo()
23 # Processes include: a single browser process; a single renderer process 57 browser_info = [x for x in proc_info['browsers']
24 # for each tab in each window; 0 or more child processes (associated with 58 if x['process_name'] == self.chrome_proc_name]
25 # plugins or other workers); and 0 or more extension processes. 59 assert len(browser_info) == 1
26 info = self.GetBrowserInfo() 60 num_actual = len(browser_info[0]['processes'])
27 actual_count = (
28 1 + # Browser process.
29 sum([len(tab_info['tabs']) for tab_info in info['windows']]) +
30 len(info['child_processes']) + len(info['extension_views']))
31 61
32 self.assertEqual(actual_count, expected_count, 62 self.assertEqual(num_actual, num_expected,
33 msg='Number of processes should be %d, but was %d.' % 63 msg='Number of processes should be %d, but was %d.\n'
34 (expected_count, actual_count)) 64 'Actual process info:\n%s' % (
65 num_expected, num_actual, self.pp.pformat(proc_info)))
35 66
36 def testProcessCountFreshProfile(self): 67 def testProcessCountFreshProfile(self):
37 """Verifies the process count in a fresh profile.""" 68 """Verifies the process count in a fresh profile."""
38 self._VerifyProcessCount(2) 69 self._VerifyProcessCount(self.proc_count_fresh_profile)
39 70
40 def testProcessCountAppendSingleTab(self): 71 def testProcessCountAppendSingleTab(self):
41 """Verifies the process count after appending a single tab.""" 72 """Verifies the process count after appending a single tab."""
42 self.AppendTab(pyauto.GURL('about:blank'), 0) 73 self.AppendTab(pyauto.GURL('about:blank'), 0)
43 self._VerifyProcessCount(3) 74 self._VerifyProcessCount(self.proc_count_fresh_profile + 1)
44 75
45 def testProcessCountNewWindow(self): 76 def testProcessCountNewWindow(self):
46 """Verifies the process count after opening a new window.""" 77 """Verifies the process count after opening a new window."""
47 self.OpenNewBrowserWindow(True) 78 self.OpenNewBrowserWindow(True)
48 self._VerifyProcessCount(3) 79 self._VerifyProcessCount(self.proc_count_fresh_profile + 1)
49 80
50 def testProcessCountFlashProcess(self): 81 def testProcessCountFlashProcess(self):
51 """Verifies the process count when the flash process is running.""" 82 """Verifies the process count when the flash process is running."""
52 flash_url = self.GetFileURLForDataPath('plugin', 'flash.swf') 83 flash_url = self.GetFileURLForDataPath('plugin', 'flash.swf')
53 self.NavigateToURL(flash_url) 84 self.NavigateToURL(flash_url)
54 self._VerifyProcessCount(3) 85 self._VerifyProcessCount(self.proc_count_fresh_profile + 1)
55 86
56 def testProcessCountExtensionProcess(self): 87 def testProcessCountExtensionProcess(self):
57 """Verifies the process count when an extension is installed.""" 88 """Verifies the process count when an extension is installed."""
58 crx_file_path = os.path.abspath( 89 crx_file_path = os.path.abspath(
59 os.path.join(self.DataDir(), 'extensions', 'page_action.crx')) 90 os.path.join(self.DataDir(), 'extensions', 'page_action.crx'))
60 self.assertTrue(self.InstallExtension(crx_file_path, False), 91 self.assertTrue(self.InstallExtension(crx_file_path, False),
61 msg='Extension install failed.') 92 msg='Extension install failed.')
62 self._VerifyProcessCount(3) 93 self._VerifyProcessCount(self.proc_count_fresh_profile + 1)
63 94
64 def testProcessCountCombination(self): 95 def testProcessCountCombination(self):
65 """Verifies process count with a combination of tabs/windows/extensions.""" 96 """Verifies process count with a combination of tabs/windows/extensions.
97
98 This test installs 1 extension, appends 2 tabs to the window, navigates 1
99 tab to a flash page, opens 1 new window, and appends 3 tabs to the new
100 window (8 new processes expected).
101 """
66 if self.IsMac(): 102 if self.IsMac():
67 # On Mac 10.5, flash files loaded too quickly after firing browser ends 103 # On Mac 10.5, flash files loaded too quickly after firing browser ends
68 # up getting downloaded, which seems to indicate that the plugin hasn't 104 # up getting downloaded, which seems to indicate that the plugin hasn't
69 # been registered yet. 105 # been registered yet.
70 # Hack to register Flash plugin on Mac 10.5. crbug.com/94123 106 # Hack to register Flash plugin on Mac 10.5. crbug.com/94123
71 self.GetPluginsInfo() 107 self.GetPluginsInfo()
72 crx_file_path = os.path.abspath( 108 crx_file_path = os.path.abspath(
73 os.path.join(self.DataDir(), 'extensions', 'page_action.crx')) 109 os.path.join(self.DataDir(), 'extensions', 'page_action.crx'))
74 self.assertTrue(self.InstallExtension(crx_file_path, False), 110 self.assertTrue(self.InstallExtension(crx_file_path, False),
75 msg='Extension install failed.') 111 msg='Extension install failed.')
76 112
77 for _ in xrange(2): 113 for _ in xrange(2):
78 self.AppendTab(pyauto.GURL('about:blank'), 0) 114 self.AppendTab(pyauto.GURL('about:blank'), 0)
79 115
80 flash_url = self.GetFileURLForDataPath('plugin', 'flash.swf') 116 flash_url = self.GetFileURLForDataPath('plugin', 'flash.swf')
81 self.NavigateToURL(flash_url) 117 self.NavigateToURL(flash_url)
82 118
83 self.OpenNewBrowserWindow(True) 119 self.OpenNewBrowserWindow(True)
84 120
85 for _ in xrange(3): 121 for _ in xrange(3):
86 self.AppendTab(pyauto.GURL('about:blank'), 1) 122 self.AppendTab(pyauto.GURL('about:blank'), 1)
87 123
88 self._VerifyProcessCount(10) 124 self._VerifyProcessCount(self.proc_count_fresh_profile + 8)
89 125
90 126
91 if __name__ == '__main__': 127 if __name__ == '__main__':
92 pyauto_functional.Main() 128 pyauto_functional.Main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698