Home | History | Annotate | Download | only in test_runner
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTESTDELEGATE_H_
      6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTESTDELEGATE_H_
      7 
      8 #include <string>
      9 
     10 #include "third_party/WebKit/public/platform/WebScreenOrientationType.h"
     11 #include "third_party/WebKit/public/platform/WebString.h"
     12 #include "third_party/WebKit/public/platform/WebURL.h"
     13 #include "third_party/WebKit/public/platform/WebVector.h"
     14 
     15 #define WEBTESTRUNNER_NEW_HISTORY_CAPTURE
     16 
     17 namespace blink {
     18 class WebBatteryStatus;
     19 class WebDeviceMotionData;
     20 class WebDeviceOrientationData;
     21 class WebFrame;
     22 class WebGamepad;
     23 class WebGamepads;
     24 class WebHistoryItem;
     25 struct WebRect;
     26 struct WebSize;
     27 struct WebURLError;
     28 }
     29 
     30 namespace content {
     31 
     32 class RendererGamepadProvider;
     33 class WebTask;
     34 class WebTestProxyBase;
     35 struct TestPreferences;
     36 
     37 class WebTestDelegate {
     38 public:
     39     // Set and clear the edit command to execute on the next call to
     40     // WebViewClient::handleCurrentKeyboardEvent().
     41     virtual void clearEditCommand() = 0;
     42     virtual void setEditCommand(const std::string& name, const std::string& value) = 0;
     43 
     44     // Sets gamepad provider to be used for tests.
     45     virtual void setGamepadProvider(RendererGamepadProvider*) = 0;
     46 
     47     // Set data to return when registering via Platform::setDeviceMotionListener().
     48     virtual void setDeviceMotionData(const blink::WebDeviceMotionData&) = 0;
     49     // Set data to return when registering via Platform::setDeviceOrientationListener().
     50     virtual void setDeviceOrientationData(const blink::WebDeviceOrientationData&) = 0;
     51 
     52     // Set orientation to set when registering via Platform::setScreenOrientationListener().
     53     virtual void setScreenOrientation(const blink::WebScreenOrientationType&) = 0;
     54 
     55     // Reset the screen orientation data used for testing.
     56     virtual void resetScreenOrientation() = 0;
     57 
     58     // Notifies blink about a change in battery status.
     59     virtual void didChangeBatteryStatus(const blink::WebBatteryStatus&) = 0;
     60 
     61     // Add a message to the text dump for the layout test.
     62     virtual void printMessage(const std::string& message) = 0;
     63 
     64     // The delegate takes ownership of the WebTask objects and is responsible
     65     // for deleting them.
     66     virtual void postTask(WebTask*) = 0;
     67     virtual void postDelayedTask(WebTask*, long long ms) = 0;
     68 
     69     // Register a new isolated filesystem with the given files, and return the
     70     // new filesystem id.
     71     virtual blink::WebString registerIsolatedFileSystem(const blink::WebVector<blink::WebString>& absoluteFilenames) = 0;
     72 
     73     // Gets the current time in milliseconds since the UNIX epoch.
     74     virtual long long getCurrentTimeInMillisecond() = 0;
     75 
     76     // Convert the provided relative path into an absolute path.
     77     virtual blink::WebString getAbsoluteWebStringFromUTF8Path(const std::string& path) = 0;
     78 
     79     // Reads in the given file and returns its contents as data URL.
     80     virtual blink::WebURL localFileToDataURL(const blink::WebURL&) = 0;
     81 
     82     // Replaces file:///tmp/LayoutTests/ with the actual path to the
     83     // LayoutTests directory.
     84     virtual blink::WebURL rewriteLayoutTestsURL(const std::string& utf8URL) = 0;
     85 
     86     // Manages the settings to used for layout tests.
     87     virtual TestPreferences* preferences() = 0;
     88     virtual void applyPreferences() = 0;
     89 
     90     // Enables or disables synchronous resize mode. When enabled, all window-sizing machinery is
     91     // short-circuited inside the renderer. This mode is necessary for some tests that were written
     92     // before browsers had multi-process architecture and rely on window resizes to happen synchronously.
     93     // The function has "unfortunate" it its name because we must strive to remove all tests
     94     // that rely on this... well, unfortunate behavior. See http://crbug.com/309760 for the plan.
     95     virtual void useUnfortunateSynchronousResizeMode(bool) = 0;
     96 
     97     // Controls auto resize mode.
     98     virtual void enableAutoResizeMode(const blink::WebSize& minSize, const blink::WebSize& maxSize) = 0;
     99     virtual void disableAutoResizeMode(const blink::WebSize&) = 0;
    100 
    101     // Clears DevTools' localStorage when an inspector test is started.
    102     virtual void clearDevToolsLocalStorage() = 0;
    103 
    104     // Opens and closes the inspector.
    105     virtual void showDevTools(const std::string& settings,
    106                               const std::string& frontend_url) = 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     // Change the device color profile while running a layout test.
    120     virtual void setDeviceColorProfile(const std::string& name) = 0;
    121 
    122     // Controls which WebView should be focused.
    123     virtual void setFocus(WebTestProxyBase*, bool) = 0;
    124 
    125     // Controls whether all cookies should be accepted or writing cookies in a
    126     // third-party context is blocked.
    127     virtual void setAcceptAllCookies(bool) = 0;
    128 
    129     // The same as rewriteLayoutTestsURL unless the resource is a path starting
    130     // with /tmp/, then return a file URL to a temporary file.
    131     virtual std::string pathToLocalResource(const std::string& resource) = 0;
    132 
    133     // Sets the POSIX locale of the current process.
    134     virtual void setLocale(const std::string&) = 0;
    135 
    136     // Invoked when the test finished.
    137     virtual void testFinished() = 0;
    138 
    139     // Invoked when the embedder should close all but the main WebView.
    140     virtual void closeRemainingWindows() = 0;
    141 
    142     virtual void deleteAllCookies() = 0;
    143 
    144     // Returns the length of the back/forward history of the main WebView.
    145     virtual int navigationEntryCount() = 0;
    146 
    147     // The following trigger navigations on the main WebViwe.
    148     virtual void goToOffset(int offset) = 0;
    149     virtual void reload() = 0;
    150     virtual void loadURLForFrame(const blink::WebURL&, const std::string& frameName) = 0;
    151 
    152     // Returns true if resource requests to external URLs should be permitted.
    153     virtual bool allowExternalPages() = 0;
    154 
    155     // Returns a text dump the back/forward history for the WebView associated
    156     // with the given WebTestProxyBase.
    157     virtual std::string dumpHistoryForWindow(WebTestProxyBase*) = 0;
    158 };
    159 
    160 }  // namespace content
    161 
    162 #endif  // CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTESTDELEGATE_H_
    163