B2G/gecko/browser/components/preferences/in-content/tests/browser_connection.js
// run a bunch of tests on the window containing connection.xul
run a bunch of tests on the window containing connection.xul
run a bunch of tests on the window containing connection . xul
function runConnectionTests(win) {
  let doc = win.document;
  let networkProxyNone = doc.getElementById("networkProxyNone");
  let networkProxyNonePref = doc.getElementById("network.proxy.no_proxies_on");
  let networkProxyTypePref = doc.getElementById("network.proxy.type");
  is(networkProxyNone.getAttribute("multiline"), "true",
     "networkProxyNone textbox is multiline");
  is(networkProxyNone.getAttribute("rows"), "2",
     "networkProxyNone textbox has two rows");
  function testSanitize(input, expected, errorMessage) {
    networkProxyNonePref.value = input;
    win.gConnectionsDialog.sanitizeNoProxiesPref();
    is(networkProxyNonePref.value, expected, errorMessage);
  }
  networkProxyTypePref.value = 1;
  is(networkProxyNone.disabled, false, "networkProxyNone textbox is enabled");
  testSanitize(".a.com", ".a.com",
               "sanitize doesn't mess up single filter");
  testSanitize(".a.com, .b.com, .c.com", ".a.com, .b.com, .c.com",
               "sanitize doesn't mess up multiple comma/space sep filters");
  testSanitize(".a.com\n.b.com", ".a.com,.b.com",
               "sanitize turns line break into comma");
  testSanitize(".a.com,\n.b.com", ".a.com,.b.com",
               "sanitize doesn't add duplicate comma after comma");
  testSanitize(".a.com\n,.b.com", ".a.com,.b.com",
               "sanitize doesn't add duplicate comma before comma");
  testSanitize(".a.com,\n,.b.com", ".a.com,,.b.com",
               "sanitize doesn't add duplicate comma surrounded by commas");
  testSanitize(".a.com, \n.b.com", ".a.com, .b.com",
               "sanitize doesn't add comma after comma/space");
  testSanitize(".a.com\n .b.com", ".a.com, .b.com",
               "sanitize adds comma before space");
  testSanitize(".a.com\n\n\n;;\n;\n.b.com", ".a.com,.b.com",
               "sanitize only adds one comma per substring of bad chars");
  testSanitize(".a.com,,.b.com", ".a.com,,.b.com",
               "duplicate commas from user are untouched");
  testSanitize(".a.com\n.b.com\n.c.com,\n.d.com,\n.e.com",
               ".a.com,.b.com,.c.com,.d.com,.e.com",
               "sanitize replaces things globally");
  networkProxyNonePref.value = ".a.com;.b.com\n.c.com";
}
function runConnectionTests ( win ) { let doc = win . document ; let networkProxyNone = doc . getElementById ( "networkProxyNone" ) ; let networkProxyNonePref = doc . getElementById ( "network.proxy.no_proxies_on" ) ; let networkProxyTypePref = doc . getElementById ( "network.proxy.type" ) ; is ( networkProxyNone . getAttribute ( "multiline" ) , "true" , "networkProxyNone textbox is multiline" ) ; is ( networkProxyNone . getAttribute ( "rows" ) , "2" , "networkProxyNone textbox has two rows" ) ; function testSanitize ( input , expected , errorMessage ) { networkProxyNonePref . value = input ; win . gConnectionsDialog . sanitizeNoProxiesPref ( ) ; is ( networkProxyNonePref . value , expected , errorMessage ) ; } networkProxyTypePref . value = 1 ; is ( networkProxyNone . disabled , false , "networkProxyNone textbox is enabled" ) ; testSanitize ( ".a.com" , ".a.com" , "sanitize doesn't mess up single filter" ) ; testSanitize ( ".a.com, .b.com, .c.com" , ".a.com, .b.com, .c.com" , "sanitize doesn't mess up multiple comma/space sep filters" ) ; testSanitize ( ".a.com\n.b.com" , ".a.com,.b.com" , "sanitize turns line break into comma" ) ; testSanitize ( ".a.com,\n.b.com" , ".a.com,.b.com" , "sanitize doesn't add duplicate comma after comma" ) ; testSanitize ( ".a.com\n,.b.com" , ".a.com,.b.com" , "sanitize doesn't add duplicate comma before comma" ) ; testSanitize ( ".a.com,\n,.b.com" , ".a.com,,.b.com" , "sanitize doesn't add duplicate comma surrounded by commas" ) ; testSanitize ( ".a.com, \n.b.com" , ".a.com, .b.com" , "sanitize doesn't add comma after comma/space" ) ; testSanitize ( ".a.com\n .b.com" , ".a.com, .b.com" , "sanitize adds comma before space" ) ; testSanitize ( ".a.com\n\n\n;;\n;\n.b.com" , ".a.com,.b.com" , "sanitize only adds one comma per substring of bad chars" ) ; testSanitize ( ".a.com,,.b.com" , ".a.com,,.b.com" , "duplicate commas from user are untouched" ) ; testSanitize ( ".a.com\n.b.com\n.c.com,\n.d.com,\n.e.com" , ".a.com,.b.com,.c.com,.d.com,.e.com" , "sanitize replaces things globally" ) ; networkProxyNonePref . value = ".a.com;.b.com\n.c.com" ; }
run a bunch of tests on the window containing connection.xul
run a bunch of tests on the window containing connection . xul
// make sure the networkProxyNone textbox is formatted properly // check if sanitizing the given input for the no_proxies_on pref results in // expected string // change this pref so proxy exceptions are actually configurable // will check that this was sanitized properly after window closes