Skip to content

Commit

Permalink
[test] add issue5762-user-data-dir for #5762
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerwang committed Mar 10, 2017
1 parent 08af739 commit e0f620a
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/sanity/issue5762-user-data-dir/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>
4 changes: 4 additions & 0 deletions test/sanity/issue5762-user-data-dir/app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "issue5762",
"main": "index.html"
}
76 changes: 76 additions & 0 deletions test/sanity/issue5762-user-data-dir/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import time
import os
import shutil
import zipfile
import platform
import subprocess

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 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)
pkgname = 'issue5762'

# copy app to test directory
if platform.system() == 'Darwin':
appdest = os.path.join(pkg1, 'nwjs.app', 'Contents', 'Resources', 'app.nw')
user_data_dir = os.path.join(os.getenv('HOME'), 'Library', 'Application Support', pkgname)
exe = os.path.join(pkg1, 'nwjs.app', 'Contents', 'MacOS', 'nwjs')
check_file = os.path.join(user_data_dir, 'Default', 'Web Data')
elif platform.system() == 'Linux':
appdest = pkg1
user_data_dir = os.path.join(os.getenv('HOME'), '.config', pkgname)
exe = os.path.join(pkg1, 'nw')
check_file = os.path.join(user_data_dir, 'Default', 'Web Data')
else:
appdest = pkg1
user_data_dir = os.path.join(os.getenv('LOCALAPPDATA'), pkgname)
check_file = os.path.join(user_data_dir, 'User Data', 'Default', 'Web Data')
exe = os.path.join(pkg1, 'nw.exe')

print "copying %s to %s" % (appdir, appdest)
copytree(appdir, appdest)

print "user data dir: %s" % (user_data_dir)
try:
shutil.rmtree(user_data_dir)
except:
pass

os.chdir(pkg1)

assert not os.path.exists(user_data_dir), "'%s' should not be existed before testing" % user_data_dir

p = subprocess.Popen([exe])
time.sleep(10)

try:
assert os.path.exists(user_data_dir)
assert os.path.exists(check_file)
finally:
p.terminate()

0 comments on commit e0f620a

Please sign in to comment.