Skip to content

Commit

Permalink
Do feature detection instead of browser detection for ui test.
Browse files Browse the repository at this point in the history
The previous `isIE()` check returned false for IE11.
  • Loading branch information
Emily Stark committed Jun 22, 2014
1 parent 69455d4 commit 2b87aa1
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/ui/render_tests.js
Expand Up @@ -15,11 +15,6 @@ var HR = HTML.HR;
var TEXTAREA = HTML.TEXTAREA;
var INPUT = HTML.INPUT;

var isIE = function () {
var myNav = navigator.userAgent.toLowerCase();
return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1]) : false;
};

Tinytest.add("ui - render - basic", function (test) {
var run = function (input, expectedInnerHTML, expectedHTML, expectedCode) {
var div = document.createElement("DIV");
Expand Down Expand Up @@ -209,6 +204,15 @@ Tinytest.add("ui - render - closures", function (test) {

});

// IE strips malformed styles like "bar::d" from the `style`
// attribute. We detect this to adjust expectations for the StyleHandler
// test below.
var malformedStylesAllowed = function () {
var div = document.createElement("div");
div.setAttribute("style", "bar::d;");
return (div.getAttribute("style") === "bar::d;");
};

Tinytest.add("ui - render - closure GC", function (test) {
// test that removing parent element removes listeners and stops autoruns.
(function () {
Expand Down Expand Up @@ -331,11 +335,14 @@ Tinytest.add("ui - render - reactive attributes", function (test) {
Deps.flush();
test.equal(canonicalizeHtml(div.innerHTML), '<span style="foo: c"></span>');

// test malformed styles - different expectations in IE from Chrome
// test malformed styles - different expectations in IE (which
// strips malformed styles) from other browsers
R.set({'style': 'foo: a; bar::d;:e; baz: c;'});
Deps.flush();
test.equal(canonicalizeHtml(div.innerHTML),
isIE() ? '<span style="foo: a; baz: c"></span>' : '<span style="foo: a; bar::d; baz: c"></span>');
malformedStylesAllowed() ?
'<span style="foo: a; bar::d; baz: c"></span>' :
'<span style="foo: a; baz: c"></span>');

// Test strange styles
R.set({'style': ' foo: c; constructor: a; __proto__: b;'});
Expand Down

1 comment on commit 2b87aa1

@avital
Copy link
Contributor

@avital avital commented on 2b87aa1 Jun 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for doing this. (cc @arbesfeld, browser detection is evil)

Please sign in to comment.