<?xml version="1.0" encoding="UTF-8"?>
<ccxml xmlns="http://www.w3.org/2002/09/ccxml" xmlns:conf="http://www.w3.org/2005/ccxml-conformance" version="1.0">
<!--
Release 1.1 - 2010-06-17
FIXED: 
ISSUE-683, script for TA 757,758,759 

Release 1.2 - 2010-07-09
FIXED: added quotes to maxage values, TAs 774, 775 (no specific ISSUE)

Release 1.3 - 2010-10-21
FIXED: ISSUE-731 - Removed quotes in maxage values, TAs 774, 775.
-->
	<conf:docsetup/>	
	<var name="chld_reason"/>
	<var name="send_id_1"/>
	<var name="cur_event_ID"/>
	<var name="time1"/>
	<var name="time2"/>
	<var name="marker"/>
	
	<script><![CDATA[
	function DelayMilliseconds(N) {
		var r_delay;
		ccxml_start_time = GetMilliseconds();
		do{
			ccxml_end_time = GetMilliseconds();
			r_delay = ccxml_end_time - ccxml_start_time;
		}while(r_delay < N);			
	   return r_delay;
   }
	   function GetMilliseconds() {
     var d = new Date();
     return d.getTime();  // ms from midnight on Jan 1, 2000.application)"/>

   }

var t_start, t_end, t_delay = 2000, t_delta, t_delta_e = 0.05 * t_delay;
		   ]]></script>
	<script><![CDATA[

var i=0;
assertions[i++] = init_assertion('774');

add_2_assert_trace('774');
add_2_assert_trace('775');
add_2_assert_trace('757');
add_2_assert_trace('758');
add_2_assert_trace('759');
add_2_assert_trace('769');

var assert_last = i - 1;
var assert_index = -1;
//
// out of the loop assertions (children?)
//
//
s_ASSERTIONS_LEFT = show_remained_assertions();
var b_in_test = false;


]]></script>
	
	<eventprocessor statevariable="current_state">
		<conf:setup type="alerting"/>
		<transition event="connection.alerting" state="init">
			<send targettype="'ccxml'" target="session.id" name="'user.timeout'" delay="TEST_LONG_TIMEOUT"/>
			<accept connectionid="event$.connectionid"/>
		</transition>
		<transition event="connection.connected" state="init">
			<conf:comment expr="'Event: ' + event$.name"/>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<transition event="user.PREPARE_NEW">
			<conf:comment expr="'Event: ' + event$.name"/>

			<if cond="assert_index &gt;= 0">
				<assign name="ASSERTION_NUM" expr="assertions[assert_index].number"/>
				<assign name="t_ASSERT_RESULT" expr="assertions[assert_index].P_F"/>
				<script>t_ASSERT_REASON = assertions[assert_index].reason</script>
				<if cond="t_ASSERT_RESULT == s_PASS">
					<conf:pass reason="t_ASSERT_REASON"/>
					<elseif cond="t_ASSERT_RESULT == s_FAIL"/>
					<conf:fail reason="t_ASSERT_REASON"/>
					<else/>
					<conf:not_exec reason="t_ASSERT_REASON"/>
				</if>
			</if>
			
			<assign name="assert_index" expr="assert_index + 1"/>
			<if cond="assert_index &gt; assert_last">
				<assign name="current_state" expr="'switching_files'"/>
				<fetch next="'8_2_2_A_UTF_8.ccxml'" type="'application/ccxml+xml'"/>
				<else/>
				<log label="s_TA" expr="s_ASSERTIONS_LEFT"/>
				<assign name="ASSERTION_NUM" expr=" assertions[assert_index].number"/>
				<assign name="t_ASSERT_REASON" expr="''"/>
				<script>assertions[assert_index].P_F = s_FAIL;</script>
				<assign name="current_state" expr="state_prefix + ASSERTION_NUM"/>
				<send targettype="'ccxml'" target="session.id" name="start_name_prefix + ASSERTION_NUM" sendid="cur_event_ID"/>
				<log label="s_TA" expr="'Loop event: SendID=' + cur_event_ID"/>
			</if>
		</transition>
        
		<transition event="user.START_ASSERTION_774" state="ASSERTION_NMBR_774">
<!--
774 
8.2.2 &lt;script&gt; 	
A <script> element may contain a maxage attribute to be used when the src attribute is specified. 
This indicates that the document is willing to use content whose age is no greater than the specified time in seconds 	emily.candell@comverse.com 	Accepted 	
-->
			<!-- FIXED ISSUE-731: removed quotes in maxage value-->
	   		<script maxage="5000" src="marker.ircgi"/>
			
			<assign name="time1" expr="marker"/>
			
			<assign name="time2" expr="marker"/>

			<conf:comment expr="'time1 = ' + Math.round(time1) + '; time2 = ' + Math.round(time2) + '.'"/>
	   
	   		<if cond="marker != undefined">
	   			<script>assertions[assert_index].P_F = s_PASS;</script>
				<conf:pass/>
                <else/>
                <script>
				    assertions[assert_index].P_F = s_FAIL; 
				</script>
	   		</if>
	   		
