From 7660fd3060f7d6b769eaeb147ded8bc9a3600952 Mon Sep 17 00:00:00 2001 From: Shane Tomlinson <stomlinson@mozilla.com> Date: Wed, 28 Mar 2012 12:57:54 +0100 Subject: [PATCH] Add the groundwork for browser specific "Enable Cookies" URLs. * Start with generic Firefox and iOS issue #1167 issue #1302 --- lib/static_resources.js | 1 + resources/static/shared/browser-support.js | 12 ++++++++- resources/static/shared/enable_cookies_url.js | 20 ++++++++++++++ resources/static/shared/error-messages.js | 5 +++- .../test/cases/shared/browser-support.js | 14 ++++++++++ .../test/cases/shared/enable_cookies_url.js | 26 +++++++++++++++++++ resources/views/test.ejs | 2 ++ 7 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 resources/static/shared/enable_cookies_url.js create mode 100644 resources/static/test/cases/shared/enable_cookies_url.js diff --git a/lib/static_resources.js b/lib/static_resources.js index 6ef48a3f3..0b25b8948 100644 --- a/lib/static_resources.js +++ b/lib/static_resources.js @@ -38,6 +38,7 @@ var common_js = [ '/shared/helpers.js', '/shared/screens.js', '/shared/browser-support.js', + '/shared/enable_cookies_url.js', '/shared/wait-messages.js', '/shared/error-messages.js', '/shared/error-display.js', diff --git a/resources/static/shared/browser-support.js b/resources/static/shared/browser-support.js index 59dde771c..c6832597a 100644 --- a/resources/static/shared/browser-support.js +++ b/resources/static/shared/browser-support.js @@ -62,6 +62,11 @@ BrowserID.BrowserSupport = (function() { return reason; } + function isIOS() { + var ua = nav.userAgent; + return ua.indexOf("like Mac OS X") > -1; + } + return { /** * Set the test environment. @@ -84,7 +89,12 @@ BrowserID.BrowserSupport = (function() { /** * IE version surfaced for crypto optimizations */ - getInternetExplorerVersion: getInternetExplorerVersion + getInternetExplorerVersion: getInternetExplorerVersion, + /** + * Check to see whether user is using iOS + * @method isIOS + */ + isIOS: isIOS }; }()); diff --git a/resources/static/shared/enable_cookies_url.js b/resources/static/shared/enable_cookies_url.js new file mode 100644 index 000000000..93fe04129 --- /dev/null +++ b/resources/static/shared/enable_cookies_url.js @@ -0,0 +1,20 @@ +/*global BrowserID: true, gettext: true*/ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +BrowserID.EnableCookiesURL = (function(){ + "use strict"; + + var bid = BrowserID, + bs = bid.BrowserSupport; + + function getURL() { + return bs.isIOS() ? + "https://support.mozilla.org/kb/how-enable-cookies-iphone" : + "http://support.mozilla.org/kb/Websites%20say%20cookies%20are%20blocked"; + } + + return { + getURL: getURL + }; +}()); diff --git a/resources/static/shared/error-messages.js b/resources/static/shared/error-messages.js index 3616066ba..48f122424 100644 --- a/resources/static/shared/error-messages.js +++ b/resources/static/shared/error-messages.js @@ -5,6 +5,8 @@ BrowserID.Errors = (function(){ "use strict"; + var enableCookiesURL = BrowserID.EnableCookiesURL.getURL(); + // NOTE: The majority of these strings do not have gettext because they are // not immediately user facing. These strings are used in the error dialog // and are only shown after the user clicks on "show more info" @@ -47,7 +49,8 @@ BrowserID.Errors = (function(){ cookiesDisabled: { title: gettext("BrowserID requires cookies"), - message: format(gettext("Please close this window, <a %s>enable cookies</a> and try again"), [" target='_blank' href='http://support.mozilla.org/en-US/kb/Websites%20say%20cookies%20are%20blocked'"]) + message: format(gettext("Please close this window, <a %s>enable cookies</a> and try again"), [" target='_blank' href='" + enableCookiesURL + "'"]) + }, cookiesEnabled: { diff --git a/resources/static/test/cases/shared/browser-support.js b/resources/static/test/cases/shared/browser-support.js index 61559345f..5acce790f 100644 --- a/resources/static/test/cases/shared/browser-support.js +++ b/resources/static/test/cases/shared/browser-support.js @@ -66,6 +66,20 @@ equal(support.isSupported(), true, "Firefox 7.01 is supported"); equal(typeof support.getNoSupportReason(), "undefined", "no reason, we are all good"); }); + + test("isIOS with userAgent that is not iOS - return false", function() { + stubNavigator.appName = "Netscape"; + stubNavigator.userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:14.0) Gecko/20120326 Firefox/14.0a1"; + + strictEqual(support.isIOS(), false, "false returned for Firefox userAgent"); + }); + + test("isIOS with userAgent that is iOS - return true", function() { + stubNavigator.userAgent = "Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5"; + + strictEqual(support.isIOS(), true, "true returned for iOS userAgent"); + }); + }()); diff --git a/resources/static/test/cases/shared/enable_cookies_url.js b/resources/static/test/cases/shared/enable_cookies_url.js new file mode 100644 index 000000000..fb48744f1 --- /dev/null +++ b/resources/static/test/cases/shared/enable_cookies_url.js @@ -0,0 +1,26 @@ +/*jshint browsers:true, forin: true, laxbreak: true */ +/*global test: true, start: true, module: true, ok: true, equal: true, BrowserID: true */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +(function() { + "use strict"; + + var bid = BrowserID, + testHelpers = bid.TestHelpers; + + module("/shared/enable_cookies_url", { + setup: function() { + testHelpers.setup(); + }, + + teardown: function() { + testHelpers.teardown(); + } + }); + + test("returns a URL", function() { + ok(bid.EnableCookiesURL.getURL(), "a URL is returned"); + }); +}()); + diff --git a/resources/views/test.ejs b/resources/views/test.ejs index 036d57740..ce0c52d74 100644 --- a/resources/views/test.ejs +++ b/resources/views/test.ejs @@ -91,6 +91,7 @@ <script src="/shared/helpers.js"></script> <script src="/shared/screens.js"></script> <script src="/shared/browser-support.js"></script> + <script src="/shared/enable_cookies_url.js"></script> <script src="/shared/wait-messages.js"></script> <script src="/shared/error-messages.js"></script> <script src="/shared/error-display.js"></script> @@ -143,6 +144,7 @@ <script src="cases/shared/tooltip.js"></script> <script src="cases/shared/error-display.js"></script> <script src="cases/shared/browser-support.js"></script> + <script src="cases/shared/enable_cookies_url.js"></script> <script src="cases/shared/validation.js"></script> <script src="cases/shared/storage.js"></script> <script src="cases/shared/xhr.js"></script> -- GitLab