Skip to content

Commit

Permalink
fixed tests broken by changing config, changed how the controller wor…
Browse files Browse the repository at this point in the history
…ks/instantiates/initializes
  • Loading branch information
Anthropohedron committed Apr 18, 2015
1 parent 45eeede commit a017ab8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
33 changes: 27 additions & 6 deletions lib/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"use strict";

var util = require("./util");
var Configuration = require("./config").Configuration;
var config = require("./config");
var Ci = require("chrome").Ci;

var topics = [
Expand All @@ -12,18 +12,17 @@ var topics = [
"http-on-examine-merged-response"
];

function Controller() {
function Observer() {
var me = this;
this.observerService = util.getService("observer-service",
"nsIObserverService");
topics.forEach(function(topic) {
me.observerService.addObserver(me, topic, false);
});
this.config = new Configuration();
this[" is valid "] = true;
}

Controller.prototype = {
Observer.prototype = {
observe: function(subject, topic) {
var httpChannel;
switch (topic) {
Expand Down Expand Up @@ -53,12 +52,34 @@ Controller.prototype = {
topics.forEach(function(topic) {
me.observerService.removeObserver(me, topic);
});
delete this.config;
delete this[" is valid "];
return true;
}

};

exports.Controller = Controller;
var observer;

if (require("sdk/system").staticArgs.supportMockXPCOM) {
exports.getObserver = function() { return observer; };
}

exports.initialize =
function initialize() {
if (observer && observer.isValid()) { return false; }
observer = new Observer();
return true;
};

exports.isValid =
function isValid() {
return !!(observer && observer.isValid());
};

exports.invalidate =
function invalidate() {
var result = observer && observer.invalidate();
observer = null;
return !!result;
};

10 changes: 4 additions & 6 deletions test/test-controller.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
var util = require("./util");
var Controller = require("./controller").Controller;
var controller = require("./controller");

exports["test controller lifecycle"] = function(assert) {
var controller = new Controller();
assert.ok(controller, "Created controller");
assert.ok(controller.initialize(), "Initialized controller");
assert.strictEqual(controller.isValid(), true,
"Controller is valid");
assert.strictEqual(controller.invalidate(), true,
Expand Down Expand Up @@ -66,10 +65,9 @@ MockObserverService.prototype = {
exports["test controller observes"] = function(assert) {
var mockObSrv = new MockObserverService(assert);
util.setMock("nsIObserverService", mockObSrv);
var controller = new Controller();
assert.ok(controller, "Created controller");
assert.ok(controller.initialize(), "Initialized controller");
mockObSrv.checkTopics("Controller subscribed to all expected topics");
mockObSrv.checkControllers(controller);
mockObSrv.checkControllers(controller.getObserver());
assert.strictEqual(controller.invalidate(), true,
"Controller invalidates");
mockObSrv.checkTopics("Controller unsubscribed from all expected topics");
Expand Down

0 comments on commit a017ab8

Please sign in to comment.