mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 00:05:36 +00:00
Bug 1066506 Allow easy debugging of websockets and sdk for Loop. r=nperriault
This commit is contained in:
parent
73af853a25
commit
f45b0af958
@ -1613,6 +1613,7 @@ pref("loop.retry_delay.limit", 300000);
|
||||
pref("loop.feedback.baseUrl", "https://input.mozilla.org/api/v1/feedback");
|
||||
pref("loop.feedback.product", "Loop");
|
||||
pref("loop.debug.websocket", false);
|
||||
pref("loop.debug.sdk", false);
|
||||
|
||||
// serverURL to be assigned by services team
|
||||
pref("services.push.serverURL", "wss://push.services.mozilla.com/");
|
||||
|
@ -68,6 +68,12 @@ loop.shared.models = (function(l10n) {
|
||||
throw new Error("missing required 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);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -29,7 +29,25 @@ loop.shared.utils = (function() {
|
||||
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 {
|
||||
getTargetPlatform: getTargetPlatform
|
||||
getTargetPlatform: getTargetPlatform,
|
||||
getBoolPreference: getBoolPreference
|
||||
};
|
||||
})();
|
||||
|
@ -36,11 +36,10 @@ loop.CallConnectionWebSocket = (function() {
|
||||
throw new Error("No websocketToken in options");
|
||||
}
|
||||
|
||||
// Save the debug pref now, to avoid getting it each time.
|
||||
if (navigator.mozLoop) {
|
||||
this._debugWebSocket =
|
||||
navigator.mozLoop.getLoopBoolPref("debug.websocket");
|
||||
}
|
||||
// Set loop.debug.sdk to true in the browser, or standalone:
|
||||
// localStorage.setItem("debug.websocket", true);
|
||||
this._debugWebSocket =
|
||||
loop.shared.utils.getBoolPreference("debug.websocket");
|
||||
|
||||
_.extend(this, Backbone.Events);
|
||||
};
|
||||
|
@ -33,6 +33,7 @@
|
||||
</script>
|
||||
|
||||
<!-- App scripts -->
|
||||
<script src="../../content/shared/js/utils.js"></script>
|
||||
<script src="../../content/shared/js/models.js"></script>
|
||||
<script src="../../content/shared/js/mixins.js"></script>
|
||||
<script src="../../content/shared/js/views.js"></script>
|
||||
@ -43,6 +44,7 @@
|
||||
<!-- Test scripts -->
|
||||
<script src="models_test.js"></script>
|
||||
<script src="mixins_test.js"></script>
|
||||
<script src="utils_test.js"></script>
|
||||
<script src="views_test.js"></script>
|
||||
<script src="router_test.js"></script>
|
||||
<script src="websocket_test.js"></script>
|
||||
|
58
browser/components/loop/test/shared/utils_test.js
Normal file
58
browser/components/loop/test/shared/utils_test.js
Normal 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user