[Win] Various DumpRenderTree Fixes.
[WebKit-https.git] / Tools / DumpRenderTree / win / FrameLoadDelegate.cpp
index 37361f4..036d8eb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2006, 2007, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2005, 2006, 2007, 2009, 2014 Apple Inc. All rights reserved.
  * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -11,7 +11,7 @@
  * 2.  Redistributions in binary form must reproduce the above copyright
  *     notice, this list of conditions and the following disclaimer in the
  *     documentation and/or other materials provided with the distribution. 
- * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
  *     its contributors may be used to endorse or promote products derived
  *     from this software without specific prior written permission. 
  *
@@ -31,6 +31,7 @@
 #include "FrameLoadDelegate.h"
 
 #include "AccessibilityController.h"
+#include <comutil.h>
 #include "DumpRenderTree.h"
 #include "EventSender.h"
 #include "GCController.h"
@@ -45,7 +46,7 @@
 #include <stdio.h>
 #include <string>
 #include <wtf/Assertions.h>
-#include <wtf/PassOwnPtr.h>
+#include <wtf/NeverDestroyed.h>
 #include <wtf/Vector.h>
 
 using std::string;
@@ -62,22 +63,21 @@ string descriptionSuitableForTestResult(IWebFrame* webFrame)
     if (FAILED(webView->mainFrame(&mainFrame)))
         return string();
 
-    BSTR frameNameBSTR;
-    if (FAILED(webFrame->name(&frameNameBSTR)) || toUTF8(frameNameBSTR).empty())
+    _bstr_t frameNameBSTR;
+    if (FAILED(webFrame->name(&frameNameBSTR.GetBSTR())) || !frameNameBSTR.length())
         return (webFrame == mainFrame) ? "main frame" : string();
 
     string frameName = (webFrame == mainFrame) ? "main frame" : "frame";
     frameName += " \"" + toUTF8(frameNameBSTR) + "\""; 
 
-    SysFreeString(frameNameBSTR); 
     return frameName;
 }
 
 FrameLoadDelegate::FrameLoadDelegate()
     : m_refCount(1)
-    , m_gcController(adoptPtr(new GCController))
-    , m_accessibilityController(adoptPtr(new AccessibilityController))
-    , m_textInputController(adoptPtr(new TextInputController))
+    , m_gcController(std::make_unique<GCController>())
+    , m_accessibilityController(std::make_unique<AccessibilityController>())
+    , m_textInputController(std::make_unique<TextInputController>())
 {
 }
 
@@ -85,7 +85,7 @@ FrameLoadDelegate::~FrameLoadDelegate()
 {
 }
 
