1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/captivedetect/test/unit/head_setprefs.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,49 @@ 1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.7 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 +'use strict'; 1.9 + 1.10 +const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; 1.11 + 1.12 +Cu.import('resource://gre/modules/XPCOMUtils.jsm'); 1.13 +Cu.import('resource://gre/modules/Services.jsm'); 1.14 +Cu.import('resource://testing-common/httpd.js'); 1.15 + 1.16 +XPCOMUtils.defineLazyServiceGetter(this, 'gCaptivePortalDetector', 1.17 + '@mozilla.org/toolkit/captive-detector;1', 1.18 + 'nsICaptivePortalDetector'); 1.19 + 1.20 +const kCanonicalSitePath = '/canonicalSite.html'; 1.21 +const kCanonicalSiteContent = 'true'; 1.22 +const kPrefsCanonicalURL = 'captivedetect.canonicalURL'; 1.23 +const kPrefsCanonicalContent = 'captivedetect.canonicalContent'; 1.24 +const kPrefsMaxWaitingTime = 'captivedetect.maxWaitingTime'; 1.25 +const kPrefsPollingTime = 'captivedetect.pollingTime'; 1.26 + 1.27 +var gServer; 1.28 +var gServerURL; 1.29 + 1.30 +function setupPrefs() { 1.31 + let prefs = Components.classes["@mozilla.org/preferences-service;1"] 1.32 + .getService(Components.interfaces.nsIPrefService) 1.33 + .QueryInterface(Components.interfaces.nsIPrefBranch); 1.34 + prefs.setCharPref(kPrefsCanonicalURL, gServerURL + kCanonicalSitePath); 1.35 + prefs.setCharPref(kPrefsCanonicalContent, kCanonicalSiteContent); 1.36 + prefs.setIntPref(kPrefsMaxWaitingTime, 0); 1.37 + prefs.setIntPref(kPrefsPollingTime, 1); 1.38 +} 1.39 + 1.40 +function run_captivedetect_test(xhr_handler, fakeUIResponse, testfun) 1.41 +{ 1.42 + gServer = new HttpServer(); 1.43 + gServer.registerPathHandler(kCanonicalSitePath, xhr_handler); 1.44 + gServer.start(-1); 1.45 + gServerURL = 'http://localhost:' + gServer.identity.primaryPort; 1.46 + 1.47 + setupPrefs(); 1.48 + 1.49 + fakeUIResponse(); 1.50 + 1.51 + testfun(); 1.52 +}