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

Side by Side Diff: functional/nacl_sdk.py

Issue 7541046: Adding pyauto tests for the NaCl SDK. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/test/
Patch Set: '' Created 9 years, 4 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 | « data/nacl_sdk/nacl_sdk_setting ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
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
4 # found in the LICENSE file.
5
6 import copy
7 import ctypes
8 from distutils import version
9 import fnmatch
10 import glob
11 import hashlib
12 import os
13 import platform
14 import random
15 import subprocess
16 import sys
17 import tarfile
18 import time
19 import urllib2
20
21 import pyauto_functional # Must be imported before pyauto.
22 import pyauto
23 import pyauto_utils
24
25 class NaClSDKTest(pyauto.PyUITest):
26 """Tests for the NaCl SDK."""
27 _EXTRACTED_NACL_SDK_DIR = 'extracted_nacl_sdk'
28
29 def testNaClSDK(self):
30 """Verify that NaCl SDK is working properly."""
31 if self._HasAllSystemRequirements() == False:
dennis_jeffrey 2011/08/08 18:00:53 if not self._HasAllSystemRequirements():
dennis_jeffrey 2011/08/08 18:00:53 This check is performed before all 3 of the tests
chrisphan 2011/08/08 23:14:39 As for Python 2.6, I don't see a way to skip a tes
chrisphan 2011/08/08 23:14:39 Done.
32 return
dennis_jeffrey 2011/08/08 18:00:53 Before returning, maybe we can log a message indic
chrisphan 2011/08/08 22:46:44 Done.
33
34 self._VerifyNaClPlugin()
35
36 self._VerifyDownloadLinks()
37
38 self._VerifyNaClSDKInstaller()
39
40 self._VerifyBuildStubProject()
41
42 self._LaunchServerAndVerifyExamples()
43
44 self._VerifyRebuildExamples()
45
46 self._VerifySelldrAndNcval()
47
48 self._RemoveDownloadedTestFile()
dennis_jeffrey 2011/08/08 18:00:53 I recommend removing the blank lines in-between ea
chrisphan 2011/08/08 22:46:44 Done.
49
50 def testVerifyNaClSDKChecksum(self):
51 """Verify NaCl SDK Checksum."""
52 if self._HasAllSystemRequirements() == False:
53 return
54
55 settings = self._GetTestSetting()
56
57 self._DownloadNaClSDK()
58
59 download_dir = os.path.join(self.DataDir(), 'downloads')
60
61 if pyauto.PyUITest.IsWin():
62 expected_shasum = settings['release_win_expected_shasum']
63 file_path = os.path.join(download_dir, 'naclsdk_win.exe')
64 elif pyauto.PyUITest.IsMac():
65 expected_shasum = settings['release_mac_expected_shasum']
66 file_path = os.path.join(download_dir, 'naclsdk_mac.tgz')
67 elif pyauto.PyUITest.IsLinux():
68 expected_shasum = settings['release_lin_expected_shasum']
69 file_path = os.path.join(download_dir, 'naclsdk_linux.tgz')
dennis_jeffrey 2011/08/08 18:00:53 maybe add an "else:" in which we fail (just to be
chrisphan 2011/08/08 22:46:44 Done.
70
71 sha = hashlib.sha1()
72 try:
73 f = open(file_path, 'rb')
74 sha.update(f.read())
75 shasum = sha.hexdigest()
76 self.assertEqual(expected_shasum, shasum,
77 msg='Unexpected checksum. Expected: %s, get: %s'
dennis_jeffrey 2011/08/08 18:00:53 nit: 'get' --> 'got'
chrisphan 2011/08/08 22:46:44 Done.
78 % (expected_shasum, shasum))
79 except IOError:
80 self.fail(msg='Cannot open %s.' % file_path)
81 finally:
82 f.close()
83
84 def testVerifyPrereleaseGallery(self):
85 """Verify Pre-release gallery examples."""
86 if self._HasAllSystemRequirements() == False:
87 return
88 settings = self._GetTestSetting()
89 examples = settings['prerelease_gallery']
90 self._OpenExamplesAndStartTest(examples)
dennis_jeffrey 2011/08/08 18:00:53 We could combine the above 3 lines: self._OpenExa
chrisphan 2011/08/08 22:46:44 Done.
91
92 def _VerifyNaClPlugin(self):
93 """Verify NaCl Plugin."""
94 settings = self._GetTestSetting()
95 examples = settings['gallery_examples']
96 self._OpenExamplesAndStartTest(examples)
dennis_jeffrey 2011/08/08 18:00:53 We could combine the above 3 lines like we did in
chrisphan 2011/08/08 22:46:44 Done.
97
98 def _VerifyDownloadLinks(self):
99 """Verify the download links."""
100 settings = self._GetTestSetting()
101 sdk_download_url = settings['post_sdk_download_url']
102 self.NavigateToURL(sdk_download_url)
dennis_jeffrey 2011/08/08 18:00:53 Combine the above 2 lines: self.NavigateToURL(set
chrisphan 2011/08/08 22:46:44 Done.
103 html = self.GetTabContents()
104
105 # Make sure the correct URL is under the correct label.
106 if pyauto.PyUITest.IsWin():
107 win_sdk_url = settings['post_win_sdk_url']
108 win_url_index = html.find(win_sdk_url)
109 self.assertTrue(win_url_index > -1,
110 msg='Missing SDK download URL: %s' % win_sdk_url)
111 win_keyword_index = html.rfind('Windows', 0, win_url_index)
112 self.assertTrue(win_keyword_index > -1,
113 msg='Misplace download link: %s' % win_sdk_url)
dennis_jeffrey 2011/08/08 18:00:53 nit: 'Misplace' --> 'Misplaced". Same at lines 12
chrisphan 2011/08/08 22:46:44 Done.
114 elif pyauto.PyUITest.IsMac():
115 mac_sdk_url = settings['post_mac_sdk_url']
116 mac_url_index = html.find(mac_sdk_url)
117 self.assertTrue(mac_url_index > -1,
118 msg='Missing SDK download URL: %s' % mac_sdk_url)
119 mac_keyword_index = html.rfind('Macintosh', 0, mac_url_index)
120 self.assertTrue(mac_keyword_index > -1,
121 msg='Misplace download link: %s' % mac_sdk_url)
122 elif pyauto.PyUITest.IsLinux():
123 lin_sdk_url = settings['post_lin_sdk_url']
124 lin_url_index = html.find(lin_sdk_url)
125 self.assertTrue(lin_url_index > -1,
126 msg='Missing SDK download URL: %s' % lin_sdk_url)
127 lin_keyword_index = html.rfind('Linux', 0, lin_url_index)
128 self.assertTrue(lin_keyword_index > -1,
129 msg='Misplace download link: %s' % lin_sdk_url)
dennis_jeffrey 2011/08/08 18:00:53 Maybe add an "else:" case in which we fail (just t
chrisphan 2011/08/08 22:46:44 Done.
130
131 def _VerifyNaClSDKInstaller(self):
132 """Verify NaCl SDK installer."""
133 search_list = [
134 'build.scons',
135 'favicon.ico',
136 'geturl/',
137 'hello_world/',
138 'hello_world_c/',
139 'httpd.py',
140 'index.html',
141 'nacl_sdk_scons/',
142 'pi_generator/',
143 'scons',
144 'sine_synth/'
145 ]
146
147 mac_lin_additional_search_items = [
148 'sel_ldr_x86_32',
149 'sel_ldr_x86_64',
150 'ncval_x86_32',
151 'ncval_x86_64'
152 ]
153
154 win_additional_search_items = [
155 'httpd.cmd',
156 'sel_ldr_x86_32.exe',
157 'sel_ldr_x86_64.exe',
158 'ncval_x86_32.exe',
159 'ncval_x86_64.exe'
160 ]
161
162 download_dir = os.path.join(self.DataDir(), 'downloads')
163
164 self._DownloadNaClSDK()
165
166 if pyauto.PyUITest.IsWin():
167 source_file = os.path.join(download_dir, 'naclsdk_win.exe')
168 self._SearchNaClSDKFileWindows(
169 search_list + win_additional_search_items, source_file)
170 elif pyauto.PyUITest.IsMac():
171 source_file = os.path.join(download_dir, 'naclsdk_mac.tgz')
172 self._SearchNaClSDKTarFile(search_list + mac_lin_additional_search_items,
173 source_file)
174 elif pyauto.PyUITest.IsLinux():
175 source_file = os.path.join(download_dir, 'naclsdk_linux.tgz')
176 self._SearchNaClSDKTarFile(search_list + mac_lin_additional_search_items,
177 source_file)
178 else:
179 self.fail(msg='NaCl SDK does not support this OS.')
180
181 self._ExtractNaClSDK()
182
183 def _VerifyBuildStubProject(self):
184 """Build stub project."""
185 stub_project_files = [
186 'build.scons',
187 'scons'
188 ]
189
190 download_dir = os.path.join(self.DataDir(), 'downloads')
191 sdk_path = os.path.join(download_dir, self._EXTRACTED_NACL_SDK_DIR)
192 project_template_path = self._GetDirectoryPath('project_templates',
193 sdk_path)
194 examples_path = self._GetDirectoryPath('examples', sdk_path)
195 init_project_path = os.path.join(project_template_path, 'init_project.py')
196
197 # Build a c project.
dennis_jeffrey 2011/08/08 18:00:53 nit: 'c' --> 'C'
chrisphan 2011/08/08 22:46:44 Done.
198 proc = subprocess.Popen(
199 ['python', init_project_path, '-n', 'hello_c', '-c', '-d',
200 examples_path], stdout=subprocess.PIPE)
201 proc.communicate()
202
203 hello_c_path = os.path.join(examples_path, 'hello_c')
204 for file in stub_project_files:
205 self.assertTrue(self._HasFile(file, hello_c_path),
206 msg='Cannot build hello_c stub project.')
207
208 # Build a cc project.
dennis_jeffrey 2011/08/08 18:00:53 nit: 'cc' --> 'C++'
chrisphan 2011/08/08 22:46:44 Done.
209 proc = subprocess.Popen(
210 ['python', init_project_path, '-n', 'hello_cc', '-c', '-d',
211 examples_path], stdout=subprocess.PIPE)
212 proc.communicate()
213
214 hello_cc_path = os.path.join(examples_path, 'hello_cc')
215 for file in stub_project_files:
216 self.assertTrue(self._HasFile(file, hello_cc_path),
217 msg='Cannot build hello_cc stub project.')
dennis_jeffrey 2011/08/08 18:00:53 Lines 197-206 and lines 208-217 are almost identic
chrisphan 2011/08/08 22:46:44 Done.
218
219 def _LaunchServerAndVerifyExamples(self):
220 """Start local HTTP server and verify examples."""
221 download_dir = os.path.join(self.DataDir(), 'downloads')
222 sdk_path = os.path.join(download_dir, self._EXTRACTED_NACL_SDK_DIR)
223 examples_path = self._GetDirectoryPath('examples', sdk_path)
224
225 # Make sure server is not open.
226 if not self._IsURLAlive('http://localhost:5103'):
dennis_jeffrey 2011/08/08 18:00:53 Shouldn't we remove the "not" here?
chrisphan 2011/08/08 22:46:44 Done.
227 self._CloseHTTPServer()
228
229 # Start HTTP server.
230 if pyauto.PyUITest.IsWin():
231 http_path = os.path.join(examples_path, 'httpd.cmd')
232 proc = subprocess.Popen([http_path], cwd=examples_path)
233 else:
234 http_path = os.path.join(examples_path, 'httpd.py')
235 proc = subprocess.Popen(['python', http_path], cwd=examples_path)
236
237 self.NavigateToURL('http://localhost:5103')
dennis_jeffrey 2011/08/08 18:00:53 Are we sure the server has started by the time we
dennis_jeffrey 2011/08/08 18:00:53 Also, should we gracefully handle the case when po
chrisphan 2011/08/08 22:46:44 Done.
chrisphan 2011/08/08 22:46:44 Done.
238 self.assertTrue(self._IsURLAlive('http://localhost:5103'),
239 msg='Cannot open HTTP server. %s' %
240 self.GetActiveTabTitle())
241
242 examples = {
243 'hello_world_c': 'http://localhost:5103/hello_world_c/'
244 'hello_world.html',
245 'hello_world': 'http://localhost:5103/hello_world/hello_world.html',
246 'geturl': 'http://localhost:5103/geturl/geturl.html',
247 'pi_generator': 'http://localhost:5103/pi_generator/pi_generator.html',
248 'sine_synth': 'http://localhost:5103/sine_synth/sine_synth.html',
249 }
250 try:
251 self._OpenExamplesAndStartTest(examples)
252 finally:
253 self._CloseHTTPServer(proc)
254
255 def _VerifyRebuildExamples(self):
256 """Re-build the examples."""
dennis_jeffrey 2011/08/08 18:00:53 'Re-build the examples and verify they are as expe
chrisphan 2011/08/08 22:46:44 Done.
257 download_dir = os.path.join(self.DataDir(), 'downloads')
258 sdk_path = os.path.join(download_dir, self._EXTRACTED_NACL_SDK_DIR)
259 examples_path = self._GetDirectoryPath('examples', sdk_path)
260 scons_path = os.path.join(examples_path, 'scons -c')
261
262 example_dirs = [
263 'geturl',
264 'hello_world',
265 'hello_world_c',
266 'pi_generator',
267 'sine_synth'
268 ]
269
270 proc = subprocess.Popen([scons_path], cwd=examples_path, shell=True)
271 proc.communicate()
272 for x in example_dirs:
273 ex_path = os.path.join(examples_path, x)
274 if self._HasFile('*.nmf', ex_path):
275 self.fail(msg='Failed running scons -c.')
276
277 scons_path = os.path.join(examples_path, 'scons')
278 proc = subprocess.Popen([scons_path], cwd=examples_path,
279 stdout=subprocess.PIPE, shell=True)
280 proc.communicate()
281
282 # Verify each example directory contains .nmf file.
283 for dir in example_dirs:
284 dir = os.path.join(examples_path, dir)
285 if not self._HasFile('*.nmf', dir):
286 self.fail(msg='Failed running scons.')
287
288 self._LaunchServerAndVerifyExamples()
289
290 def _VerifySelldrAndNcval(self):
291 """Verify sel_ldr and ncval."""
292 download_dir = os.path.join(self.DataDir(), 'downloads')
293 sdk_path = os.path.join(download_dir, self._EXTRACTED_NACL_SDK_DIR)
294 examples_path = self._GetDirectoryPath('examples', sdk_path)
dennis_jeffrey 2011/08/08 18:00:53 A lot of the helper functions in this file start w
chrisphan 2011/08/08 23:14:39 Done.
295
296 architecture = self._GetPlatformArchitecture()
297 scons_arg = None
298 if pyauto.PyUITest.IsWin():
299 if architecture == '64bit':
300 scons_arg = 'test64'
301 else:
302 scons_arg = 'test32'
303 elif pyauto.PyUITest.IsMac():
304 scons_arg = 'test64'
305 elif pyauto.PyUITest.IsLinux():
306 scons_arg = 'test64'
307 scons_path = os.path.join(examples_path, 'scons ' + scons_arg)
308
309 # Build and run the unit test.
310 proc = subprocess.Popen([scons_path], stdout=subprocess.PIPE,
311 shell=True, cwd=examples_path)
312 stdout = proc.communicate()[0]
313 lines = stdout.splitlines()
314 test_ran = False
315 for line in lines:
316 if 'Check:' in line:
317 self.assertTrue('passed' in line,
318 msg='Nacl-sel_ldr unit test failed.')
319 test_ran = True
320 self.assertTrue(test_ran,
321 msg='Failed to build and run nacl-sel_ldr unit test.')
322
323 if architecture == '64bit':
324 if not self._HasFileInTree('hello_world_x86_64.nexe', examples_path):
325 self.fail(msg='Missing file: hello_world_x86_64.nexe.')
326 else:
327 if not self._HasFileInTree('hello_world_x86_32.nexe', examples_path):
328 self.fail(msg='Missing file: hello_world_x86_32.nexe.')
329
330 # Verify that a mismatch of sel_ldr and .nexe produces an error.
331 toolchain_path = self._GetDirectoryPath('toolchain', sdk_path)
332 bin_path = self._GetDirectoryPath('bin', toolchain_path)
333 hello_world_path = self._GetDirectoryPath('hello_world', examples_path)
334 sel_32_path = os.path.join(bin_path, 'sel_ldr_x86_32')
335 sel_64_path = os.path.join(bin_path, 'sel_ldr_x86_64')
336 nexe_32_path = os.path.join(hello_world_path, 'hello_world_x86_32.nexe')
337 nexe_64_path = os.path.join(hello_world_path, 'hello_world_x86_64.nexe')
338
339 success = False
dennis_jeffrey 2011/08/08 18:00:53 We might be able to remove this line. I think the
chrisphan 2011/08/08 22:46:44 Done.
340 if architecture == '64bit':
341 success = self._RunProcessAndCheckOutput(
342 [sel_64_path, nexe_32_path], 'Error while loading')
343 else:
344 success = self._RunProcessAndCheckOutput(
345 [sel_32_path, nexe_64_path], 'Error while loading')
346 self.assertTrue(success,
347 msg='Failed to verify sel_ldr and .nexe mismatch.')
348
349 # Run the appropriate ncval for your platform on the matching .nexe.
dennis_jeffrey 2011/08/08 18:00:53 'your platform' --> 'the current platform'
chrisphan 2011/08/08 22:46:44 Done.
350 ncval_32_path = os.path.join(bin_path, 'ncval_x86_32')
351 ncval_64_path = os.path.join(bin_path, 'ncval_x86_64')
352 success = False
dennis_jeffrey 2011/08/08 18:00:53 Same comment as line 339 above.
chrisphan 2011/08/08 22:46:44 Done.
353 if architecture == '64bit':
354 success = self._RunProcessAndCheckOutput(
355 [ncval_64_path, nexe_64_path], 'is safe')
356 else:
357 success = self._RunProcessAndCheckOutput(
358 [ncval_32_path, nexe_32_path], 'is safe')
359 self.assertTrue(success, msg='Failed to verify ncval.')
360
361 # Verify that a mismatch of ncval and .nexe produces an error.
362 success = False
dennis_jeffrey 2011/08/08 18:00:53 Same comment as line 339 above.
chrisphan 2011/08/08 22:46:44 Done.
363 if architecture == '64bit':
364 success = self._RunProcessAndCheckOutput(
365 [ncval_64_path, nexe_32_path], 'is safe', is_in=False)
366 else:
367 success = self._RunProcessAndCheckOutput(
368 [ncval_32_path, nexe_64_path], 'is safe', is_in=False)
369 self.assertTrue(success, msg='Failed to verify ncval and .nexe mismatch.')
370
371 def _RemoveDownloadedTestFile(self):
372 """Delete downloaded files and dirs from downloads directory."""
373 download_dir = os.path.join(self.DataDir(), 'downloads')
374 extracted_sdk_path = os.path.join(download_dir, self._EXTRACTED_NACL_SDK_DIR )
dennis_jeffrey 2011/08/08 18:00:53 This line is just a little bit too long.
chrisphan 2011/08/08 22:46:44 Done.
375 pyauto_utils.RemovePath(extracted_sdk_path)
376
377 sdk_path = os.path.join(download_dir, 'naclsdk_win.exe')
378 pyauto_utils.RemovePath(sdk_path)
379 sdk_path = os.path.join(download_dir, 'naclsdk_mac.tgz')
380 pyauto_utils.RemovePath(sdk_path)
381 sdk_path = os.path.join(download_dir, 'naclsdk_linux.tgz')
382 pyauto_utils.RemovePath(sdk_path)
dennis_jeffrey 2011/08/08 18:00:53 We can shorten the above 6 lines: for sdk_path in
chrisphan 2011/08/08 22:46:44 Done.
383
384 def _RunProcessAndCheckOutput(self, args, look_for, is_in=True):
385 """Run process and look for string in output.
386
387 Args:
388 args: Argument strings to pass to subprocess.
389 look_for: The string to search in output.
390 is_in: True if checking if param look_for is in output.
391 False if checking if param look_out is not in output.
dennis_jeffrey 2011/08/08 18:00:53 'look_out' --> 'look_for'
chrisphan 2011/08/08 22:46:44 Done.
392
393 Returns:
394 True, if output contains parameter look_for, or
dennis_jeffrey 2011/08/08 18:00:53 'True, if output contains parameter look_for,' -->
chrisphan 2011/08/08 22:46:44 Done.
395 False otherwise.
396 """
397 proc = subprocess.Popen(args, stdout=subprocess.PIPE,
398 stderr=subprocess.PIPE)
399 (stdout, stderr) = proc.communicate()
400 lines = stdout.splitlines()
401 for line in lines:
402 if look_for in line:
403 if is_in:
404 return True
405 else:
406 return False
dennis_jeffrey 2011/08/08 18:00:53 Change the above 4 lines to this: return is_in
chrisphan 2011/08/08 22:46:44 Done.
407
408 lines = stderr.splitlines()
409 for line in lines:
410 if look_for in line:
411 if is_in:
412 return True
413 else:
414 return False
dennis_jeffrey 2011/08/08 18:00:53 Lines 400-406 and 408-414 are also very similar.
415 if is_in:
416 return False
417 else:
418 return True
dennis_jeffrey 2011/08/08 18:00:53 Change the above 4 lines to this: return not is_i
chrisphan 2011/08/08 22:46:44 Done.
419
420 def _OpenExamplesAndStartTest(self, examples):
421 """Open each example and verify that it's working.
422
423 Args:
424 examples: A dict of name to url of examples.
425 """
426 self._EnableNaClPlugin()
427
428 # Open all examples.
429 for name, url in examples.items():
430 self.AppendTab(pyauto.GURL(url))
431 self._CheckForCrashes()
432
433 # Verify all examples are working.
434 for name, url in examples.items():
435 self._VerifyAnExample(name, url)
436 self._CheckForCrashes()
437
438 # Reload all examples.
439 for _ in range(1):
dennis_jeffrey 2011/08/08 18:00:53 Doesn't this just execute once? Why is this loop
chrisphan 2011/08/08 22:46:44 Done.
440 for tab_index in range(self.GetTabCount()):
441 self.GetBrowserWindow(0).GetTab(tab_index).Reload()
442 self._CheckForCrashes()
443
444 # Verify all examples are working.
445 for name, url in examples.items():
446 self._VerifyAnExample(name, url)
447 self._CheckForCrashes()
448
449 # Randomly close a tab, check for crashes and verify all open
450 # examples operate correctly.
dennis_jeffrey 2011/08/08 18:00:53 Rather than randomly closing tabs, it might be bet
chrisphan 2011/08/08 22:46:44 Done.
451 tab_count = self.GetTabCount()
452 for index in xrange(tab_count - 1, 0, -1):
453 tab_index = None
454 if index > 1:
455 tab_index = random.randint(1, index)
456 else:
457 tab_index = 1
458
459 self.GetBrowserWindow(0).GetTab(tab_index).Close(True)
460 self._CheckForCrashes()
461
462 tabs = self.GetBrowserInfo()['windows'][0]['tabs']
463 for tab in tabs:
464 if tab['index'] > 0:
465 for name, url in examples.items():
466 if url == tab['url']:
467 self._VerifyAnExample(name, url)
468 break
469
470 def _VerifyAnExample(self, name, url):
471 """Verify NaCl Example is working.
dennis_jeffrey 2011/08/08 18:00:53 nit: 'Example' --> 'example'
chrisphan 2011/08/08 22:46:44 Done.
472
473 Args:
474 name: A string name of the example.
475 url: A string url of the example.
476 """
477 available_example_tests = {
478 'hello_world_c': self._VerifyHelloWorldExample,
479 'hello_world': self._VerifyHelloWorldExample,
480 'pi_generator': self._VerifyPiGeneratorExample,
481 'sine_synth': self._VerifySineSynthExample,
482 'geturl': self._VerifyGetURLExample,
483 'life': self._VerifyConwaysLifeExample
484 }
485
486 if not name in available_example_tests:
487 self.fail(msg='No test available for %s.' % name)
488
489 info = self.GetBrowserInfo()
490 tabs = info['windows'][0]['tabs']
491 tab_index = None
492 for tab in tabs:
493 if url == tab['url']:
494 self.ActivateTab(tab['index'])
495 tab_index = tab['index']
496 break
497
498 if tab_index != None:
dennis_jeffrey 2011/08/08 18:00:53 I think this should work too: if tab_index:
chrisphan 2011/08/08 23:14:39 Done.
499 available_example_tests[name](tab_index, name, url)
500
501 def _VerifyHelloWorldExample(self, tab_index, name, url):
502 """Verify Hello World Example.
503
504 Args:
505 tab_index: Tab index integer that the example is on.
506 name: A string name of the example.
507 url: A string url of the example.
508 """
509 wait_for = 60
dennis_jeffrey 2011/08/08 18:00:53 Maybe no need to define this as a separate variabl
chrisphan 2011/08/08 22:46:44 Done.
510 success = self.WaitUntil(
511 lambda: self.GetDOMValue(
512 'document.getElementById("statusField").innerHTML',
513 0, tab_index),
514 wait_for, expect_retval='SUCCESS')
dennis_jeffrey 2011/08/08 18:00:53 timeout=wait_for
chrisphan 2011/08/08 22:46:44 Done.
515 self.assertTrue(success, msg='Example %s failed. URL: %s' % (name, url))
516
517 js_code = """
518 window.alert = function(e) {
519 window.domAutomationController.send(String(e));
520 }
521 window.domAutomationController.send("done");
522 """
523 self.ExecuteJavascript(js_code, 0, tab_index)
524
525 result = self.ExecuteJavascript('document.helloForm.elements[1].click();',
526 0, tab_index)
527 self.assertEqual(result, '42',
528 msg='Example %s failed. URL: %s' % (name, url))
529
530 result = self.ExecuteJavascript('document.helloForm.elements[2].click();',
531 0, tab_index)
532 self.assertEqual(result, 'dlrow olleH',
533 msg='Example %s failed. URL: %s' % (name, url))
534
535 def _VerifyPiGeneratorExample(self, tab_index, name, url):
536 """Verify Pi Generator Example.
537
538 Args:
539 tab_index: Tab index integer that the example is on.
540 name: A string name of the example.
541 url: A string url of the example.
542 """
543 wait_for = 120
544 success = self.WaitUntil(
545 lambda: self.GetDOMValue('document.form.pi.value', 0, tab_index)[0:3],
546 wait_for, expect_retval='3.1')
547 self.assertTrue(success, msg='Example %s failed. URL: %s' % (name, url))
548
549 # Get top corner of pi image.
dennis_jeffrey 2011/08/08 18:00:53 nit: 'pi' --> 'Pi' to make it consistent with line
chrisphan 2011/08/08 22:46:44 Done.
550 js_code = """
551 var obj = document.getElementById('piGenerator');
552 var curleft = curtop = 0;
553 do {
554 curleft += obj.offsetLeft;
555 curtop += obj.offsetTop;
556 } while (obj = obj.offsetParent);
557 window.domAutomationController.send(curleft + "," + curtop);
558 """
559 result = self.ExecuteJavascript(js_code, 0, tab_index)
560 result_split = result.split(",")
561 x = int(result_split[0])
562 y = int(result_split[1])
563 window = self.GetBrowserInfo()['windows'][0]
564 window_to_content_x = 2
565 window_to_content_y = 80
566 pi_image_x = x + window['x'] + window_to_content_x
567 pi_image_y = y + window['y'] + window_to_content_y
568
569 if self._IsGetPixelSupported():
570 is_animating = self._IsColorChanging(pi_image_x, pi_image_y, 50, 50)
571 self.assertTrue(is_animating,
572 msg='Example %s failed. URL: %s' % (name, url))
573
574 def _VerifySineSynthExample(self, tab_index, name, url):
575 """Verify Sine Wave Synthesizer Example.
576
577 Args:
578 tab_index: Tab index integer that the example is on.
579 name: A string name of the example.
580 url: A string url of the example.
581 """
582 success = self.WaitUntil(
583 lambda: self.GetDOMValue(
584 'document.getElementById("frequency_field").value',
585 0, tab_index),
586 timeout=30, expect_retval='440')
587 self.assertTrue(success, msg='Example %s failed. URL: %s' % (name, url))
588
589 self.ExecuteJavascript(
590 'document.body.getElementsByTagName("button")[0].click();'
591 'window.domAutomationController.send("done")',
592 0, tab_index)
593
594 # TODO(chrisphan): Verify sound.
595
596 def _VerifyGetURLExample(self, tab_index, name, url):
597 """Verify GetURL Example.
598
599 Args:
600 tab_index: Tab index integer that the example is on.
601 name: A string name of the example.
602 url: A string url of the example.
603 """
604 success = self.WaitUntil(
605 lambda: self.GetDOMValue(
606 'document.getElementById("status_field").innerHTML',
607 0, tab_index),
608 timeout=60, expect_retval='SUCCESS')
609 self.assertTrue(success, msg='Example %s failed. URL: %s' % (name, url))
610
611 self.ExecuteJavascript(
612 'document.geturl_form.elements[0].click();'
613 'window.domAutomationController.send("done")',
614 0, tab_index)
615
616 js_code = """
617 var output = document.getElementById("general_output").innerHTML;
618 var result;
619 if (output.indexOf("test passed") != -1)
620 result = "pass";
621 else
622 result = "fail";
623 window.domAutomationController.send(result);
624 """
625 success = self.WaitUntil(
626 lambda: self.ExecuteJavascript(js_code, 0, tab_index),
627 timeout=30, expect_retval='pass')
628 self.assertTrue(success, msg='Example %s failed. URL: %s' % (name, url))
629
630 def _VerifyConwaysLifeExample(self, tab_index, name, url):
631 """Verify Conway's Life Example.
632
633 Args:
634 tab_index: Tab index integer that the example is on.
635 name: A string name of the example.
636 url: A string url of the example.
637 """
638 window = self.GetBrowserInfo()['windows'][0]
639 window_to_content_x = 2
640 window_to_content_y = 80
641 x = window['x'] + window_to_content_x
642 y = window['y'] + window_to_content_y
643 offset_pixel = 100
644 if self._IsGetPixelSupported():
645 wait_for = 30
dennis_jeffrey 2011/08/08 18:00:53 Similar comment as line 509 above.
chrisphan 2011/08/08 22:46:44 Done.
646 success = self.WaitUntil(
647 lambda: self._GetPixel(x + offset_pixel, y + offset_pixel),
648 wait_for, expect_retval=16777215)
dennis_jeffrey 2011/08/08 18:00:53 timeout=wait_for
chrisphan 2011/08/08 22:46:44 Done.
649 self.assertTrue(success, msg='Example %s failed. URL: %s' % (name, url))
650
651 def _IsColorChanging(self, x, y, width, height, tries=3, retry_sleep=2):
652 """Check screen for anything that is moving.
653
654 Args:
655 x: X coordinate on the screen.
656 y: Y coordinate on the screen.
657 width: Width of the area to look scan.
dennis_jeffrey 2011/08/08 18:00:53 Remove 'look'? If you do so, make the same change
chrisphan 2011/08/08 22:46:44 Done.
658 height: Height of the area to look scan.
659 tries: Number of tries.
660 retry_sleep: Sleep time in between each tries.
dennis_jeffrey 2011/08/08 18:00:53 nits: 'in between' --> 'in-between' 'tries' --> 't
chrisphan 2011/08/08 22:46:44 Done.
661
662 Returns:
663 True, if pixel color in area is changing, or
664 False otherwise.
665 """
666 color_a = self._GetAreaPixelColor(x, y, width, height)
667 for _ in xrange(tries):
668 time.sleep(retry_sleep)
669 color_b = self._GetAreaPixelColor(x, y, width, height)
670 if color_a != color_b:
671 return True
672 return False
673
674 def _IsGetPixelSupported(self):
675 """Check if get pixel is supported.
676
677 Returns:
678 True, if get pixel is supported, or
679 False otherwise.
680 """
681 if pyauto.PyUITest.IsWin():
682 return True
683 else:
684 return False
dennis_jeffrey 2011/08/08 18:00:53 Change the above 4 lines to this: return pyauto.P
chrisphan 2011/08/08 22:46:44 Done.
685
686 def _GetAreaPixelColor(self, x, y, width, height):
687 """Get an area of pixel color and return a list.
dennis_jeffrey 2011/08/08 18:00:53 'a list' --> 'a list of color code values'
chrisphan 2011/08/08 23:14:39 Done.
688
689 Args:
690 x: X coordinate on the screen.
691 y: Y coordinate on the screen.
692 width: Width of the area to look scan.
693 height: Height of the area to look scan.
694
695 Returns:
696 A list containing color codes.
697 """
698 if pyauto.PyUITest.IsMac():
699 pass # TODO(chrisphan): Do Mac.
700 elif pyauto.PyUITest.IsWin():
701 return self._GetAreaPixelColorWin(x, y, width, height)
dennis_jeffrey 2011/08/08 18:00:53 As you implement these helpers for the other platf
chrisphan 2011/08/08 22:46:44 Done.
702 elif pyauto.PyUITest.IsLinux():
703 pass # TODO(chrisphan): Do Linux.
704 return None
705
706 def _GetAreaPixelColorWin(self, x, y, width, height):
707 """Get an area of pixel color for Windows and return a list.
708
709 Args:
710 x: X coordinate on the screen.
711 y: Y coordinate on the screen.
712 width: Width of the area to look scan.
713 height: Height of the area to look scan.
714
715 Returns:
716 A list containing color codes.
717 """
718 colors = []
719 hdc = ctypes.windll.user32.GetDC(0)
720 for x_pos in xrange(x, x + width, 1):
721 for y_pos in xrange(y, y + height, 1):
722 color = ctypes.windll.gdi32.GetPixel(hdc, x_pos, y_pos)
723 colors.append(color)
724 return colors
725
726 def _GetPixel(self, x, y):
727 """Get pixel color at coordinate x and y.
728
729 Args:
730 x: X coordinate on the screen.
731 y: Y coordinate on the screen.
732
733 Returns:
734 An integer color code.
735 """
736 if pyauto.PyUITest.IsMac():
737 pass # TODO(chrisphan): Do Mac.
738 elif pyauto.PyUITest.IsWin():
739 return self._GetPixelWin(x, y)
dennis_jeffrey 2011/08/08 18:00:53 Similar comment as line 701 above.
chrisphan 2011/08/08 22:46:44 Done.
740 elif pyauto.PyUITest.IsLinux():
741 pass # TODO(chrisphan): Do Linux.
742 return None
743
744 def _GetPixelWin(self, x, y):
745 """Get pixel color at coordinate x and y for Windows
746
747 Args:
748 x: X coordinate on the screen.
749 y: Y coordinate on the screen.
750
751 Returns:
752 An integer color code.
753 """
754 hdc = ctypes.windll.user32.GetDC(0)
755 color = ctypes.windll.gdi32.GetPixel(hdc, x, y)
756 return color
757
758 def _CheckForCrashes(self, last_action=None, last_action_param=None):
759 """Check for any browser/tab crashes and hangs.
760
761 Args:
762 last_action: Specify action taken before checking for crashes.
763 last_action_param: Parameter for last action.
764 """
765 self.assertTrue(self.GetBrowserWindowCount(),
766 msg='Browser crashed, no window is open.')
767
768 info = self.GetBrowserInfo()
769 breakpad_folder = info['properties']['DIR_CRASH_DUMPS']
770 old_dmp_files = glob.glob(os.path.join(breakpad_folder, '*.dmp'))
771
772 # Verify there're no crash dump files
dennis_jeffrey 2011/08/08 18:00:53 nit: add period at end of sentence.
chrisphan 2011/08/08 22:46:44 Done.
773 for dmp_file in glob.glob(os.path.join(breakpad_folder, '*.dmp')):
774 self.assertTrue(dmp_file in old_dmp_files,
775 msg='Crash dump %s found' % dmp_file)
dennis_jeffrey 2011/08/08 18:00:53 indent this line so that the parameter lines up un
chrisphan 2011/08/08 22:46:44 Done.
776
777 # Check for any crashed tabs.
778 tabs = info['windows'][0]['tabs']
779 for tab in tabs:
780 if tab['url'] != 'about:blank':
781 if self.GetDOMValue('document.body.innerHTML', 0, tab['index']) == '':
dennis_jeffrey 2011/08/08 18:00:53 if not self.GetDOMValue('document.body.innerHTML',
chrisphan 2011/08/08 22:46:44 Done.
782 self.fail(msg='Tab crashed on %s' % tab['url'])
783
784 # TODO(chrisphan): check for tab hangs and browser hangs
785 # TODO(chrisphan): handle specific action: close browser, close tab
dennis_jeffrey 2011/08/08 18:00:53 nit: add periods at the end of the above 2 lines.
chrisphan 2011/08/08 22:46:44 Done.
786 if last_action == 'close tab':
787 pass
788 elif last_action == 'close browser':
789 pass
dennis_jeffrey 2011/08/08 18:00:53 Maybe add an "else" case that gracefully handles a
chrisphan 2011/08/08 22:46:44 Done.
790
791 def _GetPlatformArchitecture(self):
792 """Get platform architecture.
793
794 Args:
795 last_action: Specify action taken before checking for crashes.
dennis_jeffrey 2011/08/08 18:00:53 'Specify' --> 'Last'
chrisphan 2011/08/08 22:46:44 Done.
796 last_action_param: Parameter for last action.
797
798 Returns:
799 A string representing the platform architecture.
800 """
801 if pyauto.PyUITest.IsWin():
802 if os.environ['PROGRAMFILES'] == 'C:\\Program Files (x86)':
803 return '64bit'
804 else:
805 return '32bit'
806 elif pyauto.PyUITest.IsMac() or pyauto.PyUITest.IsLinux():
807 if platform.machine() == 'x86_64':
808 return '64bit'
809 else:
810 return '32bit'
811 return '32bit'
812
813 def _HasFile(self, pattern, root=os.curdir):
814 """Check if file exist in directory.
dennis_jeffrey 2011/08/08 18:00:53 'Check if a file matching the specified pattern ex
chrisphan 2011/08/08 22:46:44 Done.
815
816 Args:
817 pattern: Pattern of file name.
818 root: Directory to start looking.
819
820 Returns:
821 True, if root contains the file name pattern, or
822 False otherwise.
823 """
824 if len(glob.glob(os.path.join(root, pattern))) > 0:
825 return True
826 return False
dennis_jeffrey 2011/08/08 18:00:53 Change the above 3 lines to this: return len(glob
chrisphan 2011/08/08 22:46:44 Done.
827
828 def _HasFileInTree(self, pattern, root=os.curdir):
829 """Check if file exist in directory.
830
831 Args:
832 pattern: Pattern of file name.
833 root: Directory to start looking.
834
835 Returns:
836 True, if root contains the file name pattern, or
837 False otherwise.
838 """
dennis_jeffrey 2011/08/08 18:00:53 This docstring looks the same as for the function
chrisphan 2011/08/08 22:46:44 Done.
839 for path, dirs, files in os.walk(os.path.abspath(root)):
840 if len(fnmatch.filter(files, pattern)) > 0:
841 return True
842 return False
843
844 def _HasDir(self, pattern, root=os.curdir):
845 """Check if directory exist in another directory.
846
847 Args:
848 pattern: Pattern of directory name.
849 root: Directory to start looking.
850
851 Returns:
852 True, if root contains the directory name pattern, or
853 False otherwise.
854 """
855 for path, dirs, files in os.walk(os.path.abspath(root)):
856 if len(fnmatch.filter(dirs, pattern)) > 0:
857 return True
858 return False
dennis_jeffrey 2011/08/08 18:00:53 This function is almost exactly the same as for th
chrisphan 2011/08/08 22:46:44 Done.
859
860 def _GetDirectoryPath(self, pattern, root=os.curdir):
861 """Get the path of a directory in another directory.
862
863 Args:
864 pattern: Pattern of directory name.
865 root: Directory to start looking.
866
867 Returns:
868 A string of the path.
869 """
870 for path, dirs, files in os.walk(os.path.abspath(root)):
871 result = fnmatch.filter(dirs, pattern)
872 if len(result) > 0:
873 return os.path.join(path, result[0])
874 return None
875
876 def _HasAllSystemRequirements(self):
877 """Verify NaCl SDK Installation system requirements.
dennis_jeffrey 2011/08/08 18:00:53 nit: 'Installation' --> 'installation'
chrisphan 2011/08/08 22:46:44 Done.
878
879 Returns:
880 True, if system passed requirements, or
881 False otherwise.
882 """
883 # Check python version.
884 if sys.version_info[0:2] < (2, 5):
885 return False
886
887 # Check OS requirements.
888 if pyauto.PyUITest.IsMac():
889 mac_min_version = version.StrictVersion('10.6')
890 mac_version = version.StrictVersion(platform.mac_ver()[0])
891 if mac_version < mac_min_version:
892 return False
893 elif pyauto.PyUITest.IsWin():
894 if not (self.IsWin7() or self.IsWinVista() or self.IsWinXP()):
895 return False
896 elif pyauto.PyUITest.IsLinux():
897 pass # TODO(chrisphan): Check Lin requirements.
898 else:
899 return False
900
901 # Check for Chrome version compatibility.
902 # Nacl supports Chrome 10 and higher builds.
dennis_jeffrey 2011/08/08 18:00:53 nit: 'Nacl' --> 'NaCl'
chrisphan 2011/08/08 22:46:44 Done.
903 settings = self._GetTestSetting()
904 min_required_chrome_build = settings['min_required_chrome_build']
905 browser_info = self.GetBrowserInfo()
906 chrome_version = browser_info['properties']['ChromeVersion']
907 chrome_build = int(chrome_version.split('.')[0])
908 if chrome_build < min_required_chrome_build:
909 return False
910
911 return True
dennis_jeffrey 2011/08/08 18:00:53 Change lines 908-911 to this: return chrome_build
912
913 def _DownloadNaClSDK(self):
914 """Download NaCl SDK."""
915 settings = self._GetTestSetting()
916 win_sdk_url = settings['release_win_sdk_url']
917 mac_sdk_url = settings['release_mac_sdk_url']
918 lin_sdk_url = settings['release_lin_sdk_url']
dennis_jeffrey 2011/08/08 18:00:53 Remove the above 3 lines, and just inline the valu
chrisphan 2011/08/08 22:46:44 Done.
919
920 download_dir = os.path.join(self.DataDir(), 'downloads')
921
922 if pyauto.PyUITest.IsWin():
923 dl_file = urllib2.urlopen(win_sdk_url)
924 file_path = os.path.join(download_dir, 'naclsdk_win.exe')
925 elif pyauto.PyUITest.IsMac():
926 dl_file = urllib2.urlopen(mac_sdk_url)
927 file_path = os.path.join(download_dir, 'naclsdk_mac.tgz')
928 elif pyauto.PyUITest.IsLinux():
929 dl_file = urllib2.urlopen(lin_sdk_url)
930 file_path = os.path.join(download_dir, 'naclsdk_linux.tgz')
931 else:
932 self.fail(msg='NaCl SDK does not support this OS.')
933
934 try:
935 f = open(file_path, 'wb')
936 f.write(dl_file.read())
937 except IOError:
938 self.fail(msg='Cannot open %s.' % file_path)
939 finally:
940 f.close()
941
942
dennis_jeffrey 2011/08/08 18:00:53 Remove 1 of these blank lines.
chrisphan 2011/08/08 22:46:44 Done.
943 def _ExtractNaClSDK(self):
944 """Extract NaCl SDK."""
945 download_dir = os.path.join(self.DataDir(), 'downloads')
946 destination = os.path.join(download_dir, self._EXTRACTED_NACL_SDK_DIR)
947
948 pyauto_utils.RemovePath(destination)
949 if not os.path.exists(destination):
dennis_jeffrey 2011/08/08 18:00:53 If we remove the directory in line 948 above, why
chrisphan 2011/08/08 22:46:44 Done.
950 os.makedirs(destination)
951
952 if pyauto.PyUITest.IsWin():
953 # Requires 7-Zip to extract self-install archive.
954 seven_z_file_path = self._Get7ZipPath()
955 self.assertNotEqual(seven_z_file_path, None,
956 msg='7-Zip is required but could not be found.')
dennis_jeffrey 2011/08/08 18:00:53 indent this line by 4 more spaces
chrisphan 2011/08/08 22:46:44 Done.
957
958 source_file = os.path.join(download_dir, 'naclsdk_win.exe')
959 proc = subprocess.Popen(
960 [seven_z_file_path, 'x', source_file, '-o' + destination],
961 stdout=subprocess.PIPE)
dennis_jeffrey 2011/08/08 18:00:53 Indent these 2 lines by only 4 spaces as compared
962 proc.communicate()
963 elif pyauto.PyUITest.IsMac():
964 source_file = os.path.join(download_dir, 'naclsdk_mac.tgz')
965 tar = tarfile.open(source_file, 'r')
966 tar.extractall(destination)
967 elif pyauto.PyUITest.IsLinux():
968 source_file = os.path.join(download_dir, 'naclsdk_linux.tgz')
969 tar = tarfile.open(source_file, 'r')
970 tar.extractall(destination)
971 else:
972 self.fail(msg='NaCl SDK does not support this OS.')
973
974 def _Get7ZipPath(self):
dennis_jeffrey 2011/08/08 18:00:53 If this function only applies to Windows, maybe we
chrisphan 2011/08/08 22:46:44 Done.
975 """Check if 7-Zip is installed on Windows.
976
977 Returns:
978 String path of 7-Zip.
979 None if not exist.
dennis_jeffrey 2011/08/08 18:00:53 'String path to the 7-Zip executable, or None if i
chrisphan 2011/08/08 22:46:44 Done.
980 """
981 current_dir = os.path.dirname(__file__)
982 seven_zip_path = os.path.join(
983 current_dir, os.pardir, os.pardir,
984 os.pardir, 'third_party', '7-Zip', '7z.exe')
985
986 if os.path.isfile(seven_zip_path):
987 return seven_zip_path
988
989 # Attempt to find 7-Zip in Program Files.
990 program_files_path = os.getenv('ProgramFiles')
991 if program_files_path != None:
992 seven_zip_path = os.path.join(program_files_path, '7-Zip', '7z.exe')
993 if os.path.isfile(seven_zip_path):
994 return seven_zip_path
995 program_files_path = os.getenv('ProgramW6432')
996 if program_files_path != None:
997 seven_zip_path = os.path.join(program_files_path, '7-Zip', '7z.exe')
998 if os.path.isfile(seven_zip_path):
999 return seven_zip_path
1000
1001 return None
1002
1003 def _IsURLAlive(self, url):
1004 """Test if URL is alive."""
1005 try:
1006 urllib2.urlopen(url)
1007 except:
1008 return False
1009 return True
1010
1011 def _CloseHTTPServer(self, proc=None):
1012 """Close HTTP server.
1013
1014 Args:
1015 proc: Process that opened the HTTP server.
1016 """
1017 if not self._IsURLAlive('http://localhost:5103'):
1018 return
1019 urllib2.urlopen('http://localhost:5103?quit=1')
1020 wait_for = 30
1021 success = self.WaitUntil(
1022 lambda: self._IsURLAlive('http://localhost:5103'),
1023 timeout=wait_for, expect_retval=False)
1024 if not success:
1025 if proc == None:
1026 self.fail(msg='Fail to close HTTP server')
1027 else:
1028 if proc.poll() == None:
1029 try:
1030 proc.kill()
1031 except:
1032 pass
dennis_jeffrey 2011/08/08 18:00:53 If we get to this 'except' clause, does that mean
chrisphan 2011/08/08 22:46:44 Done.
1033
1034 def _SearchNaClSDKTarFile(self, search_list, source_file):
1035 """Search NaCl SDK tar file for example files and directories.
1036
1037 Args:
1038 search_list: A list of strings, representing file and
1039 directory names for which to search.
1040 source_file: The string name of an NaCl SDK tar file.
1041 """
1042 tar = tarfile.open(source_file, 'r')
1043
1044 # Look for files and directories in examples.
1045 files = copy.deepcopy(search_list)
1046 for tar_info in tar:
1047 file_name = tar_info.name
1048 if tar_info.isdir() and not file_name.endswith('/'):
1049 file_name = file_name + '/'
1050
1051 for name in files:
1052 if file_name.find('examples/' + name):
1053 files.remove(name)
1054 if len(files) == 0:
1055 break
1056
1057 tar.close()
1058
1059 self.assertEqual(len(files), 0,
1060 msg='Missing files or directories: %s' %
1061 ', '.join(map(str, files)))
1062
1063 def _SearchNaClSDKFileWindows(self, search_list, source_file):
1064 """Search NaCl SDK file for example files and directories.
dennis_jeffrey 2011/08/08 18:00:53 add to this docstring: 'in Windows'
chrisphan 2011/08/08 22:46:44 Done.
1065
1066 Args:
1067 search_list: A list of strings, representing file and
1068 directory names for which to search.
1069 source_file: The string name of an NaCl SDK Windows
1070 self-install archive file.
1071 """
1072 files = []
1073 for i in xrange(len(search_list)):
1074 files.append(search_list[i].replace(r'/', '\\'))
1075
1076 # Requires 7-Zip to look at self-install archive.
1077 seven_z_file_path = self._Get7ZipPath()
1078 self.assertNotEqual(seven_z_file_path, None,
1079 msg='7-Zip is required but could not be found.')
dennis_jeffrey 2011/08/08 18:00:53 indent this line more so that it lines up undernea
chrisphan 2011/08/08 23:14:39 Done.
1080
1081 proc = subprocess.Popen([seven_z_file_path, 'l', source_file],
1082 stdout=subprocess.PIPE)
1083 stdout = proc.communicate()[0]
1084 lines = stdout.splitlines()
1085 for x in lines:
1086 item_name = x.split(' ')[-1]
1087 for name in files:
1088 if item_name.find(name) > 0:
1089 files.remove(name)
1090 if len(files) == 0:
1091 break
1092
1093 self.assertEqual(len(files), 0,
1094 msg='Missing files or directories: %s' %
1095 ', '.join(map(str, files)))
1096
1097 def _EnableNaClPlugin(self):
1098 """"Enable NaCl Plugin."""
dennis_jeffrey 2011/08/08 18:00:53 nit: 'Plugin' --> 'plugin'
chrisphan 2011/08/08 22:46:44 Done.
1099 nacl_plugin = self.GetPluginsInfo().PluginForName('Chrome NaCl')
1100 if len(nacl_plugin) == 0:
dennis_jeffrey 2011/08/08 18:00:53 if not nacl_plugin:
1101 nacl_plugin = self.GetPluginsInfo().PluginForName('Native Client')
1102 if len(nacl_plugin) == 0:
dennis_jeffrey 2011/08/08 18:00:53 if not nacl_plugin:
1103 self.fail(msg='No NaCl Plugin found.')
dennis_jeffrey 2011/08/08 18:00:53 nit: 'Plugin' --> 'plugin'
chrisphan 2011/08/08 22:46:44 Done.
1104 self.EnablePlugin(nacl_plugin[0]['path'])
1105
1106 self.NavigateToURL('about:flags')
1107
1108 js_code = """
1109 chrome.send('enableFlagsExperiment', ['enable-nacl', 'true']);
1110 requestFlagsExperimentsData();
1111 window.domAutomationController.send('done');
1112 """
1113 self.ExecuteJavascript(js_code)
1114 self.RestartBrowser(False)
1115
1116 def _GetTestSetting(self):
1117 """Read the given data file and return a dictionary of items.
1118
1119 Returns:
1120 A dict mapping of keys/values in the NaCl SDK setting file.
1121 """
1122 data_file = os.path.join(self.DataDir(), 'nacl_sdk', 'nacl_sdk_setting')
1123
1124 try:
1125 f = open(data_file, 'r')
1126 except IOError:
1127 self.fail(msg='Cannot open %s.' % data_file)
1128
1129 try:
1130 dictionary = eval(f.read(), {'__builtins__': None}, None)
1131 except SyntaxError:
1132 self.fail(msg='%s is an invalid setting file.' % data_file)
1133 finally:
1134 f.close()
1135
1136 return dictionary
1137
1138
1139 if __name__ == '__main__':
1140 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « data/nacl_sdk/nacl_sdk_setting ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698