Skip to content

Commit e68837e

Browse files
committed
web: Add url_rewrite_rules integration test
1 parent 342b3fe commit e68837e

File tree

8 files changed

+201
-0
lines changed

8 files changed

+201
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package {
2+
import flash.display.MovieClip;
3+
4+
public class Other1 extends MovieClip {
5+
public function Other1() {
6+
trace("Loaded other1!");
7+
8+
var value:String = loaderInfo.parameters["v"];
9+
trace("QP Value: " + value);
10+
}
11+
}
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package {
2+
import flash.display.MovieClip;
3+
4+
public class Other2 extends MovieClip {
5+
public function Other2() {
6+
trace("Loaded other2!");
7+
}
8+
}
9+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package {
2+
import flash.display.MovieClip;
3+
import flash.events.KeyboardEvent;
4+
import flash.display.Loader;
5+
import flash.net.URLRequest;
6+
import flash.text.TextField;
7+
import flash.text.TextFormat;
8+
9+
[SWF(width="100", height="100")]
10+
public class Test extends MovieClip {
11+
public function Test() {
12+
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
13+
addChild(createLinkText());
14+
15+
trace("Loaded test!");
16+
}
17+
18+
private function onKeyDown(event: KeyboardEvent):void {
19+
if (event.charCode == 65) {
20+
var loader:Loader = new Loader();
21+
loader.load(new URLRequest("https://example.com/other1.test1"));
22+
addChild(loader);
23+
}
24+
if (event.charCode == 66) {
25+
var loader:Loader = new Loader();
26+
loader.load(new URLRequest("other1.test2"));
27+
addChild(loader);
28+
}
29+
if (event.charCode == 67) {
30+
var loader:Loader = new Loader();
31+
loader.load(new URLRequest("other2.swf"));
32+
addChild(loader);
33+
}
34+
}
35+
36+
private function createLinkText():TextField {
37+
var text:TextField = new TextField();
38+
text.x = -20;
39+
text.y = -20;
40+
text.width = 200;
41+
text.height = 200;
42+
text.htmlText = "<font size='100'><a href='http://www.example.com/[test]site.html'>CLICK</a></font>";
43+
return text;
44+
}
45+
}
46+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!doctype html>
2+
<html>
3+
4+
<head>
5+
<title>url_rewrite_rules</title>
6+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7+
8+
<script>
9+
window.RufflePlayer = window.RufflePlayer || {};
10+
window.RufflePlayer.config = {
11+
"urlRewriteRules": [
12+
// Rewriting to a relative URL
13+
[/^https?:\/\/(example.com)\/(.*)\.test1$/, "$2.swf?v=$1/$2"],
14+
// Rewriting to an absolute URL
15+
[/^(.*)\.test2$/, "$1.swf?v=$1"],
16+
// Rewriting a string (not a regex, [...], $... will do nothing)
17+
["http://www.example.com/[test]site.html", "https://www.example.com/$1/$&"],
18+
],
19+
};
20+
</script>
21+
</head>
22+
23+
<body>
24+
<div>
25+
<object type="application/x-shockwave-flash" data="test.swf" width="100" height="100" id="objectElement"></object>
26+
</div>
27+
</body>
28+
29+
</html>
891 Bytes
Binary file not shown.
722 Bytes
Binary file not shown.
1.21 KB
Binary file not shown.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import {
2+
getTraceOutput,
3+
hideHardwareAccelerationModal,
4+
injectRuffleAndWait,
5+
openTest,
6+
playAndMonitor,
7+
} from "../../utils.js";
8+
import { expect, use } from "chai";
9+
import chaiHtml from "chai-html";
10+
11+
use(chaiHtml);
12+
13+
describe("URL Rewrite Rules", () => {
14+
it("load the test", async () => {
15+
await openTest(browser, "integration_tests/url_rewrite_rules");
16+
await injectRuffleAndWait(browser);
17+
const player = await browser.$("<ruffle-object>");
18+
await playAndMonitor(browser, player, "Loaded test!\n");
19+
await hideHardwareAccelerationModal(browser, player);
20+
});
21+
22+
it("rewrites URL of other1 to a relative one", async () => {
23+
const player = await browser.$("#objectElement");
24+
25+
await browser.execute((element) => {
26+
const el = element as unknown as HTMLElement;
27+
el.focus();
28+
el.dispatchEvent(
29+
new KeyboardEvent("keydown", {
30+
key: "A",
31+
code: "A",
32+
keyCode: 65,
33+
bubbles: true,
34+
}),
35+
);
36+
}, player);
37+
38+
expect(await getTraceOutput(browser, player)).to.equal(
39+
"Loaded other1!\nQP Value: example.com/other1\n",
40+
);
41+
});
42+
43+
it("rewrites URL of other1 to an absolute one", async () => {
44+
const player = await browser.$("#objectElement");
45+
46+
await browser.execute((element) => {
47+
const el = element as unknown as HTMLElement;
48+
el.focus();
49+
el.dispatchEvent(
50+
new KeyboardEvent("keydown", {
51+
key: "B",
52+
code: "B",
53+
keyCode: 66,
54+
bubbles: true,
55+
}),
56+
);
57+
}, player);
58+
59+
expect(await getTraceOutput(browser, player)).to.equal(
60+
"Loaded other1!\nQP Value: http://localhost:4567/test/integration_tests/url_rewrite_rules/other1\n",
61+
);
62+
});
63+
64+
it("does not rewrite URL of other2", async () => {
65+
const player = await browser.$("#objectElement");
66+
67+
await browser.execute((element) => {
68+
const el = element as unknown as HTMLElement;
69+
el.focus();
70+
el.dispatchEvent(
71+
new KeyboardEvent("keydown", {
72+
key: "C",
73+
code: "C",
74+
keyCode: 67,
75+
bubbles: true,
76+
}),
77+
);
78+
}, player);
79+
80+
expect(await getTraceOutput(browser, player)).to.equal(
81+
"Loaded other2!\n",
82+
);
83+
});
84+
85+
it("rewrites URL of a clicked link", async () => {
86+
const player = await browser.$("#objectElement");
87+
88+
player.click();
89+
90+
await browser.waitUntil(
91+
async () => {
92+
return (await browser.getUrl()).startsWith(
93+
"https://www.example.com",
94+
);
95+
},
96+
{
97+
timeoutMsg: "Expected window URL to change",
98+
},
99+
);
100+
101+
expect(await browser.getUrl()).to.equal(
102+
"https://www.example.com/$1/$&",
103+
);
104+
});
105+
});

0 commit comments

Comments
 (0)