<?xml version="1.0" encoding="UTF-8" ?> | |
<!-- | |
Licensed to the Apache Software Foundation (ASF) under one | |
or more contributor license agreements. See the NOTICE file | |
distributed with this work for additional information | |
regarding copyright ownership. The ASF licenses this file | |
to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, | |
software distributed under the License is distributed on an | |
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
KIND, either express or implied. See the License for the | |
specific language governing permissions and limitations | |
under the License. | |
--> | |
<library> | |
<class name="UploadSpeedTest" extends="NetworkTest"> | |
<switch> | |
<when property="$as3"> | |
<passthrough> | |
import flash.events.*; | |
import flash.net.*; | |
import flash.utils.*; | |
</passthrough> | |
</when> | |
</switch> | |
<attribute name="startTime" type="number" value="0" /> | |
<attribute name="hostUrl" type="string" value="" /> | |
<attribute name="loaderInited" type="boolean" value="false" /> | |
<attribute name="request" value="null" /> | |
<attribute name="loader" value="null" /> | |
<handler name="oninit"> | |
this.setAttribute("testName", "Upload speed"); | |
this.setAttribute("resultText", true); | |
</handler> | |
<method name="initLoader"> | |
hostUrl = protocol + "://" + host + ":" + port + canvas.uriContext + "/networktest.upload"; | |
request = new URLRequest(hostUrl); | |
request.method = URLRequestMethod.POST; | |
request.data = getDataString(); | |
loader = new URLLoader(); | |
loader.addEventListener(Event.COMPLETE, this.onComplete); | |
loader.addEventListener(IOErrorEvent.IO_ERROR, this.onError); | |
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.onError); | |
loaderInited = true; | |
</method> | |
<method name="start"> | |
if (!loaderInited) { | |
this.initLoader(); | |
} | |
this.log("start test... " + hostUrl); | |
startTime = getTimer(); | |
loader.load(request); | |
</method> | |
<method name="forcedStop"> | |
loader.close(); | |
this.log("stopped"); | |
</method> | |
<method name="onComplete" args="e"> | |
if (running) { | |
var endTime = getTimer(); | |
var loadTime = endTime - startTime; | |
var loadTimeSec = loadTime/1000; | |
var mBytes = request.data.length/(1024*1024); | |
var speed = mBytes / loadTimeSec; | |
var report = "report:\n"; | |
report += "Bytes uploaded: " + mBytes + " Mb\n"; | |
report += "Upload time: " + loadTimeSec + " s\n"; | |
report += "Upload speed: " + speed + " Mb/s\n"; | |
resultLabel.setAttribute("text", ""); | |
resultLabel.addFormat("%.2f\n%s", speed, "Mb/s"); | |
this.log(report); | |
this.setPassed(); | |
} | |
</method> | |
<method name="onError" args="e"> | |
if (running) { | |
this.log("error - " + e); | |
this.setFailed(); | |
} | |
</method> | |
<!-- returns a 1 Mb string--> | |
<method name="getDataString"> | |
<![CDATA[ | |
var result = ""; | |
var str64 = "0000000000000000000000000000000000000000000000000000000000000000"; | |
for (var i=0; i<16384; i++) { | |
result += str64; | |
} | |
return result; | |
]]> | |
</method> | |
</class> | |
</library> |