<!--
775 	
8.2.2 &lt;script&gt; 	
The document is not willing to use stale script content, unless maxstale is also provided. 	emily.candell@comverse.com 	Accepted 	
-->

	   		<assign name="ASSERTION_NUM" expr="'775'"/>
			<assign name="current_state" expr="'ASSERTION_NMBR_775_PART_2'"/>
	   		
	   		<send targettype="'ccxml'" target="session.id" name="'user.next'" delay="'3000ms'"/>
		</transition>
		
		<transition event="user.next" state="ASSERTION_NMBR_775_PART_2">
		
			<!-- FIXED ISSUE-731: removed quotes in maxage value -->
	   		<script src="marker.ircgi" maxage="1000"/>

			<assign name="time2" expr="marker"/>

			<conf:comment expr="'time1 = ' + Math.round(time1) + '; time2 = ' + Math.round(time2) + '.'"/>
	   		
	   		<if cond="Math.round(time2) &gt; Math.round(time1)">
	   			<conf:pass/>
	   		<else/>
	   			<conf:fail/>
	   		</if>
	
	   		<assign name="current_state" expr="'ASSERTION_NMBR_757'"/>
	   		<send targettype="'ccxml'" target="session.id" name="'user.next'"/>
		</transition>
		
		<transition event="user.next" state="ASSERTION_NMBR_757">
<!--
757 	
8.2.2 &lt;script&gt; 	
<script> encloses computations written in the ECMAScript Compact Profile scripting language 	emily.candell@comverse.com 	Accepted 	
-->

<!--
758 	
8.2.2 &lt;script&gt; 	An implementation MUST support the ECMAScript Compact Profile 	emily.candell@comverse.com 	Accepted 	
-->

<!--
759 	
8.2.2 &lt;script&gt; 	
An implementation MAY support the full ECMA-262 ECMAScript specification. 	
emily.candell@comverse.com 	Accepted 	
-->
<!-- FIXED ISSUE-683:  declaration of var2 and var3 added in the following script -->
			<script>var var1=1;
					var1++;
					var var2 = var1;
					var myAry = new Array();
					myAry["ary"] = var2;
					myAry["ary"]++;
					var var3 = myAry["ary"];
			</script>
			
			<if cond="var3==3">
				<assign name="ASSERTION_NUM" expr="'757'"/>
				<conf:pass/>
				<assign name="ASSERTION_NUM" expr="'758'"/>
				<conf:pass/>
				<assign name="ASSERTION_NUM" expr="'759'"/>
				<conf:pass/>
			<else/>
				<assign name="chld_reason" expr="'script tag does not support ECMAScript Compact Profile.'"/>
				<assign name="ASSERTION_NUM" expr="'757'"/>
				<conf:fail reason="chld_reason"/>
				<assign name="ASSERTION_NUM" expr="'758'"/>
				<conf:fail reason="chld_reason"/>
				<assign name="ASSERTION_NUM" expr="'759'"/>
				<conf:fail reason="chld_reason"/>
			</if>
	   		 
<!--
769 	
8.2.2 &lt;script&gt; 	
A <script> element may contain a fetchid atribute that contains an ECMAScript expression which returns the fetch identifier of a completed fetch request, 
acquired either in a fetch with the fetchid attribute, or from the fetchid attribute of a fetch.done event. 	
emily.candell@comverse.com 	Accepted 	
-->
			<assign name="current_state" expr="'ASSERTION_NMBR_769'"/>
			<assign name="ASSERTION_NUM" expr="'769'"/>
			<fetch next="'fetch_script.es'" type="'text/ecmascript'"/>
		</transition>

		<transition event="fetch.done" state="ASSERTION_NMBR_769">
			<conf:comment expr="'Event: ' + event$.name"/>
			<script fetchid="event$.fetchid"/>
			<if cond="fetch_script_called==true">
				<conf:pass/>
				<else/>
				<assign name="chld_reason" expr="'A fetched script did not run correctly; ' +
					'value of fetch_script_called is ' + fetch_script_called + ', should be true.'"/>
				<conf:fail reason="chld_reason"/>
			</if>
			<script>application.fetchid_763 = event$.fetchid;</script>	
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>			
		</transition>
		
		<transition event="fetch.done" state="ASSERTION_NMBR_763">
			<conf:comment expr="'Event: ' + event$.name"/>
			<goto fetchid="event$.fetchid"/>
		</transition>

		<transition event="fetch.done" state="switching_files">
			<goto fetchid="event$.fetchid"/>
		</transition>
		
		<transition event="user.timeout">
			<assign name="current_state" expr="'GEN'"/>
			<conf:uncond_exit expr="'TEST-TIMEOUT.' + show_remained_assertions()"/>
		</transition>

		<transition event="send.successful">
			<conf:comment expr="'Event: ' + event$.name + ' (generic handler) state=' + current_state"/>
		</transition>

		<transition event="*">
			<assign name="t_ASSERT_REASON" expr="'UNEXPECTED EVENT ' + event$.name + ' IN STATE ' + current_state"/>
			<conf:comment expr="t_ASSERT_REASON"/>
			<conf:uncond_exit/>
			<if cond="current_state == 'init'">
				<conf:uncond_exit expr="'Did not come out from init state.'"/>
				<else/>
				<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
			</if>
		</transition>

	</eventprocessor>
</ccxml>
