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_TEST_TEST_WEBKIT_PLATFORM_SUPPORT_H_
6#define CONTENT_TEST_TEST_WEBKIT_PLATFORM_SUPPORT_H_
7
8#include "base/compiler_specific.h"
9#include "base/files/scoped_temp_dir.h"
10#include "content/child/blink_platform_impl.h"
11#include "content/child/simple_webmimeregistry_impl.h"
12#include "content/child/webfileutilities_impl.h"
13#include "content/renderer/compositor_bindings/web_compositor_support_impl.h"
14#include "content/test/mock_webclipboard_impl.h"
15#include "content/test/weburl_loader_mock_factory.h"
16#include "third_party/WebKit/public/platform/WebUnitTestSupport.h"
17
18namespace base {
19class StatsTable;
20}
21
22namespace blink {
23class WebLayerTreeView;
24}
25
26namespace content {
27
28// An implementation of WebKitPlatformSupport for tests.
29class TestWebKitPlatformSupport
30    : public blink::WebUnitTestSupport,
31      public BlinkPlatformImpl {
32 public:
33  TestWebKitPlatformSupport();
34  virtual ~TestWebKitPlatformSupport();
35
36  virtual blink::WebMimeRegistry* mimeRegistry();
37  virtual blink::WebClipboard* clipboard();
38  virtual blink::WebFileUtilities* fileUtilities();
39  virtual blink::WebIDBFactory* idbFactory();
40
41  virtual blink::WebURLLoader* createURLLoader();
42  virtual blink::WebString userAgent() OVERRIDE;
43  virtual blink::WebData loadResource(const char* name);
44  virtual blink::WebString queryLocalizedString(
45      blink::WebLocalizedString::Name name);
46  virtual blink::WebString queryLocalizedString(
47      blink::WebLocalizedString::Name name,
48      const blink::WebString& value);
49  virtual blink::WebString queryLocalizedString(
50      blink::WebLocalizedString::Name name,
51      const blink::WebString& value1,
52      const blink::WebString& value2);
53  virtual blink::WebString defaultLocale();
54
55#if defined(OS_WIN) || defined(OS_MACOSX)
56  void SetThemeEngine(blink::WebThemeEngine* engine);
57  virtual blink::WebThemeEngine* themeEngine();
58#endif
59
60  virtual blink::WebCompositorSupport* compositorSupport();
61
62  WebURLLoaderMockFactory* url_loader_factory() {
63    return url_loader_factory_.get();
64  }
65
66  const base::FilePath& file_system_root() const {
67    return file_system_root_.path();
68  }
69
70  virtual blink::WebGestureCurve* createFlingAnimationCurve(
71      blink::WebGestureDevice device_source,
72      const blink::WebFloatPoint& velocity,
73      const blink::WebSize& cumulative_scroll) OVERRIDE;
74
75  virtual blink::WebUnitTestSupport* unitTestSupport();
76
77  // WebUnitTestSupport implementation
78  virtual void registerMockedURL(const blink::WebURL& url,
79                                 const blink::WebURLResponse& response,
80                                 const blink::WebString& filePath);
81  virtual void registerMockedErrorURL(const blink::WebURL& url,
82                                      const blink::WebURLResponse& response,
83                                      const blink::WebURLError& error);
84  virtual void unregisterMockedURL(const blink::WebURL& url);
85  virtual void unregisterAllMockedURLs();
86  virtual void serveAsynchronousMockedRequests();
87  virtual blink::WebString webKitRootDir();
88  virtual blink::WebLayerTreeView* createLayerTreeViewForTesting();
89  virtual blink::WebData readFromFile(const blink::WebString& path);
90
91 private:
92  SimpleWebMimeRegistryImpl mime_registry_;
93  scoped_ptr<MockWebClipboardImpl> mock_clipboard_;
94  WebFileUtilitiesImpl file_utilities_;
95  base::ScopedTempDir file_system_root_;
96  scoped_ptr<WebURLLoaderMockFactory> url_loader_factory_;
97  WebCompositorSupportImpl compositor_support_;
98  scoped_ptr<base::StatsTable> stats_table_;
99
100#if defined(OS_WIN) || defined(OS_MACOSX)
101  blink::WebThemeEngine* active_theme_engine_;
102#endif
103  DISALLOW_COPY_AND_ASSIGN(TestWebKitPlatformSupport);
104};
105
106}  // namespace content
107
108#endif  // CONTENT_TEST_TEST_WEBKIT_PLATFORM_SUPPORT_H_
109