[Win] Update DRT to match Mac Logic
authorbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Oct 2014 22:08:12 +0000 (22:08 +0000)
committerbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Oct 2014 22:08:12 +0000 (22:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137787

Reviewed by Dean Jackson.

* DumpRenderTree/win/DumpRenderTree.cpp:
(initialize): 0 -> nullptr
(runTest): Initialize MSG structure before using.
(main): Add CRT debug flags if building DRT with debug malloc on Windows.
Also, cleanly shut down COM when exiting.
* DumpRenderTree/win/FrameLoadDelegate.cpp:
(FrameLoadDelegate::didChangeLocationWithinPageForFrame): Move from
header and add printf to match Mac.
(FrameLoadDelegate::windowScriptObjectAvailable): Ditto.
* DumpRenderTree/win/FrameLoadDelegate.h:
(FrameLoadDelegate::didChangeLocationWithinPageForFrame): Deleted.
(FrameLoadDelegate::windowScriptObjectAvailable): Deleted.
* DumpRenderTree/win/ResourceLoadDelegate.cpp:
(isLocalhost): Added.
(hostIsUsedBySomeTestsToGenerateError): Added.
(ResourceLoadDelegate::willSendRequest): Add logic to mimic Mac's use
of certain error and redirect host names.
* DumpRenderTree/win/UIDelegate.cpp:
(UIDelegate::runJavaScriptAlertPanelWithMessage): Use 'done' flag to decide if
anything should be output to the console. This modifies behavior to match the Mac.
(UIDelegate::runJavaScriptConfirmPanelWithMessage): Ditto.
(UIDelegate::runJavaScriptTextInputPanelWithPrompt): Ditto.
(UIDelegate::runBeforeUnloadConfirmPanelWithMessage): Ditto.
(UIDelegate::webViewAddMessageToConsole): Ditto.
* WinLauncher/PageLoadTestClient.cpp:
(PageLoadTestClient::pageLoadEndedAtTime): Drive-by-fix for an assertion that I
added last week.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@174796 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/DumpRenderTree/win/DumpRenderTree.cpp
Tools/DumpRenderTree/win/FrameLoadDelegate.cpp
Tools/DumpRenderTree/win/FrameLoadDelegate.h
Tools/DumpRenderTree/win/ResourceLoadDelegate.cpp
Tools/DumpRenderTree/win/UIDelegate.cpp
Tools/WinLauncher/PageLoadTestClient.cpp

index 646ecf4..d57e58c 100644 (file)
@@ -1,3 +1,38 @@
+2014-10-16  Brent Fulgham  <bfulgham@apple.com>
+
+        [Win] Update DRT to match Mac Logic
+        https://bugs.webkit.org/show_bug.cgi?id=137787
+
+        Reviewed by Dean Jackson.
+
+        * DumpRenderTree/win/DumpRenderTree.cpp:
+        (initialize): 0 -> nullptr
+        (runTest): Initialize MSG structure before using.
+        (main): Add CRT debug flags if building DRT with debug malloc on Windows.
+        Also, cleanly shut down COM when exiting.
+        * DumpRenderTree/win/FrameLoadDelegate.cpp:
+        (FrameLoadDelegate::didChangeLocationWithinPageForFrame): Move from
+        header and add printf to match Mac.
+        (FrameLoadDelegate::windowScriptObjectAvailable): Ditto.
+        * DumpRenderTree/win/FrameLoadDelegate.h:
+        (FrameLoadDelegate::didChangeLocationWithinPageForFrame): Deleted.
+        (FrameLoadDelegate::windowScriptObjectAvailable): Deleted.
+        * DumpRenderTree/win/ResourceLoadDelegate.cpp:
+        (isLocalhost): Added.
+        (hostIsUsedBySomeTestsToGenerateError): Added.
+        (ResourceLoadDelegate::willSendRequest): Add logic to mimic Mac's use
+        of certain error and redirect host names.
+        * DumpRenderTree/win/UIDelegate.cpp:
+        (UIDelegate::runJavaScriptAlertPanelWithMessage): Use 'done' flag to decide if
+        anything should be output to the console. This modifies behavior to match the Mac.
+        (UIDelegate::runJavaScriptConfirmPanelWithMessage): Ditto.
+        (UIDelegate::runJavaScriptTextInputPanelWithPrompt): Ditto.
+        (UIDelegate::runBeforeUnloadConfirmPanelWithMessage): Ditto.
+        (UIDelegate::webViewAddMessageToConsole): Ditto.
+        * WinLauncher/PageLoadTestClient.cpp:
+        (PageLoadTestClient::pageLoadEndedAtTime): Drive-by-fix for an assertion that I
+        added last week.
+
 2014-10-16  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r174754.
index 9b63d39..381782c 100644 (file)
@@ -309,7 +309,7 @@ static void initialize()
             dllRegisterServer();
 
     // Init COM
-    OleInitialize(0);
+    OleInitialize(nullptr);
 
     static LPCTSTR fontsToInstall[] = {
         TEXT("AHEM____.ttf"),
@@ -1064,6 +1064,7 @@ static void runTest(const string& inputLine)
     WorkQueue::shared()->clear();
     WorkQueue::shared()->setFrozen(false);
 
+    MSG msg = { 0 };
     HWND hostWindow;
     webView->hostWindow(&hostWindow);
 
@@ -1077,7 +1078,6 @@ static void runTest(const string& inputLine)
     request->setHTTPMethod(methodBStr);
     frame->loadRequest(request.get());
 
-    MSG msg;
     while (true) {
 #if USE(CF)
         CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true);
@@ -1241,6 +1241,11 @@ static LONG WINAPI exceptionFilter(EXCEPTION_POINTERS*)
 
 int main(int argc, const char* argv[])
 {
+#ifdef _CRTDBG_MAP_ALLOC
+    _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
+    _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
+#endif
+
     // Cygwin calls ::SetErrorMode(SEM_FAILCRITICALERRORS), which we will inherit. This is bad for
     // testing/debugging, as it causes the post-mortem debugger not to be invoked. We reset the
     // error mode here to work around Cygwin's behavior. See <http://webkit.org/b/55222>.
@@ -1399,6 +1404,11 @@ int main(int argc, const char* argv[])
 #endif
 
     shutDownWebKit();
+#ifdef _CRTDBG_MAP_ALLOC
+    _CrtDumpMemoryLeaks();
+#endif
+
+    ::OleUninitialize();
 
     return 0;
 }
index 036d8eb..abba4c8 100644 (file)
@@ -139,6 +139,14 @@ HRESULT FrameLoadDelegate::didReceiveServerRedirectForProvisionalLoadForFrame(IW
     return S_OK;
 }
 
+HRESULT FrameLoadDelegate::didChangeLocationWithinPageForFrame(IWebView* , IWebFrame* frame)
+{
+    if (!done && gTestRunner->dumpFrameLoadCallbacks())
+        printf("%s - didChangeLocationWithinPageForFrame\n", descriptionSuitableForTestResult(frame).c_str());
+
+    return S_OK;
+}
+
 HRESULT FrameLoadDelegate::didFailProvisionalLoadWithError(IWebView* /*webView*/, IWebError* error, IWebFrame* frame)
 {
     if (!done && gTestRunner->dumpFrameLoadCallbacks())
@@ -282,6 +290,16 @@ HRESULT FrameLoadDelegate::willCloseFrame(IWebView* /*webView*/, IWebFrame* /*fr
     return E_NOTIMPL;
 }
 
+HRESULT FrameLoadDelegate::windowScriptObjectAvailable(IWebView*, JSContextRef, JSObjectRef)
+{
+    if (!done && gTestRunner->dumpFrameLoadCallbacks())
+        printf("?? - windowScriptObjectAvailable\n");
+
+    ASSERT_NOT_REACHED();
+
+    return S_OK;
+}
+
 HRESULT FrameLoadDelegate::didClearWindowObject(IWebView*, JSContextRef, JSObjectRef, IWebFrame*)
 {
     return E_NOTIMPL;
index e4c21d3..b5dccd3 100644 (file)
@@ -89,9 +89,7 @@ public:
         /* [in] */ IWebError *error,
         /* [in] */ IWebFrame *forFrame);
 
-    virtual HRESULT STDMETHODCALLTYPE didChangeLocationWithinPageForFrame( 
-        /* [in] */ IWebView *webView,
-        /* [in] */ IWebFrame *frame) { return E_NOTIMPL; } 
+    virtual HRESULT STDMETHODCALLTYPE didChangeLocationWithinPageForFrame(IWebView*, IWebFrame*);
 
     virtual HRESULT STDMETHODCALLTYPE willPerformClientRedirectToURL( 
         /* [in] */ IWebView *webView,
@@ -108,16 +106,10 @@ public:
         /* [in] */ IWebView *webView,
         /* [in] */ IWebFrame *frame);
 
-    virtual HRESULT STDMETHODCALLTYPE windowScriptObjectAvailable( 
-        /* [in] */ IWebView *sender,
-        /* [in] */ JSContextRef context,
-        /* [in] */ JSObjectRef windowObject) { return E_NOTIMPL; }
-
-    virtual /* [local] */ HRESULT STDMETHODCALLTYPE didClearWindowObject( 
-        /* [in] */ IWebView* webView,
-        /* [in] */ JSContextRef context,
-        /* [in] */ JSObjectRef windowObject,
-        /* [in] */ IWebFrame* frame);
+    virtual HRESULT STDMETHODCALLTYPE windowScriptObjectAvailable(IWebView*,
+JSContextRef, JSObjectRef windowObject);
+
+    virtual /* [local] */ HRESULT STDMETHODCALLTYPE didClearWindowObject(IWebView*, JSContextRef, JSObjectRef windowObject, IWebFrame*);
 
     // IWebFrameLoadDelegatePrivate
     virtual HRESULT STDMETHODCALLTYPE didFinishDocumentLoadForFrame( 
index d647905..449c1a7 100644 (file)
@@ -35,6 +35,7 @@
 #include <comutil.h>
 #include <sstream>
 #include <tchar.h>
+#include <wtf/RetainPtr.h>
 #include <wtf/Vector.h>
 
 using namespace std;
@@ -217,6 +218,17 @@ HRESULT ResourceLoadDelegate::removeIdentifierForRequest(
     return S_OK;
 }
 
+static bool isLocalhost(CFStringRef host)
+{
+    return kCFCompareEqualTo == CFStringCompare(host, CFSTR("127.0.0.1"), 0)
+        || kCFCompareEqualTo == CFStringCompare(host, CFSTR("localhost"), 0);
+}
+
+static bool hostIsUsedBySomeTestsToGenerateError(CFStringRef host)
+{
+    return kCFCompareEqualTo == CFStringCompare(host, CFSTR("255.255.255.255"), 0);
+}
+
 HRESULT ResourceLoadDelegate::willSendRequest(IWebView* webView, unsigned long identifier, IWebURLRequest* request,
     IWebURLResponse* redirectResponse, IWebDataSource* dataSource, IWebURLRequest** newRequest)
 {
@@ -229,22 +241,56 @@ HRESULT ResourceLoadDelegate::willSendRequest(IWebView* webView, unsigned long i
 
     if (!done && !gTestRunner->deferMainResourceDataLoad()) {
         COMPtr<IWebDataSourcePrivate> dataSourcePrivate(Query, dataSource);
-        if (!dataSourcePrivate)
+        if (!dataSourcePrivate) {
+            *newRequest = nullptr;
             return E_FAIL;
+        }
         dataSourcePrivate->setDeferMainResourceDataLoad(FALSE);
     }
 
     if (!done && gTestRunner->willSendRequestReturnsNull()) {
-        *newRequest = 0;
+        *newRequest = nullptr;
         return S_OK;
     }
 
     if (!done && gTestRunner->willSendRequestReturnsNullOnRedirect() && redirectResponse) {
         printf("Returning null for this redirect\n");
-        *newRequest = 0;
+        *newRequest = nullptr;
         return S_OK;
     }
 
+    _bstr_t urlBstr;
+    if (FAILED(request->URL(&urlBstr.GetBSTR()))) {
+        printf("Request has no URL\n");
+        *newRequest = nullptr;
+        return E_FAIL;
+    }
+
+    RetainPtr<CFStringRef> str = adoptCF(CFStringCreateWithCString(0, static_cast<const char*>(urlBstr), kCFStringEncodingWindowsLatin1));
+    RetainPtr<CFURLRef> url = adoptCF(CFURLCreateWithString(kCFAllocatorDefault, str.get(), nullptr));
+    if (url) {
+        RetainPtr<CFStringRef> host = adoptCF(CFURLCopyHostName(url.get()));
+        RetainPtr<CFStringRef> scheme = adoptCF(CFURLCopyScheme(url.get()));
+
+        if (host && ((kCFCompareEqualTo == CFStringCompare(scheme.get(), CFSTR("http"), kCFCompareCaseInsensitive))
+            || (kCFCompareEqualTo == CFStringCompare(scheme.get(), CFSTR("https"), kCFCompareCaseInsensitive)))) {
+            RetainPtr<CFStringRef> testPathOrURL = adoptCF(CFStringCreateWithCString(kCFAllocatorDefault, gTestRunner->testPathOrURL().c_str(), kCFStringEncodingWindowsLatin1));
+            RetainPtr<CFMutableStringRef> lowercaseTestPathOrURL = adoptCF(CFStringCreateMutableCopy(kCFAllocatorDefault, CFStringGetLength(testPathOrURL.get()), testPathOrURL.get()));
+            RetainPtr<CFLocaleRef> locale = CFLocaleCopyCurrent();
+            CFStringLowercase(lowercaseTestPathOrURL.get(), locale.get());
+            RetainPtr<CFStringRef> testHost;
+            if (CFStringHasPrefix(lowercaseTestPathOrURL.get(), CFSTR("http:")) || CFStringHasPrefix(lowercaseTestPathOrURL.get(), CFSTR("https:"))) {
+                RetainPtr<CFURLRef> testPathURL = adoptCF(CFURLCreateWithString(kCFAllocatorDefault, lowercaseTestPathOrURL.get(), nullptr));
+                testHost = adoptCF(CFURLCopyHostName(testPathURL.get()));
+            }
+            if (!isLocalhost(host.get()) && !hostIsUsedBySomeTestsToGenerateError(host.get()) && (!testHost || isLocalhost(testHost.get()))) {
+                printf("Blocked access to external URL %s\n", static_cast<const char*>(urlBstr));
+                *newRequest = nullptr;
+                return S_OK;
+            }
+        }
+    }
+
     IWebMutableURLRequest* requestCopy = 0;
     request->mutableCopy(&requestCopy);
     const set<string>& clearHeaders = gTestRunner->willSendRequestClearHeaders();
index e2faac1..7d0c640 100644 (file)
@@ -367,15 +367,19 @@ HRESULT UIDelegate::webViewFrame(IWebView* /*sender*/, RECT* frame)
 
 HRESULT UIDelegate::runJavaScriptAlertPanelWithMessage(IWebView* /*sender*/, BSTR message)
 {
-    printf("ALERT: %S\n", message ? message : L"");
-    fflush(stdout);
+    if (!done) {
+        printf("ALERT: %S\n", message ? message : L"");
+        fflush(stdout);
+    }
 
     return S_OK;
 }
 
 HRESULT UIDelegate::runJavaScriptConfirmPanelWithMessage(IWebView* /*sender*/, BSTR message, BOOL* result)
 {
-    printf("CONFIRM: %S\n", message ? message : L"");
+    if (!done)
+        printf("CONFIRM: %S\n", message ? message : L"");
+
     *result = TRUE;
 
     return S_OK;
@@ -383,7 +387,9 @@ HRESULT UIDelegate::runJavaScriptConfirmPanelWithMessage(IWebView* /*sender*/, B
 
 HRESULT UIDelegate::runJavaScriptTextInputPanelWithPrompt(IWebView* /*sender*/, BSTR message, BSTR defaultText, BSTR* result)
 {
-    printf("PROMPT: %S, default text: %S\n", message ? message : L"", defaultText ? defaultText : L"");
+    if (!done)
+        printf("PROMPT: %S, default text: %S\n", message ? message : L"", defaultText ? defaultText : L"");
+
     *result = SysAllocString(defaultText);
 
     return S_OK;
@@ -393,13 +399,20 @@ HRESULT UIDelegate::runBeforeUnloadConfirmPanelWithMessage(IWebView* /*sender*/,
 {
     if (!result)
         return E_POINTER;
-    printf("CONFIRM NAVIGATION: %S\n", message ? message : L"");
+
+    if (!done)
+        printf("CONFIRM NAVIGATION: %S\n", message ? message : L"");
+
     *result = !gTestRunner->shouldStayOnPageAfterHandlingBeforeUnload();
+
     return S_OK;
 }
 
 HRESULT UIDelegate::webViewAddMessageToConsole(IWebView* /*sender*/, BSTR message, int lineNumber, BSTR url, BOOL isError)
 {
+    if (done)
+        return S_OK;
+
     wstring newMessage;
     if (message) {
         newMessage = message;
index 408d1f2..576acde 100644 (file)
@@ -121,7 +121,7 @@ void PageLoadTestClient::didEndResourceLoad(uint64_t resourceIdentifier)
 
 void PageLoadTestClient::pageLoadEndedAtTime(CFAbsoluteTime endTime)
 {
-    ASSERT(m_endTimes.size() == m_currentRepetition);
+    ASSERT(!m_pageLoadTesting || m_endTimes.size() == m_currentRepetition);
     m_endTimes.append(endTime);
 
     if (m_currentRepetition) {