1 /* 2 * Copyright (C) 2012 Google 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 are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef WebTestDelegate_h 32 #define WebTestDelegate_h 33 34 #include "public/platform/WebString.h" 35 #include "public/platform/WebURL.h" 36 #include "public/platform/WebVector.h" 37 #include <string> 38 39 #define WEBTESTRUNNER_NEW_HISTORY_CAPTURE 40 41 namespace WebKit { 42 class WebDeviceMotionData; 43 class WebFrame; 44 class WebGamepads; 45 class WebHistoryItem; 46 struct WebRect; 47 struct WebSize; 48 struct WebURLError; 49 } 50 51 namespace WebTestRunner { 52 53 struct WebPreferences; 54 class WebTask; 55 class WebTestProxyBase; 56 57 class WebTestDelegate { 58 public: 59 // Set and clear the edit command to execute on the next call to 60 // WebViewClient::handleCurrentKeyboardEvent(). 61 virtual void clearEditCommand() = 0; 62 virtual void setEditCommand(const std::string& name, const std::string& value) = 0; 63 64 // Set the gamepads to return from Platform::sampleGamepads(). 65 virtual void setGamepadData(const WebKit::WebGamepads&) = 0; 66 67 virtual void setDeviceMotionData(const WebKit::WebDeviceMotionData&) = 0; 68 69 // Add a message to the text dump for the layout test. 70 virtual void printMessage(const std::string& message) = 0; 71 72 // The delegate takes ownership of the WebTask objects and is responsible 73 // for deleting them. 74 virtual void postTask(WebTask*) = 0; 75 virtual void postDelayedTask(WebTask*, long long ms) = 0; 76 77 // Register a new isolated filesystem with the given files, and return the 78 // new filesystem id. 79 virtual WebKit::WebString registerIsolatedFileSystem(const WebKit::WebVector<WebKit::WebString>& absoluteFilenames) = 0; 80 81 // Gets the current time in milliseconds since the UNIX epoch. 82 virtual long long getCurrentTimeInMillisecond() = 0; 83 84 // Convert the provided relative path into an absolute path. 85 virtual WebKit::WebString getAbsoluteWebStringFromUTF8Path(const std::string& path) = 0; 86 87 // Reads in the given file and returns its contents as data URL. 88 virtual WebKit::WebURL localFileToDataURL(const WebKit::WebURL&) = 0; 89 90 // Replaces file:///tmp/LayoutTests/ with the actual path to the 91 // LayoutTests directory. 92 virtual WebKit::WebURL rewriteLayoutTestsURL(const std::string& utf8URL) = 0; 93 94 // Manages the settings to used for layout tests. 95 virtual WebPreferences* preferences() = 0; 96 virtual void applyPreferences() = 0; 97 98 // Resizes the WebView to the given size. 99 virtual void setClientWindowRect(const WebKit::WebRect&) = 0; 100 101 // Controls auto resize mode. 102 virtual void enableAutoResizeMode(const WebKit::WebSize& minSize, const WebKit::WebSize& maxSize) { } 103 virtual void disableAutoResizeMode(const WebKit::WebSize&) { } 104 105 // Opens and closes the inspector. 106 virtual void showDevTools() = 0; 107 virtual void closeDevTools() = 0; 108 109 // Evaluate the given script in the DevTools agent. 110 virtual void evaluateInWebInspector(long callID, const std::string& script) = 0; 111 112 // Controls WebSQL databases. 113 virtual void clearAllDatabases() = 0; 114 virtual void setDatabaseQuota(int) = 0; 115 116 // Controls the device scale factor of the main WebView for hidpi tests. 117 virtual void setDeviceScaleFactor(float) = 0; 118 119 // Controls which WebView should be focused. 120 virtual void setFocus(WebTestProxyBase*, bool) = 0; 121 122 // Controls whether all cookies should be accepted or writing cookies in a 123 // third-party context is blocked. 124 virtual void setAcceptAllCookies(bool) = 0; 125 126 // The same as rewriteLayoutTestsURL unless the resource is a path starting 127 // with /tmp/, then return a file URL to a temporary file. 128 virtual std::string pathToLocalResource(const std::string& resource) = 0; 129 130 // Sets the POSIX locale of the current process. 131 virtual void setLocale(const std::string&) = 0; 132 133 // Invoked when the test finished. 134 virtual void testFinished() = 0; 135 136 // DEPRECATED: Invoked if the test timed out. 137 virtual void testTimedOut() { }; 138 139 // DEPRECATED: If true, never abort a test because of a timeout. 140 virtual bool isBeingDebugged() { return false; }; 141 142 // DEPRECATED: The time in milliseconds after which a test is considered to have timed 143 // out. 144 virtual int layoutTestTimeout() { return 0; }; 145 146 // Invoked when the embedder should close all but the main WebView. 147 virtual void closeRemainingWindows() = 0; 148 149 virtual void deleteAllCookies() = 0; 150 151 // Returns the length of the back/forward history of the main WebView. 152 virtual int navigationEntryCount() = 0; 153 154 // The following trigger navigations on the main WebViwe. 155 virtual void goToOffset(int offset) = 0; 156 virtual void reload() = 0; 157 virtual void loadURLForFrame(const WebKit::WebURL&, const std::string& frameName) = 0; 158 159 // Returns true if resource requests to external URLs should be permitted. 160 virtual bool allowExternalPages() = 0; 161 162 // Returns the back/forward history for the WebView associated with the 163 // given WebTestProxyBase as well as the index of the current entry. 164 virtual void captureHistoryForWindow(WebTestProxyBase*, WebKit::WebVector<WebKit::WebHistoryItem>*, size_t* currentEntryIndex) = 0; 165 }; 166 167 } 168 169 #endif // WebTestDelegate_h 170