michael@0: /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: 'use strict'; michael@0: michael@0: const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; michael@0: michael@0: Cu.import('resource://gre/modules/XPCOMUtils.jsm'); michael@0: Cu.import('resource://gre/modules/Services.jsm'); michael@0: Cu.import('resource://testing-common/httpd.js'); michael@0: michael@0: XPCOMUtils.defineLazyServiceGetter(this, 'gCaptivePortalDetector', michael@0: '@mozilla.org/toolkit/captive-detector;1', michael@0: 'nsICaptivePortalDetector'); michael@0: michael@0: const kCanonicalSitePath = '/canonicalSite.html'; michael@0: const kCanonicalSiteContent = 'true'; michael@0: const kPrefsCanonicalURL = 'captivedetect.canonicalURL'; michael@0: const kPrefsCanonicalContent = 'captivedetect.canonicalContent'; michael@0: const kPrefsMaxWaitingTime = 'captivedetect.maxWaitingTime'; michael@0: const kPrefsPollingTime = 'captivedetect.pollingTime'; michael@0: michael@0: var gServer; michael@0: var gServerURL; michael@0: michael@0: function setupPrefs() { michael@0: let prefs = Components.classes["@mozilla.org/preferences-service;1"] michael@0: .getService(Components.interfaces.nsIPrefService) michael@0: .QueryInterface(Components.interfaces.nsIPrefBranch); michael@0: prefs.setCharPref(kPrefsCanonicalURL, gServerURL + kCanonicalSitePath); michael@0: prefs.setCharPref(kPrefsCanonicalContent, kCanonicalSiteContent); michael@0: prefs.setIntPref(kPrefsMaxWaitingTime, 0); michael@0: prefs.setIntPref(kPrefsPollingTime, 1); michael@0: } michael@0: michael@0: function run_captivedetect_test(xhr_handler, fakeUIResponse, testfun) michael@0: { michael@0: gServer = new HttpServer(); michael@0: gServer.registerPathHandler(kCanonicalSitePath, xhr_handler); michael@0: gServer.start(-1); michael@0: gServerURL = 'http://localhost:' + gServer.identity.primaryPort; michael@0: michael@0: setupPrefs(); michael@0: michael@0: fakeUIResponse(); michael@0: michael@0: testfun(); michael@0: }