forked from jquery-archive/jquery-mobile
/
support_core.js
94 lines (74 loc) · 2.65 KB
/
support_core.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* mobile support unit tests
*/
$.testHelper.excludeFileProtocol(function(){
var prependToFn = $.fn.prependTo,
libName = "jquery.mobile.support.js";
module(libName, {
teardown: function(){
//NOTE undo any mocking
$.fn.prependTo = prependToFn;
}
});
// 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
});
document.ontouchend = true;
window.history.pushState = function(){};
window.history.replaceState = function(){};
$.mobile.media = function(){ return true; };
$.testHelper.reloadLib(libName);
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"];
$.testHelper.reloadLib(libName);
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/");
$.testHelper.reloadLib(libName);
ok($.support.dynamicBaseTag);
});
test( "detects no dynamic base tag when new base element added and base href unchanged", function(){
mockBaseCheck('testurl');
$.testHelper.reloadLib(libName);
ok(!$.support.dynamicBaseTag);
});
test( "jQM's IE browser check properly detects IE versions", function(){
$.testHelper.reloadLib(libName);
//here we're just comparing our version to what the conditional compilation finds
var ie = !!$.browser.msie, //get a boolean
version = parseInt( $.browser.version, 10),
jqmdetectedver = $.mobile.browser.ie;
if( ie ){
same(version, jqmdetectedver, "It's IE and the version is correct");
}
else{
same(ie, jqmdetectedver, "It's not IE");
}
});
//TODO propExists testing, refactor propExists into mockable method
//TODO scrollTop testing, refactor scrollTop logic into mockable method
});