Home | History | Annotate | Download | only in renderer
      1 // Copyright (c) 2012 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_WEBKIT_TEST_RUNNER_H_
      6 #define CONTENT_SHELL_WEBKIT_TEST_RUNNER_H_
      7 
      8 #include <vector>
      9 
     10 #include "base/files/file_path.h"
     11 #include "base/memory/scoped_ptr.h"
     12 #include "content/public/common/page_state.h"
     13 #include "content/public/renderer/render_view_observer.h"
     14 #include "content/public/renderer/render_view_observer_tracker.h"
     15 #include "content/shell/common/shell_test_configuration.h"
     16 #include "third_party/WebKit/public/testing/WebPreferences.h"
     17 #include "third_party/WebKit/public/testing/WebTestDelegate.h"
     18 #include "v8/include/v8.h"
     19 
     20 class SkCanvas;
     21 
     22 namespace WebKit {
     23 class WebDeviceMotionData;
     24 struct WebRect;
     25 }
     26 
     27 namespace WebTestRunner {
     28 class WebTestProxyBase;
     29 }
     30 
     31 namespace content {
     32 
     33 // This is the renderer side of the webkit test runner.
     34 class WebKitTestRunner : public RenderViewObserver,
     35                          public RenderViewObserverTracker<WebKitTestRunner>,
     36                          public WebTestRunner::WebTestDelegate {
     37  public:
     38   explicit WebKitTestRunner(RenderView* render_view);
     39   virtual ~WebKitTestRunner();
     40 
     41   // RenderViewObserver implementation.
     42   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
     43   virtual void DidClearWindowObject(WebKit::WebFrame* frame) OVERRIDE;
     44   virtual void Navigate(const GURL& url) OVERRIDE;
     45   virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame,
     46                                         bool is_new_navigation) OVERRIDE;
     47   virtual void DidFailProvisionalLoad(
     48       WebKit::WebFrame* frame, const WebKit::WebURLError& error) OVERRIDE;
     49 
     50   // WebTestDelegate implementation.
     51   virtual void clearEditCommand();
     52   virtual void setEditCommand(const std::string& name,
     53                               const std::string& value);
     54   virtual void setGamepadData(const WebKit::WebGamepads& gamepads);
     55   virtual void setDeviceMotionData(const WebKit::WebDeviceMotionData& data);
     56   virtual void printMessage(const std::string& message);
     57   virtual void postTask(::WebTestRunner::WebTask* task);
     58   virtual void postDelayedTask(::WebTestRunner::WebTask* task,
     59                                long long ms);
     60   virtual WebKit::WebString registerIsolatedFileSystem(
     61       const WebKit::WebVector<WebKit::WebString>& absolute_filenames);
     62   virtual long long getCurrentTimeInMillisecond();
     63   virtual WebKit::WebString getAbsoluteWebStringFromUTF8Path(
     64       const std::string& utf8_path);
     65   virtual WebKit::WebURL localFileToDataURL(const WebKit::WebURL& file_url);
     66   virtual WebKit::WebURL rewriteLayoutTestsURL(const std::string& utf8_url);
     67   virtual ::WebTestRunner::WebPreferences* preferences();
     68   virtual void applyPreferences();
     69   virtual std::string makeURLErrorDescription(const WebKit::WebURLError& error);
     70   virtual void setClientWindowRect(const WebKit::WebRect& rect);
     71   virtual void enableAutoResizeMode(const WebKit::WebSize& min_size,
     72                                     const WebKit::WebSize& max_size);
     73   virtual void disableAutoResizeMode(const WebKit::WebSize& new_size);
     74   virtual void showDevTools();
     75   virtual void closeDevTools();
     76   virtual void evaluateInWebInspector(long call_id, const std::string& script);
     77   virtual void clearAllDatabases();
     78   virtual void setDatabaseQuota(int quota);
     79   virtual void setDeviceScaleFactor(float factor);
     80   virtual void setFocus(WebTestRunner::WebTestProxyBase* proxy, bool focus);
     81   virtual void setAcceptAllCookies(bool accept);
     82   virtual std::string pathToLocalResource(const std::string& resource);
     83   virtual void setLocale(const std::string& locale);
     84   virtual void testFinished();
     85   virtual void closeRemainingWindows();
     86   virtual void deleteAllCookies();
     87   virtual int navigationEntryCount();
     88   virtual void goToOffset(int offset);
     89   virtual void reload();
     90   virtual void loadURLForFrame(const WebKit::WebURL& url,
     91                                const std::string& frame_name);
     92   virtual bool allowExternalPages();
     93   virtual void captureHistoryForWindow(
     94       WebTestRunner::WebTestProxyBase* proxy,
     95       WebKit::WebVector<WebKit::WebHistoryItem>* history,
     96       size_t* currentEntryIndex);
     97 
     98   void Reset();
     99 
    100   void set_proxy(::WebTestRunner::WebTestProxyBase* proxy) { proxy_ = proxy; }
    101   ::WebTestRunner::WebTestProxyBase* proxy() const { return proxy_; }
    102 
    103  private:
    104   // Message handlers.
    105   void OnSetTestConfiguration(const ShellTestConfiguration& params);
    106   void OnSessionHistory(
    107       const std::vector<int>& routing_ids,
    108       const std::vector<std::vector<PageState> >& session_histories,
    109       const std::vector<unsigned>& current_entry_indexes);
    110   void OnReset();
    111   void OnNotifyDone();
    112 
    113   // After finishing the test, retrieves the audio, text, and pixel dumps from
    114   // the TestRunner library and sends them to the browser process.
    115   void CaptureDump();
    116 
    117   ::WebTestRunner::WebTestProxyBase* proxy_;
    118 
    119   RenderView* focused_view_;
    120 
    121   ::WebTestRunner::WebPreferences prefs_;
    122 
    123   ShellTestConfiguration test_config_;
    124 
    125   std::vector<int> routing_ids_;
    126   std::vector<std::vector<PageState> > session_histories_;
    127   std::vector<unsigned> current_entry_indexes_;
    128 
    129   bool is_main_window_;
    130 
    131   bool focus_on_next_commit_;
    132 
    133   DISALLOW_COPY_AND_ASSIGN(WebKitTestRunner);
    134 };
    135 
    136 }  // namespace content
    137 
    138 #endif  // CONTENT_SHELL_WEBKIT_TEST_RUNNER_H_
    139