Index: functional/nacl_sdk.py |
=================================================================== |
--- functional/nacl_sdk.py (revision 137770) |
+++ functional/nacl_sdk.py (working copy) |
@@ -12,13 +12,14 @@ |
import logging |
import os |
import platform |
+import re |
import shutil |
import subprocess |
import sys |
-import tarfile |
import tempfile |
import urllib2 |
import xml.dom.minidom |
+import zipfile |
import pyauto_functional # Must be imported before pyauto. |
import pyauto |
@@ -29,49 +30,15 @@ |
"""Tests for the NaCl SDK.""" |
_extracted_sdk_path = None |
_temp_dir = None |
+ _pepper_versions = [] |
+ _updated_pepper_versions = [] |
+ _latest_updated_pepper_versions = [] |
_settings = { |
- 'release_win_sdk_url': 'http://commondatastorage.googleapis.com/' |
- 'nativeclient-mirror/nacl/nacl_sdk/staging/naclsdk_win.exe', |
- 'release_mac_sdk_url': 'http://commondatastorage.googleapis.com/' |
- 'nativeclient-mirror/nacl/nacl_sdk/staging/naclsdk_mac.tgz', |
- 'release_lin_sdk_url': 'http://commondatastorage.googleapis.com/' |
- 'nativeclient-mirror/nacl/nacl_sdk/staging/naclsdk_linux.tgz', |
- 'expected_md5_url': 'http://commondatastorage.googleapis.com/' |
- 'nativeclient-mirror', |
- 'release_win_expected_md5_key': 'nacl/nacl_sdk/staging/naclsdk_win.exe', |
- 'release_mac_expected_md5_key': 'nacl/nacl_sdk/staging/naclsdk_mac.tgz', |
- 'release_lin_expected_md5_key': 'nacl/nacl_sdk/staging/' |
- 'naclsdk_linux.tgz', |
'post_sdk_download_url': 'http://code.google.com/chrome/nativeclient/' |
- 'docs/download.html', |
- 'post_win_sdk_url': 'http://commondatastorage.googleapis.com/' |
- 'nativeclient-mirror/nacl/nacl_sdk/naclsdk_win.exe', |
- 'post_mac_sdk_url': 'http://commondatastorage.googleapis.com/' |
- 'nativeclient-mirror/nacl/nacl_sdk/naclsdk_mac.tgz', |
- 'post_lin_sdk_url': 'http://commondatastorage.googleapis.com/' |
- 'nativeclient-mirror/nacl/nacl_sdk/naclsdk_linux.tgz', |
+ 'docs/download.html', |
+ 'post_sdk_zip': 'http://commondatastorage.googleapis.com/' |
+ 'nativeclient-mirror/nacl/nacl_sdk/nacl_sdk.zip', |
'min_required_chrome_build': 14, |
- 'gallery_examples': { |
- 'life': 'http://nacl-gallery.appspot.com/life/life.html', |
- 'hello_world': 'http://nacl-gallery.appspot.com/hello_world/' |
- 'hello_world.html', |
- 'pi_generator': 'http://nacl-gallery.appspot.com/pi_generator/' |
- 'pi_generator.html', |
- 'sine_synth': 'http://nacl-gallery.appspot.com/sine_synth/' |
- 'sine_synth.html' |
- }, |
- 'prerelease_gallery': { |
- 'hello_world': 'http://4.nacl-gallery.appspot.com/hello_world/' |
- 'hello_world.html', |
- 'hello_world_c': 'http://4.nacl-gallery.appspot.com/hello_world_c/' |
- 'hello_world.html', |
- 'life': 'http://4.nacl-gallery.appspot.com/life/life.html', |
- 'pi_generator': 'http://4.nacl-gallery.appspot.com/pi_generator/' |
- 'pi_generator.html', |
- 'sine_synth': 'http://4.nacl-gallery.appspot.com/sine_synth/' |
- 'sine_synth.html', |
- 'geturl': 'http://4.nacl-gallery.appspot.com/geturl/geturl.html' |
- } |
} |
def tearDown(self): |
@@ -84,73 +51,17 @@ |
logging.info('System does not meet the requirements.') |
return |
self._extracted_sdk_path = tempfile.mkdtemp() |
- |
self._VerifyDownloadLinks() |
self._VerifyNaClSDKInstaller() |
- self._VerifyBuildStubProject() |
+ self._VerifyInstall() |
+ self._VerifyUpdate() |
self._LaunchServerAndVerifyExamples() |
- self._VerifyRebuildExamples() |
- self._VerifySelldrAndNcval() |
- def testVerifyNaClSDKChecksum(self): |
- """Verify NaCl SDK Checksum.""" |
- if not self._HasAllSystemRequirements(): |
- logging.info('System does not meet the requirements.') |
- return |
- |
- self._DownloadNaClSDK() |
- |
- if pyauto.PyUITest.IsWin(): |
- expected_md5_key = self._settings['release_win_expected_md5_key'] |
- file_path = os.path.join(self._temp_dir, 'naclsdk_win.exe') |
- elif pyauto.PyUITest.IsMac(): |
- expected_md5_key = self._settings['release_mac_expected_md5_key'] |
- file_path = os.path.join(self._temp_dir, 'naclsdk_mac.tgz') |
- elif pyauto.PyUITest.IsLinux(): |
- expected_md5_key = self._settings['release_lin_expected_md5_key'] |
- file_path = os.path.join(self._temp_dir, 'naclsdk_linux.tgz') |
- else: |
- self.fail(msg='NaCl SDK does not support this OS.') |
- |
- # Get expected MD5. |
- expected_md5_url = self._settings['expected_md5_url'] |
- response = urllib2.urlopen(expected_md5_url) |
- dom = xml.dom.minidom.parseString(response.read()) |
- dom_content = dom.getElementsByTagName('Contents') |
- expected_md5 = None |
- for con in dom_content: |
- if (self._GetXMLNodeData(con.getElementsByTagName('Key')[0].childNodes) |
- == expected_md5_key): |
- node = con.getElementsByTagName('ETag')[0].childNodes |
- expected_md5 = self._GetXMLNodeData(node).strip('"') |
- self.assertTrue(expected_md5, |
- msg='Cannot get expected MD5 from %s.' % expected_md5_url) |
- |
- md5 = hashlib.md5() |
- md5.update(open(file_path).read()) |
- md5_sum = md5.hexdigest() |
- self.assertEqual(expected_md5, md5_sum, |
- msg='Unexpected checksum. Expected: %s, got: %s' |
- % (expected_md5, md5_sum)) |
- |
- def testVerifyNaClPlugin(self): |
- """Verify NaCl plugin.""" |
- if not self._HasAllSystemRequirements(): |
- logging.info('System does not meet the requirements.') |
- return |
- self._OpenExamplesAndStartTest( |
- self._settings['gallery_examples']) |
- |
- def testVerifyPrereleaseGallery(self): |
- """Verify Pre-release gallery examples.""" |
- if not self._HasAllSystemRequirements(): |
- logging.info('System does not meet the requirements.') |
- return |
- self._OpenExamplesAndStartTest( |
- self._settings['prerelease_gallery']) |
- |
def _VerifyDownloadLinks(self): |
- """Verify the download links.""" |
+ """Verify the download links. |
+ |
+ Simply verify that NaCl download links exist in html page. |
+ """ |
html = None |
for i in xrange(3): |
try: |
@@ -161,268 +72,120 @@ |
self.assertTrue(html, |
msg='Cannot open URL: %s' % |
self._settings['post_sdk_download_url']) |
+ sdk_url = self._settings['post_sdk_zip'] |
+ self.assertTrue(sdk_url in html, |
+ msg='Missing SDK download URL: %s' % sdk_url) |
- # Make sure the correct URL is under the correct label. |
- if pyauto.PyUITest.IsWin(): |
- win_sdk_url = self._settings['post_win_sdk_url'] |
- win_url_index = html.find(win_sdk_url) |
- self.assertTrue(win_url_index > -1, |
- msg='Missing SDK download URL: %s' % win_sdk_url) |
- win_keyword_index = html.rfind('Windows', 0, win_url_index) |
- self.assertTrue(win_keyword_index > -1, |
- msg='Misplaced download link: %s' % win_sdk_url) |
- elif pyauto.PyUITest.IsMac(): |
- mac_sdk_url = self._settings['post_mac_sdk_url'] |
- mac_url_index = html.find(mac_sdk_url) |
- self.assertTrue(mac_url_index > -1, |
- msg='Missing SDK download URL: %s' % mac_sdk_url) |
- mac_keyword_index = html.rfind('Macintosh', 0, mac_url_index) |
- self.assertTrue(mac_keyword_index > -1, |
- msg='Misplaced download link: %s' % mac_sdk_url) |
- elif pyauto.PyUITest.IsLinux(): |
- lin_sdk_url = self._settings['post_lin_sdk_url'] |
- lin_url_index = html.find(lin_sdk_url) |
- self.assertTrue(lin_url_index > -1, |
- msg='Missing SDK download URL: %s' % lin_sdk_url) |
- lin_keyword_index = html.rfind('Linux', 0, lin_url_index) |
- self.assertTrue(lin_keyword_index > -1, |
- msg='Misplaced download link: %s' % lin_sdk_url) |
- else: |
- self.fail(msg='NaCl SDK does not support this OS.') |
- |
def _VerifyNaClSDKInstaller(self): |
"""Verify NaCl SDK installer.""" |
search_list = [ |
- 'build.scons', |
- 'favicon.ico', |
- 'geturl/', |
- 'hello_world/', |
- 'hello_world_c/', |
- 'httpd.py', |
- 'index.html', |
- 'nacl_sdk_scons/', |
- 'pi_generator/', |
- 'scons', |
- 'sine_synth/' |
+ 'sdk_cache/', |
+ 'sdk_tools/', |
] |
- |
mac_lin_additional_search_items = [ |
- 'sel_ldr_x86_32', |
- 'sel_ldr_x86_64', |
- 'ncval_x86_32', |
- 'ncval_x86_64' |
+ 'naclsdk', |
] |
- |
win_additional_search_items = [ |
- 'httpd.cmd', |
- 'sel_ldr_x86_32.exe', |
- 'sel_ldr_x86_64.exe', |
- 'ncval_x86_32.exe', |
- 'ncval_x86_64.exe' |
+ 'naclsdk.bat' |
] |
- |
self._DownloadNaClSDK() |
- |
+ self._ExtractNaClSDK() |
if pyauto.PyUITest.IsWin(): |
- self._ExtractNaClSDK() |
- self._SearchNaClSDKFileWindows( |
+ self._SearchNaClSDKFile( |
search_list + win_additional_search_items) |
- elif pyauto.PyUITest.IsMac(): |
- source_file = os.path.join(self._temp_dir, 'naclsdk_mac.tgz') |
- self._SearchNaClSDKTarFile(search_list + mac_lin_additional_search_items, |
- source_file) |
- self._ExtractNaClSDK() |
- elif pyauto.PyUITest.IsLinux(): |
- source_file = os.path.join(self._temp_dir, 'naclsdk_linux.tgz') |
- self._SearchNaClSDKTarFile(search_list + mac_lin_additional_search_items, |
- source_file) |
- self._ExtractNaClSDK() |
+ elif pyauto.PyUITest.IsMac() or pyauto.PyUITest.IsLinux(): |
+ self._SearchNaClSDKFile( |
+ search_list + mac_lin_additional_search_items) |
else: |
self.fail(msg='NaCl SDK does not support this OS.') |
- def _VerifyBuildStubProject(self): |
- """Build stub project.""" |
- stub_project_files = [ |
- 'build.scons', |
- 'scons' |
- ] |
- project_template_path = self._GetDirectoryPath('project_templates', |
- self._extracted_sdk_path) |
- examples_path = self._GetDirectoryPath('examples', |
- self._extracted_sdk_path) |
- init_project_path = os.path.join(project_template_path, 'init_project.py') |
- |
- # Build a C project. |
- subprocess.call( |
- ['python', init_project_path, '-n', 'hello_c', '-c', '-d', |
- examples_path], stdout=subprocess.PIPE) |
- |
- hello_c_path = os.path.join(examples_path, 'hello_c') |
- for file in stub_project_files: |
- self.assertTrue(self._HasFile(file, hello_c_path), |
- msg='Cannot build C stub project.') |
- |
- # Build a C++ project. |
- subprocess.call( |
- ['python', init_project_path, '-n', 'hello_cc', '-d', |
- examples_path], stdout=subprocess.PIPE) |
- |
- hello_cc_path = os.path.join(examples_path, 'hello_cc') |
- for file in stub_project_files: |
- self.assertTrue(self._HasFile(file, hello_cc_path), |
- msg='Cannot build C++ stub project.') |
- |
- def _LaunchServerAndVerifyExamples(self): |
- """Start local HTTP server and verify examples.""" |
- # Make sure server is not open. |
- if self._IsURLAlive('http://localhost:5103'): |
- self._CloseHTTPServer() |
- |
- # Start HTTP server. |
- examples_path = self._GetDirectoryPath('examples', |
- self._extracted_sdk_path) |
+ def _VerifyInstall(self): |
+ """Install NACL sdk.""" |
+ # Executing naclsdk(.bat) list |
if pyauto.PyUITest.IsWin(): |
- http_path = os.path.join(examples_path, 'httpd.cmd') |
- proc = subprocess.Popen([http_path], cwd=examples_path) |
+ source_file = os.path.join( |
+ self._extracted_sdk_path, 'nacl_sdk', 'naclsdk.bat') |
+ elif pyauto.PyUITest.IsMac() or pyauto.PyUITest.IsLinux(): |
+ source_file = os.path.join( |
+ self._extracted_sdk_path, 'nacl_sdk', 'naclsdk') |
+ subprocess.call(['chmod', '-R', '755', self._extracted_sdk_path]) |
else: |
- http_path = os.path.join(examples_path, 'httpd.py') |
- proc = subprocess.Popen(['python', http_path], cwd=examples_path) |
+ self.fail(msg='NaCl SDK does not support this OS.') |
+ subprocess.Popen([source_file, 'list'], |
+ stdout=subprocess.PIPE, |
+ stderr=subprocess.PIPE).communicate() |
- success = self.WaitUntil( |
- lambda: self._IsURLAlive('http://localhost:5103'), |
- timeout=30, retry_sleep=1, expect_retval=True) |
- self.assertTrue(success, |
- msg='Cannot open HTTP server. %s' % |
- self.GetActiveTabTitle()) |
- |
- examples = { |
- 'hello_world_c': 'http://localhost:5103/hello_world_c/' |
- 'hello_world.html', |
- 'hello_world': 'http://localhost:5103/hello_world/hello_world.html', |
- 'geturl': 'http://localhost:5103/geturl/geturl.html', |
- 'pi_generator': 'http://localhost:5103/pi_generator/pi_generator.html', |
- 'sine_synth': 'http://localhost:5103/sine_synth/sine_synth.html', |
- } |
- try: |
- self._OpenExamplesAndStartTest(examples) |
- finally: |
- self._CloseHTTPServer(proc) |
- |
- def _VerifyRebuildExamples(self): |
- """Re-build the examples and verify they are as expected.""" |
- example_dirs = [ |
- 'geturl', |
- 'hello_world', |
- 'hello_world_c', |
- 'pi_generator', |
- 'sine_synth' |
- ] |
- examples_path = self._GetDirectoryPath('examples', |
- self._extracted_sdk_path) |
- |
- scons_path = os.path.join(examples_path, 'scons -c') |
- subprocess.call([scons_path], cwd=examples_path, shell=True) |
- for x in example_dirs: |
- ex_path = os.path.join(examples_path, x) |
- self.assertFalse(self._HasFile('*.nmf', ex_path), |
- msg='Failed running scons -c.') |
- |
- scons_path = os.path.join(examples_path, 'scons') |
- proc = subprocess.Popen([scons_path], cwd=examples_path, |
- stdout=subprocess.PIPE, shell=True) |
- proc.communicate() |
- |
- # Verify each example directory contains .nmf file. |
- for dir in example_dirs: |
- dir = os.path.join(examples_path, dir) |
- if not self._HasFile('*.nmf', dir): |
- self.fail(msg='Failed running scons.') |
- |
- self._LaunchServerAndVerifyExamples() |
- |
- def _VerifySelldrAndNcval(self): |
- """Verify sel_ldr and ncval.""" |
- architecture = self._GetPlatformArchitecture() |
- scons_arg = None |
+ def _VerifyUpdate(self): |
+ """Update NACL sdk""" |
+ # Executing naclsdk(.bat) update |
if pyauto.PyUITest.IsWin(): |
- if architecture == '64bit': |
- scons_arg = 'test64' |
- else: |
- scons_arg = 'test32' |
- elif pyauto.PyUITest.IsMac(): |
- scons_arg = 'test64' |
- elif pyauto.PyUITest.IsLinux(): |
- scons_arg = 'test64' |
- |
- examples_path = self._GetDirectoryPath('examples', |
- self._extracted_sdk_path) |
- scons_path = os.path.join(examples_path, 'scons ' + scons_arg) |
- |
- # Build and run the unit test. |
- proc = subprocess.Popen([scons_path], stdout=subprocess.PIPE, |
- shell=True, cwd=examples_path) |
- lines = proc.communicate()[0].splitlines() |
- test_ran = False |
- |
- for line in lines: |
- if 'Check:' in line: |
- self.assertTrue('passed' in line, |
- msg='Nacl-sel_ldr unit test failed.') |
- test_ran = True |
- self.assertTrue(test_ran, |
- msg='Failed to build and run nacl-sel_ldr unit test.') |
- |
- if architecture == '64bit': |
- self.assertTrue( |
- self._HasPathInTree('hello_world_x86_64.nexe', |
- True, root=examples_path), |
- msg='Missing file: hello_world_x86_64.nexe.') |
+ source_file = os.path.join(self._extracted_sdk_path, 'nacl_sdk', |
+ 'naclsdk.bat') |
+ elif pyauto.PyUITest.IsMac() or pyauto.PyUITest.IsLinux(): |
+ source_file = os.path.join(self._extracted_sdk_path, 'nacl_sdk', |
+ 'naclsdk') |
else: |
- self.assertTrue( |
- self._HasPathInTree('hello_world_x86_32.nexe', |
- True, root=examples_path), |
- msg='Missing file: hello_world_x86_32.nexe.') |
+ self.fail(msg='NaCl SDK does not support this OS.') |
+ # Executing nacl_sdk(.bat) update to get the latest version. |
+ updated_output = subprocess.Popen([source_file, 'update'], |
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] |
+ self._updated_pepper_versions.extend( |
+ re.findall('Updating bundle (pepper_[0-9]{2})', updated_output)) |
+ self._updated_pepper_versions = list(set(self._updated_pepper_versions)) |
+ self._updated_pepper_versions.sort(key=str.lower) |
+ updated_pepper_versions_len = len(self._updated_pepper_versions) |
+ self._latest_updated_pepper_versions = filter( |
+ lambda x: x >= 'pepper_18', self._updated_pepper_versions) |
- # Verify that a mismatch of sel_ldr and .nexe produces an error. |
- toolchain_path = self._GetDirectoryPath('toolchain', |
- self._extracted_sdk_path) |
- bin_path = self._GetDirectoryPath('bin', toolchain_path) |
- hello_world_path = self._GetDirectoryPath('hello_world', examples_path) |
- sel_32_path = os.path.join(bin_path, 'sel_ldr_x86_32') |
- sel_64_path = os.path.join(bin_path, 'sel_ldr_x86_64') |
- nexe_32_path = os.path.join(hello_world_path, 'hello_world_x86_32.nexe') |
- nexe_64_path = os.path.join(hello_world_path, 'hello_world_x86_64.nexe') |
+ def _LaunchServerAndVerifyExamples(self): |
+ """Start local HTTP server and verify examples.""" |
+ for pepper_version in self._latest_updated_pepper_versions: |
+ if self._ChromeAndPepperVersion(pepper_version): |
+ examples_path = os.path.join(self._extracted_sdk_path, 'nacl_sdk', |
+ pepper_version, 'examples') |
+ # Close server if it's already open. |
+ if self._IsURLAlive('http://localhost:5103'): |
+ self._CloseHTTPServer() |
+ # Launch local http server. |
+ proc = subprocess.Popen(['make RUN'], shell=True, cwd=examples_path) |
+ self.WaitUntil( |
+ lambda: self._IsURLAlive('http://localhost:5103'), |
+ timeout=150, retry_sleep=1) |
- if architecture == '64bit': |
- success = self._RunProcessAndCheckOutput( |
- [sel_64_path, nexe_32_path], 'Error while loading') |
- else: |
- success = self._RunProcessAndCheckOutput( |
- [sel_32_path, nexe_64_path], 'Error while loading') |
- self.assertTrue(success, |
- msg='Failed to verify sel_ldr and .nexe mismatch.') |
+ examples = { |
+ 'dynamic_library_open': 'http://localhost:5103/dlopen/dlopen.html', |
+ 'geturl': 'http://localhost:5103/geturl/geturl.html', |
+ 'input_events': 'http://localhost:5103/input_events' |
+ '/input_events.html', |
+ 'load_progress': |
+ 'http://localhost:5103/load_progress/load_progress.html', |
+ 'multithreaded_input_events': |
+ 'http://localhost:5103/multithreaded_input_events' |
+ '/mt_input_events.html', |
+ 'pi_generator': |
+ 'http://localhost:5103/pi_generator/pi_generator.html', |
+ 'sine_synth': 'http://localhost:5103/sine_synth/sine_synth.html', |
+ 'web_socket': |
+ 'http://localhost:5103/websocket/websocket.html', |
+ } |
+ try: |
+ self._OpenExamplesAndStartTest(examples) |
+ finally: |
+ self._CloseHTTPServer(proc) |
- # Run the appropriate ncval for the platform on the matching .nexe. |
- ncval_32_path = os.path.join(bin_path, 'ncval_x86_32') |
- ncval_64_path = os.path.join(bin_path, 'ncval_x86_64') |
+ else: |
+ self.pprint('Pepper Version %s does not match the Chrome version %s.' |
+ % (pepper_version, |
+ self.GetBrowserInfo()['properties']['ChromeVersion'])) |
- if architecture == '64bit': |
- success = self._RunProcessAndCheckOutput( |
- [ncval_64_path, nexe_64_path], 'is safe') |
- else: |
- success = self._RunProcessAndCheckOutput( |
- [ncval_32_path, nexe_32_path], 'is safe') |
- self.assertTrue(success, msg='Failed to verify ncval.') |
+ def _ChromeAndPepperVersion(self, pepper_version='pepper_18'): |
+ """Determine if chrome and pepper version matach""" |
+ version_number = re.findall('pepper_([0-9]{2})', pepper_version) |
+ browser_info = self.GetBrowserInfo() |
+ chrome_version = browser_info['properties']['ChromeVersion'] |
+ chrome_build = int(chrome_version.split('.')[0]) |
+ return int(chrome_build) == int(version_number[0]) |
- # Verify that a mismatch of ncval and .nexe produces an error. |
- if architecture == '64bit': |
- success = self._RunProcessAndCheckOutput( |
- [ncval_64_path, nexe_32_path], 'is safe', is_in=False) |
- else: |
- success = self._RunProcessAndCheckOutput( |
- [ncval_32_path, nexe_64_path], 'is safe', is_in=False) |
- self.assertTrue(success, msg='Failed to verify ncval and .nexe mismatch.') |
- |
def _RemoveDownloadedTestFile(self): |
"""Delete downloaded files and dirs from downloads directory.""" |
if self._extracted_sdk_path and os.path.exists(self._extracted_sdk_path): |
@@ -432,43 +195,20 @@ |
shutil.rmtree(self._extracted_sdk_path, ignore_errors=True) |
return os.path.exists(self._extracted_sdk_path) |
- success = self.WaitUntil(_RemoveFile, retry_sleep=2, expect_retval=False) |
+ success = self.WaitUntil(_RemoveFile, retry_sleep=2, |
+ expect_retval=False) |
self.assertTrue(success, |
msg='Cannot remove %s' % self._extracted_sdk_path) |
if self._temp_dir: |
pyauto_utils.RemovePath(self._temp_dir) |
- def _RunProcessAndCheckOutput(self, args, look_for, is_in=True): |
- """Run process and look for string in output. |
- |
- Args: |
- args: Argument strings to pass to subprocess. |
- look_for: The string to search in output. |
- is_in: True if checking if param look_for is in output. |
- False if checking if param look_for is not in output. |
- |
- Returns: |
- True, if output contains parameter |look_for| and |is_in| is True, or |
- False otherwise. |
- """ |
- proc = subprocess.Popen(args, stdout=subprocess.PIPE, |
- stderr=subprocess.PIPE) |
- (stdout, stderr) = proc.communicate() |
- lines = (stdout + stderr).splitlines() |
- for line in lines: |
- if look_for in line: |
- return is_in |
- return not is_in |
- |
def _OpenExamplesAndStartTest(self, examples): |
"""Open each example and verify that it's working. |
Args: |
examples: A dict of name to url of examples. |
""" |
- self._EnableNaClPlugin() |
- |
# Open all examples. |
for name, url in examples.items(): |
self.AppendTab(pyauto.GURL(url)) |
@@ -479,17 +219,6 @@ |
self._VerifyAnExample(name, url) |
self._CheckForCrashes() |
- # Reload all examples. |
- for _ in range(2): |
- for tab_index in range(self.GetTabCount()): |
- self.GetBrowserWindow(0).GetTab(tab_index).Reload() |
- self._CheckForCrashes() |
- |
- # Verify all examples are working. |
- for name, url in examples.items(): |
- self._VerifyAnExample(name, url) |
- self._CheckForCrashes() |
- |
# Close each tab, check for crashes and verify all open |
# examples operate correctly. |
tab_count = self.GetTabCount() |
@@ -513,12 +242,15 @@ |
url: A string url of the example. |
""" |
available_example_tests = { |
- 'hello_world_c': self._VerifyHelloWorldExample, |
- 'hello_world': self._VerifyHelloWorldExample, |
- 'pi_generator': self._VerifyPiGeneratorExample, |
- 'sine_synth': self._VerifySineSynthExample, |
- 'geturl': self._VerifyGetURLExample, |
- 'life': self._VerifyConwaysLifeExample |
+ 'dynamic_library_open': self._VerifyDynamicLibraryOpen, |
+ 'geturl': self._VerifyGetURLExample, |
+ 'input_events': self._VerifyInputEventsExample, |
+ 'load_progress': self._VerifyLoadProgressExample, |
+ 'multithreaded_input_events': |
+ self._VerifyMultithreadedInputEventsExample, |
+ 'pi_generator': self._VerifyPiGeneratorExample, |
+ 'sine_synth': self._VerifySineSynthExample, |
+ 'web_socket': self._VerifyWebSocketExample, |
} |
if not name in available_example_tests: |
@@ -536,269 +268,258 @@ |
if tab_index: |
available_example_tests[name](tab_index, name, url) |
- def _VerifyHelloWorldExample(self, tab_index, name, url): |
- """Verify Hello World Example. |
+ def _VerifyElementPresent(self, element_id, expected_value, tab_index, msg, |
+ attribute='innerHTML', timeout=150): |
+ """Determine if dom element has the expected value. |
Args: |
- tab_index: Tab index integer that the example is on. |
- name: A string name of the example. |
- url: A string url of the example. |
+ element_id: Dom element's id. |
+ expected_value: String to be matched against the Dom element. |
+ tab_index: Tab index to work on. |
+ attribute: Attribute to match |expected_value| against, if |
+ given. Defaults to 'innerHTML'. |
+ timeout: The max timeout (in secs) for which to wait. |
""" |
+ js_code = """ |
+ var output = document.getElementById('%s').%s; |
+ var result; |
+ if (output.indexOf('%s') != -1) |
+ result = 'pass'; |
+ else |
+ result = 'fail'; |
+ window.domAutomationController.send(result); |
+ """ % (element_id, attribute, expected_value) |
success = self.WaitUntil( |
- lambda: self.GetDOMValue( |
- 'document.getElementById("statusField").innerHTML', |
- tab_index), |
- timeout=60, expect_retval='SUCCESS') |
- self.assertTrue(success, msg='Example %s failed. URL: %s' % (name, url)) |
+ lambda: self.ExecuteJavascript(js_code, tab_index), |
+ timeout=timeout, expect_retval='pass') |
+ self.assertTrue(success, msg=msg) |
+ def _CreateJSToSimulateMouseclick(self): |
+ """Create javascript to simulate mouse click event.""" |
js_code = """ |
- window.alert = function(e) { |
- window.domAutomationController.send(String(e)); |
- } |
- window.domAutomationController.send("done"); |
+ var rightClick = document.createEvent('MouseEvents'); |
+ rightClick.initMouseEvent( |
+ 'mousedown', true, true, document, |
+ 1, 32, 121, 10, 100, |
+ false, false, false, false, |
+ 2, document.getElementById('event_module') |
+ ); |
+ document.getElementById('event_module').dispatchEvent(rightClick); |
+ window.domAutomationController.send('done'); |
""" |
- self.ExecuteJavascript(js_code, tab_index) |
+ return js_code |
- result = self.ExecuteJavascript('document.helloForm.elements[1].click();', |
- tab_index) |
- self.assertEqual(result, '42', |
- msg='Example %s failed. URL: %s' % (name, url)) |
+ def _VerifyInputEventsExample(self, tab_index, name, url): |
+ """Verify Input Events Example. |
- result = self.ExecuteJavascript('document.helloForm.elements[2].click();', |
- tab_index) |
- self.assertEqual(result, 'dlrow olleH', |
- msg='Example %s failed. URL: %s' % (name, url)) |
- |
- def _VerifyPiGeneratorExample(self, tab_index, name, url): |
- """Verify Pi Generator Example. |
- |
Args: |
tab_index: Tab index integer that the example is on. |
name: A string name of the example. |
url: A string url of the example. |
""" |
+ success = self._VerifyElementPresent('eventString', 'DidChangeView', |
+ tab_index, msg='Example %s failed. URL: %s' % (name, url)) |
+ |
+ # Simulate mouse click on event module. |
+ js_code = self._CreateJSToSimulateMouseclick() |
+ self.ExecuteJavascript(js_code, tab_index) |
+ |
+ # Check if 'eventString' has handled above mouse click. |
success = self.WaitUntil( |
- lambda: self.GetDOMValue('document.form.pi.value', 0, tab_index)[0:3], |
- timeout=120, expect_retval='3.1') |
+ lambda: re.search('DidHandleInputEvent', self.GetDOMValue( |
+ 'document.getElementById("eventString").innerHTML', |
+ tab_index)).group(), expect_retval='DidHandleInputEvent') |
self.assertTrue(success, msg='Example %s failed. URL: %s' % (name, url)) |
- # Get top corner of Pi image. |
- js_code = """ |
- var obj = document.getElementById('piGenerator'); |
- var curleft = curtop = 0; |
- do { |
- curleft += obj.offsetLeft; |
- curtop += obj.offsetTop; |
- } while (obj = obj.offsetParent); |
- window.domAutomationController.send(curleft + ", " + curtop); |
- """ |
- result = self.ExecuteJavascript(js_code, tab_index) |
- result_split = result.split(', ') |
- x = int(result_split[0]) |
- y = int(result_split[1]) |
- window = self.GetBrowserInfo()['windows'][0] |
- window_to_content_x = 2 |
- window_to_content_y = 80 |
- pi_image_x = x + window['x'] + window_to_content_x |
- pi_image_y = y + window['y'] + window_to_content_y |
+ def _VerifyMultithreadedInputEventsExample(self, tab_index, name, url): |
+ """Verify Input Events Example. |
- if self._IsGetPixelSupported(): |
- is_animating = self._IsColorChanging(pi_image_x, pi_image_y, 50, 50) |
- self.assertTrue(is_animating, |
- msg='Example %s failed. URL: %s' % (name, url)) |
- |
- def _VerifySineSynthExample(self, tab_index, name, url): |
- """Verify Sine Wave Synthesizer Example. |
- |
Args: |
tab_index: Tab index integer that the example is on. |
name: A string name of the example. |
url: A string url of the example. |
""" |
success = self.WaitUntil( |
- lambda: self.GetDOMValue( |
- 'document.getElementById("frequency_field").value', |
- tab_index), |
- timeout=30, expect_retval='440') |
+ lambda: bool(self.GetDOMValue( |
+ 'document.getElementById("eventString").innerHTML', |
+ tab_index).find('DidChangeView') + 1)) |
+ |
self.assertTrue(success, msg='Example %s failed. URL: %s' % (name, url)) |
- self.ExecuteJavascript( |
- 'document.body.getElementsByTagName("button")[0].click();' |
- 'window.domAutomationController.send("done")', |
- tab_index) |
+ # Simulate mouse click on event module. |
+ js_code = self._CreateJSToSimulateMouseclick() |
+ self.ExecuteJavascript(js_code, tab_index) |
- # TODO(chrisphan): Verify sound. |
+ # Check if above mouse click is handled. |
+ success = self._VerifyElementPresent('eventString', 'Mouse event', |
+ tab_index, msg='Example %s failed. URL: %s' % (name, url)) |
- def _VerifyGetURLExample(self, tab_index, name, url): |
- """Verify GetURL Example. |
+ # Kill worker thread and queue |
+ js_code = """ |
+ document.getElementsByTagName('button')[0].click(); |
+ window.domAutomationController.send('done'); |
+ """ |
+ self.ExecuteJavascript(js_code, tab_index) |
+ # Check if main thread has cancelled queue. |
+ success = self._VerifyElementPresent('eventString', 'Received cancel', |
+ tab_index, msg='Example %s failed. URL: %s' % (name, url)) |
+ |
+ # Simulate mouse click on event module. |
+ js_code = self._CreateJSToSimulateMouseclick() |
+ self.ExecuteJavascript(js_code, tab_index) |
+ |
+ # Check if above mouse click is not handled after killing worker thread. |
+ def _CheckMouseClickEventStatus(): |
+ return self.GetDOMValue( |
+ 'document.getElementById("eventString").innerHTML', |
+ tab_index).find('Mouse event', self.GetDOMValue( |
+ 'document.getElementById("eventString").innerHTML', tab_index).find( |
+ 'Received cancel')) |
+ |
+ success = self.WaitUntil(_CheckMouseClickEventStatus, expect_retval=-1) |
+ self.assertTrue(success, msg='Example %s failed. URL: %s' % (name, url)) |
+ |
+ def _VerifyWebSocketExample(self, tab_index, name, url): |
+ """Verify Web Socket Open Example. |
+ |
Args: |
tab_index: Tab index integer that the example is on. |
name: A string name of the example. |
url: A string url of the example. |
""" |
+ # Check if example is loaded. |
success = self.WaitUntil( |
lambda: self.GetDOMValue( |
- 'document.getElementById("status_field").innerHTML', |
- tab_index), |
- timeout=60, expect_retval='SUCCESS') |
+ 'document.getElementById("statusField").innerHTML', tab_index), |
+ expect_retval='SUCCESS') |
self.assertTrue(success, msg='Example %s failed. URL: %s' % (name, url)) |
- self.ExecuteJavascript( |
- 'document.geturl_form.elements[0].click();' |
- 'window.domAutomationController.send("done")', |
- tab_index) |
+ # Simulate clicking on Connect button to establish a connection. |
+ js_code = """ |
+ document.getElementsByTagName('input')[1].click(); |
+ window.domAutomationController.send('done'); |
+ """ |
+ self.ExecuteJavascript(js_code, tab_index) |
+ # Check if connected |
+ success = self._VerifyElementPresent('log', 'connected', tab_index, |
+ msg='Example %s failed. URL: %s' % (name, url), attribute='value') |
+ |
+ # Simulate clicking on Send button to send text message in log. |
js_code = """ |
- var output = document.getElementById("general_output").innerHTML; |
- var result; |
- if (output.indexOf("test passed") != -1) |
- result = "pass"; |
- else |
- result = "fail"; |
- window.domAutomationController.send(result); |
+ document.getElementsByTagName('input')[3].click(); |
+ window.domAutomationController.send('done'); |
""" |
+ self.ExecuteJavascript(js_code, tab_index) |
success = self.WaitUntil( |
- lambda: self.ExecuteJavascript(js_code, tab_index), |
- timeout=30, expect_retval='pass') |
+ lambda: bool(re.search('send:', self.GetDOMValue( |
+ 'document.getElementById("log").value', tab_index)))) |
self.assertTrue(success, msg='Example %s failed. URL: %s' % (name, url)) |
- def _VerifyConwaysLifeExample(self, tab_index, name, url): |
- """Verify Conway's Life Example. |
+ def _VerifyDynamicLibraryOpen(self, tab_index, name, url): |
+ """Verify Dynamic Library Open Example. |
Args: |
tab_index: Tab index integer that the example is on. |
name: A string name of the example. |
url: A string url of the example. |
""" |
- window = self.GetBrowserInfo()['windows'][0] |
- window_to_content_x = 2 |
- window_to_content_y = 80 |
- x = window['x'] + window_to_content_x |
- y = window['y'] + window_to_content_y |
- offset_pixel = 100 |
- if self._IsGetPixelSupported(): |
- success = self.WaitUntil( |
- lambda: self._GetPixel(x + offset_pixel, y + offset_pixel), |
- timeout=30, expect_retval=16777215) |
- self.assertTrue(success, msg='Example %s failed. URL: %s' % (name, url)) |
+ # Check if example is loaded. |
+ success = self._VerifyElementPresent('consolec', 'Eightball loaded', |
+ tab_index, msg='Example %s failed. URL: %s' % (name, url)) |
- def _GetXMLNodeData(self, nodelist): |
- rc = [] |
- for node in nodelist: |
- if node.nodeType == node.TEXT_NODE: |
- rc.append(node.data) |
- return ''.join(rc) |
- |
- def _IsColorChanging(self, x, y, width, height): |
- """Check screen for anything that is moving. |
- |
- Args: |
- x: X coordinate on the screen. |
- y: Y coordinate on the screen. |
- width: Width of the area to scan. |
- height: Height of the area to scan. |
- |
- Returns: |
- True, if pixel color in area is changing, or |
- False otherwise. |
+ # Simulate clicking on ASK button and check answer log for desired answer. |
+ js_code = """ |
+ document.getElementsByTagName('input')[1].click(); |
+ window.domAutomationController.send('done'); |
""" |
- color_a = self._GetAreaPixelColor(x, y, width, height) |
- def _HasColorChanged(): |
- color_b = self._GetAreaPixelColor(x, y, width, height) |
- return color_a != color_b |
+ self.ExecuteJavascript(js_code, tab_index) |
+ def _CheckAnswerLog(): |
+ return bool(re.search(r'NO|YES|42|MAYBE NOT|DEFINITELY|' |
+ 'ASK ME TOMORROW|MAYBE|PARTLY CLOUDY', |
+ self.GetDOMValue('document.getElementById("answerlog").innerHTML', |
+ tab_index))) |
- return self.WaitUntil(_HasColorChanged, timeout=6, |
- retry_sleep=2, expect_retval=True) |
+ success = self.WaitUntil(_CheckAnswerLog) |
+ self.assertTrue(success, msg='Example %s failed. URL: %s' % (name, url)) |
- def _IsGetPixelSupported(self): |
- """Check if get pixel is supported. |
+ def _VerifyLoadProgressExample(self, tab_index, name, url): |
+ """Verify Dynamic Library Open Example. |
- Returns: |
- True, if get pixel is supported, or |
- False otherwise. |
- """ |
- return pyauto.PyUITest.IsWin() |
- |
- def _GetAreaPixelColor(self, x, y, width, height): |
- """Get an area of pixel color and return a list of color code values. |
- |
Args: |
- x: X coordinate on the screen. |
- y: Y coordinate on the screen. |
- width: Width of the area to scan. |
- height: Height of the area to scan. |
- |
- Returns: |
- A list containing color codes. |
+ tab_index: Tab index integer that the example is on. |
+ name: A string name of the example. |
+ url: A string url of the example. |
""" |
- if pyauto.PyUITest.IsMac(): |
- pass # TODO(chrisphan): Do Mac. |
- elif pyauto.PyUITest.IsWin(): |
- return self._GetAreaPixelColorWin(x, y, width, height) |
- elif pyauto.PyUITest.IsLinux(): |
- pass # TODO(chrisphan): Do Linux. |
- return None |
+ # Check if example loads and displays loading progress. |
+ success = self.WaitUntil( |
+ lambda: self.GetDOMValue( |
+ 'document.getElementById("status_field").innerHTML', tab_index), |
+ timeout=150, expect_retval='SUCCESS') |
+ self.assertTrue(success, msg='Example %s failed. URL: %s' % (name, url)) |
- def _GetAreaPixelColorWin(self, x, y, width, height): |
- """Get an area of pixel color for Windows and return a list. |
+ def _CheckLoadProgressStatus(): |
+ return re.search( |
+ r'(loadstart).+(progress:).+(load).+(loadend).+(lastError:)', |
+ self.GetDOMValue( |
+ 'document.getElementById("event_log_field").innerHTML', tab_index)) |
+ success = self.WaitUntil(_CheckLoadProgressStatus) |
+ self.assertTrue(success, msg='Example %s failed. URL: %s' % (name, url)) |
- Args: |
- x: X coordinate on the screen. |
- y: Y coordinate on the screen. |
- width: Width of the area to scan. |
- height: Height of the area to scan. |
+ def _VerifyPiGeneratorExample(self, tab_index, name, url): |
+ """Verify Pi Generator Example. |
- Returns: |
- A list containing color codes. |
- """ |
- colors = [] |
- hdc = ctypes.windll.user32.GetDC(0) |
- for x_pos in xrange(x, x + width, 1): |
- for y_pos in xrange(y, y + height, 1): |
- color = ctypes.windll.gdi32.GetPixel(hdc, x_pos, y_pos) |
- colors.append(color) |
- return colors |
- |
- def _GetPixel(self, x, y): |
- """Get pixel color at coordinate x and y. |
- |
Args: |
- x: X coordinate on the screen. |
- y: Y coordinate on the screen. |
- |
- Returns: |
- An integer color code. |
+ tab_index: Tab index integer that the example is on. |
+ name: A string name of the example. |
+ url: A string url of the example. |
""" |
- if pyauto.PyUITest.IsMac(): |
- pass # TODO(chrisphan): Do Mac. |
- elif pyauto.PyUITest.IsWin(): |
- return self._GetPixelWin(x, y) |
- elif pyauto.PyUITest.IsLinux(): |
- pass # TODO(chrisphan): Do Linux. |
- return None |
+ success = self.WaitUntil( |
+ lambda: self.GetDOMValue('document.form.pi.value', tab_index)[0:3], |
+ expect_retval='3.1') |
+ self.assertTrue(success, msg='Example %s failed. URL: %s' % (name, url)) |
- def _GetPixelWin(self, x, y): |
- """Get pixel color at coordinate x and y for Windows |
+ def _VerifySineSynthExample(self, tab_index, name, url): |
+ """Verify Sine Wave Synthesizer Example. |
Args: |
- x: X coordinate on the screen. |
- y: Y coordinate on the screen. |
- |
- Returns: |
- An integer color code. |
+ tab_index: Tab index integer that the example is on. |
+ name: A string name of the example. |
+ url: A string url of the example. |
""" |
- hdc = ctypes.windll.user32.GetDC(0) |
- color = ctypes.windll.gdi32.GetPixel(hdc, x, y) |
- return color |
+ success = self.WaitUntil( |
+ lambda: self.GetDOMValue( |
+ 'document.getElementById("frequency_field").value', |
+ tab_index), timeout=150, expect_retval='440') |
+ self.assertTrue(success, msg='Example %s failed. URL: %s' % (name, url)) |
+ self.ExecuteJavascript( |
+ 'document.body.getElementsByTagName("button")[0].click();' |
+ 'window.domAutomationController.send("done")', |
+ tab_index) |
- def _CheckForCrashes(self, last_action=None, last_action_param=None): |
- """Check for any browser/tab crashes and hangs. |
+ def _VerifyGetURLExample(self, tab_index, name, url): |
+ """Verify GetURL Example. |
Args: |
- last_action: Specify action taken before checking for crashes. |
- last_action_param: Parameter for last action. |
+ tab_index: Tab index integer that the example is on. |
+ name: A string name of the example. |
+ url: A string url of the example. |
""" |
+ success = self.WaitUntil( |
+ lambda: self.GetDOMValue( |
+ 'document.getElementById("status_field").innerHTML', |
+ tab_index), timeout=150, expect_retval='SUCCESS') |
+ self.assertTrue(success, msg='Example %s failed. URL: %s' % (name, url)) |
+ self.ExecuteJavascript( |
+ 'document.geturl_form.elements[0].click();' |
+ 'window.domAutomationController.send("done")', |
+ tab_index) |
+ success = self._VerifyElementPresent('general_output', 'test passed', |
+ tab_index, msg='Example %s failed. URL: %s' % (name, url)) |
+ |
+ def _CheckForCrashes(self): |
+ """Check for any browser/tab crashes and hangs.""" |
self.assertTrue(self.GetBrowserWindowCount(), |
msg='Browser crashed, no window is open.') |
@@ -818,22 +539,9 @@ |
if not self.GetDOMValue('document.body.innerHTML', tab['index']): |
self.fail(msg='Tab crashed on %s' % tab['url']) |
- # TODO(chrisphan): Check for tab hangs and browser hangs. |
- # TODO(chrisphan): Handle specific action: close browser, close tab. |
- if last_action == 'close tab': |
- pass |
- elif last_action == 'close browser': |
- pass |
- else: |
- pass |
- |
def _GetPlatformArchitecture(self): |
"""Get platform architecture. |
- Args: |
- last_action: Last action taken before checking for crashes. |
- last_action_param: Parameter for last action. |
- |
Returns: |
A string representing the platform architecture. |
""" |
@@ -849,19 +557,6 @@ |
return '32bit' |
return '32bit' |
- def _HasFile(self, pattern, root=os.curdir): |
- """Check if a file matching the specified pattern exists in a directory. |
- |
- Args: |
- pattern: Pattern of file name. |
- root: Directory to start looking. |
- |
- Returns: |
- True, if root contains the file name pattern, or |
- False otherwise. |
- """ |
- return len(glob.glob(os.path.join(root, pattern))) |
- |
def _HasPathInTree(self, pattern, is_file, root=os.curdir): |
"""Recursively checks if a file/directory matching a pattern exists. |
@@ -883,22 +578,6 @@ |
return True |
return False |
- def _GetDirectoryPath(self, pattern, root=os.curdir): |
- """Get the path of a directory in another directory. |
- |
- Args: |
- pattern: Pattern of directory name. |
- root: Directory to start looking. |
- |
- Returns: |
- A string of the path. |
- """ |
- for path, dirs, files in os.walk(os.path.abspath(root)): |
- result = fnmatch.filter(dirs, pattern) |
- if result: |
- return os.path.join(path, result[0]) |
- return None |
- |
def _HasAllSystemRequirements(self): |
"""Verify NaCl SDK installation system requirements. |
@@ -928,24 +607,15 @@ |
# NaCl supports Chrome 10 and higher builds. |
min_required_chrome_build = self._settings['min_required_chrome_build'] |
browser_info = self.GetBrowserInfo() |
- chrome_version = browser_info['properties']['ChromeVersion'] |
+ chrome_version = browser_info['properties']['ChromeVersion'] |
chrome_build = int(chrome_version.split('.')[0]) |
return chrome_build >= min_required_chrome_build |
def _DownloadNaClSDK(self): |
"""Download NaCl SDK.""" |
self._temp_dir = tempfile.mkdtemp() |
- if pyauto.PyUITest.IsWin(): |
- dl_file = urllib2.urlopen(self._settings['release_win_sdk_url']) |
- file_path = os.path.join(self._temp_dir, 'naclsdk_win.exe') |
- elif pyauto.PyUITest.IsMac(): |
- dl_file = urllib2.urlopen(self._settings['release_mac_sdk_url']) |
- file_path = os.path.join(self._temp_dir, 'naclsdk_mac.tgz') |
- elif pyauto.PyUITest.IsLinux(): |
- dl_file = urllib2.urlopen(self._settings['release_lin_sdk_url']) |
- file_path = os.path.join(self._temp_dir, 'naclsdk_linux.tgz') |
- else: |
- self.fail(msg='NaCl SDK does not support this OS.') |
+ dl_file = urllib2.urlopen(self._settings['post_sdk_zip']) |
+ file_path = os.path.join(self._temp_dir, 'nacl_sdk.zip') |
try: |
f = open(file_path, 'wb') |
@@ -957,24 +627,12 @@ |
def _ExtractNaClSDK(self): |
"""Extract NaCl SDK.""" |
- if pyauto.PyUITest.IsWin(): |
- source_file = os.path.join(self._temp_dir, 'naclsdk_win.exe') |
- proc = subprocess.Popen([source_file, '/S', '/D=' + |
- self._extracted_sdk_path], |
- stdout=subprocess.PIPE) |
- proc.communicate() |
- if not os.listdir(self._extracted_sdk_path): |
- self.fail(msg='Failed to extract NaCl SDK.') |
- elif pyauto.PyUITest.IsMac(): |
- source_file = os.path.join(self._temp_dir, 'naclsdk_mac.tgz') |
- tar = tarfile.open(source_file, 'r') |
- tar.extractall(self._extracted_sdk_path) |
- elif pyauto.PyUITest.IsLinux(): |
- source_file = os.path.join(self._temp_dir, 'naclsdk_linux.tgz') |
- tar = tarfile.open(source_file, 'r') |
- tar.extractall(self._extracted_sdk_path) |
+ source_file = os.path.join(self._temp_dir, 'nacl_sdk.zip') |
+ if zipfile.is_zipfile(source_file): |
+ zip = zipfile.ZipFile(source_file, 'r') |
+ zip.extractall(self._extracted_sdk_path) |
else: |
- self.fail(msg='NaCl SDK does not support this OS.') |
+ self.fail(msg='%s is not a valid zip file' % source_file) |
def _IsURLAlive(self, url): |
"""Test if URL is alive.""" |
@@ -1001,7 +659,7 @@ |
urllib2.urlopen('http://localhost:5103?quit=1') |
success = self.WaitUntil( |
lambda: self._IsURLAlive('http://localhost:5103'), |
- timeout=30, retry_sleep=1, expect_retval=False) |
+ retry_sleep=1, expect_retval=False) |
if not success: |
if not proc: |
self.fail(msg='Failed to close HTTP server.') |
@@ -1010,38 +668,9 @@ |
try: |
proc.kill() |
except: |
- self.fail(msg='Failed to close HTTP server') |
+ self.fail(msg='Failed to close HTTP server.') |
- def _SearchNaClSDKTarFile(self, search_list, source_file): |
- """Search NaCl SDK tar file for example files and directories. |
- |
- Args: |
- search_list: A list of strings, representing file and |
- directory names for which to search. |
- source_file: The string name of an NaCl SDK tar file. |
- """ |
- tar = tarfile.open(source_file, 'r') |
- |
- # Look for files and directories in examples. |
- files = copy.deepcopy(search_list) |
- for tar_info in tar: |
- file_name = tar_info.name |
- if tar_info.isdir() and not file_name.endswith('/'): |
- file_name = file_name + '/' |
- |
- for name in files: |
- if file_name.find('examples/' + name): |
- files.remove(name) |
- if not files: |
- break |
- |
- tar.close() |
- |
- self.assertEqual(len(files), 0, |
- msg='Missing files or directories: %s' % |
- ', '.join(map(str, files))) |
- |
- def _SearchNaClSDKFileWindows(self, search_list): |
+ def _SearchNaClSDKFile(self, search_list): |
"""Search NaCl SDK file for example files and directories in Windows. |
Args: |
@@ -1059,28 +688,18 @@ |
msg='Missing files or directories: %s' % |
', '.join(map(str, missing_items))) |
- def _EnableNaClPlugin(self): |
- """Enable NaCl plugin.""" |
- nacl_plugin = (self.GetPluginsInfo().PluginForName('Chrome NaCl') or |
- self.GetPluginsInfo().PluginForName('Native Client')) |
- if not nacl_plugin: |
- self.fail(msg='No NaCl plugin found.') |
- self.EnablePlugin(nacl_plugin[0]['path']) |
+ def ExtraChromeFlags(self): |
+ """Ensures Nacl is enabled. |
- self.NavigateToURL('about:flags') |
- |
- js_code = """ |
- chrome.send('enableFlagsExperiment', ['enable-nacl', 'true']); |
- requestFlagsExperimentsData(); |
- window.domAutomationController.send('done'); |
+ Returns: |
+ A list of extra flags to pass to Chrome when it is launched. |
""" |
- self.ExecuteJavascript(js_code) |
- self.RestartBrowser(False) |
+ extra_chrome_flags = [ |
+ '--enable-nacl', |
+ '--enable-nacl-exception-handling', |
+ '--nacl-gdb', |
+ ] |
+ return pyauto.PyUITest.ExtraChromeFlags(self) + extra_chrome_flags |
- self.NavigateToURL('about://version') |
- self.assertEqual(self.FindInPage('--enable-nacl')['match_count'], 1, |
- msg='Missing expected Chrome flag --enable-nacl.') |
- |
- |
if __name__ == '__main__': |
pyauto_functional.Main() |