// htmltest.cpp - CHtmlView. Wine's WebBrowser control needs Gecko to
// show a page, so the test registers a WebBrowser of its own for
// CLSID_WebBrowser in this process (CoRegisterClassObject). It keeps what
// the view asks of it, answers with fixed values, and fires the events a
// browser fires while it navigates. The test checks:
// - the view makes the control and its IWebBrowser2 (m_pBrowserApp),
// the browser fills the view and follows its size;
// - Navigate, the Navigate2 forms (URL, posted data, item list) and
// LoadFromResource, with their arguments;
// - the events reach the handlers with their arguments turned into
// strings, and a handler's cancel goes back to the browser;
// - the properties, PutProperty/GetProperty, ExecWB and QueryStatusWB,
// ID_FILE_PRINT, the forms commands and GetSource on the document;
// - the site's IDocHostUIHandler asks the view's On* functions;
// - PreTranslateMessage gives the browser its keys first;
// - the browser is let go when the frame closes.
// And CDHtmlDialog, over a page of fake elements (a document whose
// document.all finds them, each with its events' connection point):
// - the browser covers the dialog, which shows the page in its
// resources, takes the page's title, and fills the page with its data
// when the document is complete;
// - the DDX_DHtml functions both ways: values, numbers, a check box,
// radio buttons, a select's index, text and value, inner text and
// HTML, a property of an ActiveX control in the page;
// - the element functions and the page's control's properties;
// - the DHTML event map by id, class and tag, and the document's own
// events, with GetEvent while a handler runs;
// - the host flags, and window.external only for a page on this
// computer;
// - a new page moves the handlers to it; closing lets everything go.
#include
#include
#include "htmltest.h"
#ifdef _WINPORT
#include "htmlstubs-port.h"
#else
#ifdef _WINPORT
#include "htmlstubs-port.h"
#else
#include "htmlstubs.h"
#endif
#endif
#include "testutil.h"
static const TCHAR kBrowserClass[] = _T("HtmlTestBrowser");
// =====================================================================
// The document the browser shows: its source, and the forms commands.
class CFakeDoc final : public IDispatch, public IPersistStreamInit, public IOleCommandTarget {
public:
LONG m_nRef;
DWORD m_nLastExec;
CFakeDoc() : m_nRef(1), m_nLastExec(0) {}
STDMETHOD(QueryInterface)(REFIID iid, void** ppv) {
if (iid == IID_IUnknown || iid == IID_IDispatch)
*ppv = static_cast(this);
else if (iid == IID_IPersistStreamInit || iid == IID_IPersist)
*ppv = static_cast(this);
else if (iid == IID_IOleCommandTarget)
*ppv = static_cast(this);
else {
*ppv = NULL;
return E_NOINTERFACE;
}
AddRef();
return S_OK;
}
STDMETHOD_(ULONG, AddRef)() { return (ULONG)::InterlockedIncrement(&m_nRef); }
STDMETHOD_(ULONG, Release)() {
LONG n = ::InterlockedDecrement(&m_nRef);
if (n == 0) delete this;
return (ULONG)n;
}
// IDispatch
STDMETHOD(GetTypeInfoCount)(UINT* pc) {
*pc = 0;
return S_OK;
}
STDMETHOD(GetTypeInfo)(UINT, LCID, ITypeInfo**) { return E_NOTIMPL; }
STDMETHOD(GetIDsOfNames)(REFIID, LPOLESTR*, UINT, LCID, DISPID*) { return E_NOTIMPL; }
STDMETHOD(Invoke)(DISPID, REFIID, LCID, WORD, DISPPARAMS*, VARIANT*, EXCEPINFO*, UINT*) {
return DISP_E_MEMBERNOTFOUND;
}
// IPersistStreamInit: the page is UTF-8.
STDMETHOD(GetClassID)(CLSID* p) {
*p = CLSID_NULL;
return S_OK;
}
STDMETHOD(IsDirty)() { return S_FALSE; }
STDMETHOD(Load)(LPSTREAM) { return E_NOTIMPL; }
STDMETHOD(Save)(LPSTREAM pStm, BOOL) {
static const char kPage[] = "Caf\xc3\xa9";
return pStm->Write(kPage, sizeof(kPage) - 1, NULL);
}
STDMETHOD(GetSizeMax)(ULARGE_INTEGER*) { return E_NOTIMPL; }
STDMETHOD(InitNew)() { return S_OK; }
// IOleCommandTarget: forms command 7 is there and checked; others are not.
STDMETHOD(QueryStatus)(const GUID* pguid, ULONG cCmds, OLECMD* prgCmds, OLECMDTEXT*) {
static const GUID kForms3 = {
0xde4ba900, 0x59ca, 0x11cf, {0x95, 0x92, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}};
if (pguid == NULL || *pguid != kForms3) return OLECMDERR_E_UNKNOWNGROUP;
for (ULONG i = 0; i < cCmds; i++)
prgCmds[i].cmdf =
prgCmds[i].cmdID == 7 ? OLECMDF_SUPPORTED | OLECMDF_ENABLED | OLECMDF_LATCHED : 0;
return S_OK;
}
STDMETHOD(Exec)(const GUID*, DWORD nCmdID, DWORD, VARIANT* pIn, VARIANT* pOut) {
m_nLastExec = nCmdID;
if (pOut != NULL) {
::VariantInit(pOut);
pOut->vt = VT_I4;
pOut->lVal = (LONG)nCmdID * 2 + (pIn != NULL && pIn->vt == VT_I4 ? pIn->lVal : 0);
}
return S_OK;
}
};
// =====================================================================
// A page's elements, for CDHtmlDialog: a document, its elements and
// collections, and the events' object. Each answers what the dialog asks
// (htmlstubs.h answers the rest with E_NOTIMPL).
// One event connection point, with room for one sink.
class CFakeEvents : public IConnectionPoint {
public:
IUnknown* m_pOwner;
IID m_iid;
LPDISPATCH m_pSink;
CFakeEvents(IUnknown* pOwner, REFIID iid) : m_pOwner(pOwner), m_iid(iid), m_pSink(NULL) {}
~CFakeEvents() {
if (m_pSink != NULL) m_pSink->Release();
}
STDMETHOD(QueryInterface)(REFIID iid, void** ppv) {
if (iid == IID_IUnknown || iid == IID_IConnectionPoint) {
*ppv = this;
AddRef();
return S_OK;
}
*ppv = NULL;
return E_NOINTERFACE;
}
STDMETHOD_(ULONG, AddRef)() { return m_pOwner->AddRef(); }
STDMETHOD_(ULONG, Release)() { return m_pOwner->Release(); }
STDMETHOD(GetConnectionInterface)(IID* p) {
*p = m_iid;
return S_OK;
}
STDMETHOD(GetConnectionPointContainer)(IConnectionPointContainer** pp) {
return m_pOwner->QueryInterface(IID_IConnectionPointContainer, (void**)pp);
}
STDMETHOD(Advise)(LPUNKNOWN pUnk, DWORD* pdwCookie) {
*pdwCookie = 0;
if (m_pSink != NULL) return CONNECT_E_ADVISELIMIT;
// The sink answers the events' interface.
if (FAILED(pUnk->QueryInterface(m_iid, (void**)&m_pSink))) return CONNECT_E_CANNOTCONNECT;
*pdwCookie = 7;
return S_OK;
}
STDMETHOD(Unadvise)(DWORD dwCookie) {
if (dwCookie != 7 || m_pSink == NULL) return CONNECT_E_NOCONNECTION;
m_pSink->Release();
m_pSink = NULL;
return S_OK;
}
STDMETHOD(EnumConnections)(IEnumConnections** pp) {
*pp = NULL;
return E_NOTIMPL;
}
};
static const IID kDIID_HTMLElementEvents2 = {
0x3050f60f, 0x98b5, 0x11cf, {0xbb, 0x82, 0x00, 0xaa, 0x00, 0xbd, 0xce, 0x0b}};
static const IID kDIID_HTMLDocumentEvents2 = {
0x3050f613, 0x98b5, 0x11cf, {0xbb, 0x82, 0x00, 0xaa, 0x00, 0xbd, 0xce, 0x0b}};
#define FAKE_REFCOUNT \
LONG m_nRef; \
STDMETHOD_(ULONG, AddRef)() { return (ULONG)::InterlockedIncrement(&m_nRef); } \
STDMETHOD_(ULONG, Release)() { \
LONG n = ::InterlockedDecrement(&m_nRef); \
if (n == 0) delete this; \
return (ULONG)n; \
}
#define FAKE_DISPATCH_INFO \
STDMETHOD(GetTypeInfoCount)(UINT* pc) { \
*pc = 0; \
return S_OK; \
} \
STDMETHOD(GetTypeInfo)(UINT, LCID, ITypeInfo**) { return E_NOTIMPL; } \
STDMETHOD(GetIDsOfNames)(REFIID, LPOLESTR*, UINT, LCID, DISPID*) { return E_NOTIMPL; }
static int g_nDomAlive = 0;
class CFakeElement;
// The object an event handler can ask about the event.
class CFakeEventObj final : public CStubHTMLEventObj {
public:
FAKE_REFCOUNT
IHTMLElement* m_pSrc;
explicit CFakeEventObj(IHTMLElement* pSrc) : m_nRef(1), m_pSrc(pSrc) { m_pSrc->AddRef(); }
~CFakeEventObj() { m_pSrc->Release(); }
STDMETHOD(QueryInterface)(REFIID iid, void** ppv) {
if (iid == IID_IUnknown || iid == IID_IDispatch || iid == IID_IHTMLEventObj) {
*ppv = static_cast(this);
AddRef();
return S_OK;
}
*ppv = NULL;
return E_NOINTERFACE;
}
FAKE_DISPATCH_INFO
STDMETHOD(Invoke)(DISPID, REFIID, LCID, WORD, DISPPARAMS*, VARIANT*, EXCEPINFO*, UINT*) {
return DISP_E_MEMBERNOTFOUND;
}
STDMETHOD(get_srcElement)(IHTMLElement** p) {
*p = m_pSrc;
m_pSrc->AddRef();
return S_OK;
}
STDMETHOD(get_type)(BSTR* p) {
*p = ::SysAllocString(L"click");
return S_OK;
}
};
class CFakeElement final : public CStubHTMLElement, public IConnectionPointContainer {
public:
FAKE_REFCOUNT
CString m_strId, m_strClass, m_strTag, m_strText, m_strHtml;
CMap m_props;
CArray m_options; // a