Skip to content

Commit c8597b3

Browse files
wanghongjuanrogerwang
authored andcommitted
[test] Add test for issue5787
- Add test for issue nwjs#5787 - This case is passed on v0.31.1
1 parent a08215c commit c8597b3

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "5787",
3+
"main": "test.html"
4+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<!doctype html>
2+
3+
<meta name="robots" content="noindex">
4+
<html>
5+
<head>
6+
<meta charset="utf-8" />
7+
<title>5787</title>
8+
9+
</head>
10+
<body>
11+
<h1>2D panning</h1>
12+
<h2>z + x = 1</h2>
13+
<form name="f" id="f">
14+
<label for="pan" hidden="hidden">Pan</label>
15+
<input type="range" name="pan" id="pan" value="0" min="-1" max="1" step="any" />
16+
<label for="x">x</label>
17+
<output id="x">0</output>
18+
<label for="y">y</label>
19+
<output id="y">0</output>
20+
<label for="z">z</label>
21+
<output id="z">1</output>
22+
</form>
23+
<div id="msg"></div>
24+
<script id="jsbin-javascript">
25+
var test = new Audio;
26+
test.src = "broken.ogg";
27+
window.AudioContext = window.AudioContext || window.webkitAudioContext;
28+
var audio = new Audio(),
29+
context = new AudioContext(),
30+
url = "ACDC_-_Back_In_Black-sample.ogg",
31+
panner = context.createPanner(),
32+
onError = function(e) {
33+
console.log('There was an error!! ',e);
34+
document.getElementById('msg').innerHTML = 'There was an error!! ' + e
35+
},
36+
source;
37+
url = "broken.ogg";
38+
//audio.crossOrigin = "anonymous";
39+
40+
// set up audio graph
41+
audio.src = url;
42+
43+
source = context.createMediaElementSource(audio);
44+
context.listener.setPosition(0, 0, 0);
45+
panner.setPosition(0, 0, 1);
46+
panner.panningModel = 'equalpower';
47+
source.connect( panner );
48+
panner.connect( context.destination );
49+
50+
source.mediaElement.play();
51+
52+
// 2D Panning
53+
function changePan(ev) {
54+
var x = document.getElementById('pan').valueAsNumber,
55+
y = 0,
56+
z = 1 - Math.abs(x),
57+
parent = this.parentNode;
58+
console.log(x,y,z);
59+
document.getElementById('msg').innerHTML = "X: " + x + '\t Y: ' + y + "\t Z: " + z;
60+
panner.setPosition(x,y,z);
61+
// update labels
62+
document.getElementById('x').value = x;
63+
document.getElementById('y').value = y;
64+
document.getElementById('z').value = z;
65+
}
66+
67+
// attach form events to audioContext
68+
document.addEventListener("DOMContentLoaded", function(event) {
69+
document.getElementById('pan').addEventListener('change',changePan);
70+
});
71+
nw.Window.get().showDevTools();
72+
</script>
73+
</body>
74+
</html>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
import sys
3+
4+
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
5+
from nw_util import *
6+
7+
from selenium import webdriver
8+
from selenium.webdriver.chrome.options import Options
9+
10+
chrome_options = Options()
11+
chrome_options.add_argument("nwapp=" + os.path.dirname(os.path.abspath(__file__)))
12+
13+
driver = webdriver.Chrome(executable_path=os.environ["CHROMEDRIVER"], chrome_options=chrome_options)
14+
try:
15+
print driver.current_url
16+
switch_to_app(driver)
17+
print driver.current_url
18+
print "wait for devtools open"
19+
wait_window_handles(driver, 2)
20+
print driver.window_handles
21+
print "switch to devtools"
22+
switch_to_devtools(driver)
23+
print "click Console panel"
24+
devtools_click_tab(driver, "console")
25+
print "check if there is warning message in console panel"
26+
elems = driver.find_elements_by_class_name("console-message-text")
27+
output = ""
28+
if len(elems) > 2:
29+
for i in range(len(elems)):
30+
if "MediaElementAudioSource" in elems[i].get_attribute("innerHTML"):
31+
output = elems[i].get_attribute("innerHTML")
32+
break
33+
elif len(elems) == 1:
34+
output = elems[0].get_attribute("innerHTML")
35+
else:
36+
output = ""
37+
print output
38+
assert("MediaElementAudioSource" not in output)
39+
assert(output is "")
40+
41+
finally:
42+
driver.quit()

0 commit comments

Comments
 (0)