| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
package com.netscape.javascript.qa.drivers; |
| 7 |
|
| 8 |
import java.io.*; |
| 9 |
|
| 10 |
import java.applet.Applet; |
| 11 |
import java.util.Vector; |
| 12 |
import netscape.security.PrivilegeManager; |
| 13 |
import netscape.javascript.JSObject; |
| 14 |
import com.netscape.javascript.qa.liveconnect.LiveConnectTest; |
| 15 |
import com.netscape.javascript.qa.liveconnect.jsobject.JSObject_001; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public class LiveNavEnv extends NavEnv { |
| 30 |
TestFile file; |
| 31 |
TestSuite suite; |
| 32 |
LiveNavDrv driver; |
| 33 |
private JSObject result; |
| 34 |
JSObject opener; |
| 35 |
JSObject testcases; |
| 36 |
JSObject location; |
| 37 |
|
| 38 |
boolean evaluatedSuccessfully = false; |
| 39 |
JSObject window; |
| 40 |
|
| 41 |
Applet applet; |
| 42 |
|
| 43 |
private String WINDOW_NAME; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public LiveNavEnv( TestFile file, TestSuite suite, LiveNavDrv driver ) { |
| 54 |
super( file, suite, driver ); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public Object executeTestFile() { |
| 65 |
try { |
| 66 |
location = (JSObject) window.getMember( "location" ); |
| 67 |
driver.p( file.name ); |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
String classname = (file.name.substring(0, file.name.length() - |
| 73 |
".class".length()) + ".html" ); |
| 74 |
|
| 75 |
String s = driver.HTTP_PATH + classname; |
| 76 |
|
| 77 |
System.out.println( "trying to set browser window to " + s ); |
| 78 |
|
| 79 |
location.setMember( "href", s ); |
| 80 |
evaluatedSuccessfully = waitForCompletion(); |
| 81 |
|
| 82 |
} catch ( Exception e ) { |
| 83 |
driver.p( file.name + " failed with exception: " + e ); |
| 84 |
file.exception = e.toString(); |
| 85 |
if ( file.name.endsWith( "-n.js" ) ) { |
| 86 |
this.file.passed = true; |
| 87 |
evaluatedSuccessfully = true; |
| 88 |
} else { |
| 89 |
this.file.passed = false; |
| 90 |
this.suite.passed = false; |
| 91 |
evaluatedSuccessfully = false; |
| 92 |
} |
| 93 |
} |
| 94 |
return null; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
public Applet getApplet() { |
| 113 |
Object document = (Object) window.getMember("document"); |
| 114 |
Object applets = ((JSObject) document).getMember("applets"); |
| 115 |
return (Applet) ((JSObject) applets).getSlot( 0 ); |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
public void getAppletClass(Applet applet) { |
| 125 |
try { |
| 126 |
driver.p( "the class of applet is " + |
| 127 |
applet.getClass().toString() ); |
| 128 |
|
| 129 |
driver.p( "is it a JSObject_001? " + |
| 130 |
(applet instanceof JSObject_001 )); |
| 131 |
|
| 132 |
driver.p( "is it a LiveConnectTest? " + |
| 133 |
(applet instanceof LiveConnectTest )); |
| 134 |
|
| 135 |
driver.p( "is it an Applet? " + |
| 136 |
(applet instanceof Applet )); |
| 137 |
|
| 138 |
driver.p( "Try to cast applet to JSObject_001" ); |
| 139 |
|
| 140 |
|
| 141 |
driver.p( ((JSObject_001) applet).toString() ); |
| 142 |
|
| 143 |
} catch ( Exception e ) { |
| 144 |
driver.p( "parseResult threw exception: " + e ); |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
public boolean parseResult() { |
| 162 |
applet = getApplet(); |
| 163 |
|
| 164 |
Vector label = null; |
| 165 |
Vector value = null; |
| 166 |
|
| 167 |
try { |
| 168 |
FileReader fr = new FileReader( |
| 169 |
driver.OUTPUT_DIRECTORY.getAbsolutePath()+ |
| 170 |
(driver.OUTPUT_DIRECTORY.getAbsolutePath().endsWith(File.separator) |
| 171 |
? "" |
| 172 |
: File.separator ) + |
| 173 |
LiveConnectTest.TEMP_LOG_NAME); |
| 174 |
BufferedReader br = new BufferedReader( fr ); |
| 175 |
String classname = br.readLine(); |
| 176 |
boolean passed = (new Boolean(br.readLine())).booleanValue(); |
| 177 |
int length = (new Double(br.readLine())).intValue(); |
| 178 |
int no_passed = (new Double(br.readLine())).intValue(); |
| 179 |
int no_failed = (new Double(br.readLine())).intValue(); |
| 180 |
if ( ! passed ) { |
| 181 |
this.file.passed = false; |
| 182 |
this.suite.passed = false; |
| 183 |
} |
| 184 |
this.file.totalCases += length; |
| 185 |
|
| 186 |
this.file.casesPassed += no_passed; |
| 187 |
this.suite.casesPassed += no_passed; |
| 188 |
|
| 189 |
this.file.casesFailed += no_failed; |
| 190 |
this.suite.casesFailed += no_failed; |
| 191 |
|
| 192 |
} catch ( IOException e ) { |
| 193 |
driver.p( e.toString() ); |
| 194 |
return false; |
| 195 |
} |
| 196 |
return true; |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
public void close() { |
| 204 |
applet.destroy(); |
| 205 |
opener.eval( WINDOW_NAME +".close()" ); |
| 206 |
opener.eval( "delete " + WINDOW_NAME ); |
| 207 |
} |
| 208 |
} |