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 blink { 42 class WebDeviceMotionData; 43 class WebDeviceOrientationData; 44 class WebFrame; 45 class WebGamepads; 46 class WebHistoryItem; 47 struct WebRect; 48 struct WebSize; 49 struct WebURLError; 50 } 51 52 namespace WebTestRunner { 53 54 struct WebPreferences; 55 class WebTask; 56 class WebTestProxyBase; 57 58 class WebTestDelegate { 59 public: 60 // Set and clear the edit command to execute on the next call to 61 // WebViewClient::handleCurrentKeyboardEvent(). 62 virtual void clearEditCommand() = 0; 63 virtual void setEditCommand(const std::string& name, const std::string& value) = 0; 64 65 // Set the gamepads to return from Platform::sampleGamepads(). 66 virtual void setGamepadData(const blink::WebGamepads&) = 0; 67 68 // Set data to return when registering via Platform::setDeviceMotionListener(). 69 virtual void setDeviceMotionData(const blink::WebDeviceMotionData&) = 0; 70 // Set data to return when registering via Platform::setDeviceOrientationListener(). 71 virtual void setDeviceOrientationData(const blink::WebDeviceOrientationData&) = 0; 72 73 // Add a message to the text dump for the layout test. 74 virtual void printMessage(const std::string& message) = 0; 75 76 // The delegate takes ownership of the WebTask objects and is responsible 77 // for deleting them. 78 virtual void postTask(WebTask*) = 0; 79 virtual void postDelayedTask(WebTask*, long long ms) = 0; 80 81 // Register a new isolated filesystem with the given files, and return the 82 // new filesystem id. 83 virtual blink::WebString registerIsolatedFileSystem(const blink::WebVector<blink::WebString>& absoluteFilenames) = 0; 84 85 // Gets the current time in milliseconds since the UNIX epoch. 86 virtual long long getCurrentTimeInMillisecond() = 0; 87 88 // Convert the provided relative path into an absolute path. 89 virtual blink::WebString getAbsoluteWebStringFromUTF8Path(const std::string& path) = 0; 90 91 // Reads in the given file and returns its contents as data URL. 92 virtual blink::WebURL localFileToDataURL(const blink::WebURL&) = 0; 93 94 // Replaces file:///tmp/LayoutTests/ with the actual path to the 95 // LayoutTests directory. 96 virtual blink::WebURL rewriteLayoutTestsURL(const std::string& utf8URL) = 0; 97 98 // Manages the settings to used for layout tests. 99 virtual WebPreferences* preferences() = 0; 100 virtual void applyPreferences() = 0; 101 102 // Enables or disables synchronous resize mode. When enabled, all window-sizing machinery is 103 // short-circuited inside the renderer. This mode is necessary for some tests that were written 104 // before browsers had multi-process architecture and rely on window resizes to happen synchronously. 105 // The function has "unfortunate" it its name because we must strive to remove all tests 106 // that rely on this... well, unfortunate behavior. See http://crbug.com/309760 for the plan. 107 virtual void useUnfortunateSynchronousResizeMode(bool) = 0; 108 109 // Controls auto resize mode. 110 virtual void enableAutoResizeMode(const blink::WebSize& minSize, const blink::WebSize& maxSize) = 0; 111 virtual void disableAutoResizeMode(const blink::WebSize&) = 0; 112 113 // Opens and closes the inspector. 114 virtual void showDevTools() = 0; 115 virtual void closeDevTools() = 0; 116 117 // Evaluate the given script in the DevTools agent. 118 virtual void evaluateInWebInspector(long callID, const std::string& script) = 0; 119 120 // Controls WebSQL databases. 121 virtual void clearAllDatabases() = 0; 122 virtual void setDatabaseQuota(int) = 0; 123 124 // Controls the device scale factor of the main WebView for hidpi tests. 125 virtual void setDeviceScaleFactor(float) = 0; 126 127 // Controls which WebView should be focused. 128 virtual void setFocus(WebTestProxyBase*, bool) = 0; 129 130 // Controls whether all cookies should be accepted or writing cookies in a 131 // third-party context is blocked. 132 virtual void setAcceptAllCookies(bool) = 0; 133 134 // The same as rewriteLayoutTestsURL unless the resource is a path starting 135 // with /tmp/, then return a file URL to a temporary file. 136 virtual std::string pathToLocalResource(const std::string& resource) = 0; 137 138 // Sets the POSIX locale of the current process. 139 virtual void setLocale(const std::string&) = 0; 140 141 // Invoked when the test finished. 142 virtual void testFinished() = 0; 143 144 // Invoked when the embedder should close all but the main WebView. 145 virtual void closeRemainingWindows() = 0; 146 147 virtual void deleteAllCookies() = 0; 148 149 // Returns the length of the back/forward history of the main WebView. 150 virtual int navigationEntryCount() = 0; 151 152 // The following trigger navigations on the main WebViwe. 153 virtual void goToOffset(int offset) = 0; 154 virtual void reload() = 0; 155 virtual void loadURLForFrame(const blink::WebURL&, const std::string& frameName) = 0; 156 157 // Returns true if resource requests to external URLs should be permitted. 158 virtual bool allowExternalPages() = 0; 159 160 // Returns the back/forward history for the WebView associated with the 161 // given WebTestProxyBase as well as the index of the current entry. 162 virtual void captureHistoryForWindow(WebTestProxyBase*, blink::WebVector<blink::WebHistoryItem>*, size_t* currentEntryIndex) = 0; 163 }; 164 165 } 166 167 #endif // WebTestDelegate_h 168