OLD | NEW |
---|---|
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 FRESH_PROFILE_PROC_COUNT = { | 15 FRESH_PROFILE_PROC_COUNT = { |
16 'win': 2, # Processes: browser, tab. | 16 'win': 2, # Processes: browser, tab. |
17 'mac': 2, # Processes: browser, tab. | 17 'mac': 2, # Processes: browser, tab. |
18 'linux': 4, # Processes: browser, tab, sandbox helper, zygote. | 18 'linux': 4, # Processes: browser, tab, sandbox helper, zygote. |
19 'chromeos': 5, # Processes: browser, tab, sandbox helper, zygote, GPU. | 19 'chromeos': 4, # Processes: browser, tab, sandbox helper, zygote. |
20 } | 20 } |
21 | 21 |
22 CHROME_PROCESS_NAME = { | 22 CHROME_PROCESS_NAME = { |
23 'win': 'chrome.exe', | 23 'win': 'chrome.exe', |
24 'mac': 'Chromium', | 24 'mac': 'Chromium', |
25 'linux': 'chrome', | 25 'linux': 'chrome', |
26 'chromeos': 'chrome', | 26 'chromeos': 'chrome', |
27 } | 27 } |
28 | 28 |
29 def Debug(self): | 29 def Debug(self): |
(...skipping 27 matching lines...) Expand all Loading... | |
57 """Verifies the number of Chrome-related processes is as expected. | 57 """Verifies the number of Chrome-related processes is as expected. |
58 | 58 |
59 Args: | 59 Args: |
60 num_expected: An integer representing the expected number of Chrome- | 60 num_expected: An integer representing the expected number of Chrome- |
61 related processes that should currently exist. | 61 related processes that should currently exist. |
62 """ | 62 """ |
63 proc_info = self.GetProcessInfo() | 63 proc_info = self.GetProcessInfo() |
64 browser_info = [x for x in proc_info['browsers'] | 64 browser_info = [x for x in proc_info['browsers'] |
65 if x['process_name'] == self.chrome_proc_name] | 65 if x['process_name'] == self.chrome_proc_name] |
66 assert len(browser_info) == 1 | 66 assert len(browser_info) == 1 |
67 num_actual = len(browser_info[0]['processes']) | 67 # Utility processes may show up any time. Ignore them. |
68 processes = [x for x in browser_info[0]['processes'] | |
69 if x['child_process_type'] != 'Utility'] | |
70 num_actual = len(processes) | |
68 | 71 |
69 self.assertEqual(num_actual, num_expected, | 72 self.assertEqual(num_actual, num_expected, |
70 msg='Number of processes should be %d, but was %d.\n' | 73 msg='Number of processes (ignoring Utility processes) ' |
74 'should be %d, but was %d.\n' | |
71 'Actual process info:\n%s' % ( | 75 'Actual process info:\n%s' % ( |
72 num_expected, num_actual, self.pformat(proc_info))) | 76 num_expected, num_actual, self.pformat(proc_info))) |
73 | 77 |
74 def testProcessCountFreshProfile(self): | 78 def testProcessCountFreshProfile(self): |
75 """Verifies the process count in a fresh profile.""" | 79 """Verifies the process count in a fresh profile.""" |
76 self._VerifyProcessCount(self.proc_count_fresh_profile) | 80 self._VerifyProcessCount(self.proc_count_fresh_profile) |
77 | 81 |
78 def testProcessCountAppendSingleTab(self): | 82 def testProcessCountAppendSingleTab(self): |
79 """Verifies the process count after appending a single tab.""" | 83 """Verifies the process count after appending a single tab.""" |
80 self.AppendTab(pyauto.GURL('about:blank'), 0) | 84 self.AppendTab(pyauto.GURL('about:blank'), 0) |
81 self._VerifyProcessCount(self.proc_count_fresh_profile + 1) | 85 self._VerifyProcessCount(self.proc_count_fresh_profile + 1) |
82 | 86 |
83 def testProcessCountNewWindow(self): | 87 def testProcessCountNewWindow(self): |
84 """Verifies the process count after opening a new window.""" | 88 """Verifies the process count after opening a new window.""" |
85 self.OpenNewBrowserWindow(True) | 89 self.OpenNewBrowserWindow(True) |
86 self._VerifyProcessCount(self.proc_count_fresh_profile + 1) | 90 self._VerifyProcessCount(self.proc_count_fresh_profile + 1) |
87 | 91 |
88 def testProcessCountFlashProcess(self): | 92 def testProcessCountFlashProcess(self): |
89 """Verifies the process count when the flash process is running.""" | 93 """Verifies the process count when the flash process is running.""" |
90 flash_url = self.GetFileURLForDataPath('plugin', 'flash.swf') | 94 flash_url = self.GetFileURLForDataPath('plugin', 'flash.swf') |
91 self.NavigateToURL(flash_url) | 95 self.NavigateToURL(flash_url) |
92 self._VerifyProcessCount(self.proc_count_fresh_profile + 1) | 96 if self.IsChromeOS(): |
97 # Flash triggers an extra GPU process on ChromeOS. | |
98 self._VerifyProcessCount(self.proc_count_fresh_profile + 2) | |
99 else: | |
100 self._VerifyProcessCount(self.proc_count_fresh_profile + 1) | |
93 | 101 |
94 def testProcessCountExtensionProcess(self): | 102 def testProcessCountExtensionProcess(self): |
95 """Verifies the process count when an extension is installed.""" | 103 """Verifies the process count when an extension is installed.""" |
96 crx_file_path = os.path.abspath( | 104 crx_file_path = os.path.abspath( |
97 os.path.join(self.DataDir(), 'extensions', 'page_action.crx')) | 105 os.path.join(self.DataDir(), 'extensions', 'page_action.crx')) |
98 self.assertTrue(self.InstallExtension(crx_file_path, False), | 106 self.assertTrue(self.InstallExtension(crx_file_path, False), |
99 msg='Extension install failed.') | 107 msg='Extension install failed.') |
100 self._VerifyProcessCount(self.proc_count_fresh_profile + 1) | 108 self._VerifyProcessCount(self.proc_count_fresh_profile + 1) |
101 | 109 |
102 def testProcessCountCombination(self): | 110 def testProcessCountCombination(self): |
(...skipping 18 matching lines...) Expand all Loading... | |
121 self.AppendTab(pyauto.GURL('about:blank'), 0) | 129 self.AppendTab(pyauto.GURL('about:blank'), 0) |
122 | 130 |
123 flash_url = self.GetFileURLForDataPath('plugin', 'flash.swf') | 131 flash_url = self.GetFileURLForDataPath('plugin', 'flash.swf') |
124 self.NavigateToURL(flash_url) | 132 self.NavigateToURL(flash_url) |
125 | 133 |
126 self.OpenNewBrowserWindow(True) | 134 self.OpenNewBrowserWindow(True) |
127 | 135 |
128 for _ in xrange(3): | 136 for _ in xrange(3): |
129 self.AppendTab(pyauto.GURL('about:blank'), 1) | 137 self.AppendTab(pyauto.GURL('about:blank'), 1) |
130 | 138 |
131 self._VerifyProcessCount(self.proc_count_fresh_profile + 8) | 139 if self.IsChromeOS(): |
140 # an extra gpu process | |
dennis_jeffrey
2011/11/23 00:56:11
nit: # Flash triggers an extra GPU process on Chro
| |
141 self._VerifyProcessCount(self.proc_count_fresh_profile + 9) | |
142 else: | |
143 self._VerifyProcessCount(self.proc_count_fresh_profile + 8) | |
132 | 144 |
133 | 145 |
134 if __name__ == '__main__': | 146 if __name__ == '__main__': |
135 pyauto_functional.Main() | 147 pyauto_functional.Main() |
OLD | NEW |