|
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 'use strict'; |
|
6 |
|
7 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; |
|
8 |
|
9 Cu.import('resource://gre/modules/XPCOMUtils.jsm'); |
|
10 Cu.import('resource://gre/modules/Services.jsm'); |
|
11 Cu.import('resource://testing-common/httpd.js'); |
|
12 |
|
13 XPCOMUtils.defineLazyServiceGetter(this, 'gCaptivePortalDetector', |
|
14 '@mozilla.org/toolkit/captive-detector;1', |
|
15 'nsICaptivePortalDetector'); |
|
16 |
|
17 const kCanonicalSitePath = '/canonicalSite.html'; |
|
18 const kCanonicalSiteContent = 'true'; |
|
19 const kPrefsCanonicalURL = 'captivedetect.canonicalURL'; |
|
20 const kPrefsCanonicalContent = 'captivedetect.canonicalContent'; |
|
21 const kPrefsMaxWaitingTime = 'captivedetect.maxWaitingTime'; |
|
22 const kPrefsPollingTime = 'captivedetect.pollingTime'; |
|
23 |
|
24 var gServer; |
|
25 var gServerURL; |
|
26 |
|
27 function setupPrefs() { |
|
28 let prefs = Components.classes["@mozilla.org/preferences-service;1"] |
|
29 .getService(Components.interfaces.nsIPrefService) |
|
30 .QueryInterface(Components.interfaces.nsIPrefBranch); |
|
31 prefs.setCharPref(kPrefsCanonicalURL, gServerURL + kCanonicalSitePath); |
|
32 prefs.setCharPref(kPrefsCanonicalContent, kCanonicalSiteContent); |
|
33 prefs.setIntPref(kPrefsMaxWaitingTime, 0); |
|
34 prefs.setIntPref(kPrefsPollingTime, 1); |
|
35 } |
|
36 |
|
37 function run_captivedetect_test(xhr_handler, fakeUIResponse, testfun) |
|
38 { |
|
39 gServer = new HttpServer(); |
|
40 gServer.registerPathHandler(kCanonicalSitePath, xhr_handler); |
|
41 gServer.start(-1); |
|
42 gServerURL = 'http://localhost:' + gServer.identity.primaryPort; |
|
43 |
|
44 setupPrefs(); |
|
45 |
|
46 fakeUIResponse(); |
|
47 |
|
48 testfun(); |
|
49 } |