Bug 942470 - Don't apply user agent update if updates have been disabled. r=fabrice
authorJim Chen <nchen@mozilla.com>
Fri, 06 Dec 2013 10:22:18 -0500
changeset 174852 906f5a72000038420ef7a7854569a1e6457dfb6d
parent 174851 c149ae799213aa893269dd04396047ec66e2eb7a
child 174853 013d080dbc299471934d0252d3dd45d7188b2376
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice
bugs942470
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 942470 - Don't apply user agent update if updates have been disabled. r=fabrice
netwerk/protocol/http/UserAgentUpdates.jsm
netwerk/test/mochitests/mochitest.ini
netwerk/test/mochitests/test_user_agent_updates_reset.html
--- a/netwerk/protocol/http/UserAgentUpdates.jsm
+++ b/netwerk/protocol/http/UserAgentUpdates.jsm
@@ -75,17 +75,22 @@ this.UserAgentUpdates = {
     if (!gInitialized) {
       return;
     }
     gInitialized = false;
     Services.prefs.removeObserver(PREF_UPDATES, this);
   },
 
   _applyUpdate: function(update) {
-    this._callback(update);
+    // Check pref again in case it has changed
+    if (update && this._getPref(PREF_UPDATES_ENABLED, false)) {
+      this._callback(update);
+    } else {
+      this._callback(null);
+    }
   },
 
   _applySavedUpdate: function() {
     if (!this._getPref(PREF_UPDATES_ENABLED, false)) {
       // remove previous overrides
       this._applyUpdate(null);
       return;
     }
--- a/netwerk/test/mochitests/mochitest.ini
+++ b/netwerk/test/mochitests/mochitest.ini
@@ -1,11 +1,10 @@
 [DEFAULT]
 support-files =
   partial_content.sjs
   user_agent.sjs
   user_agent_update.sjs
 
 [test_partially_cached_content.html]
 [test_user_agent_overrides.html]
-skip-if = true # bug 942470, intermittently fails to unset overrides
 [test_user_agent_updates.html]
-skip-if = true # bug 942470, intermittently fails to unset overrides
+[test_user_agent_updates_reset.html]
new file mode 100644
--- /dev/null
+++ b/netwerk/test/mochitests/test_user_agent_updates_reset.html
@@ -0,0 +1,44 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=942470
+-->
+<head>
+  <title>Test for Bug 942470</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=942470">Mozilla Bug 942470</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+/** Test for Bug 942470 **/
+
+function getUA(host) {
+  var url = location.pathname;
+  url = host + url.slice(0, url.lastIndexOf('/')) + '/user_agent.sjs';
+
+  var xhr = new XMLHttpRequest();
+  xhr.open('GET', url, false); // sync request
+  xhr.send();
+  is(xhr.status, 200, 'request failed');
+  is(typeof xhr.response, 'string', 'invalid response');
+  return xhr.response;
+}
+
+const UA_OVERRIDE = "DummyUserAgent";
+
+info("User agent is " + navigator.userAgent);
+isnot(navigator.userAgent, UA_OVERRIDE,
+  "navigator.userAgent is not reverted");
+isnot(getUA(location.origin), UA_OVERRIDE,
+  "User-Agent is not reverted");
+
+</script>
+</pre>
+</body>
+</html>