2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef TestInvocation_h
27 #define TestInvocation_h
29 #include "JSWrappable.h"
30 #include "TestOptions.h"
31 #include "UIScriptContext.h"
32 #include "WhatToDump.h"
33 #include <WebKit/WKRetainPtr.h>
35 #include <wtf/Noncopyable.h>
36 #include <wtf/Seconds.h>
37 #include <wtf/text/StringBuilder.h>
41 class TestInvocation final : public UIScriptContextDelegate {
42 WTF_MAKE_NONCOPYABLE(TestInvocation);
44 explicit TestInvocation(WKURLRef, const TestOptions&);
48 bool urlContains(const char*) const;
50 const TestOptions& options() const { return m_options; }
52 void setIsPixelTest(const std::string& expectedPixelHash);
54 void setCustomTimeout(WTF::Seconds duration) { m_timeout = duration; }
55 void setDumpJSConsoleLogInStdErr(bool value) { m_dumpJSConsoleLogInStdErr = value; }
57 WTF::Seconds shortTimeout() const;
60 void didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
61 WKRetainPtr<WKTypeRef> didReceiveSynchronousMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody);
63 static void dumpWebProcessUnresponsiveness(const char* errorMessage);
64 void outputText(const WTF::String&);
69 void didRemoveSwipeSnapshot();
71 void notifyDownloadDone();
73 void didClearStatisticsThroughWebsiteDataRemoval();
74 void didResetStatisticsToConsistentState();
75 void didSetBlockCookiesForHost();
76 void didSetStatisticsDebugMode();
77 void didSetPrevalentResourceForDebugMode();
78 void didSetLastSeen();
79 void didSetPrevalentResource();
80 void didSetVeryPrevalentResource();
81 void didSetHasHadUserInteraction();
82 void didReceiveAllStorageAccessEntries(Vector<String>& domains);
84 void didRemoveAllSessionCredentials();
86 void dumpResourceLoadStatistics();
88 bool canOpenWindows() const { return m_canOpenWindows; }
91 WKRetainPtr<WKMutableDictionaryRef> createTestSettingsDictionary();
94 static void dump(const char* textToStdout, const char* textToStderr = 0, bool seenError = false);
95 enum class SnapshotResultType { WebView, WebContents };
96 void dumpPixelsAndCompareWithExpected(SnapshotResultType, WKArrayRef repaintRects, WKImageRef = nullptr);
97 void dumpAudio(WKDataRef);
98 bool compareActualHashToExpectedAndDumpResults(const char[33]);
100 static void forceRepaintDoneCallback(WKErrorRef, void* context);
102 struct UIScriptInvocationData {
104 WebKit::WKRetainPtr<WKStringRef> scriptString;
105 TestInvocation* testInvocation;
107 static void runUISideScriptAfterUpdateCallback(WKErrorRef, void* context);
109 bool shouldLogHistoryClientCallbacks() const;
111 void runUISideScript(WKStringRef, unsigned callbackID);
112 // UIScriptContextDelegate
113 void uiScriptDidComplete(const String& result, unsigned callbackID) override;
115 const TestOptions m_options;
117 WKRetainPtr<WKURLRef> m_url;
118 WTF::String m_urlString;
120 std::string m_expectedPixelHash;
122 WTF::Seconds m_timeout;
123 bool m_dumpJSConsoleLogInStdErr { false };
126 bool m_startedTesting { false };
127 bool m_gotInitialResponse { false };
128 bool m_gotFinalMessage { false };
129 bool m_gotRepaint { false };
130 bool m_error { false };
132 bool m_waitUntilDone { false };
133 bool m_dumpFrameLoadCallbacks { false };
134 bool m_dumpPixels { false };
135 bool m_pixelResultIsPending { false };
136 bool m_shouldDumpResourceLoadStatistics { false };
137 bool m_canOpenWindows { false };
138 WhatToDump m_whatToDump { WhatToDump::RenderTree };
140 StringBuilder m_textOutput;
141 String m_savedResourceLoadStatistics;
142 WKRetainPtr<WKDataRef> m_audioResult;
143 WKRetainPtr<WKImageRef> m_pixelResult;
144 WKRetainPtr<WKArrayRef> m_repaintRects;
146 std::unique_ptr<UIScriptContext> m_UIScriptContext;
147 UIScriptInvocationData* m_pendingUIScriptInvocationData { nullptr };
152 #endif // TestInvocation_h