diff --git a/tests/unit/media/index.html b/tests/unit/media/index.html index 846add95..920d80a2 100644 --- a/tests/unit/media/index.html +++ b/tests/unit/media/index.html @@ -23,13 +23,6 @@
- -
-
-
...
-
-
-
diff --git a/tests/unit/support/index.html b/tests/unit/support/index.html index 14f1d8c2..bac2a0cb 100644 --- a/tests/unit/support/index.html +++ b/tests/unit/support/index.html @@ -24,13 +24,6 @@
- -
-
-
...
-
-
-
diff --git a/tests/unit/support/support_core.js b/tests/unit/support/support_core.js index 1e984411..e41350db 100644 --- a/tests/unit/support/support_core.js +++ b/tests/unit/support/support_core.js @@ -1,36 +1,88 @@ /* * mobile support unit tests */ + (function( $ ) { - var reloadLib = function(){ - $("script[src$=support.js]").appendTo("body"); - }; + //NOTE alert tester that running the file locally will not work for these tests + if ( location.protocol == "file:" ) { + var message = "Tests require script reload and cannot be run via file: protocol"; - module("mobile.support", { - teardown: function(){ - $("body script[src$=support.js]").remove(); - } - }); + test(message, function(){ + ok(false, message); + }); + } else { + var reloadCount = 0, + lib = $("script[src$=support.js]"), + src = lib.attr('src'), + reloadLib = function(){ + //NOTE append "cache breaker" to force reload + lib.attr('src', src + "?" + reloadCount++); + $("body").append(lib); + }, + prependToFn = $.fn.prependTo; - // NOTE test has debatable value, only prevents property name changes - // and improper sources for attribute checks - test( "detects functionality from basic properties and attributes", function(){ - // TODO expose properties for less brittle tests - $.extend(window, { - orientation: true, - WebKitTransitionEvent: true + module("mobile.support", { + teardown: function(){ + //NOTE undo any mocking + $.fn.prependTo = prependToFn; + } }); - document["ontouchend"] = true; - history.pushState = function(){}; - $.mobile.media = function(){ return true; }; + // NOTE following two tests have debatable value as they only + // prevent property name changes and improper attribute checks + test( "detects functionality from basic affirmative properties and attributes", function(){ + // TODO expose properties for less brittle tests + $.extend(window, { + WebKitTransitionEvent: true, + orientation: true + }); - reloadLib(); + document.ontouchend = true; - ok($.support.orientation); - ok($.support.cssTransitions); - ok($.support.touch); - ok($.support.pushState); - ok($.support.mediaquery); - }); + history.pushState = function(){}; + $.mobile.media = function(){ return true; }; + + reloadLib(); + + ok($.support.orientation); + ok($.support.touch); + ok($.support.cssTransitions); + ok($.support.pushState); + ok($.support.mediaquery); + }); + + test( "detects functionality from basic negative properties and attributes (where possible)", function(){ + delete window["orientation"]; + delete document["ontouchend"]; + + reloadLib(); + + ok(!$.support.orientation); + ok(!$.support.touch); + }); + + // NOTE mocks prependTo to simulate base href updates or lack thereof + var mockBaseCheck = function( url ){ + var prependToFn = $.fn.prependTo; + + $.fn.prependTo = function( selector ){ + var result = prependToFn.call($(this), selector); + if(this[0].href && this[0].href.indexOf("testurl") != -1) + result = [{href: url}]; + return result; + }; + }; + + test( "detects dynamic base tag when new base element added and base href updates", function(){ + mockBaseCheck(location.protocol + '//' + location.host + location.pathname + "ui-dir/"); + reloadLib(); + ok($.support.dynamicBaseTag); + }); + + test( "detects no dynamic base tag when new base element added and base href unchanged", function(){ + mockBaseCheck('testurl'); + reloadLib(); + ok(!$.support.dynamicBaseTag); + }); + } })(jQuery); \ No newline at end of file