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

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: Addressed second round of review comments. 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
« no previous file with comments | « chrome/test/functional/PYAUTO_TESTS ('k') | chrome/test/pyautolib/pyauto.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 7
8 import pyauto_functional 8 import pyauto_functional
9 import pyauto 9 import pyauto
10 10
11 11
12 class ProcessCountTest(pyauto.PyUITest): 12 class ProcessCountTest(pyauto.PyUITest):
13 """Tests to ensure the number of Chrome-related processes is as expected.""" 13 """Tests to ensure the number of Chrome-related processes is as expected."""
14 14
15 def _VerifyProcessCount(self, expected_count): 15 FRESH_PROFILE_PROC_COUNT = {
16 'win': 2, # Processes: browser, tab.
17 'mac': 2, # Processes: browser, tab.
18 'linux': 4, # Processes: browser, tab, sandbox helper, zygote.
19 'chromeos': 5, # Processes: browser, tab, sandbox helper, zygote, GPU.
20 }
21
22 CHROME_PROCESS_NAME = {
23 'win': 'chrome.exe',
24 'mac': 'Chromium',
25 'linux': 'chrome',
26 'chromeos': 'chrome',
27 }
28
29 def setUp(self):
30 self.proc_count_fresh_profile = 0
31 self.chrome_proc_name = ''
32 if self.IsChromeOS():
33 self.proc_count_fresh_profile = self.FRESH_PROFILE_PROC_COUNT['chromeos']
34 self.chrome_proc_name = self.CHROME_PROCESS_NAME['chromeos']
35 elif self.IsWin():
36 self.proc_count_fresh_profile = self.FRESH_PROFILE_PROC_COUNT['win']
37 self.chrome_proc_name = self.CHROME_PROCESS_NAME['win']
38 elif self.IsMac():
39 self.proc_count_fresh_profile = self.FRESH_PROFILE_PROC_COUNT['mac']
40 self.chrome_proc_name = self.CHROME_PROCESS_NAME['mac']
41 elif self.IsLinux():
42 self.proc_count_fresh_profile = self.FRESH_PROFILE_PROC_COUNT['linux']
43 self.chrome_proc_name = self.CHROME_PROCESS_NAME['linux']
44
45 pyauto.PyUITest.setUp(self)
46
47 def _VerifyProcessCount(self, num_expected):
16 """Verifies the number of Chrome-related processes is as expected. 48 """Verifies the number of Chrome-related processes is as expected.
17 49
18 Args: 50 Args:
19 expected_count: An integer representing the expected number of Chrome- 51 num_expected: An integer representing the expected number of Chrome-
20 related processes that should currently exist. 52 related processes that should currently exist.
21 """ 53 """
22 # Compute the actual number of Chrome-related processes that exist. 54 proc_info = self.GetProcessInfo()
23 # Processes include: a single browser process; a single renderer process 55 browser_info = [x for x in proc_info['browsers']
24 # for each tab in each window; 0 or more child processes (associated with 56 if x['process_name'] == self.chrome_proc_name]
25 # plugins or other workers); and 0 or more extension processes. 57 assert len(browser_info) == 1
26 info = self.GetBrowserInfo() 58 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 59
32 self.assertEqual(actual_count, expected_count, 60 self.assertEqual(num_actual, num_expected,
33 msg='Number of processes should be %d, but was %d.' % 61 msg='Number of processes should be %d, but was %d.\n'
34 (expected_count, actual_count)) 62 'Actual process info:\n%s' % (
63 num_expected, num_actual, self.pformat(proc_info)))
35 64
36 def testProcessCountFreshProfile(self): 65 def testProcessCountFreshProfile(self):
37 """Verifies the process count in a fresh profile.""" 66 """Verifies the process count in a fresh profile."""
38 self._VerifyProcessCount(2) 67 self._VerifyProcessCount(self.proc_count_fresh_profile)
39 68
40 def testProcessCountAppendSingleTab(self): 69 def testProcessCountAppendSingleTab(self):
41 """Verifies the process count after appending a single tab.""" 70 """Verifies the process count after appending a single tab."""
42 self.AppendTab(pyauto.GURL('about:blank'), 0) 71 self.AppendTab(pyauto.GURL('about:blank'), 0)
43 self._VerifyProcessCount(3) 72 self._VerifyProcessCount(self.proc_count_fresh_profile + 1)
44 73
45 def testProcessCountNewWindow(self): 74 def testProcessCountNewWindow(self):
46 """Verifies the process count after opening a new window.""" 75 """Verifies the process count after opening a new window."""
47 self.OpenNewBrowserWindow(True) 76 self.OpenNewBrowserWindow(True)
48 self._VerifyProcessCount(3) 77 self._VerifyProcessCount(self.proc_count_fresh_profile + 1)
49 78
50 def testProcessCountFlashProcess(self): 79 def testProcessCountFlashProcess(self):
51 """Verifies the process count when the flash process is running.""" 80 """Verifies the process count when the flash process is running."""
52 flash_url = self.GetFileURLForDataPath('plugin', 'flash.swf') 81 flash_url = self.GetFileURLForDataPath('plugin', 'flash.swf')
53 self.NavigateToURL(flash_url) 82 self.NavigateToURL(flash_url)
54 self._VerifyProcessCount(3) 83 self._VerifyProcessCount(self.proc_count_fresh_profile + 1)
55 84
56 def testProcessCountExtensionProcess(self): 85 def testProcessCountExtensionProcess(self):
57 """Verifies the process count when an extension is installed.""" 86 """Verifies the process count when an extension is installed."""
58 crx_file_path = os.path.abspath( 87 crx_file_path = os.path.abspath(
59 os.path.join(self.DataDir(), 'extensions', 'page_action.crx')) 88 os.path.join(self.DataDir(), 'extensions', 'page_action.crx'))
60 self.assertTrue(self.InstallExtension(crx_file_path, False), 89 self.assertTrue(self.InstallExtension(crx_file_path, False),
61 msg='Extension install failed.') 90 msg='Extension install failed.')
62 self._VerifyProcessCount(3) 91 self._VerifyProcessCount(self.proc_count_fresh_profile + 1)
63 92
64 def testProcessCountCombination(self): 93 def testProcessCountCombination(self):
65 """Verifies process count with a combination of tabs/windows/extensions.""" 94 """Verifies process count with a combination of tabs/windows/extensions.
95
96 This test installs 1 extension, appends 2 tabs to the window, navigates 1
97 tab to a flash page, opens 1 new window, and appends 3 tabs to the new
98 window (8 new processes expected).
99 """
66 if self.IsMac(): 100 if self.IsMac():
67 # On Mac 10.5, flash files loaded too quickly after firing browser ends 101 # 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 102 # up getting downloaded, which seems to indicate that the plugin hasn't
69 # been registered yet. 103 # been registered yet.
70 # Hack to register Flash plugin on Mac 10.5. crbug.com/94123 104 # Hack to register Flash plugin on Mac 10.5. crbug.com/94123
71 self.GetPluginsInfo() 105 self.GetPluginsInfo()
72 crx_file_path = os.path.abspath( 106 crx_file_path = os.path.abspath(
73 os.path.join(self.DataDir(), 'extensions', 'page_action.crx')) 107 os.path.join(self.DataDir(), 'extensions', 'page_action.crx'))
74 self.assertTrue(self.InstallExtension(crx_file_path, False), 108 self.assertTrue(self.InstallExtension(crx_file_path, False),
75 msg='Extension install failed.') 109 msg='Extension install failed.')
76 110
77 for _ in xrange(2): 111 for _ in xrange(2):
78 self.AppendTab(pyauto.GURL('about:blank'), 0) 112 self.AppendTab(pyauto.GURL('about:blank'), 0)
79 113
80 flash_url = self.GetFileURLForDataPath('plugin', 'flash.swf') 114 flash_url = self.GetFileURLForDataPath('plugin', 'flash.swf')
81 self.NavigateToURL(flash_url) 115 self.NavigateToURL(flash_url)
82 116
83 self.OpenNewBrowserWindow(True) 117 self.OpenNewBrowserWindow(True)
84 118
85 for _ in xrange(3): 119 for _ in xrange(3):
86 self.AppendTab(pyauto.GURL('about:blank'), 1) 120 self.AppendTab(pyauto.GURL('about:blank'), 1)
87 121
88 self._VerifyProcessCount(10) 122 self._VerifyProcessCount(self.proc_count_fresh_profile + 8)
89 123
90 124
91 if __name__ == '__main__': 125 if __name__ == '__main__':
92 pyauto_functional.Main() 126 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « chrome/test/functional/PYAUTO_TESTS ('k') | chrome/test/pyautolib/pyauto.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698