webengine/osswebengine/WebKitTools/DumpRenderTree/win/LayoutTestControllerWin.cpp
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2  * Copyright (C) 2006, 2007 Apple Inc.  All rights reserved.
       
     3  *
       
     4  * Redistribution and use in source and binary forms, with or without
       
     5  * modification, are permitted provided that the following conditions
       
     6  * are met:
       
     7  *
       
     8  * 1.  Redistributions of source code must retain the above copyright
       
     9  *     notice, this list of conditions and the following disclaimer. 
       
    10  * 2.  Redistributions in binary form must reproduce the above copyright
       
    11  *     notice, this list of conditions and the following disclaimer in the
       
    12  *     documentation and/or other materials provided with the distribution. 
       
    13  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
       
    14  *     its contributors may be used to endorse or promote products derived
       
    15  *     from this software without specific prior written permission. 
       
    16  *
       
    17  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
       
    18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
       
    20  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
       
    21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
       
    22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
       
    23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
       
    24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
       
    26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    27  */
       
    28 
       
    29 #include "DumpRenderTree.h"
       
    30 #include "LayoutTestController.h"
       
    31 
       
    32 #include "EditingDelegate.h"
       
    33 #include "WorkQueue.h"
       
    34 #include "WorkQueueItem.h"
       
    35 #include <WebCore/COMPtr.h>
       
    36 #include <wtf/Platform.h>
       
    37 #include <wtf/RetainPtr.h>
       
    38 #include <wtf/Vector.h>
       
    39 #include <JavaScriptCore/Assertions.h>
       
    40 #include <JavaScriptCore/JavaScriptCore.h>
       
    41 #include <JavaScriptCore/JSRetainPtr.h>
       
    42 #include <WebKit/IWebViewPrivate.h>
       
    43 #include <string>
       
    44 #include <CoreFoundation/CoreFoundation.h>
       
    45 
       
    46 using std::string;
       
    47 using std::wstring;
       
    48 
       
    49 void LayoutTestController::addDisallowedURL(JSStringRef url)
       
    50 {
       
    51     // FIXME: Implement!
       
    52 }
       
    53 
       
    54 void LayoutTestController::clearBackForwardList()
       
    55 {
       
    56     COMPtr<IWebView> webView;
       
    57     if (FAILED(frame->webView(&webView)))
       
    58         return;
       
    59 
       
    60     COMPtr<IWebBackForwardList> backForwardList;
       
    61     if (FAILED(webView->backForwardList(&backForwardList)))
       
    62         return;
       
    63 
       
    64     COMPtr<IWebHistoryItem> item;
       
    65     if (FAILED(backForwardList->currentItem(&item)))
       
    66         return;
       
    67 
       
    68     // We clear the history by setting the back/forward list's capacity to 0
       
    69     // then restoring it back and adding back the current item.
       
    70     int capacity;
       
    71     if (FAILED(backForwardList->capacity(&capacity)))
       
    72         return;
       
    73 
       
    74     backForwardList->setCapacity(0);
       
    75     backForwardList->setCapacity(capacity);
       
    76     backForwardList->addItem(item.get());
       
    77     backForwardList->goToItem(item.get());
       
    78 }
       
    79 
       
    80 JSStringRef LayoutTestController::copyDecodedHostName(JSStringRef name)
       
    81 {
       
    82     // FIXME: Implement!
       
    83     return 0;
       
    84 }
       
    85 
       
    86 JSStringRef LayoutTestController::copyEncodedHostName(JSStringRef name)
       
    87 {
       
    88     // FIXME: Implement!
       
    89     return 0;
       
    90 }
       
    91 
       
    92 void LayoutTestController::display()
       
    93 {
       
    94     displayWebView();
       
    95 }
       
    96 
       
    97 void LayoutTestController::keepWebHistory()
       
    98 {
       
    99     // FIXME: Implement!
       
   100 }
       
   101 
       
   102 void LayoutTestController::notifyDone()
       
   103 {
       
   104     // Same as on mac.  This can be shared.
       
   105     if (m_waitToDump && !topLoadingFrame && !WorkQueue::shared()->count())
       
   106         dump();
       
   107     m_waitToDump = false;
       
   108 }
       
   109 
       
   110 void LayoutTestController::queueBackNavigation(int howFarBack)
       
   111 {
       
   112     // Same as on mac.  This can be shared.
       
   113     WorkQueue::shared()->queue(new BackItem(howFarBack));
       
   114 }
       
   115 
       
   116 void LayoutTestController::queueForwardNavigation(int howFarForward)
       
   117 {
       
   118     // Same as on mac.  This can be shared.
       
   119     WorkQueue::shared()->queue(new ForwardItem(howFarForward));
       
   120 }
       
   121 
       
   122 static wstring jsStringRefToWString(JSStringRef jsStr)
       
   123 {
       
   124     size_t length = JSStringGetLength(jsStr);
       
   125     Vector<WCHAR> buffer(length + 1);
       
   126     memcpy(buffer.data(), JSStringGetCharactersPtr(jsStr), length * sizeof(WCHAR));
       
   127     buffer[length] = '\0';
       
   128 
       
   129     return buffer.data();
       
   130 }
       
   131 
       
   132 void LayoutTestController::queueLoad(JSStringRef url, JSStringRef target)
       
   133 {
       
   134     COMPtr<IWebDataSource> dataSource;
       
   135     if (FAILED(frame->dataSource(&dataSource)))
       
   136         return;
       
   137 
       
   138     COMPtr<IWebURLResponse> response;
       
   139     if (FAILED(dataSource->response(&response)) || !response)
       
   140         return;
       
   141 
       
   142     BSTR responseURLBSTR;
       
   143     if (FAILED(response->URL(&responseURLBSTR)))
       
   144         return;
       
   145     wstring responseURL(responseURLBSTR, SysStringLen(responseURLBSTR));
       
   146     SysFreeString(responseURLBSTR);
       
   147 
       
   148     // FIXME: We should do real relative URL resolution here.
       
   149     int lastSlash = responseURL.rfind('/');
       
   150     if (lastSlash != -1)
       
   151         responseURL = responseURL.substr(0, lastSlash);
       
   152 
       
   153     wstring wURL = jsStringRefToWString(url);
       
   154     wstring wAbosuluteURL = responseURL + TEXT("/") + wURL;
       
   155     JSRetainPtr<JSStringRef> jsAbsoluteURL(Adopt, JSStringCreateWithCharacters(wAbosuluteURL.data(), wAbosuluteURL.length()));
       
   156 
       
   157     WorkQueue::shared()->queue(new LoadItem(jsAbsoluteURL.get(), target));
       
   158 }
       
   159 
       
   160 void LayoutTestController::queueReload()
       
   161 {
       
   162     WorkQueue::shared()->queue(new ReloadItem);
       
   163 }
       
   164 
       
   165 void LayoutTestController::queueScript(JSStringRef script)
       
   166 {
       
   167     WorkQueue::shared()->queue(new ScriptItem(script));
       
   168 }
       
   169 
       
   170 void LayoutTestController::setAcceptsEditing(bool acceptsEditing)
       
   171 {
       
   172     COMPtr<IWebView> webView;
       
   173     if (FAILED(frame->webView(&webView)))
       
   174         return;
       
   175 
       
   176     COMPtr<IWebViewEditing> viewEditing;
       
   177     if (FAILED(webView->QueryInterface(&viewEditing)))
       
   178         return;
       
   179 
       
   180     COMPtr<IWebEditingDelegate> delegate;
       
   181     if (FAILED(viewEditing->editingDelegate(&delegate)))
       
   182         return;
       
   183 
       
   184     EditingDelegate* editingDelegate = (EditingDelegate*)(IWebEditingDelegate*)delegate.get();
       
   185     editingDelegate->setAcceptsEditing(acceptsEditing);
       
   186 }
       
   187 
       
   188 void LayoutTestController::setCustomPolicyDelegate(bool setDelegate)
       
   189 {
       
   190     // FIXME: Implement!
       
   191 }
       
   192 
       
   193 void LayoutTestController::setMainFrameIsFirstResponder(bool flag)
       
   194 {
       
   195     // FIXME: Implement!
       
   196 }
       
   197 
       
   198 void LayoutTestController::setTabKeyCyclesThroughElements(bool shouldCycle)
       
   199 {
       
   200     COMPtr<IWebView> webView;
       
   201     if (FAILED(frame->webView(&webView)))
       
   202         return;
       
   203 
       
   204     COMPtr<IWebViewPrivate> viewPrivate;
       
   205     if (FAILED(webView->QueryInterface(&viewPrivate)))
       
   206         return;
       
   207 
       
   208     viewPrivate->setTabKeyCyclesThroughElements(shouldCycle ? TRUE : FALSE);
       
   209 }
       
   210 
       
   211 void LayoutTestController::setUseDashboardCompatibilityMode(bool flag)
       
   212 {
       
   213     // FIXME: Implement!
       
   214 }
       
   215 
       
   216 void LayoutTestController::setUserStyleSheetEnabled(bool flag)
       
   217 {
       
   218     // FIXME: Implement!
       
   219 }
       
   220 
       
   221 void LayoutTestController::setUserStyleSheetLocation(JSStringRef path)
       
   222 {
       
   223     // FIXME: Implement!
       
   224 }
       
   225 
       
   226 void LayoutTestController::setWindowIsKey(bool flag)
       
   227 {
       
   228     // FIXME: Implement!
       
   229 }
       
   230 
       
   231 static const CFTimeInterval waitToDumpWatchdogInterval = 10.0;
       
   232 
       
   233 static void waitUntilDoneWatchdogFired(CFRunLoopTimerRef timer, void* info)
       
   234 {
       
   235     const char* message = "FAIL: Timed out waiting for notifyDone to be called\n";
       
   236     fprintf(stderr, message);
       
   237     fprintf(stdout, message);
       
   238     dump();
       
   239 }
       
   240 
       
   241 void LayoutTestController::setWaitToDump(bool waitUntilDone)
       
   242 {
       
   243     // Same as on mac.  This can be shared.
       
   244     m_waitToDump = waitUntilDone;
       
   245     if (m_waitToDump && !waitToDumpWatchdog)
       
   246         ::waitToDumpWatchdog = CFRunLoopTimerCreate(0, 0, waitToDumpWatchdogInterval, 0, 0, waitUntilDoneWatchdogFired, NULL);
       
   247 }
       
   248 
       
   249 int LayoutTestController::windowCount()
       
   250 {
       
   251     // FIXME: Implement!
       
   252     return 1;
       
   253 }