Skip to content

Commit

Permalink
Patch Fallback handling, and extend hooking
Browse files Browse the repository at this point in the history
  • Loading branch information
robcolburn committed Jul 24, 2015
1 parent 204578d commit a43dd7a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
8 changes: 5 additions & 3 deletions js/app_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@
* Primary URL that we will attempt to redirect to.
*/
function app_link (platforms, fallbackUrl) {
// Set variables, allowing before hooks to alter.
app_link.platforms = platforms;
app_link.fallbackUrl = fallbackUrl;
// Exexcute any before hooks.
if (app_link.before) {
return app_link.before(function() {
app_link.before = null;
app_link(platforms, fallbackUrl);
app_link(app_link.platforms, app_link.fallbackUrl);
});
}
// Add referrer to fallback (Server is unable to do this accurately).
var platform = platforms.app_link_platform_fallback;
if (platform && platform.supports_qs) {
fallbackUrl = app_link.applyReferrer(app_link.fallbackUrl);
app_link.fallbackUrl = app_link.applyReferrer(app_link.fallbackUrl);
}
// Determine the user's platform.
var platformKey = app_link.getPlatformKey(navigator.userAgent) || app_link.getPlatformKey(navigator.appVersion);
Expand All @@ -52,7 +55,6 @@ function app_link (platforms, fallbackUrl) {
el.className = "";
}
// If we don't recognize the platform, or have data about the platform -- fallback.
app_link.fallbackUrl = fallbackUrl;
if (!platform) {
return app_link.fallback();
}
Expand Down
19 changes: 15 additions & 4 deletions test/app_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,23 @@ describe("App Link Redirects", function() {
* Test Async Before Hook.
*/
describe("Before Hook", function() {
it("Should run sync.", function(done) {
it("Modifies fallback variable.", function(done) {
testApplinkRedirect({inject: function() {
app_link.before = function(cb){ cb(); };
}}, applink.app_link_platform_fallback.fallback_url, done);
app_link.before = function(cb){
app_link.fallbackUrl += "?a=b";
cb();
};
}}, applink.app_link_platform_fallback.fallback_url + "?a=b", done);
});
it("Modifies platform variables.", function(done) {
testApplinkRedirect({browser: "iPhone", inject: function() {
app_link.before = function(cb){
app_link.platforms.app_link_platform_iphone.app_url += "?a=b";
cb();
};
}}, applink.app_link_platform_iphone.app_url + "?a=b", done);
});
it("Should wait for async.", function(done) {
it("Wait for async.", function(done) {
testApplinkRedirect({inject: function() {
app_link.before = function(cb){ setTimeout(cb, 33); };
}}, applink.app_link_platform_fallback.fallback_url, done);
Expand Down

0 comments on commit a43dd7a

Please sign in to comment.