-HRESULT STDMETHODCALLTYPE FrameLoadDelegate::QueryInterface(REFIID riid, void** ppvObject)
+HRESULT FrameLoadDelegate::QueryInterface(REFIID riid, void** ppvObject)
 {
     *ppvObject = 0;
     if (IsEqualGUID(riid, IID_IUnknown))
@@ -103,12 +103,12 @@ HRESULT STDMETHODCALLTYPE FrameLoadDelegate::QueryInterface(REFIID riid, void**
     return S_OK;
 }
 
-ULONG STDMETHODCALLTYPE FrameLoadDelegate::AddRef(void)
+ULONG FrameLoadDelegate::AddRef(void)
 {
     return ++m_refCount;
 }
 
-ULONG STDMETHODCALLTYPE FrameLoadDelegate::Release(void)
+ULONG FrameLoadDelegate::Release(void)
 {
     ULONG newRef = --m_refCount;
     if (!newRef)
@@ -118,11 +118,9 @@ ULONG STDMETHODCALLTYPE FrameLoadDelegate::Release(void)
 }
 
 
-HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didStartProvisionalLoadForFrame( 
-    /* [in] */ IWebView* webView,
-    /* [in] */ IWebFrame* frame) 
+HRESULT FrameLoadDelegate::didStartProvisionalLoadForFrame(IWebView* /*webView*/, IWebFrame* frame)
 {
-    if (!done && gLayoutTestController->dumpFrameLoadCallbacks())
+    if (!done && gTestRunner->dumpFrameLoadCallbacks())
         printf("%s - didStartProvisionalLoadForFrame\n", descriptionSuitableForTestResult(frame).c_str());
 
     // Make sure we only set this once per test.  If it gets cleared, and then set again, we might
@@ -133,33 +131,26 @@ HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didStartProvisionalLoadForFrame(
     return S_OK; 
 }
 
-HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didReceiveServerRedirectForProvisionalLoadForFrame( 
-    /* [in] */ IWebView *webView,
-    /* [in] */ IWebFrame *frame)
+HRESULT FrameLoadDelegate::didReceiveServerRedirectForProvisionalLoadForFrame(IWebView* /*webView*/, IWebFrame* frame)
 { 
-    if (!done && gLayoutTestController->dumpFrameLoadCallbacks())
+    if (!done && gTestRunner->dumpFrameLoadCallbacks())
         printf("%s - didReceiveServerRedirectForProvisionalLoadForFrame\n", descriptionSuitableForTestResult(frame).c_str());
 
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didFailProvisionalLoadWithError( 
-    /* [in] */ IWebView *webView,
-    /* [in] */ IWebError *error,
-    /* [in] */ IWebFrame *frame)
+HRESULT FrameLoadDelegate::didFailProvisionalLoadWithError(IWebView* /*webView*/, IWebError* error, IWebFrame* frame)
 {
-    if (!done && gLayoutTestController->dumpFrameLoadCallbacks())
+    if (!done && gTestRunner->dumpFrameLoadCallbacks())
         printf("%s - didFailProvisionalLoadWithError\n", descriptionSuitableForTestResult(frame).c_str());
 
     locationChangeDone(error, frame);
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didCommitLoadForFrame( 
-    /* [in] */ IWebView *webView,
-    /* [in] */ IWebFrame *frame)
+HRESULT FrameLoadDelegate::didCommitLoadForFrame(IWebView* webView, IWebFrame* frame)
 {
-    if (!done && gLayoutTestController->dumpFrameLoadCallbacks())
+    if (!done && gTestRunner->dumpFrameLoadCallbacks())
         printf("%s - didCommitLoadForFrame\n", descriptionSuitableForTestResult(frame).c_str());
 
     COMPtr<IWebViewPrivate> webViewPrivate;
@@ -171,24 +162,21 @@ HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didCommitLoadForFrame(
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didReceiveTitle( 
-    /* [in] */ IWebView *webView,
-    /* [in] */ BSTR title,
-    /* [in] */ IWebFrame *frame)
+HRESULT FrameLoadDelegate::didReceiveTitle(IWebView* /*webView*/, BSTR title, IWebFrame* frame)
 {
-    if (!done && gLayoutTestController->dumpFrameLoadCallbacks())
+    if (!done && gTestRunner->dumpFrameLoadCallbacks())
         printf("%s - didReceiveTitle: %S\n", descriptionSuitableForTestResult(frame).c_str(), title);
 
-    if (::gLayoutTestController->dumpTitleChanges() && !done)
-        printf("TITLE CHANGED: %S\n", title ? title : L"");
+    if (::gTestRunner->dumpTitleChanges() && !done)
+        printf("TITLE CHANGED: '%S'\n", title ? title : L"");
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didChangeIcons(
+HRESULT FrameLoadDelegate::didChangeIcons(
     /* [in] */ IWebView* webView,
     /* [in] */ IWebFrame* frame)
 {
-    if (!done && gLayoutTestController->dumpIconChanges())
+    if (!done && gTestRunner->dumpIconChanges())
         printf("%s - didChangeIcons\n", descriptionSuitableForTestResult(frame).c_str());
 
     return S_OK;
@@ -201,7 +189,7 @@ void FrameLoadDelegate::processWork()
         return;
 
     // if we finish all the commands, we're ready to dump state
-    if (WorkQueue::shared()->processWork() && !::gLayoutTestController->waitToDump())
+    if (WorkQueue::shared()->processWork() && !::gTestRunner->waitToDump())
         dump();
 }
 
@@ -213,7 +201,7 @@ void FrameLoadDelegate::resetToConsistentState()
 typedef Vector<COMPtr<FrameLoadDelegate> > DelegateVector;
 static DelegateVector& delegatesWithDelayedWork()
 {
-    DEFINE_STATIC_LOCAL(DelegateVector, delegates, ());
+    static NeverDestroyed<DelegateVector> delegates;
     return delegates;
 }
 
@@ -240,7 +228,7 @@ void FrameLoadDelegate::locationChangeDone(IWebError*, IWebFrame* frame)
     topLoadingFrame = 0;
     WorkQueue::shared()->setFrozen(true);
 
-    if (::gLayoutTestController->waitToDump())
+    if (::gTestRunner->waitToDump())
         return;
 
     if (WorkQueue::shared()->count()) {
@@ -253,57 +241,43 @@ void FrameLoadDelegate::locationChangeDone(IWebError*, IWebFrame* frame)
     dump();
 }
 
-HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didFinishLoadForFrame( 
-    /* [in] */ IWebView* webView,
-    /* [in] */ IWebFrame* frame)
+HRESULT FrameLoadDelegate::didFinishLoadForFrame(IWebView* /*webView*/, IWebFrame* frame)
 {
-    if (!done && gLayoutTestController->dumpFrameLoadCallbacks())
+    if (!done && gTestRunner->dumpFrameLoadCallbacks())
         printf("%s - didFinishLoadForFrame\n", descriptionSuitableForTestResult(frame).c_str());
 
     locationChangeDone(0, frame);
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didFailLoadWithError( 
-    /* [in] */ IWebView* webView,
-    /* [in] */ IWebError* error,
-    /* [in] */ IWebFrame* frame)
+HRESULT FrameLoadDelegate::didFailLoadWithError(IWebView* /*webView*/, IWebError* error, IWebFrame* frame)
 {
-    if (!done && gLayoutTestController->dumpFrameLoadCallbacks())
+    if (!done && gTestRunner->dumpFrameLoadCallbacks())
         printf("%s - didFailLoadWithError\n", descriptionSuitableForTestResult(frame).c_str());
 
     locationChangeDone(error, frame);
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE FrameLoadDelegate::willPerformClientRedirectToURL( 
-    /* [in] */ IWebView *webView,
-    /* [in] */ BSTR url,  
-    /* [in] */ double delaySeconds,
-    /* [in] */ DATE fireDate,
-    /* [in] */ IWebFrame *frame)
+HRESULT FrameLoadDelegate::willPerformClientRedirectToURL(IWebView* /*webView*/, BSTR url, double /*delaySeconds*/, DATE /*fireDate*/, IWebFrame* frame)
 {
-    if (!done && gLayoutTestController->dumpFrameLoadCallbacks())
+    if (!done && gTestRunner->dumpFrameLoadCallbacks())
         printf("%s - willPerformClientRedirectToURL: %S \n", descriptionSuitableForTestResult(frame).c_str(),
                 urlSuitableForTestResult(std::wstring(url, ::SysStringLen(url))).c_str());
 
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didCancelClientRedirectForFrame( 
-    /* [in] */ IWebView *webView,
-    /* [in] */ IWebFrame *frame)
+HRESULT FrameLoadDelegate::didCancelClientRedirectForFrame(IWebView* /*webView*/, IWebFrame* frame)
 {
-    if (!done && gLayoutTestController->dumpFrameLoadCallbacks())
+    if (!done && gTestRunner->dumpFrameLoadCallbacks())
         printf("%s - didCancelClientRedirectForFrame\n", descriptionSuitableForTestResult(frame).c_str());
 
     return S_OK;
 }
 
 
-HRESULT STDMETHODCALLTYPE FrameLoadDelegate::willCloseFrame( 
-    /* [in] */ IWebView *webView,
-    /* [in] */ IWebFrame *frame)
+HRESULT FrameLoadDelegate::willCloseFrame(IWebView* /*webView*/, IWebFrame* /*frame*/)
 {
     return E_NOTIMPL;
 }
@@ -360,7 +334,7 @@ void FrameLoadDelegate::didClearWindowObjectForFrameInStandardWorld(IWebFrame* f
 
     JSValueRef exception = 0;
 
-    ::gLayoutTestController->makeWindowObject(context, windowObject, &exception);
+    ::gTestRunner->makeWindowObject(context, windowObject, &exception);
     ASSERT(!exception);
 
     m_gcController->makeWindowObject(context, windowObject, &exception);
@@ -380,11 +354,9 @@ void FrameLoadDelegate::didClearWindowObjectForFrameInStandardWorld(IWebFrame* f
     WebCoreTestSupport::injectInternalsObject(context);
 }
 
-HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didFinishDocumentLoadForFrame( 
-    /* [in] */ IWebView *sender,
-    /* [in] */ IWebFrame *frame)
+HRESULT FrameLoadDelegate::didFinishDocumentLoadForFrame(IWebView* /*sender*/, IWebFrame* frame)
 {
-    if (!done && gLayoutTestController->dumpFrameLoadCallbacks())
+    if (!done && gTestRunner->dumpFrameLoadCallbacks())
         printf("%s - didFinishDocumentLoadForFrame\n",
                 descriptionSuitableForTestResult(frame).c_str());
     if (!done) {
@@ -404,40 +376,32 @@ HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didFinishDocumentLoadForFrame(
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didHandleOnloadEventsForFrame( 
-    /* [in] */ IWebView *sender,
-    /* [in] */ IWebFrame *frame)
+HRESULT FrameLoadDelegate::didHandleOnloadEventsForFrame(IWebView* /*sender*/, IWebFrame* frame)
 {
-    if (!done && gLayoutTestController->dumpFrameLoadCallbacks())
+    if (!done && gTestRunner->dumpFrameLoadCallbacks())
         printf("%s - didHandleOnloadEventsForFrame\n",
                 descriptionSuitableForTestResult(frame).c_str());
 
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didFirstVisuallyNonEmptyLayoutInFrame( 
-    /* [in] */ IWebView *sender,
-    /* [in] */ IWebFrame *frame)
+HRESULT FrameLoadDelegate::didFirstVisuallyNonEmptyLayoutInFrame(IWebView* /*sender*/, IWebFrame* /*frame*/)
 {
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didDisplayInsecureContent( 
-    /* [in] */ IWebView *sender)
+HRESULT FrameLoadDelegate::didDisplayInsecureContent(IWebView* /*sender*/)
 {
-    if (!done && gLayoutTestController->dumpFrameLoadCallbacks())
+    if (!done && gTestRunner->dumpFrameLoadCallbacks())
         printf("didDisplayInsecureContent\n");
 
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE FrameLoadDelegate::didRunInsecureContent( 
-    /* [in] */ IWebView *sender,
-    /* [in] */ IWebSecurityOrigin *origin)
+HRESULT FrameLoadDelegate::didRunInsecureContent(IWebView* /*sender*/, IWebSecurityOrigin* /*origin*/)
 {
-    if (!done && gLayoutTestController->dumpFrameLoadCallbacks())
+    if (!done && gTestRunner->dumpFrameLoadCallbacks())
         printf("didRunInsecureContent\n");
 
     return S_OK;
 }
-