Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: chrome/content/tests/notification.js

Issue 11193004: Use mock XMLHttpRequest object to speed up tests (Closed)
Patch Set: Created July 25, 2013, 1:58 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/content/common.js ('k') | chrome/content/tests/synchronizer.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/content/tests/notification.js
===================================================================
--- a/chrome/content/tests/notification.js
+++ b/chrome/content/tests/notification.js
@@ -1,12 +1,11 @@
(function()
{
let testRunner = null;
- let server = null;
let randomResult = 0.5;
let originalInfo;
let info = require("info");
module("Notification handling",
{
setup: function()
@@ -14,52 +13,44 @@
testRunner = this;
preparePrefs.call(this);
setupVirtualTime.call(this, function(wrapTimer)
{
let NotificationModule = getModuleGlobal("notification");
NotificationModule.downloader._timer = wrapTimer(NotificationModule.downloader._timer);
}, "notification", "downloader");
-
- server = new nsHttpServer();
- server.start(1234);
+ setupVirtualXMLHttp.call(this, "notification", "downloader");
originalInfo = {};
for (let key in info)
originalInfo[key] = info[key];
info.addonName = "adblockpluschrome";
info.addonVersion = "1.4.1";
info.application = "chrome";
info.applicationVersion = "27.0";
info.platform = "chromium";
info.platformVersion = "12.0";
- Prefs.notificationurl = "http://127.0.0.1:1234/notification.json";
+ Prefs.notificationurl = "http://example.com/notification.json";
Prefs.notificationdata = {};
// Replace Math.random() function
let DownloaderGlobal = Cu.getGlobalForObject(getModuleGlobal("downloader"));
this._origRandom = DownloaderGlobal.Math.random;
DownloaderGlobal.Math.random = function() randomResult;
randomResult = 0.5;
},
teardown: function()
{
restorePrefs.call(this);
restoreVirtualTime.call(this);
-
- stop();
- server.stop(function()
- {
- server = null;
- start();
- });
+ restoreVirtualXMLHttp.call(this);
for (let key in originalInfo)
info[key] = originalInfo[key];
if (this._origRandom)
{
let DownloaderGlobal = Cu.getGlobalForObject(getModuleGlobal("downloader"));
DownloaderGlobal.Math.random = this._origRandom;
@@ -67,28 +58,24 @@
}
Notification.init();
}
});
function registerHandler(notifications)
{
- server.registerPathHandler("/notification.json", function(metadata, response)
+ testRunner.registerHandler("/notification.json", function(metadata)
{
- response.setStatusLine("1.1", "200", "OK");
- response.setHeader("Content-Type", "application/json");
-
let notification = {
version: 55,
notifications: notifications
};
- let result = JSON.stringify(notification);
- response.bodyOutputStream.write(result, result.length);
+ return [Cr.NS_OK, 200, JSON.stringify(notification)];
});
}
function fixConstructors(object)
{
// deepEqual() expects that the constructors used in expected objects and
// the ones in the actual results are the same. That means that we actually
// have to construct our objects in the context of the notification module.
« no previous file with comments | « chrome/content/common.js ('k') | chrome/content/tests/synchronizer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld