gecko/embedding/qa/jstests/nsIFontListTest.txt

231 lines
8.2 KiB
Plaintext

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title> nsIFontList Interface Test </title>
<!-- ***** 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 Corporation.
- Portions created by the Initial Developer are Copyright (C) 1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- 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 ***** -->
<!-- Descrpt: nsIFontList Interface Test Case
Author: dsirnapalli@netscape.com
Revs: 07.26.01 - Created
Last Run On: 10.23.01.-->
<!-- script below is ngdriverspecific -->
<script type="text/javascript" src="http://bubblegum/ngdriver/suites/testlib.js">
</script>
<script type="text/javascript">
res = "";
function getBrowserVersion()
{
res = res + "<font color='#CC6600'> NOTE: </font>" + "<br>";
res = res + "For the Test Case to run correctly include the following line into your prefs.js file." + "<br>";
res = res + 'user_pref("signed.applets.codebase_principal_support", true);' + "<br>";
res = res + 'prefs.js can be found at' + '<br>';
res = res + 'WINNT:C:\\WINNT\\Profiles\\profileyouareusing\\Application Data\\MfcEmbed\\Profiles\\default\\somefolder.slt\\prefs.js' + '<br>';
res = res + 'WIN98:C:\\WINDOWS\\Application Data\\MfcEmbed\\Profiles\\default\\somefolder.slt\\prefs.js' + '<br>';
res = res + '<br><hr ALIGN=LEFT SIZE=5 NOSHADE WIDTH="80%">' + '\n';
res = res + '<b><h3><font color="#CC6600"> Browser Info </font></h3></b>' + '\n';
res = res + '<table BORDER COLS=2 WIDTH="70%">' + '\n';
res = res + ' <tr>' + '\n';
res = res + ' <td WIDTH="30%"><b> App Name: </b></td>' + '\n';
res = res + ' <td>' + navigator.appName + '</td>' + '\n';
res = res + ' </tr>' + '\n';
res = res + ' <tr>' + '\n';
res = res + ' <td><b> User Agent: </b></td>' + '\n';
res = res + ' <td>' + navigator.userAgent + '</td>' + '\n';
res = res + ' </tr>' + '\n';
res = res + ' <tr>' + '\n';
res = res + ' <td><b> Code Name: </b></td>' + '\n';
res = res + ' <td>' + navigator.appCodeName + '</td>' + '\n';
res = res + ' </tr>' + '\n';
res = res + ' <tr>' + '\n';
res = res + ' <td><b> App Version: </b></td>' + '\n';
res = res + ' <td>' + navigator.appVersion + '</td>' + '\n';
res = res + ' </tr>' + '\n';
res = res + ' <tr>' + '\n';
res = res + ' <td><b> Language: </b></td>' + '\n';
res = res + ' <td>' + navigator.language + '</td>' + '\n';
res = res + ' </tr>' + '\n';
res = res + ' <tr>' + '\n';
res = res + ' <td><b> Platform: </b></td>' + '\n';
res = res + ' <td>' + navigator.platform + '</td>' + '\n';
res = res + ' </tr>' + '\n';
res = res + '</table>' + '\n';
res = res + '<br><hr ALIGN=LEFT SIZE=5 NOSHADE WIDTH="80%">' + '\n';
}
function getFontList()
{
try
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
var fontListObj = Components.classes["@mozilla.org/gfx/fontlist;1"].createInstance();
if (fontListObj)
fontListObj = fontListObj.QueryInterface(Components.interfaces.nsIFontList);
/*
this can be done in a single stmt.
var fontListObj = Components.classes["@mozilla.org/gfx/fontlist;1"].
createInstance(Components.interfaces.nsIFontList);
*/
}
catch(e) {
alert("Exception: " + e);
}
return fontListObj;
}
function getDescription(groupname)
{
var descriptivename;
if(groupname == "x-western")
descriptivename = " (American/Western European)";
else if(groupname == "ar")
descriptivename = " (Arabic)";
else if(groupname == "el")
descriptivename = " (Greek)";
else if(groupname == "he")
descriptivename = " (Hebrew)";
else if(groupname == "ja")
descriptivename = " (Japanese)";
else if(groupname == "ko")
descriptivename = " (Korean)";
else if(groupname == "th")
descriptivename = " (Thai)";
else if(groupname == "tr")
descriptivename = " (Turkish)";
else if(groupname == "x-baltic")
descriptivename = " (Baltic)";
else if(groupname == "x-central-euro")
descriptivename = " (Eastern European)";
else if(groupname == "x-cyrillic")
descriptivename = " (Russian)";
else if(groupname == "zh-CN")
descriptivename = " (China)";
else if(groupname == "zh-TW")
descriptivename = " (Taiwan)";
return descriptivename;
}
function constructFontList(fontList)
{
try
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
res = res + '<b><h3><font color="#CC6600"> Available Fonts </font></h3></b>' + '\n';
for(i=0; i<langgroup.length; i++)
{
res = res + '<br><b><u>' + langgroup[i] + '</u>' + getDescription(langgroup[i]) + '</b> <br><br>';
res = res + '<table BORDER COLS=2 WIDTH="90%">' + '\n';
for(j=0; j<fonttype.length; j++)
{
res = res + '<tr>' + '\n';
res = res + '<td WIDTH="20%"><b>' + fonttype[j] + ':' + '</b></td>';
res = res + '<td>';
var tempres = "";
var fontEnumerator = fontList.availableFonts(langgroup[i], fonttype[j]);
while (fontEnumerator.hasMoreElements())
{
var fontName = fontEnumerator.getNext();
fontName = fontName.QueryInterface(Components.interfaces.nsISupportsString);
var fontNameStr = fontName.toString();
if (fontEnumerator.hasMoreElements())
tempres = tempres + fontNameStr + ", ";
else
tempres = tempres + fontNameStr;
}
res = res + tempres;
res = res + '</td>';
res = res + ' </tr>' + '\n';
}
res = res + '</table>';
}
res = res + '<br><hr ALIGN=LEFT SIZE=5 NOSHADE WIDTH="80%">' + '\n';
}
catch(e) {
alert("Exception: " + e);
}
}
function displayResults()
{
document.results.textarea.value = res;
if (top.name == "testWindow")
{
fixSubmit();
}
else
{
document.write(document.results.textarea.value);
}
}
</script>
</head>
<body onLoad="displayResults();">
<!-- 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 langgroup = new Array("x-western", "ar", "el", "he", "ja", "ko",
"th", "tr", "x-baltic", "x-central-euro",
"x-cyrillic", "zh-CN", "zh-TW");
var fonttype = new Array( "serif" , "sans-serif", "cursive",
"fantasy", "monospace");
getBrowserVersion();
var fontList = getFontList();
constructFontList(fontList);
</script>
</body>
</html>