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