embedding/qa/jstests/nsIDocCharsetTest.txt
author roc+@cs.cmu.edu
Thu, 26 Jul 2007 02:47:43 -0700
changeset 4032 31b8a46f0c4c8fb0af384305ecb87881d571b464
parent 1 9b2a99adc05e53cd4010de512f50118594756650
permissions -rw-r--r--
Bug 387969. Use CSS 'text-rendering' property to control text quality. r=pavlov,r+sr=bzbarsky

<!-- ***** BEGIN LICENSE BLOCK *****
   - Version: MPL 1.1/GPL 2.0/LGPL 2.1
   -
   - The contents of this file are subject to the Mozilla Public License Version
   - 1.1 (the "License"); you may not use this file except in compliance with
   - the License. You may obtain a copy of the License at
   - http://www.mozilla.org/MPL/
   -
   - Software distributed under the License is distributed on an "AS IS" basis,
   - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
   - for the specific language governing rights and limitations under the
   - License.
   -
   - The Original Code is Mozilla Communicator Test Cases.
   -
   - The Initial Developer of the Original Code is Netscape Communications
   - Corp.  Portions created by Netscape Communications Corp. are
   - Copyright (C) 1999 Netscape Communications Corp.  All
   - Rights Reserved.
   -
   - Contributor(s):
   -   dsirnapalli@netscape.com.
   -
   - Alternatively, the contents of this file may be used under the terms of
   - either the GNU General Public License Version 2 or later (the "GPL"), or
   - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
   - in which case the provisions of the GPL or the LGPL are applicable instead
   - of those above. If you wish to allow use of your version of this file only
   - under the terms of either the GPL or the LGPL, and not to allow others to
   - use your version of this file under the terms of the MPL, indicate your
   - decision by deleting the provisions above and replace them with the notice
   - and other provisions required by the LGPL or the GPL. If you do not delete
   - the provisions above, a recipient may use your version of this file under
   - the terms of any one of the MPL, the GPL or the LGPL.
   -
   - ***** END LICENSE BLOCK ***** -->

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<title> nsIDocCharset Interface Test </title>
<!-- Descrpt: nsIDocCharset Interface Test Case
     Author: 
     Revs: 09.10.01 - Created
     Last Run On:10.23.01.
  -->
<head>

<!-- script below is ngdriverspecific  -->
<script type="text/javascript" src="http://bubblegum/ngdriver/suites/testlib.js">
</script>

<script type="text/javascript">

function getnsIDOMWindow()
{
  try
  {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    var domobject = window.QueryInterface(Components.interfaces.nsIDOMWindow);
  }
  catch(e) {
    dump ("\nError getting nsIDOMWindow\n");
  }
  return domobject;
}

function getdocCharset()
{
  try
  {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    // You get nsIDocCharset by GI' ing off nsIDOMWindow.
    // nsIDOMWindow doesnot implement getInterface directly. So you need to QI first.
    var charsetObj = domWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                              .getInterface(Components.interfaces.nsIDocCharset);
    return(charsetObj);
  }
  catch(e) {
    dump ("\nError getting nsIDocCharset\n");
  }
}

function constructResult(initialcharset, charset)
{
  var results = "";

  initialcharsetvalue = "Fail";
  charsetvalue = "Fail";

  initialcharsetcolor = "white";
  charsetcolor = "white";

  if(initialcharset != null) initialcharsetvalue = "Pass" ;
  if(charset == setCharsetValueTo) charsetvalue = "Pass" ;

  if(initialcharset == null) initailcharsetcolor = "red" ;
  if(charset != setCharsetValueTo) charsetcolor = "red" ;

  results = results + "<html>";

  results = results + "<font color='#CC6600'> NOTE: </font>" + "<br>";
  results = results + "For the Test Case to run correctly include the following line into your prefs.js file." + "<br>";
  results = results + 'user_pref("signed.applets.codebase_principal_support", true);' + "<br>";
  results = results + 'prefs.js can be found at' + '<br>';
  results = results + 'WINNT:C:\\WINNT\\Profiles\\profileyouareusing\\Application Data\\MfcEmbed\\Profiles\\default\\somefolder.slt\\prefs.js' + '<br>';
  results = results + 'WIN98:C:\\WINDOWS\\Application Data\\MfcEmbed\\Profiles\\default\\somefolder.slt\\prefs.js' + '<br>';
  results = results + '<br><hr ALIGN=LEFT SIZE=5 NOSHADE WIDTH="80%">' + '\n';

  results = results + "  <table bgcolor='white' border='4'>";
  results = results + "  <tbody>";
  results = results + "  <caption> <center> <b> nsIDocCharset Results </b> </center> </caption><br>";
  results = results + "    <tr>";
  results = results + "      <td> <b> Case# </b> </td>";
  results = results + "      <td> <b> Description </b> </td>";
  results = results + "      <td> <b> Value </b> </td>";
  results = results + "      <td> <b> Result </b> </td>";
  results = results + "    </tr>";
  results = results + "    <tr bgcolor = '" + initialcharsetcolor + "'>";
  results = results + "      <td> 1 </td>";
  results = results + "      <td> Initial charset value </td>";
  results = results + "      <td>" + initialcharset + "</td>";
  results = results + "      <td>" + initialcharsetvalue + "</td>";
  results = results + "    </tr>";
  results = results + "    <tr bgcolor = '" + charsetcolor + "'>";
  results = results + "      <td> 2 </td>";
  results = results + "      <td> charset value after setting </td>";
  results = results + "      <td>" + charset + "</td>";
  results = results + "      <td>" + charsetvalue + "</td>";
  results = results + "    </tr>";
  results = results + "  </tbody>";
  results = results + "  </table>";

  results = results + '<br><hr ALIGN=LEFT SIZE=5 NOSHADE WIDTH="80%">' + '\n';
  results = results + "</html>";

  document.results.textarea.value = results;
  if (top.name == "testWindow")
  {
   	fixSubmit();
  }
  else
  {
  	document.write(document.results.textarea.value);
  }
}

</script>

<script language="JavaScript">

function createCookie(name,value,days)
{
  if (days)
  {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++)
  {
    var c = ca[i];
    while (c.charAt(0)==' ')
      c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function eraseCookie(name)
{
  createCookie(name,"",-1);
}

</script>

</head>
<body>

<!-- form below is ngdriverspecific  -->
<form name="results" action="/ngdriver/cgi-bin/writeresults.cgi" method="post">
<script type="text/javascript">
document.write('<input name="resultsfile" type="hidden" value="' + window.opener.document.resultsform.resultsfile.value + '">');
</script>
<input type="hidden" name="textarea">
</form>

<script type="text/javascript">

var domWindow = getnsIDOMWindow();
var docCharset = getdocCharset();
var setCharsetValueTo = "ISO-8859-1";

if(readCookie("docCharset") == null)
{
  try
  {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    var charsetValue = docCharset.charset;
    docCharset.charset = setCharsetValueTo;
  }
  catch(e) {
    dump ("\nError getting nsIDocCharset\n");
  }

  createCookie("docCharset", charsetValue, 14);
  window.location.reload();
}
else
{
  var cookieValue = readCookie("docCharset");
  try
  {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    constructResult(cookieValue, docCharset.charset);
  }
  catch(e) {
    dump ("\nError getting nsIDocCharset\n");
  }
  eraseCookie("docCharset");
}
</script>

</body>
</html>