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

language C++;

include "modules/dochand/win.h";
include "modules/doc/frm_doc.h";
include "modules/dochand/fdelm.h";
include "modules/display/prn_info.h";

html
{
	"<html><body><h1>Hello</html>"
}

test("print preview simple page")
{
	verify(state.doc);
	Window* win = state.doc->GetWindow();
	verify(win);
	verify(!win->GetPreviewMode());
	verify(!win->GetPrintMode());

	win->TogglePrintMode(TRUE); // Go to preview mode

	verify(win->GetPreviewMode());
	verify(!win->GetPrintMode());

	FramesDocument* print_doc = state.doc->GetDocManager()->GetPrintDoc();
	verify(print_doc);
	verify(print_doc->IsPrintDocument());

	win->TogglePrintMode(TRUE);

	verify(!win->GetPreviewMode());
	verify(!win->GetPrintMode());

	print_doc = state.doc->GetDocManager()->GetPrintDoc();
	verify(!print_doc);
}



html
{
	"<html><body><h1>Hello<iframe src='data:text/html,<h1>Tomato</t1>'></iframe></html>"
}

test("CreatePrintLayout")
disabled; // Not tested yet
{
	FramesDocElm* ifrm_root = state.doc->GetIFrmRoot();
	verify(ifrm_root);
	verify(ifrm_root->FirstChild());
	verify(ifrm_root->FirstChild() == ifrm_root->LastChild());

	Window* window = state.doc->GetWindow();
	verify(window);
	BOOL preview = TRUE;
	//	PrinterInfo* printer_info = window->GetPrinterInfo(preview);
	//	verify(printer_info);
	PrinterInfo printer_info;
	PrintDevice* pd = printer_info.GetPrintDevice();
	verify(pd);
	FramesDocument print_doc(state.doc->GetDocManager(), URL(), 800, 600, -1);
	OP_BOOLEAN result = print_doc.CreatePrintLayout(pd, state.doc, 800, 600, TRUE /* what is this? */, preview);
	verify(result == OpBoolean::IS_TRUE);

	// Check that the iframes were cloned
	FramesDocElm* print_ifrm_root = print_doc.GetIFrmRoot();
	verify(print_ifrm_root);
	verify(print_ifrm_root);
	verify(print_ifrm_root->FirstChild());
	verify(print_ifrm_root->FirstChild() == print_ifrm_root->LastChild());
}

test("print preview page with iframe")
{
	verify(state.doc);
	Window* win = state.doc->GetWindow();
	verify(win);
	verify(!win->GetPreviewMode());
	verify(!win->GetPrintMode());

	win->TogglePrintMode(TRUE); // Go to preview mode

	verify(win->GetPreviewMode());
	verify(!win->GetPrintMode());

	FramesDocument* print_doc = state.doc->GetDocManager()->GetPrintDoc();
	verify(print_doc);
	verify(print_doc->IsPrintDocument());

	win->TogglePrintMode(TRUE);

	verify(!win->GetPreviewMode());
	verify(!win->GetPrintMode());

	print_doc = state.doc->GetDocManager()->GetPrintDoc();
	verify(!print_doc);
}
