Skip to content

Commit 899315e

Browse files
committed
[test] add case for nwjs#6216: flash permission with content settings
1 parent 292f367 commit 899315e

File tree

9 files changed

+228
-0
lines changed

9 files changed

+228
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# LGPL
2+
This test case contains certain Linux system libraries licensed under LGPL.
3+
4+
# FlashPlayer
5+
Adobe(R) Flash(R) Player used in this test case can be downloaded from
6+
https://get.adobe.com/flashplayer/
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package {
2+
import flash.display.Sprite;
3+
import flash.external.ExternalInterface;
4+
import flash.system.Security;
5+
import flash.text.TextField;
6+
import flash.text.TextFormat;
7+
8+
public class HelloWorld extends Sprite {
9+
10+
public function HelloWorld() {
11+
Security.allowDomain('*');
12+
ExternalInterface.marshallExceptions = true;
13+
14+
var myFormat:TextFormat = new TextFormat();
15+
myFormat.size = 32;
16+
17+
var display_txt:TextField = new TextField();
18+
display_txt.defaultTextFormat = myFormat;
19+
display_txt.width = 300;
20+
display_txt.wordWrap = true;
21+
addChild(display_txt);
22+
23+
if (ExternalInterface.available) {
24+
display_txt.text = 'ExternalInterface is available';
25+
try {
26+
ExternalInterface.call('out', 'result', 'success');
27+
} catch (e:Error) {
28+
display_txt.text = e.toString();
29+
}
30+
} else {
31+
display_txt.text = 'ExternalInterface is NOT available';
32+
}
33+
}
34+
35+
private function ready():String {
36+
return 'success';
37+
}
38+
}
39+
}
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Compile AS to SWF
2+
3+
1. Download Flex-SDK from http://www.adobe.com/devnet/flex/flex-sdk-download.html
4+
2. Extract downloaded zip file
5+
3. Execute `<flex-sdk>/bin/mxmlc HelloWorld.as`
6+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<title></title>
7+
<link rel="stylesheet" href="">
8+
</head>
9+
<body>
10+
<script>
11+
chrome.contentSettings.plugins.set({
12+
primaryPattern: '<all_urls>',
13+
resourceIdentifier: {
14+
id: 'adobe-flash-player'
15+
},
16+
setting: "block"
17+
});
18+
</script>
19+
<embed width="400" src="HelloWorld.swf" AllowScriptAccess="always"/>
20+
<script>
21+
function out(id, message) {
22+
var h1 = document.createElement('h1');
23+
h1.setAttribute('id', id);
24+
h1.innerHTML = message;
25+
document.body.appendChild(h1);
26+
}
27+
</script>
28+
</body>
29+
</html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "flash-test",
3+
"main": "http://localhost:8000/index.html",
4+
"node-remote": ["<all_urls>"],
5+
"webview": {
6+
"partitions": [
7+
{
8+
"name": "trusted",
9+
"accessible_resources": [ "<all_urls>" ]
10+
}
11+
]
12+
}
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python
2+
3+
import SimpleHTTPServer
4+
import SocketServer
5+
import sys
6+
7+
PORT = int(sys.argv[1])
8+
9+
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
10+
11+
httpd = SocketServer.TCPServer(("", PORT), Handler)
12+
13+
print "serving at port", PORT
14+
httpd.serve_forever()
15+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('fs').writeFileSync(process.argv[2], process.arch);
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import time
2+
import os
3+
import shutil
4+
import zipfile
5+
import platform
6+
import subprocess
7+
import selenium
8+
9+
from selenium import webdriver
10+
from selenium.webdriver.chrome.options import Options
11+
from selenium.webdriver.common import utils
12+
13+
testdir = os.path.dirname(os.path.abspath(__file__))
14+
nwdist = os.path.join(os.path.dirname(os.environ['CHROMEDRIVER']), 'nwdist')
15+
16+
appdir = os.path.join(testdir, 'app')
17+
pkg1 = os.path.join(testdir, 'pkg1')
18+
arch = os.path.join(pkg1, 'arch')
19+
20+
try:
21+
shutil.rmtree(pkg1)
22+
except:
23+
pass
24+
25+
def compress(from_dir, to_file):
26+
from_dir = os.path.normpath(from_dir)
27+
to_file = os.path.normpath(to_file)
28+
29+
z = zipfile.ZipFile(to_file, 'w', compression=zipfile.ZIP_DEFLATED)
30+
for root, dirs, files in os.walk(from_dir):
31+
for f in files:
32+
_path = os.path.join(root, f)
33+
z.write(_path, _path.replace(from_dir+os.sep, ''))
34+
z.close()
35+
36+
def copytree(src, dst, symlinks=False, ignore=None):
37+
if not os.path.exists(dst):
38+
os.makedirs(dst)
39+
for item in os.listdir(src):
40+
s = os.path.join(src, item)
41+
d = os.path.join(dst, item)
42+
if os.path.isdir(s):
43+
copytree(s, d, symlinks, ignore)
44+
else:
45+
if not os.path.exists(d) or os.stat(s).st_mtime - os.stat(d).st_mtime > 1:
46+
shutil.copy2(s, d)
47+
48+
def nw_arch():
49+
subprocess.check_output([os.path.join(pkg1, 'nw'), os.path.join(testdir, 'show-arch.js'), arch])
50+
with open(arch, 'r') as arch_file:
51+
return arch_file.read()
52+
53+
########### start test ############
54+
# create test directory
55+
#os.mkdir(pkg1)
56+
57+
# copy nw to test directory
58+
print "copying %s to %s" % (nwdist, pkg1)
59+
copytree(nwdist, pkg1)
60+
61+
# copy app & flash plugin to test directory
62+
if platform.system() == 'Darwin':
63+
# check nwjs version
64+
versions = subprocess.check_output([os.path.join(pkg1, 'nwjs.app', 'Contents', 'MacOS', 'nwjs'), '--version'])
65+
pluginsrc = os.path.join(testdir, '../../data/PepperFlash/mac')
66+
appdest = os.path.join(pkg1, 'nwjs.app', 'Contents', 'Resources', 'app.nw')
67+
plugindest = os.path.join(pkg1, 'nwjs.app', 'Contents', 'Versions', versions.split()[1], 'nwjs Framework.framework', 'Internet Plug-Ins', 'PepperFlash')
68+
else:
69+
if platform.system() == 'Linux':
70+
pluginsrc = os.path.join(testdir, "../../data/PepperFlash/linux_%s" % nw_arch())
71+
else:
72+
pluginsrc = os.path.join(testdir, "../../data/PepperFlash/win_%s" % nw_arch())
73+
appdest = pkg1
74+
plugindest = os.path.join(pkg1, 'PepperFlash')
75+
print "copying %s to %s" % (appdir, appdest)
76+
copytree(appdir, appdest)
77+
78+
print "copying %s to %s" % (pluginsrc, plugindest)
79+
copytree(pluginsrc, plugindest)
80+
81+
# start testing server
82+
os.chdir(appdest)
83+
port = str(utils.free_port())
84+
server = subprocess.Popen(['python', os.path.join(testdir, 'http-server.py'), port])
85+
86+
# create manifest for test
87+
manifest = open(os.path.join(appdest, 'package.json'), 'w')
88+
manifest.write('''
89+
{
90+
"name": "flash-test",
91+
"main": "http://localhost:%s/index.html",
92+
"node-remote": ["<all_urls>"],
93+
"webview": {
94+
"partitions": [
95+
{
96+
"name": "trusted",
97+
"accessible_resources": [ "<all_urls>" ]
98+
}
99+
]
100+
}
101+
}
102+
''' % (port))
103+
manifest.close()
104+
105+
driver_path=os.path.join(pkg1, 'chromedriver')
106+
driver = webdriver.Chrome(executable_path=driver_path)
107+
driver.implicitly_wait(2)
108+
time.sleep(1)
109+
try:
110+
print driver.current_url
111+
try:
112+
result = driver.find_element_by_id('result')
113+
print "should not have any output here: ", result.get_attribute('innerHTML')
114+
assert(False)
115+
except selenium.common.exceptions.NoSuchElementException:
116+
pass
117+
finally:
118+
server.terminate()
119+
driver.quit()

0 commit comments

Comments
 (0)