Skip to content

Commit

Permalink
web: Add url_rewrite_rules integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
kjarosh committed Oct 29, 2024
1 parent c7a5661 commit 85a196f
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package {
import flash.display.MovieClip;

public class Other1 extends MovieClip {
public function Other1() {
trace("Loaded other1!");

var value:String = loaderInfo.parameters["v"];
trace("QP Value: " + value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package {
import flash.display.MovieClip;

public class Other2 extends MovieClip {
public function Other2() {
trace("Loaded other2!");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package {
import flash.display.MovieClip;
import flash.events.KeyboardEvent;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.text.TextFormat;

[SWF(width="100", height="100")]
public class Test extends MovieClip {
public function Test() {
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
addChild(createLinkText());

trace("Loaded test!");
}

private function onKeyDown(event: KeyboardEvent):void {
if (event.charCode == 65) {
var loader:Loader = new Loader();
loader.load(new URLRequest("https://example.com/other1.test1"));
addChild(loader);
}
if (event.charCode == 66) {
var loader:Loader = new Loader();
loader.load(new URLRequest("other1.test2"));
addChild(loader);
}
if (event.charCode == 67) {
var loader:Loader = new Loader();
loader.load(new URLRequest("other2.swf"));
addChild(loader);
}
}

private function createLinkText():TextField {
var text:TextField = new TextField();
text.x = -20;
text.y = -20;
text.width = 200;
text.height = 200;
text.htmlText = "<font size='100'><a href='http://www.example.com/[test]site.html'>CLICK</a></font>";
return text;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!doctype html>
<html>

<head>
<title>url_rewrite_rules</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script>
window.RufflePlayer = window.RufflePlayer || {};
window.RufflePlayer.config = {
"urlRewriteRules": [
// Rewriting to a relative URL
[/^https?:\/\/(example.com)\/(.*)\.test1$/, "$2.swf?v=$1/$2"],
// Rewriting to an absolute URL
[/^(.*)\.test2$/, "$1.swf?v=$1"],
// Rewriting a string (not a regex, [...], $... will do nothing)
["http://www.example.com/[test]site.html", "https://www.example.com/$1/$&"],
],
};
</script>
</head>

<body>
<div>
<object type="application/x-shockwave-flash" data="test.swf" width="100" height="100" id="objectElement"></object>
</div>
</body>

</html>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import {
getTraceOutput,
hideHardwareAccelerationModal,
injectRuffleAndWait,
openTest,
playAndMonitor,
} from "../../utils.js";
import { expect, use } from "chai";
import chaiHtml from "chai-html";

use(chaiHtml);

describe("URL Rewrite Rules", () => {
it("load the test", async () => {
await openTest(browser, "integration_tests/url_rewrite_rules");
await injectRuffleAndWait(browser);
const player = await browser.$("<ruffle-object>");
await playAndMonitor(browser, player, "Loaded test!\n");
await hideHardwareAccelerationModal(browser, player);
});

it("rewrites URL of other1 to a relative one", async () => {
const player = await browser.$("#objectElement");

await browser.execute((element) => {
const el = element as unknown as HTMLElement;
el.focus();
el.dispatchEvent(
new KeyboardEvent("keydown", {
key: "A",
code: "A",
keyCode: 65,
bubbles: true,
}),
);
}, player);

expect(await getTraceOutput(browser, player)).to.equal(
"Loaded other1!\nQP Value: example.com/other1\n",
);
});

it("rewrites URL of other1 to an absolute one", async () => {
const player = await browser.$("#objectElement");

await browser.execute((element) => {
const el = element as unknown as HTMLElement;
el.focus();
el.dispatchEvent(
new KeyboardEvent("keydown", {
key: "B",
code: "B",
keyCode: 66,
bubbles: true,
}),
);
}, player);

expect(await getTraceOutput(browser, player)).to.equal(
"Loaded other1!\nQP Value: http://localhost:4567/test/integration_tests/url_rewrite_rules/other1\n",
);
});

it("does not rewrite URL of other2", async () => {
const player = await browser.$("#objectElement");

await browser.execute((element) => {
const el = element as unknown as HTMLElement;
el.focus();
el.dispatchEvent(
new KeyboardEvent("keydown", {
key: "C",
code: "C",
keyCode: 67,
bubbles: true,
}),
);
}, player);

expect(await getTraceOutput(browser, player)).to.equal(
"Loaded other2!\n",
);
});

it("rewrites URL of a clicked link", async () => {
const player = await browser.$("#objectElement");

player.click();

await browser.waitUntil(
async () => {
return (await browser.getUrl()).startsWith(
"https://www.example.com",
);
},
{
timeoutMsg: "Expected window URL to change",
},
);

expect(await browser.getUrl()).to.equal(
"https://www.example.com/$1/$&",
);
});
});

0 comments on commit 85a196f

Please sign in to comment.