Bug 1066506 Allow easy debugging of websockets and sdk for Loop. r=nperriault

This commit is contained in:
Mark Banner 2014-09-12 16:49:38 +01:00
parent 73af853a25
commit f45b0af958
6 changed files with 90 additions and 6 deletions

View File

@ -1613,6 +1613,7 @@ pref("loop.retry_delay.limit", 300000);
pref("loop.feedback.baseUrl", "https://input.mozilla.org/api/v1/feedback"); pref("loop.feedback.baseUrl", "https://input.mozilla.org/api/v1/feedback");
pref("loop.feedback.product", "Loop"); pref("loop.feedback.product", "Loop");
pref("loop.debug.websocket", false); pref("loop.debug.websocket", false);
pref("loop.debug.sdk", false);
// serverURL to be assigned by services team // serverURL to be assigned by services team
pref("services.push.serverURL", "wss://push.services.mozilla.com/"); pref("services.push.serverURL", "wss://push.services.mozilla.com/");

View File

@ -68,6 +68,12 @@ loop.shared.models = (function(l10n) {
throw new Error("missing required sdk"); throw new Error("missing required sdk");
} }
this.sdk = options.sdk; this.sdk = options.sdk;
// Set loop.debug.sdk to true in the browser, or standalone:
// localStorage.setItem("debug.sdk", true);
if (loop.shared.utils.getBoolPreference("debug.sdk")) {
this.sdk.setLogLevel(this.sdk.DEBUG);
}
}, },
/** /**

View File

@ -29,7 +29,25 @@ loop.shared.utils = (function() {
return platform; return platform;
} }
/**
* Used for getting a boolean preference. It will either use the browser preferences
* (if navigator.mozLoop is defined) or try to get them from localStorage.
*
* @param {String} prefName The name of the preference. Note that mozLoop adds
* 'loop.' to the start of the string.
*
* @return The value of the preference, or false if not available.
*/
function getBoolPreference(prefName) {
if (navigator.mozLoop) {
return !!navigator.mozLoop.getLoopBoolPref(prefName);
}
return !!localStorage.getItem(prefName);
}
return { return {
getTargetPlatform: getTargetPlatform getTargetPlatform: getTargetPlatform,
getBoolPreference: getBoolPreference
}; };
})(); })();

View File

@ -36,11 +36,10 @@ loop.CallConnectionWebSocket = (function() {
throw new Error("No websocketToken in options"); throw new Error("No websocketToken in options");
} }
// Save the debug pref now, to avoid getting it each time. // Set loop.debug.sdk to true in the browser, or standalone:
if (navigator.mozLoop) { // localStorage.setItem("debug.websocket", true);
this._debugWebSocket = this._debugWebSocket =
navigator.mozLoop.getLoopBoolPref("debug.websocket"); loop.shared.utils.getBoolPreference("debug.websocket");
}
_.extend(this, Backbone.Events); _.extend(this, Backbone.Events);
}; };

View File

@ -33,6 +33,7 @@
</script> </script>
<!-- App scripts --> <!-- App scripts -->
<script src="../../content/shared/js/utils.js"></script>
<script src="../../content/shared/js/models.js"></script> <script src="../../content/shared/js/models.js"></script>
<script src="../../content/shared/js/mixins.js"></script> <script src="../../content/shared/js/mixins.js"></script>
<script src="../../content/shared/js/views.js"></script> <script src="../../content/shared/js/views.js"></script>
@ -43,6 +44,7 @@
<!-- Test scripts --> <!-- Test scripts -->
<script src="models_test.js"></script> <script src="models_test.js"></script>
<script src="mixins_test.js"></script> <script src="mixins_test.js"></script>
<script src="utils_test.js"></script>
<script src="views_test.js"></script> <script src="views_test.js"></script>
<script src="router_test.js"></script> <script src="router_test.js"></script>
<script src="websocket_test.js"></script> <script src="websocket_test.js"></script>

View File

@ -0,0 +1,58 @@
/* 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/. */
/* global loop, sinon */
/* jshint newcap:false */
var expect = chai.expect;
describe("loop.shared.utils", function() {
"use strict";
var sandbox;
var sharedUtils = loop.shared.utils;
beforeEach(function() {
sandbox = sinon.sandbox.create();
});
afterEach(function() {
sandbox.restore();
});
describe("#getBoolPreference", function() {
afterEach(function() {
navigator.mozLoop = undefined;
localStorage.removeItem("test.true");
});
describe("mozLoop set", function() {
beforeEach(function() {
navigator.mozLoop = {
getLoopBoolPref: function(prefName) {
return prefName === "test.true";
}
};
});
it("should return the mozLoop preference", function() {
expect(sharedUtils.getBoolPreference("test.true")).eql(true);
});
it("should not use the localStorage value", function() {
localStorage.setItem("test.false", true);
expect(sharedUtils.getBoolPreference("test.false")).eql(false);
});
});
describe("mozLoop not set", function() {
it("should return the localStorage value", function() {
localStorage.setItem("test.true", true);
expect(sharedUtils.getBoolPreference("test.true")).eql(true);
});
});
});
});