Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] test case for #5097 #5157

Merged
merged 1 commit into from
Jul 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions test/sanity/issue5097-packaged-create-file-in-arg/app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>test package</title>
</head>
<body>
<h1 id='result'>test package</h1>
<script>
document.getElementById('result').innerHTML = 'success';
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "test-package",
"main": "index.html"
}
81 changes: 81 additions & 0 deletions test/sanity/issue5097-packaged-create-file-in-arg/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import time
import os
import shutil
import zipfile
import platform

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

testdir = os.path.dirname(os.path.abspath(__file__))
nwdist = os.path.join(os.path.dirname(os.environ['CHROMEDRIVER']), 'nwdist')

appdir = os.path.join(testdir, 'app')
pkg1 = os.path.join(testdir, 'pkg1')

try:
shutil.rmtree(pkg1)
except:
pass

def compress(from_dir, to_file):
from_dir = os.path.normpath(from_dir)
to_file = os.path.normpath(to_file)

z = zipfile.ZipFile(to_file, 'w', compression=zipfile.ZIP_DEFLATED)
for root, dirs, files in os.walk(from_dir):
for f in files:
_path = os.path.join(root, f)
z.write(_path, _path.replace(from_dir+os.sep, ''))
z.close()

def copytree(src, dst, symlinks=False, ignore=None):
if not os.path.exists(dst):
os.makedirs(dst)
for item in os.listdir(src):
s = os.path.join(src, item)
d = os.path.join(dst, item)
if os.path.isdir(s):
copytree(s, d, symlinks, ignore)
else:
if not os.path.exists(d) or os.stat(s).st_mtime - os.stat(d).st_mtime > 1:
shutil.copy2(s, d)

# create test directory
os.mkdir(pkg1)

# copy nw to test directory
print "copying %s to %s" % (nwdist, pkg1)
copytree(nwdist, pkg1)

# copy app to test directory
if platform.system() == 'Darwin':
appdest = os.path.join(pkg1, 'nwjs.app', 'Contents', 'Resources', 'app.nw')
else:
appdest = pkg1
print "copying %s to %s" % (appdir, appdest)
copytree(appdir, appdest)

# change working directory to pkg1
# because in #5097, unexpected_file will be created in current working directory
os.chdir(pkg1)

# unexpected file should not exists before test
unexpected_file = 'unexpected_file'
assert not os.path.exists(unexpected_file), "'%s' should not be existed before testing" % unexpected_file

chrome_options = Options()
chrome_options.add_nw_argument(unexpected_file)
driver_path=os.path.join(pkg1, 'chromedriver')
driver = webdriver.Chrome(executable_path=driver_path, chrome_options=chrome_options)
time.sleep(1)
try:
print driver.current_url
result = driver.find_element_by_id('result')
print result.get_attribute('innerHTML')
assert("success" in result.get_attribute('innerHTML'))
finally:
driver.quit()

# unexpected file should not exists after test
assert not os.path.exists(unexpected_file), "'%s' should not be existed after testing" % unexpected_file