-
-
Notifications
You must be signed in to change notification settings - Fork 809
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
web: Add url_rewrite_rules integration test
- Loading branch information
Showing
8 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
web/packages/selfhosted/test/integration_tests/url_rewrite_rules/Other1.as
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
web/packages/selfhosted/test/integration_tests/url_rewrite_rules/Other2.as
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
web/packages/selfhosted/test/integration_tests/url_rewrite_rules/Test.as
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
web/packages/selfhosted/test/integration_tests/url_rewrite_rules/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+891 Bytes
web/packages/selfhosted/test/integration_tests/url_rewrite_rules/other1.swf
Binary file not shown.
Binary file added
BIN
+722 Bytes
web/packages/selfhosted/test/integration_tests/url_rewrite_rules/other2.swf
Binary file not shown.
Binary file added
BIN
+1.21 KB
web/packages/selfhosted/test/integration_tests/url_rewrite_rules/test.swf
Binary file not shown.
105 changes: 105 additions & 0 deletions
105
web/packages/selfhosted/test/integration_tests/url_rewrite_rules/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/$&", | ||
); | ||
}); | ||
}); |