<?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-10-25
FIXED: 
ISSUE-732: New ccxml document for the test of TA 773 (and child 1174) 
-->

	<conf:docsetup/>
	<var name="ConnectionID" expr="undefined"/>
	<var name="childSessionId" expr="undefined"/>
	<var name="mySendId" expr="undefined"/>
	<var name="bCcxmlCreatedReceived" expr="false"/>
	<var name="bCcxmlExitReceived" expr="false"/>
	<var name="bUnconditionalKillSent" expr="false"/>
		
	<script><![CDATA[
	   function GetMilliseconds() {
     var d = new Date();
     return d.getTime();  // ms from midnight on Jan 1, 2000.
   }

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('773');


add_2_assert_trace('1174');

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_VERY_LONG_TIMEOUT"/>
			<accept connectionid="event$.connectionid"/>
		</transition>
		
		<transition event="connection.connected" state="init">
			<assign name="ConnectionID" expr="event$.connectionid"/>
			<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">
				<log label="s_TA" expr="s_ASSERTIONS_LEFT"/>
				<conf:uncond_exit expr="'DONE'"/>
				<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_773" state="ASSERTION_NMBR_773">
			<!--
773 	
8.2.2 &lt;script&gt; 	
A <script> element may contain a timeout attribute to be used when the src attribute is specified. 
The script fetch will fail if not completed at the end of this interval. 
A failed fetch will return the error.fetch event. 	emily.candell@comverse.com 	Accepted 	
ass_773_aux.txml

-->
			<conf:comment expr="'Event: ' + event$.name"/>
			<createccxml next="'ass_773_aux.ccxml'" sessionid="childSessionId"/>			
			<send target="session.id" targettype="'ccxml'" name="'killCreatedSession'" delay="'15000ms'" sendid="mySendId"/>
		</transition>		

		<transition event="ccxml.created" state="ASSERTION_NMBR_773">
			<conf:comment expr="'Event: ' + event$.name"/>
			<assign name="bCcxmlCreatedReceived" expr="true"/>			
		</transition>		
		
		<transition event="error.createccxml" state="ASSERTION_NMBR_773">
			<conf:comment expr="'Event: ' + event$.name"/>
			<!-- PASS if script preloading is supported-->
			<script>assertions[assert_index].P_F = s_PASS;</script>			
			<assign name="ASSERTION_NUM" expr="'1174'"/>
			<conf:pass/>
		</transition>		

		<transition event="ccxml.exit" state="ASSERTION_NMBR_773">
			<conf:comment expr="'Event: ' + event$.name"/>
			<if cond="event$.values.ErrorReason == 'ErrorFetch for timeout on script'">
				<script>assertions[assert_index].P_F = s_PASS;</script>
				<assign name="ASSERTION_NUM" expr="'1174'"/>
				<conf:pass/>
			<else/>	
				<script>assertions[assert_index].P_F = s_FAIL;</script>
					<assign name="ASSERTION_NUM" expr="'1174'"/>
					<conf:fail/>
			</if>
			<assign name="bCcxmlExitReceived" expr="true"/>
		</transition>		

		<transition event="killCreatedSession" state="ASSERTION_NMBR_773">
			<conf:comment expr="'Event: ' + event$.name + ', bCcxmlCreatedReceived => ' +  bCcxmlCreatedReceived + ', bCcxmlExitReceived => ' + bCcxmlExitReceived "/>
			
			<if cond="bCcxmlCreatedReceived">
				<if cond="!bCcxmlExitReceived">
					<script>assertions[assert_index].P_F = s_FAIL;</script>
					<assign name="ASSERTION_NUM" expr="'1174'"/>
					<conf:fail/>
					<assign name="bUnconditionalKillSent" expr="true"/>
					<send target="childSessionId" targettype="'ccxml'" name="'ccxml.kill.unconditional'" sendid="mySendId"/>
				<else/>
					<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>	
				</if>				
			<else/>
				<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>	
			</if>
		</transition>	

		<transition event="ccxml.exit" state="ASSERTION_NMBR_773" cond="bUnconditionalKillSent">
			<conf:comment expr="'Event: ' + event$.name"/>			
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</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"/>
			<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>
