r81128 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81127‎ | r81128 | r81129 >
Date:12:51, 28 January 2011
Author:reedy
Status:reverted (Comments)
Tags:
Comment:
Tests for WikimediaMobile Redirect JS and a tweak requested by Google

Adding in a test suite to check that our Regex matchers for UserAgents
are acting correctly.

Also, modified the way we are testing for Android to only respond when the
word "Mobile" is included. This was requested by the Android team.


Commiting on behalf of hcatlin
Modified paths:
  • /trunk/extensions/WikimediaMobile/MobileRedirect.js (modified) (history)
  • /trunk/extensions/WikimediaMobile/tests (added) (history)
  • /trunk/extensions/WikimediaMobile/tests/user_agent.js (added) (history)

Diff [purge]

Index: trunk/extensions/WikimediaMobile/tests/user_agent.js
@@ -0,0 +1,50 @@
 2+/*
 3+ User Agent Tests
 4+
 5+ This is an incomplete test set. As you hit issues, please add strings that
 6+ may be problematic.
 7+
 8+ Written by Hampton Catlin
 9+*/
 10+
 11+var regex = /(Mobile.*Safari|webOS|NetFront|Opera Mini|SEMC-Browser|PlayStation Portable|Nintendo Wii|BlackBerry)/;
 12+
 13+var runTests = function() {
 14+ // iPhone
 15+ shouldRedirect("Mozilla/5.0 (iPhone; U; CPU iPhone OS 2_2 like Mac OS X; en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5G77 Safari/525.20");
 16+ // Android on HTC Desire
 17+ shouldRedirect("Mozilla/5.0 (Linux; U; Android 2.1-update1; de-de; HTC Desire 1.19.161.5 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17");
 18+ // Nintendo Wii
 19+ shouldRedirect("Opera/9.30 (Nintendo Wii; U; ; 2047-7;pt-br)");
 20+ // Netfront PDA
 21+ shouldRedirect("Mozilla/5.0 (PDA; NF35WMPRO/1.0; like Gecko) NetFront/3.5");
 22+ // Palm Pre
 23+ shouldRedirect("Mozilla/5.0 (webOS/1.0; U; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1 Pre/1.0");
 24+ // Safari on Mac OS X
 25+ shouldIgnore("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; en-us) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4");
 26+ // Chrome on OS X
 27+ shouldIgnore("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.237 Safari/534.10");
 28+}
 29+
 30+var doesMatch = function(user_agent) {
 31+ return regex.test(user_agent);
 32+}
 33+
 34+var runTest = function(user_agent, should_be) {
 35+ var result = doesMatch(user_agent);
 36+ if(result == should_be) {
 37+ print("OK")
 38+ } else {
 39+ print("FAIL: '" + user_agent + "'")
 40+ }
 41+}
 42+
 43+var shouldRedirect = function(user_agent) {
 44+ runTest(user_agent, true);
 45+}
 46+
 47+var shouldIgnore = function(user_agent) {
 48+ runTest(user_agent, false);
 49+}
 50+
 51+runTests();
Property changes on: trunk/extensions/WikimediaMobile/tests/user_agent.js
___________________________________________________________________
Added: svn:eol-style
152 + native
Index: trunk/extensions/WikimediaMobile/MobileRedirect.js
@@ -5,7 +5,7 @@
66 *
77 * You can turn off the redirect by setting the cookie "stopMobileRedirect=true"
88 */
9 -if ( /(Android|iPhone|iPod|webOS|NetFront|Opera Mini|SEMC-Browser|PlayStation Portable|Nintendo Wii|BlackBerry)/
 9+if ( /(Mobile.*Safari|webOS|NetFront|Opera Mini|SEMC-Browser|PlayStation Portable|Nintendo Wii|BlackBerry)/
1010 .test( navigator.userAgent ) )
1111 {
1212 (function () {

Follow-up revisions

RevisionCommit summaryAuthorDate
r81700Fix bug 27238: revert the rest of r81128 (tests were already removed): change...brion08:29, 8 February 2011

Comments

#Comment by Tfinc (talk | contribs)   09:28, 2 February 2011

If we were only changing the Android redirect what made us also drop iPhone|iPod ?

#Comment by Reedy (talk | contribs)   09:47, 2 February 2011

No idea, you'll need to poke Hampton (as he won't get notification of this) - I was just committing it on his behalf

#Comment by Brion VIBBER (talk | contribs)   08:18, 8 February 2011

broke iPad, now goes to mobile site which really sucks on a full tablet: bugzilla:27238

Status & tagging log