/* -*- Mode: c++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
group "doc.javascripturls";
require init;

include "modules/doc/frm_doc.h";
include "modules/doc/documentorigin.h";
include "modules/dochand/fdelm.h";

language ecmascript;

html
{
	//! <html><body>
	//! <div id="i"></div>
	//! <iframe id="idoc" width=100 height=100 src="javascript:%09%0D%0Atop.document.getElementById('i').innerHTML='PASS'%3B"></iframe>
	//! </body></html>
}

test("Decode %0A, %0D, %09 - bug 231781")
{
	var div = document.getElementById("i");
	verify(div);
	verify(div.innerHTML == "PASS");
}

html
{
	//! <html><body>
	//! <div id="i"></div>
	//! <iframe id="idoc" width=100 height=100 src="javascript:top.document.getElementById('i').innerHTML=''+(101%2525)"></iframe>
	//! </body></html>
}

test("Only decode the string once")
{
	// 101%2525 == 101%25 -> 1
	// If buggy we would get 101%2525 -> 101%25 -> 101% -> parse error
	var div = document.getElementById("i");
	verify(div);
	verify(div.innerHTML == "1");
}

html
{
	//! <html><body>
	//! <div id="i"></div>
	//! <iframe id="idoc" width=100 height=100 src="javascript:top.document.getElementById('i').innerHTML='http://datos.stereo-productions.com%2Fmusicbox%2FSP034.swf'"></iframe>
	//! </body></html>
}

test("Decode javascript urls - bug 186234")
{
	var div = document.getElementById("i");
	verify(div);
	verify(div.innerHTML == "http://datos.stereo-productions.com/musicbox/SP034.swf");
}
html
{
	//! <iframe src="javascript:x=1"></iframe>
}

test("Shared origin")
language C++;
{
	const DocumentOrigin* origin1 = state.doc->GetOrigin();
	verify(origin1);
	HTML_Element* ifrm_elm = find_element("iframe");
	verify(ifrm_elm);
	FramesDocElm* fdelm = FramesDocElm::GetFrmDocElmByHTML(ifrm_elm);
	verify(fdelm);
	FramesDocument* iframe_doc = fdelm->GetDocManager()->GetCurrentDoc();
	verify(iframe_doc);
	const DocumentOrigin* origin2 = iframe_doc->GetOrigin();

	verify(origin1 == origin2);
}
