Skip to content

Commit

Permalink
Updated test cases
Browse files Browse the repository at this point in the history
Updated detect.html test cases to include IE
Added ie.html test cases to test for __proto__ requirement
Updated runner.coffee to include ie.html test cases
  • Loading branch information
Stefan Andres Charsley committed Sep 13, 2013
1 parent 81fce95 commit 5dc42ff
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 7 deletions.
6 changes: 0 additions & 6 deletions src/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@
playbook = ua.match(/PlayBook/),
chrome = ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/),
firefox = ua.match(/Firefox\/([\d.]+)/),
<<<<<<< HEAD
ie = ua.match(/MSIE ([\d.]+)/)
=======
safari = webkit && ua.match(/Mobile\//) && !chrome,
webview = ua.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/) && !chrome
>>>>>>> upstream/master

// Todo: clean this up with a better OS/browser seperation:
// - discern (more) between multiple browsers on android
Expand All @@ -50,12 +47,9 @@
if (!silk && os.android && ua.match(/Kindle Fire/)) browser.silk = true
if (chrome) browser.chrome = true, browser.version = chrome[1]
if (firefox) browser.firefox = true, browser.version = firefox[1]
<<<<<<< HEAD
if (ie) browser.ie = true, browser.verson = ie[1]
=======
if (safari && (ua.match(/Safari/) || !!os.ios)) browser.safari = true
if (webview) browser.webview = true
>>>>>>> upstream/master

os.tablet = !!(ipad || playbook || (android && !ua.match(/Mobile/)) || (firefox && ua.match(/Tablet/)))
os.phone = !!(!os.tablet && !os.ipod && (android || iphone || webos || blackberry || bb10 ||
Expand Down
8 changes: 8 additions & 0 deletions test/detect.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ <h1>Browser detection</h1>
Firefox_6_0_2: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:6.0.2) Gecko/20100101 Firefox/6.0.2",
Firefox_Mobile_Simulator: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:2.1.1) Gecko/ Firefox/4.0.2pre Fennec/4.0.1",

Windows_IE: "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)",
Windows_RT_Surface: "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; ARM; Trident/6.0; Touch)",
Windows_Phone_8: "Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; HTC; Windows Phone 8X by HTC)"
}
Expand Down Expand Up @@ -365,6 +366,13 @@ <h1>Browser detection</h1>
t.assertFalse(os.tablet)
t.assertTrue(browser.chrome)
})
},

testIE: function(t) {
detect(UA.Windows_IE, function(os, browser){
t.assertTrue(browser.ie)
t.assertEqual("10.0", browser.version)
})
}
})
})()
Expand Down
63 changes: 63 additions & 0 deletions test/ie.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="stylesheet" href="test.css">
<title>__proto__ requirement checking</title>
<script src="../vendor/evidence.js"></script>
<script src="evidence_runner.js"></script>
<script src="../src/ie.js"></script>
</head>
<body>
<h1>__proto__ requirement</h1>
<p id="results">
Running… see browser console for results
</p>

<script>
(function () {
Evidence('ZeptoDetectTest', {
testProtoExistance: function (t) {
var testObj = {}
t.assertFalse(testObj.__proto__ === undefined)
},

testProtoAssignment: function (t) {
var myProto = {
myFunc: function () {
return "hello "
},
myProperty: "world"
}

var testObj = {}
t.assertTrue(testObj.myFunc === undefined)
t.assertTrue(testObj.myProperty === undefined)

testObj.__proto__ = myProto

var testVar = testObj.myFunc()
t.assertEqual("hello ", testVar)

testVar += testObj.myProperty
t.assertEqual("hello world", testVar)
},

testProtoNesting: function (t) {
var myProto1 = { property1: "hello" }
var myProto2 = { property2: "world" }
var testObj = {}

myProto2.__proto__ = myProto1
t.assertEqual("hello", myProto2.property1)

testObj.__proto__ = myProto2
t.assertEqual("hello", testObj.property1)
t.assertEqual("world", testObj.property2)
}
})
})()
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion test/runner.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if args.length > 0
suites = args
else
# by default, run all test/*.html pages
modules = 'zepto ajax data detect event form fx selector stack'.split /\s+/
modules = 'ie zepto ajax data detect event form fx selector stack'.split /\s+/
suites = modules.map (name)-> "test/#{name}.html"

page = require('webpage').create()
Expand Down

0 comments on commit 5dc42ff

Please sign in to comment.