Home | History | Annotate | Download | only in InjectedBundle
      1 /*
      2  * Copyright (C) 2010 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  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
     14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
     17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     23  * THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #ifndef LayoutTestController_h
     27 #define LayoutTestController_h
     28 
     29 #include "JSWrappable.h"
     30 #include <JavaScriptCore/JSRetainPtr.h>
     31 #include <WebKit2/WKBundleScriptWorld.h>
     32 #include <string>
     33 #include <wtf/PassRefPtr.h>
     34 
     35 #if PLATFORM(MAC)
     36 #include <wtf/RetainPtr.h>
     37 typedef RetainPtr<CFRunLoopTimerRef> PlatformTimerRef;
     38 #elif PLATFORM(WIN)
     39 typedef UINT_PTR PlatformTimerRef;
     40 #elif PLATFORM(QT)
     41 #include <QTimer>
     42 typedef QTimer PlatformTimerRef;
     43 #endif
     44 
     45 namespace WTR {
     46 
     47 class LayoutTestController : public JSWrappable {
     48 public:
     49     static PassRefPtr<LayoutTestController> create();
     50     virtual ~LayoutTestController();
     51 
     52     // JSWrappable
     53     virtual JSClassRef wrapperClass();
     54 
     55     void makeWindowObject(JSContextRef, JSObjectRef windowObject, JSValueRef* exception);
     56 
     57     // The basics.
     58     void dumpAsText();
     59     void dumpChildFramesAsText() { m_whatToDump = AllFramesText; }
     60     void waitUntilDone();
     61     void notifyDone();
     62 
     63     // Other dumping.
     64     void dumpBackForwardList() { m_shouldDumpBackForwardListsForAllWindows = true; }
     65     void dumpChildFrameScrollPositions() { m_shouldDumpAllFrameScrollPositions = true; }
     66     void dumpEditingCallbacks() { m_dumpEditingCallbacks = true; }
     67     void dumpSelectionRect() { } // Will need to do something when we support pixel tests.
     68     void dumpStatusCallbacks() { m_dumpStatusCallbacks = true; }
     69     void dumpTitleChanges() { m_dumpTitleChanges = true; }
     70     void dumpFullScreenCallbacks() { m_dumpFullScreenCallbacks = true; }
     71 
     72     // Special options.
     73     void keepWebHistory();
     74     void setAcceptsEditing(bool value) { m_shouldAllowEditing = value; }
     75     void setCanOpenWindows(bool);
     76     void setCloseRemainingWindowsWhenComplete(bool value) { m_shouldCloseExtraWindows = value; }
     77     void setXSSAuditorEnabled(bool);
     78     void setAllowUniversalAccessFromFileURLs(bool);
     79     void setAllowFileAccessFromFileURLs(bool);
     80 
     81     // Special DOM functions.
     82     JSValueRef computedStyleIncludingVisitedInfo(JSValueRef element);
     83     JSRetainPtr<JSStringRef> counterValueForElementById(JSStringRef elementId);
     84     void clearBackForwardList();
     85     void execCommand(JSStringRef name, JSStringRef argument);
     86     bool isCommandEnabled(JSStringRef name);
     87     JSRetainPtr<JSStringRef> markerTextForListItem(JSValueRef element);
     88     unsigned windowCount();
     89     JSValueRef shadowRoot(JSValueRef element);
     90 
     91     // Repaint testing.
     92     void testRepaint() { m_testRepaint = true; }
     93     void repaintSweepHorizontally() { m_testRepaintSweepHorizontally = true; }
     94     void display();
     95 
     96     // Animation testing.
     97     unsigned numberOfActiveAnimations() const;
     98     bool pauseAnimationAtTimeOnElementWithId(JSStringRef animationName, double time, JSStringRef elementId);
     99     void suspendAnimations();
    100     void resumeAnimations();
    101 
    102     // Compositing testing.
    103     JSRetainPtr<JSStringRef> layerTreeAsText() const;
    104 
    105     // UserContent testing.
    106     void addUserScript(JSStringRef source, bool runAtStart, bool allFrames);
    107     void addUserStyleSheet(JSStringRef source, bool allFrames);
    108 
    109     // Text search testing.
    110     bool findString(JSStringRef, JSValueRef optionsArray);
    111 
    112     // Local storage
    113     void clearAllDatabases();
    114     void setDatabaseQuota(uint64_t);
    115     JSRetainPtr<JSStringRef> pathToLocalResource(JSStringRef);
    116 
    117     // Printing
    118     int numberOfPages(double pageWidthInPixels, double pageHeightInPixels);
    119     int pageNumberForElementById(JSStringRef, double pageWidthInPixels, double pageHeightInPixels);
    120     JSRetainPtr<JSStringRef> pageSizeAndMarginsInPixels(int pageIndex, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft);
    121     bool isPageBoxVisible(int pageIndex);
    122 
    123     enum WhatToDump { RenderTree, MainFrameText, AllFramesText };
    124     WhatToDump whatToDump() const { return m_whatToDump; }
    125 
    126     bool shouldDumpAllFrameScrollPositions() const { return m_shouldDumpAllFrameScrollPositions; }
    127     bool shouldDumpBackForwardListsForAllWindows() const { return m_shouldDumpBackForwardListsForAllWindows; }
    128     bool shouldDumpEditingCallbacks() const { return m_dumpEditingCallbacks; }
    129     bool shouldDumpMainFrameScrollPosition() const { return m_whatToDump == RenderTree; }
    130     bool shouldDumpStatusCallbacks() const { return m_dumpStatusCallbacks; }
    131     bool shouldDumpTitleChanges() const { return m_dumpTitleChanges; }
    132     bool shouldDumpPixels() const { return m_dumpPixels; }
    133     bool shouldDumpFullScreenCallbacks() const { return m_dumpFullScreenCallbacks; }
    134 
    135     bool waitToDump() const { return m_waitToDump; }
    136     void waitToDumpWatchdogTimerFired();
    137     void invalidateWaitToDumpWatchdogTimer();
    138 
    139     bool shouldAllowEditing() const { return m_shouldAllowEditing; }
    140 
    141     bool shouldCloseExtraWindowsAfterRunningTest() const { return m_shouldCloseExtraWindows; }
    142 
    143     void evaluateScriptInIsolatedWorld(JSContextRef, unsigned worldID, JSStringRef script);
    144     static unsigned worldIDForWorld(WKBundleScriptWorldRef);
    145 
    146     void showWebInspector();
    147     void closeWebInspector();
    148     void evaluateInWebInspector(long callId, JSStringRef script);
    149     void setTimelineProfilingEnabled(bool);
    150 
    151     void setPOSIXLocale(JSStringRef);
    152 
    153     bool willSendRequestReturnsNull() { return m_willSendRequestReturnsNull; }
    154     void setWillSendRequestReturnsNull(bool f) { m_willSendRequestReturnsNull = f; }
    155 
    156 private:
    157     static const double waitToDumpWatchdogTimerInterval;
    158 
    159     LayoutTestController();
    160 
    161     void platformInitialize();
    162     void initializeWaitToDumpWatchdogTimerIfNeeded();
    163 
    164     WhatToDump m_whatToDump;
    165     bool m_shouldDumpAllFrameScrollPositions;
    166     bool m_shouldDumpBackForwardListsForAllWindows;
    167 
    168     bool m_shouldAllowEditing;
    169     bool m_shouldCloseExtraWindows;
    170 
    171     bool m_dumpEditingCallbacks;
    172     bool m_dumpStatusCallbacks;
    173     bool m_dumpTitleChanges;
    174     bool m_dumpPixels;
    175     bool m_dumpFullScreenCallbacks;
    176     bool m_waitToDump; // True if waitUntilDone() has been called, but notifyDone() has not yet been called.
    177     bool m_testRepaint;
    178     bool m_testRepaintSweepHorizontally;
    179 
    180     bool m_willSendRequestReturnsNull;
    181 
    182     PlatformTimerRef m_waitToDumpWatchdogTimer;
    183 };
    184 
    185 } // namespace WTR
    186 
    187 #endif // LayoutTestController_h
    188