diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-14 01:24:47 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-14 01:24:47 +0000 |
commit | 3469ea224416a6bf15f08133516f0c11913eebe1 (patch) | |
tree | 917248385278e4f6fc95094d81fb1bdfa8d0262f /webkit | |
parent | cb6b3902049d0bb227f486511c79220bc51afcc6 (diff) | |
download | chromium_src-3469ea224416a6bf15f08133516f0c11913eebe1.zip chromium_src-3469ea224416a6bf15f08133516f0c11913eebe1.tar.gz chromium_src-3469ea224416a6bf15f08133516f0c11913eebe1.tar.bz2 |
Move source files from webkit/support to content/test
BUG=265753
TEST=content_unittests, webkit_unit_tests, content_shell
R=jamesr@chromium.org,tkent@chromium.org,jochen@chromium.org
Review URL: https://chromiumcodereview.appspot.com/23526028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223201 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/webkit_glue.gypi | 3 | ||||
-rw-r--r-- | webkit/support/mock_webclipboard_impl.cc | 204 | ||||
-rw-r--r-- | webkit/support/mock_webclipboard_impl.h | 60 | ||||
-rw-r--r-- | webkit/support/test_webkit_platform_support.cc | 320 | ||||
-rw-r--r-- | webkit/support/test_webkit_platform_support.h | 111 | ||||
-rw-r--r-- | webkit/support/web_gesture_curve_mock.cc | 32 | ||||
-rw-r--r-- | webkit/support/web_gesture_curve_mock.h | 32 | ||||
-rw-r--r-- | webkit/support/web_layer_tree_view_impl_for_testing.cc | 179 | ||||
-rw-r--r-- | webkit/support/web_layer_tree_view_impl_for_testing.h | 87 | ||||
-rw-r--r-- | webkit/support/webkit_support.cc | 94 | ||||
-rw-r--r-- | webkit/support/webkit_support.gyp | 1 | ||||
-rw-r--r-- | webkit/support/webkit_support.gypi | 109 | ||||
-rw-r--r-- | webkit/support/webkit_support.h | 17 | ||||
-rw-r--r-- | webkit/support/webkit_support_glue.cc | 33 | ||||
-rw-r--r-- | webkit/support/weburl_loader_mock.cc | 98 | ||||
-rw-r--r-- | webkit/support/weburl_loader_mock.h | 64 | ||||
-rw-r--r-- | webkit/support/weburl_loader_mock_factory.cc | 192 | ||||
-rw-r--r-- | webkit/support/weburl_loader_mock_factory.h | 115 |
18 files changed, 3 insertions, 1748 deletions
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index adbd54d..c2c3fed 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -9,6 +9,9 @@ 'cflags+': ['-Wno-narrowing'], 'cflags_cc+': ['-Wno-narrowing'], }, + 'variables': { + 'chromium_code': 1, + }, 'targets': [ { 'target_name': 'glue_child', diff --git a/webkit/support/mock_webclipboard_impl.cc b/webkit/support/mock_webclipboard_impl.cc deleted file mode 100644 index f1c6d42..0000000 --- a/webkit/support/mock_webclipboard_impl.cc +++ /dev/null @@ -1,204 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "webkit/support/mock_webclipboard_impl.h" - -#include <algorithm> - -#include "base/logging.h" -#include "base/stl_util.h" -#include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" -#include "third_party/WebKit/public/platform/WebCommon.h" -#include "third_party/WebKit/public/platform/WebDragData.h" -#include "third_party/WebKit/public/platform/WebImage.h" -#include "third_party/WebKit/public/platform/WebURL.h" -#include "ui/base/clipboard/clipboard.h" -#include "ui/gfx/codec/png_codec.h" -#include "ui/gfx/size.h" -#include "webkit/glue/webkit_glue.h" -#include "webkit/renderer/clipboard_utils.h" - -using WebKit::WebDragData; -using WebKit::WebString; -using WebKit::WebURL; -using WebKit::WebVector; - -MockWebClipboardImpl::MockWebClipboardImpl() { -} - -MockWebClipboardImpl::~MockWebClipboardImpl() { -} - -bool MockWebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) { - switch (format) { - case FormatPlainText: - return !m_plainText.isNull(); - - case FormatHTML: - return !m_htmlText.isNull(); - - case FormatSmartPaste: - return m_writeSmartPaste; - - default: - NOTREACHED(); - return false; - } - - switch (buffer) { - case BufferStandard: - break; - case BufferSelection: -#if defined(OS_POSIX) && !defined(OS_MACOSX) - break; -#endif - default: - NOTREACHED(); - return false; - } - - return true; -} - -WebVector<WebString> MockWebClipboardImpl::readAvailableTypes( - Buffer buffer, bool* containsFilenames) { - *containsFilenames = false; - std::vector<WebString> results; - if (!m_plainText.isEmpty()) { - results.push_back(WebString("text/plain")); - } - if (!m_htmlText.isEmpty()) { - results.push_back(WebString("text/html")); - } - if (!m_image.isNull()) { - results.push_back(WebString("image/png")); - } - for (std::map<base::string16, base::string16>::const_iterator it = - m_customData.begin(); - it != m_customData.end(); ++it) { - CHECK(std::find(results.begin(), results.end(), it->first) == - results.end()); - results.push_back(it->first); - } - return results; -} - -WebKit::WebString MockWebClipboardImpl::readPlainText( - WebKit::WebClipboard::Buffer buffer) { - return m_plainText; -} - -// TODO(wtc): set output argument *url. -WebKit::WebString MockWebClipboardImpl::readHTML( - WebKit::WebClipboard::Buffer buffer, WebKit::WebURL* url, - unsigned* fragmentStart, unsigned* fragmentEnd) { - *fragmentStart = 0; - *fragmentEnd = static_cast<unsigned>(m_htmlText.length()); - return m_htmlText; -} - -WebKit::WebData MockWebClipboardImpl::readImage( - WebKit::WebClipboard::Buffer buffer) { - std::string data; - std::vector<unsigned char> encoded_image; - // TODO(dcheng): Verify that we can assume the image is ARGB8888. Note that - // for endianess reasons, it will be BGRA8888 on Windows. - const SkBitmap& bitmap = m_image.getSkBitmap(); - SkAutoLockPixels lock(bitmap); - gfx::PNGCodec::Encode(static_cast<unsigned char*>(bitmap.getPixels()), -#if defined(OS_ANDROID) - gfx::PNGCodec::FORMAT_RGBA, -#else - gfx::PNGCodec::FORMAT_BGRA, -#endif - gfx::Size(bitmap.width(), bitmap.height()), - bitmap.rowBytes(), - false /* discard_transparency */, - std::vector<gfx::PNGCodec::Comment>(), - &encoded_image); - data.assign(reinterpret_cast<char*>(vector_as_array(&encoded_image)), - encoded_image.size()); - return data; -} - -WebKit::WebString MockWebClipboardImpl::readCustomData( - WebKit::WebClipboard::Buffer buffer, - const WebKit::WebString& type) { - std::map<base::string16, base::string16>::const_iterator it = - m_customData.find(type); - if (it != m_customData.end()) - return it->second; - return WebKit::WebString(); -} - -void MockWebClipboardImpl::writeHTML( - const WebKit::WebString& htmlText, const WebKit::WebURL& url, - const WebKit::WebString& plainText, bool writeSmartPaste) { - clear(); - - m_htmlText = htmlText; - m_plainText = plainText; - m_writeSmartPaste = writeSmartPaste; -} - -void MockWebClipboardImpl::writePlainText(const WebKit::WebString& plain_text) { - clear(); - - m_plainText = plain_text; -} - -void MockWebClipboardImpl::writeURL( - const WebKit::WebURL& url, const WebKit::WebString& title) { - clear(); - - m_htmlText = WebString::fromUTF8(webkit_clipboard::URLToMarkup(url, title)); - m_plainText = url.spec().utf16(); -} - -void MockWebClipboardImpl::writeImage(const WebKit::WebImage& image, - const WebKit::WebURL& url, const WebKit::WebString& title) { - if (!image.isNull()) { - clear(); - - m_plainText = m_htmlText; - m_htmlText = WebString::fromUTF8( - webkit_clipboard::URLToImageMarkup(url, title)); - m_image = image; - } -} - -void MockWebClipboardImpl::writeDataObject(const WebDragData& data) { - clear(); - - const WebVector<WebDragData::Item>& itemList = data.items(); - for (size_t i = 0; i < itemList.size(); ++i) { - const WebDragData::Item& item = itemList[i]; - switch (item.storageType) { - case WebDragData::Item::StorageTypeString: { - if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeText)) { - m_plainText = item.stringData; - continue; - } - if (EqualsASCII(item.stringType, ui::Clipboard::kMimeTypeHTML)) { - m_htmlText = item.stringData; - continue; - } - m_customData.insert(std::make_pair(item.stringType, item.stringData)); - continue; - } - case WebDragData::Item::StorageTypeFilename: - case WebDragData::Item::StorageTypeBinaryData: - NOTREACHED(); // Currently unused by the clipboard implementation. - } - } -} - -void MockWebClipboardImpl::clear() { - m_plainText = WebString(); - m_htmlText = WebString(); - m_image.reset(); - m_customData.clear(); - m_writeSmartPaste = false; -} diff --git a/webkit/support/mock_webclipboard_impl.h b/webkit/support/mock_webclipboard_impl.h deleted file mode 100644 index 61efcf4..0000000 --- a/webkit/support/mock_webclipboard_impl.h +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// This file mocks out just enough of the WebClipboard API for running the -// webkit tests. This is so we can run webkit tests without them sharing a -// clipboard, which allows for running them in parallel and having the tests -// not interact with actual user actions. - -#ifndef WEBKIT_SUPPORT_MOCK_WEBCLIPBOARD_IMPL_H_ -#define WEBKIT_SUPPORT_MOCK_WEBCLIPBOARD_IMPL_H_ - -#include <map> - -#include "base/strings/string16.h" -#include "third_party/WebKit/public/platform/WebClipboard.h" -#include "third_party/WebKit/public/platform/WebDragData.h" -#include "third_party/WebKit/public/platform/WebImage.h" - -class MockWebClipboardImpl : public WebKit::WebClipboard { - public: - MockWebClipboardImpl(); - virtual ~MockWebClipboardImpl(); - - virtual bool isFormatAvailable(WebKit::WebClipboard::Format format, - WebKit::WebClipboard::Buffer buffer); - virtual WebKit::WebVector<WebKit::WebString> readAvailableTypes( - WebKit::WebClipboard::Buffer buffer, bool* containsFilenames); - - virtual WebKit::WebString readPlainText(WebKit::WebClipboard::Buffer buffer); - virtual WebKit::WebString readHTML(WebKit::WebClipboard::Buffer buffer, - WebKit::WebURL* url, - unsigned* fragmentStart, - unsigned* fragmentEnd); - virtual WebKit::WebData readImage(WebKit::WebClipboard::Buffer buffer); - virtual WebKit::WebString readCustomData(WebKit::WebClipboard::Buffer buffer, - const WebKit::WebString& type); - - virtual void writePlainText(const WebKit::WebString& plain_text); - virtual void writeHTML( - const WebKit::WebString& htmlText, const WebKit::WebURL& url, - const WebKit::WebString& plainText, bool writeSmartPaste); - virtual void writeURL( - const WebKit::WebURL& url, const WebKit::WebString& title); - virtual void writeImage( - const WebKit::WebImage& image, const WebKit::WebURL& url, - const WebKit::WebString& title); - virtual void writeDataObject(const WebKit::WebDragData& data); - - private: - void clear(); - - WebKit::WebString m_plainText; - WebKit::WebString m_htmlText; - WebKit::WebImage m_image; - std::map<base::string16, base::string16> m_customData; - bool m_writeSmartPaste; -}; - -#endif // WEBKIT_SUPPORT_MOCK_WEBCLIPBOARD_IMPL_H_ diff --git a/webkit/support/test_webkit_platform_support.cc b/webkit/support/test_webkit_platform_support.cc deleted file mode 100644 index ae0a7e5..0000000 --- a/webkit/support/test_webkit_platform_support.cc +++ /dev/null @@ -1,320 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "webkit/support/test_webkit_platform_support.h" - -#include "base/command_line.h" -#include "base/file_util.h" -#include "base/files/file_path.h" -#include "base/files/scoped_temp_dir.h" -#include "base/metrics/stats_counters.h" -#include "base/path_service.h" -#include "base/strings/utf_string_conversions.h" -#include "media/base/media.h" -#include "net/cookies/cookie_monster.h" -#include "net/test/spawned_test_server/spawned_test_server.h" -#include "third_party/WebKit/public/platform/WebData.h" -#include "third_party/WebKit/public/platform/WebFileSystem.h" -#include "third_party/WebKit/public/platform/WebStorageArea.h" -#include "third_party/WebKit/public/platform/WebStorageNamespace.h" -#include "third_party/WebKit/public/platform/WebString.h" -#include "third_party/WebKit/public/platform/WebURL.h" -#include "third_party/WebKit/public/web/WebDatabase.h" -#include "third_party/WebKit/public/web/WebKit.h" -#include "third_party/WebKit/public/web/WebRuntimeFeatures.h" -#include "third_party/WebKit/public/web/WebScriptController.h" -#include "third_party/WebKit/public/web/WebSecurityPolicy.h" -#include "third_party/WebKit/public/web/WebStorageEventDispatcher.h" -#include "v8/include/v8.h" -#include "webkit/browser/database/vfs_backend.h" -#include "webkit/child/webkitplatformsupport_impl.h" -#include "webkit/glue/simple_webmimeregistry_impl.h" -#include "webkit/glue/webkit_glue.h" -#include "webkit/renderer/compositor_bindings/web_compositor_support_impl.h" -#include "webkit/support/mock_webclipboard_impl.h" -#include "webkit/support/web_gesture_curve_mock.h" -#include "webkit/support/web_layer_tree_view_impl_for_testing.h" -#include "webkit/support/weburl_loader_mock_factory.h" - -#if defined(OS_WIN) -#include "third_party/WebKit/public/platform/win/WebThemeEngine.h" -#elif defined(OS_MACOSX) -#include "base/mac/mac_util.h" -#endif - -using WebKit::WebScriptController; -using webkit::WebLayerTreeViewImplForTesting; - -TestWebKitPlatformSupport::TestWebKitPlatformSupport() { - v8::V8::SetCounterFunction(base::StatsTable::FindLocation); - - WebKit::initialize(this); - WebKit::setLayoutTestMode(true); - WebKit::WebSecurityPolicy::registerURLSchemeAsLocal( - WebKit::WebString::fromUTF8("test-shell-resource")); - WebKit::WebSecurityPolicy::registerURLSchemeAsNoAccess( - WebKit::WebString::fromUTF8("test-shell-resource")); - WebKit::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated( - WebKit::WebString::fromUTF8("test-shell-resource")); - WebKit::WebSecurityPolicy::registerURLSchemeAsEmptyDocument( - WebKit::WebString::fromUTF8("test-shell-resource")); - WebScriptController::enableV8SingleThreadMode(); - WebKit::WebRuntimeFeatures::enableApplicationCache(true); - WebKit::WebRuntimeFeatures::enableDatabase(true); - WebKit::WebRuntimeFeatures::enableNotifications(true); - WebKit::WebRuntimeFeatures::enableTouch(true); - - // Load libraries for media and enable the media player. - bool enable_media = false; - base::FilePath module_path; - if (PathService::Get(base::DIR_MODULE, &module_path)) { -#if defined(OS_MACOSX) - if (base::mac::AmIBundled()) - module_path = module_path.DirName().DirName().DirName(); -#endif - if (media::InitializeMediaLibrary(module_path)) - enable_media = true; - } - WebKit::WebRuntimeFeatures::enableMediaPlayer(enable_media); - LOG_IF(WARNING, !enable_media) << "Failed to initialize the media library.\n"; - - // TODO(joth): Make a dummy geolocation service implemenation for - // test_shell, and set this to true. http://crbug.com/36451 - WebKit::WebRuntimeFeatures::enableGeolocation(false); - - file_utilities_.set_sandbox_enabled(false); - - if (!file_system_root_.CreateUniqueTempDir()) { - LOG(WARNING) << "Failed to create a temp dir for the filesystem." - "FileSystem feature will be disabled."; - DCHECK(file_system_root_.path().empty()); - } - -#if defined(OS_WIN) - // Ensure we pick up the default theme engine. - SetThemeEngine(NULL); -#endif - - net::CookieMonster::EnableFileScheme(); - - // Test shell always exposes the GC. - webkit_glue::SetJavaScriptFlags(" --expose-gc"); -} - -TestWebKitPlatformSupport::~TestWebKitPlatformSupport() { -} - -WebKit::WebMimeRegistry* TestWebKitPlatformSupport::mimeRegistry() { - return &mime_registry_; -} - -WebKit::WebClipboard* TestWebKitPlatformSupport::clipboard() { - // Mock out clipboard calls so that tests don't mess - // with each other's copies/pastes when running in parallel. - return &mock_clipboard_; -} - -WebKit::WebFileUtilities* TestWebKitPlatformSupport::fileUtilities() { - return &file_utilities_; -} - -WebKit::WebIDBFactory* TestWebKitPlatformSupport::idbFactory() { - NOTREACHED() << - "IndexedDB cannot be tested with in-process harnesses."; - return NULL; -} - -WebKit::WebURLLoader* TestWebKitPlatformSupport::createURLLoader() { - return url_loader_factory_.CreateURLLoader( - webkit_glue::WebKitPlatformSupportImpl::createURLLoader()); -} - -WebKit::WebData TestWebKitPlatformSupport::loadResource(const char* name) { - if (!strcmp(name, "deleteButton")) { - // Create a red 30x30 square. - const char red_square[] = - "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" - "\x00\x00\x00\x1e\x00\x00\x00\x1e\x04\x03\x00\x00\x00\xc9\x1e\xb3" - "\x91\x00\x00\x00\x30\x50\x4c\x54\x45\x00\x00\x00\x80\x00\x00\x00" - "\x80\x00\x80\x80\x00\x00\x00\x80\x80\x00\x80\x00\x80\x80\x80\x80" - "\x80\xc0\xc0\xc0\xff\x00\x00\x00\xff\x00\xff\xff\x00\x00\x00\xff" - "\xff\x00\xff\x00\xff\xff\xff\xff\xff\x7b\x1f\xb1\xc4\x00\x00\x00" - "\x09\x70\x48\x59\x73\x00\x00\x0b\x13\x00\x00\x0b\x13\x01\x00\x9a" - "\x9c\x18\x00\x00\x00\x17\x49\x44\x41\x54\x78\x01\x63\x98\x89\x0a" - "\x18\x50\xb9\x33\x47\xf9\xa8\x01\x32\xd4\xc2\x03\x00\x33\x84\x0d" - "\x02\x3a\x91\xeb\xa5\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60" - "\x82"; - return WebKit::WebData(red_square, arraysize(red_square)); - } - return webkit_glue::WebKitPlatformSupportImpl::loadResource(name); -} - -WebKit::WebString TestWebKitPlatformSupport::queryLocalizedString( - WebKit::WebLocalizedString::Name name) { - // Returns placeholder strings to check if they are correctly localized. - switch (name) { - case WebKit::WebLocalizedString::OtherDateLabel: - return ASCIIToUTF16("<<OtherDateLabel>>"); - case WebKit::WebLocalizedString::OtherMonthLabel: - return ASCIIToUTF16("<<OtherMonthLabel>>"); - case WebKit::WebLocalizedString::OtherTimeLabel: - return ASCIIToUTF16("<<OtherTimeLabel>>"); - case WebKit::WebLocalizedString::OtherWeekLabel: - return ASCIIToUTF16("<<OtherWeekLabel>>"); - case WebKit::WebLocalizedString::CalendarClear: - return ASCIIToUTF16("<<CalendarClear>>"); - case WebKit::WebLocalizedString::CalendarToday: - return ASCIIToUTF16("<<CalendarToday>>"); - case WebKit::WebLocalizedString::ThisMonthButtonLabel: - return ASCIIToUTF16("<<ThisMonthLabel>>"); - case WebKit::WebLocalizedString::ThisWeekButtonLabel: - return ASCIIToUTF16("<<ThisWeekLabel>>"); - case WebKit::WebLocalizedString::WeekFormatTemplate: - return ASCIIToUTF16("Week $2, $1"); - default: - return WebKitPlatformSupportImpl::queryLocalizedString(name); - } -} - -WebKit::WebString TestWebKitPlatformSupport::queryLocalizedString( - WebKit::WebLocalizedString::Name name, const WebKit::WebString& value) { - if (name == WebKit::WebLocalizedString::ValidationRangeUnderflow) - return ASCIIToUTF16("range underflow"); - if (name == WebKit::WebLocalizedString::ValidationRangeOverflow) - return ASCIIToUTF16("range overflow"); - return WebKitPlatformSupportImpl::queryLocalizedString(name, value); -} - -WebKit::WebString TestWebKitPlatformSupport::queryLocalizedString( - WebKit::WebLocalizedString::Name name, - const WebKit::WebString& value1, - const WebKit::WebString& value2) { - if (name == WebKit::WebLocalizedString::ValidationTooLong) - return ASCIIToUTF16("too long"); - if (name == WebKit::WebLocalizedString::ValidationStepMismatch) - return ASCIIToUTF16("step mismatch"); - return WebKitPlatformSupportImpl::queryLocalizedString(name, value1, value2); -} - -WebKit::WebString TestWebKitPlatformSupport::defaultLocale() { - return ASCIIToUTF16("en-US"); -} - -#if defined(OS_WIN) || defined(OS_MACOSX) -void TestWebKitPlatformSupport::SetThemeEngine(WebKit::WebThemeEngine* engine) { - active_theme_engine_ = engine ? - engine : WebKitPlatformSupportImpl::themeEngine(); -} - -WebKit::WebThemeEngine* TestWebKitPlatformSupport::themeEngine() { - return active_theme_engine_; -} -#endif - -WebKit::WebCompositorSupport* -TestWebKitPlatformSupport::compositorSupport() { - return &compositor_support_; -} - -base::string16 TestWebKitPlatformSupport::GetLocalizedString(int message_id) { - return base::string16(); -} - -base::StringPiece TestWebKitPlatformSupport::GetDataResource( - int resource_id, - ui::ScaleFactor scale_factor) { - return base::StringPiece(); -} - -webkit_glue::ResourceLoaderBridge* -TestWebKitPlatformSupport::CreateResourceLoader( - const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { - NOTREACHED(); - return NULL; -} - -webkit_glue::WebSocketStreamHandleBridge* -TestWebKitPlatformSupport::CreateWebSocketBridge( - WebKit::WebSocketStreamHandle* handle, - webkit_glue::WebSocketStreamHandleDelegate* delegate) { - NOTREACHED(); - return NULL; -} - -WebKit::WebGestureCurve* TestWebKitPlatformSupport::createFlingAnimationCurve( - int device_source, - const WebKit::WebFloatPoint& velocity, - const WebKit::WebSize& cumulative_scroll) { - // Caller will retain and release. - return new WebGestureCurveMock(velocity, cumulative_scroll); -} - -WebKit::WebUnitTestSupport* TestWebKitPlatformSupport::unitTestSupport() { - return this; -} - -void TestWebKitPlatformSupport::registerMockedURL( - const WebKit::WebURL& url, - const WebKit::WebURLResponse& response, - const WebKit::WebString& file_path) { - url_loader_factory_.RegisterURL(url, response, file_path); -} - -void TestWebKitPlatformSupport::registerMockedErrorURL( - const WebKit::WebURL& url, - const WebKit::WebURLResponse& response, - const WebKit::WebURLError& error) { - url_loader_factory_.RegisterErrorURL(url, response, error); -} - -void TestWebKitPlatformSupport::unregisterMockedURL(const WebKit::WebURL& url) { - url_loader_factory_.UnregisterURL(url); -} - -void TestWebKitPlatformSupport::unregisterAllMockedURLs() { - url_loader_factory_.UnregisterAllURLs(); -} - -void TestWebKitPlatformSupport::serveAsynchronousMockedRequests() { - url_loader_factory_.ServeAsynchronousRequests(); -} - -WebKit::WebString TestWebKitPlatformSupport::webKitRootDir() { - base::FilePath path; - PathService::Get(base::DIR_SOURCE_ROOT, &path); - path = path.Append(FILE_PATH_LITERAL("third_party/WebKit")); - path = base::MakeAbsoluteFilePath(path); - CHECK(!path.empty()); - std::string path_ascii = path.MaybeAsASCII(); - CHECK(!path_ascii.empty()); - return WebKit::WebString::fromUTF8(path_ascii.c_str()); -} - - -WebKit::WebLayerTreeView* - TestWebKitPlatformSupport::createLayerTreeViewForTesting() { - scoped_ptr<WebLayerTreeViewImplForTesting> view( - new WebLayerTreeViewImplForTesting()); - - if (!view->Initialize()) - return NULL; - return view.release(); -} - -WebKit::WebLayerTreeView* - TestWebKitPlatformSupport::createLayerTreeViewForTesting( - TestViewType type) { - DCHECK_EQ(TestViewTypeUnitTest, type); - return createLayerTreeViewForTesting(); -} - -WebKit::WebData TestWebKitPlatformSupport::readFromFile( - const WebKit::WebString& path) { - base::FilePath file_path = base::FilePath::FromUTF16Unsafe(path); - - std::string buffer; - base::ReadFileToString(file_path, &buffer); - - return WebKit::WebData(buffer.data(), buffer.size()); -} diff --git a/webkit/support/test_webkit_platform_support.h b/webkit/support/test_webkit_platform_support.h deleted file mode 100644 index 0a4e4cb..0000000 --- a/webkit/support/test_webkit_platform_support.h +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef WEBKIT_SUPPORT_TEST_WEBKIT_PLATFORM_SUPPORT_H_ -#define WEBKIT_SUPPORT_TEST_WEBKIT_PLATFORM_SUPPORT_H_ - -#include "base/compiler_specific.h" -#include "base/files/scoped_temp_dir.h" -#include "third_party/WebKit/public/platform/WebUnitTestSupport.h" -#include "webkit/child/webkitplatformsupport_child_impl.h" -#include "webkit/glue/simple_webmimeregistry_impl.h" -#include "webkit/glue/webfileutilities_impl.h" -#include "webkit/renderer/compositor_bindings/web_compositor_support_impl.h" -#include "webkit/support/mock_webclipboard_impl.h" -#include "webkit/support/weburl_loader_mock_factory.h" - -namespace WebKit { -class WebLayerTreeView; -} - -// An implementation of WebKitPlatformSupport for tests. -class TestWebKitPlatformSupport : - public WebKit::WebUnitTestSupport, - public webkit_glue::WebKitPlatformSupportChildImpl { - public: - TestWebKitPlatformSupport(); - virtual ~TestWebKitPlatformSupport(); - - virtual WebKit::WebMimeRegistry* mimeRegistry(); - virtual WebKit::WebClipboard* clipboard(); - virtual WebKit::WebFileUtilities* fileUtilities(); - virtual WebKit::WebIDBFactory* idbFactory(); - - virtual WebKit::WebURLLoader* createURLLoader(); - virtual WebKit::WebData loadResource(const char* name); - virtual WebKit::WebString queryLocalizedString( - WebKit::WebLocalizedString::Name name); - virtual WebKit::WebString queryLocalizedString( - WebKit::WebLocalizedString::Name name, - const WebKit::WebString& value); - virtual WebKit::WebString queryLocalizedString( - WebKit::WebLocalizedString::Name name, - const WebKit::WebString& value1, - const WebKit::WebString& value2); - virtual WebKit::WebString defaultLocale(); - -#if defined(OS_WIN) || defined(OS_MACOSX) - void SetThemeEngine(WebKit::WebThemeEngine* engine); - virtual WebKit::WebThemeEngine *themeEngine(); -#endif - - virtual WebKit::WebCompositorSupport* compositorSupport(); - - WebURLLoaderMockFactory* url_loader_factory() { - return &url_loader_factory_; - } - - const base::FilePath& file_system_root() const { - return file_system_root_.path(); - } - - virtual base::string16 GetLocalizedString(int message_id) OVERRIDE; - virtual base::StringPiece GetDataResource( - int resource_id, - ui::ScaleFactor scale_factor) OVERRIDE; - virtual webkit_glue::ResourceLoaderBridge* CreateResourceLoader( - const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) - OVERRIDE; - virtual webkit_glue::WebSocketStreamHandleBridge* CreateWebSocketBridge( - WebKit::WebSocketStreamHandle* handle, - webkit_glue::WebSocketStreamHandleDelegate* delegate) OVERRIDE; - - virtual WebKit::WebGestureCurve* createFlingAnimationCurve( - int device_source, - const WebKit::WebFloatPoint& velocity, - const WebKit::WebSize& cumulative_scroll); - - virtual WebKit::WebUnitTestSupport* unitTestSupport(); - - // WebUnitTestSupport implementation - virtual void registerMockedURL(const WebKit::WebURL& url, - const WebKit::WebURLResponse& response, - const WebKit::WebString& filePath); - virtual void registerMockedErrorURL(const WebKit::WebURL& url, - const WebKit::WebURLResponse& response, - const WebKit::WebURLError& error); - virtual void unregisterMockedURL(const WebKit::WebURL& url); - virtual void unregisterAllMockedURLs(); - virtual void serveAsynchronousMockedRequests(); - virtual WebKit::WebString webKitRootDir(); - virtual WebKit::WebLayerTreeView* createLayerTreeViewForTesting(); - virtual WebKit::WebLayerTreeView* createLayerTreeViewForTesting( - TestViewType type); - virtual WebKit::WebData readFromFile(const WebKit::WebString& path); - - private: - webkit_glue::SimpleWebMimeRegistryImpl mime_registry_; - MockWebClipboardImpl mock_clipboard_; - webkit_glue::WebFileUtilitiesImpl file_utilities_; - base::ScopedTempDir file_system_root_; - WebURLLoaderMockFactory url_loader_factory_; - webkit::WebCompositorSupportImpl compositor_support_; - -#if defined(OS_WIN) || defined(OS_MACOSX) - WebKit::WebThemeEngine* active_theme_engine_; -#endif - DISALLOW_COPY_AND_ASSIGN(TestWebKitPlatformSupport); -}; - -#endif // WEBKIT_SUPPORT_TEST_WEBKIT_PLATFORM_SUPPORT_H_ diff --git a/webkit/support/web_gesture_curve_mock.cc b/webkit/support/web_gesture_curve_mock.cc deleted file mode 100644 index a3b4917..0000000 --- a/webkit/support/web_gesture_curve_mock.cc +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "webkit/support/web_gesture_curve_mock.h" - -#include "third_party/WebKit/public/platform/WebFloatSize.h" -#include "third_party/WebKit/public/platform/WebGestureCurveTarget.h" -#include "webkit/support/weburl_loader_mock_factory.h" - -WebGestureCurveMock::WebGestureCurveMock(const WebKit::WebFloatPoint& velocity, - const WebKit::WebSize& cumulative_scroll) - : velocity_(velocity), - cumulative_scroll_(cumulative_scroll) { -} - -WebGestureCurveMock::~WebGestureCurveMock() { -} - -bool WebGestureCurveMock::apply(double time, - WebKit::WebGestureCurveTarget* target) { - WebKit::WebSize displacement(velocity_.x * time, velocity_.y * time); - WebKit::WebFloatSize increment(displacement.width - cumulative_scroll_.width, - displacement.height - cumulative_scroll_.height); - cumulative_scroll_ = displacement; - target->notifyCurrentFlingVelocity(WebKit::WebFloatSize(velocity_.x, - velocity_.y)); - // scrollBy() could delete this curve if the animation is over, so don't - // touch any member variables after making that call. - target->scrollBy(increment); - return true; -} diff --git a/webkit/support/web_gesture_curve_mock.h b/webkit/support/web_gesture_curve_mock.h deleted file mode 100644 index f05f4e9..0000000 --- a/webkit/support/web_gesture_curve_mock.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef WEBKIT_SUPPORT_WEB_GESTURE_CURVE_MOCK_H_ -#define WEBKIT_SUPPORT_WEB_GESTURE_CURVE_MOCK_H_ - -#include "base/memory/scoped_ptr.h" -#include "third_party/WebKit/public/platform/WebFloatPoint.h" -#include "third_party/WebKit/public/platform/WebGestureCurve.h" -#include "third_party/WebKit/public/platform/WebSize.h" - -// A simple class for mocking a WebGestureCurve. The curve flings at velocity -// indefinitely. -class WebGestureCurveMock : public WebKit::WebGestureCurve { - public: - WebGestureCurveMock(const WebKit::WebFloatPoint& velocity, - const WebKit::WebSize& cumulative_scroll); - virtual ~WebGestureCurveMock(); - - // Returns false if curve has finished and can no longer be applied. - virtual bool apply(double time, - WebKit::WebGestureCurveTarget* target) OVERRIDE; - - private: - WebKit::WebFloatPoint velocity_; - WebKit::WebSize cumulative_scroll_; - - DISALLOW_COPY_AND_ASSIGN(WebGestureCurveMock); -}; - -#endif // WEBKIT_SUPPORT_WEB_GESTURE_CURVE_MOCK_H_ diff --git a/webkit/support/web_layer_tree_view_impl_for_testing.cc b/webkit/support/web_layer_tree_view_impl_for_testing.cc deleted file mode 100644 index 93bfcbe..0000000 --- a/webkit/support/web_layer_tree_view_impl_for_testing.cc +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "webkit/support/web_layer_tree_view_impl_for_testing.h" - -#include "base/command_line.h" -#include "base/strings/string_number_conversions.h" -#include "base/synchronization/lock.h" -#include "cc/base/switches.h" -#include "cc/debug/test_context_provider.h" -#include "cc/input/input_handler.h" -#include "cc/layers/layer.h" -#include "cc/output/output_surface.h" -#include "cc/trees/layer_tree_host.h" -#include "third_party/WebKit/public/platform/Platform.h" -#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" -#include "third_party/WebKit/public/platform/WebLayer.h" -#include "third_party/WebKit/public/platform/WebLayerTreeView.h" -#include "third_party/WebKit/public/platform/WebRenderingStats.h" -#include "third_party/WebKit/public/platform/WebSize.h" -#include "webkit/common/gpu/test_context_provider_factory.h" -#include "webkit/renderer/compositor_bindings/web_layer_impl.h" -#include "webkit/support/test_webkit_platform_support.h" - -using WebKit::WebColor; -using WebKit::WebGraphicsContext3D; -using WebKit::WebRect; -using WebKit::WebRenderingStats; -using WebKit::WebSize; - -namespace webkit { - -WebLayerTreeViewImplForTesting::WebLayerTreeViewImplForTesting() {} - -WebLayerTreeViewImplForTesting::~WebLayerTreeViewImplForTesting() {} - -bool WebLayerTreeViewImplForTesting::Initialize() { - cc::LayerTreeSettings settings; - - // For web contents, layer transforms should scale up the contents of layers - // to keep content always crisp when possible. - settings.layer_transforms_should_scale_layer_contents = true; - - // Accelerated animations are enabled for unit tests. - settings.accelerated_animation_enabled = true; - layer_tree_host_ = cc::LayerTreeHost::Create(this, settings, NULL); - if (!layer_tree_host_) - return false; - return true; -} - -void WebLayerTreeViewImplForTesting::setSurfaceReady() { - layer_tree_host_->SetLayerTreeHostClientReady(); -} - -void WebLayerTreeViewImplForTesting::setRootLayer( - const WebKit::WebLayer& root) { - layer_tree_host_->SetRootLayer( - static_cast<const WebLayerImpl*>(&root)->layer()); -} - -void WebLayerTreeViewImplForTesting::clearRootLayer() { - layer_tree_host_->SetRootLayer(scoped_refptr<cc::Layer>()); -} - -void WebLayerTreeViewImplForTesting::setViewportSize( - const WebSize& unused_deprecated, - const WebSize& device_viewport_size) { - layer_tree_host_->SetViewportSize(device_viewport_size); -} - -WebSize WebLayerTreeViewImplForTesting::layoutViewportSize() const { - return layer_tree_host_->device_viewport_size(); -} - -WebSize WebLayerTreeViewImplForTesting::deviceViewportSize() const { - return layer_tree_host_->device_viewport_size(); -} - -void WebLayerTreeViewImplForTesting::setDeviceScaleFactor( - float device_scale_factor) { - layer_tree_host_->SetDeviceScaleFactor(device_scale_factor); -} - -float WebLayerTreeViewImplForTesting::deviceScaleFactor() const { - return layer_tree_host_->device_scale_factor(); -} - -void WebLayerTreeViewImplForTesting::setBackgroundColor(WebColor color) { - layer_tree_host_->set_background_color(color); -} - -void WebLayerTreeViewImplForTesting::setHasTransparentBackground( - bool transparent) { - layer_tree_host_->set_has_transparent_background(transparent); -} - -void WebLayerTreeViewImplForTesting::setVisible(bool visible) { - layer_tree_host_->SetVisible(visible); -} - -void WebLayerTreeViewImplForTesting::setPageScaleFactorAndLimits( - float page_scale_factor, - float minimum, - float maximum) { - layer_tree_host_->SetPageScaleFactorAndLimits( - page_scale_factor, minimum, maximum); -} - -void WebLayerTreeViewImplForTesting::startPageScaleAnimation( - const WebKit::WebPoint& scroll, - bool use_anchor, - float new_page_scale, - double duration_sec) {} - -void WebLayerTreeViewImplForTesting::setNeedsAnimate() { - layer_tree_host_->SetNeedsAnimate(); -} - -void WebLayerTreeViewImplForTesting::setNeedsRedraw() { - layer_tree_host_->SetNeedsRedraw(); -} - -bool WebLayerTreeViewImplForTesting::commitRequested() const { - return layer_tree_host_->CommitRequested(); -} - -void WebLayerTreeViewImplForTesting::composite() { - layer_tree_host_->Composite(base::TimeTicks::Now()); -} - -void WebLayerTreeViewImplForTesting::didStopFlinging() {} - -bool WebLayerTreeViewImplForTesting::compositeAndReadback( - void* pixels, const WebRect& rect_in_device_viewport) { - return layer_tree_host_->CompositeAndReadback(pixels, - rect_in_device_viewport); -} - -void WebLayerTreeViewImplForTesting::finishAllRendering() { - layer_tree_host_->FinishAllRendering(); -} - -void WebLayerTreeViewImplForTesting::setDeferCommits(bool defer_commits) { - layer_tree_host_->SetDeferCommits(defer_commits); -} - -void WebLayerTreeViewImplForTesting::renderingStats(WebRenderingStats&) const {} - -void WebLayerTreeViewImplForTesting::Layout() { -} - -void WebLayerTreeViewImplForTesting::ApplyScrollAndScale( - gfx::Vector2d scroll_delta, - float page_scale) {} - -scoped_ptr<cc::OutputSurface> -WebLayerTreeViewImplForTesting::CreateOutputSurface(bool fallback) { - return make_scoped_ptr( - new cc::OutputSurface(cc::TestContextProvider::Create())); -} - -void WebLayerTreeViewImplForTesting::ScheduleComposite() { -} - -scoped_refptr<cc::ContextProvider> -WebLayerTreeViewImplForTesting::OffscreenContextProviderForMainThread() { - return webkit::gpu::TestContextProviderFactory::GetInstance()-> - OffscreenContextProviderForMainThread(); -} - -scoped_refptr<cc::ContextProvider> -WebLayerTreeViewImplForTesting::OffscreenContextProviderForCompositorThread() { - NOTREACHED(); - return NULL; -} - -} // namespace webkit diff --git a/webkit/support/web_layer_tree_view_impl_for_testing.h b/webkit/support/web_layer_tree_view_impl_for_testing.h deleted file mode 100644 index 612f0f0..0000000 --- a/webkit/support/web_layer_tree_view_impl_for_testing.h +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef WEBKIT_SUPPORT_WEB_LAYER_TREE_VIEW_IMPL_FOR_TESTING_H_ -#define WEBKIT_SUPPORT_WEB_LAYER_TREE_VIEW_IMPL_FOR_TESTING_H_ - -#include "base/memory/scoped_ptr.h" -#include "cc/trees/layer_tree_host_client.h" -#include "third_party/WebKit/public/platform/WebLayerTreeView.h" - -namespace cc { -class LayerTreeHost; -} - -namespace WebKit { class WebLayer; } - -namespace webkit { - -class WebLayerTreeViewImplForTesting : public WebKit::WebLayerTreeView, - public cc::LayerTreeHostClient { - public: - WebLayerTreeViewImplForTesting(); - virtual ~WebLayerTreeViewImplForTesting(); - - bool Initialize(); - - // WebKit::WebLayerTreeView implementation. - virtual void setSurfaceReady(); - virtual void setRootLayer(const WebKit::WebLayer& layer); - virtual void clearRootLayer(); - virtual void setViewportSize(const WebKit::WebSize& unused_deprecated, - const WebKit::WebSize& device_viewport_size); - virtual WebKit::WebSize layoutViewportSize() const; - virtual WebKit::WebSize deviceViewportSize() const; - virtual void setDeviceScaleFactor(float scale_factor); - virtual float deviceScaleFactor() const; - virtual void setBackgroundColor(WebKit::WebColor); - virtual void setHasTransparentBackground(bool transparent); - virtual void setVisible(bool visible); - virtual void setPageScaleFactorAndLimits(float page_scale_factor, - float minimum, - float maximum); - virtual void startPageScaleAnimation(const WebKit::WebPoint& destination, - bool use_anchor, - float new_page_scale, - double duration_sec); - virtual void setNeedsAnimate(); - virtual void setNeedsRedraw(); - virtual bool commitRequested() const; - virtual void composite(); - virtual void didStopFlinging(); - virtual bool compositeAndReadback(void* pixels, const WebKit::WebRect& rect); - virtual void finishAllRendering(); - virtual void setDeferCommits(bool defer_commits); - virtual void renderingStats( - WebKit::WebRenderingStats& stats) const; // NOLINT(runtime/references) - - // cc::LayerTreeHostClient implementation. - virtual void WillBeginFrame() OVERRIDE {} - virtual void DidBeginFrame() OVERRIDE {} - virtual void Animate(double frame_begin_time) OVERRIDE {} - virtual void Layout() OVERRIDE; - virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float page_scale) - OVERRIDE; - virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback) - OVERRIDE; - virtual void DidInitializeOutputSurface(bool success) OVERRIDE {} - virtual void WillCommit() OVERRIDE {} - virtual void DidCommit() OVERRIDE {} - virtual void DidCommitAndDrawFrame() OVERRIDE {} - virtual void DidCompleteSwapBuffers() OVERRIDE {} - virtual void ScheduleComposite() OVERRIDE; - virtual scoped_refptr<cc::ContextProvider> - OffscreenContextProviderForMainThread() OVERRIDE; - virtual scoped_refptr<cc::ContextProvider> - OffscreenContextProviderForCompositorThread() OVERRIDE; - - private: - scoped_ptr<cc::LayerTreeHost> layer_tree_host_; - - DISALLOW_COPY_AND_ASSIGN(WebLayerTreeViewImplForTesting); -}; - -} // namespace webkit - -#endif // WEBKIT_SUPPORT_WEB_LAYER_TREE_VIEW_IMPL_FOR_TESTING_H_ diff --git a/webkit/support/webkit_support.cc b/webkit/support/webkit_support.cc deleted file mode 100644 index 6f9d41a..0000000 --- a/webkit/support/webkit_support.cc +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "webkit/support/webkit_support.h" - -#include "base/message_loop/message_loop.h" -#include "base/run_loop.h" -#include "third_party/WebKit/public/web/WebCache.h" -#include "third_party/WebKit/public/web/WebKit.h" -#include "third_party/WebKit/public/web/WebRuntimeFeatures.h" -#include "url/url_util.h" -#include "webkit/common/user_agent/user_agent.h" -#include "webkit/common/user_agent/user_agent_util.h" -#include "webkit/support/test_webkit_platform_support.h" - -#if defined(OS_ANDROID) -#include "base/android/jni_android.h" -#include "net/android/network_library.h" -#endif - -#if defined(OS_MACOSX) -#include "base/test/mock_chrome_application_mac.h" -#endif - -namespace { - -class TestEnvironment { - public: -#if defined(OS_ANDROID) - // Android UI message loop goes through Java, so don't use it in tests. - typedef base::MessageLoop MessageLoopType; -#else - typedef base::MessageLoopForUI MessageLoopType; -#endif - - TestEnvironment() { - main_message_loop_.reset(new MessageLoopType); - - // TestWebKitPlatformSupport must be instantiated after MessageLoopType. - webkit_platform_support_.reset(new TestWebKitPlatformSupport); - } - - TestWebKitPlatformSupport* webkit_platform_support() const { - return webkit_platform_support_.get(); - } - - private: - scoped_ptr<MessageLoopType> main_message_loop_; - scoped_ptr<TestWebKitPlatformSupport> webkit_platform_support_; -}; - -TestEnvironment* test_environment; - -} // namespace - -namespace webkit_support { - -void SetUpTestEnvironmentForUnitTests() { - WebKit::WebRuntimeFeatures::enableStableFeatures(true); - WebKit::WebRuntimeFeatures::enableExperimentalFeatures(true); - WebKit::WebRuntimeFeatures::enableTestOnlyFeatures(true); - -#if defined(OS_ANDROID) - JNIEnv* env = base::android::AttachCurrentThread(); - net::android::RegisterNetworkLibrary(env); -#endif - -#if defined(OS_MACOSX) - mock_cr_app::RegisterMockCrApp(); -#endif - - // Explicitly initialize the GURL library before spawning any threads. - // Otherwise crash may happend when different threads try to create a GURL - // at same time. - url_util::Initialize(); - test_environment = new TestEnvironment; - webkit_glue::SetUserAgent(webkit_glue::BuildUserAgentFromProduct( - "DumpRenderTree/0.0.0.0"), false); -} - -void TearDownTestEnvironment() { - // Flush any remaining messages before we kill ourselves. - // http://code.google.com/p/chromium/issues/detail?id=9500 - base::RunLoop().RunUntilIdle(); - - if (RunningOnValgrind()) - WebKit::WebCache::clear(); - WebKit::shutdown(); - delete test_environment; - test_environment = NULL; -} - -} // namespace webkit_support diff --git a/webkit/support/webkit_support.gyp b/webkit/support/webkit_support.gyp index 5bbf80a..f7d6d5f 100644 --- a/webkit/support/webkit_support.gyp +++ b/webkit/support/webkit_support.gyp @@ -11,7 +11,6 @@ 'includes': [ '../../build/win_precompile.gypi', '../glue/webkit_glue.gypi', - 'webkit_support.gypi', ], }], ], diff --git a/webkit/support/webkit_support.gypi b/webkit/support/webkit_support.gypi deleted file mode 100644 index e8227f0..0000000 --- a/webkit/support/webkit_support.gypi +++ /dev/null @@ -1,109 +0,0 @@ -# Copyright (c) 2012 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -{ - 'variables': { - 'chromium_code': 1, - }, - 'targets': [ - { - 'target_name': 'webkit_support', - 'type': 'static_library', - 'variables': { 'enable_wexit_time_destructors': 1, }, - 'dependencies': [ - '<(DEPTH)/base/base.gyp:base', - '<(DEPTH)/base/base.gyp:base_i18n', - '<(DEPTH)/base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', - '<(DEPTH)/cc/cc.gyp:cc', - '<(DEPTH)/media/media.gyp:media', - '<(DEPTH)/net/net.gyp:net', - '<(DEPTH)/skia/skia.gyp:skia', - '<(DEPTH)/testing/gtest.gyp:gtest', - '<(DEPTH)/ui/gl/gl.gyp:gl', - '<(DEPTH)/ui/ui.gyp:shell_dialogs', - '<(DEPTH)/ui/ui.gyp:ui', - '<(DEPTH)/webkit/common/gpu/webkit_gpu.gyp:webkit_gpu', - '<(DEPTH)/webkit/common/user_agent/webkit_user_agent.gyp:user_agent', - '<(DEPTH)/webkit/common/webkit_common.gyp:webkit_common', - '<(DEPTH)/webkit/renderer/compositor_bindings/compositor_bindings.gyp:webkit_compositor_bindings', - '<(DEPTH)/webkit/renderer/compositor_bindings/compositor_bindings.gyp:webkit_compositor_support', - '<(DEPTH)/webkit/renderer/webkit_renderer.gyp:webkit_renderer', - '<(DEPTH)/webkit/storage_browser.gyp:webkit_storage_browser', - '<(DEPTH)/webkit/storage_common.gyp:webkit_storage_common', - 'glue', - 'glue_child', - 'webkit_support_common', - ], - 'include_dirs': [ - '<(SHARED_INTERMEDIATE_DIR)/webkit', # for a header generated by grit - ], - 'defines': [ - # Technically not a unit test but require functions available only to - # unit tests. - 'UNIT_TEST' - ], - 'sources': [ - 'test_webkit_platform_support.cc', - 'test_webkit_platform_support.h', - 'webkit_support.cc', - 'webkit_support.h', - 'webkit_support_glue.cc', - 'weburl_loader_mock.cc', - 'weburl_loader_mock.h', - 'weburl_loader_mock_factory.cc', - 'weburl_loader_mock_factory.h', - 'web_gesture_curve_mock.cc', - 'web_gesture_curve_mock.h', - 'web_layer_tree_view_impl_for_testing.cc', - 'web_layer_tree_view_impl_for_testing.h', - ], - 'conditions': [ - ['OS=="mac"', { - 'copies': [{ - 'destination': '<(SHARED_INTERMEDIATE_DIR)/webkit', - 'files': [ - '../tools/test_shell/resources/missingImage.png', - '../tools/test_shell/resources/textAreaResizeCorner.png', - ], - }], - },{ # OS!="mac" - 'copies': [{ - 'destination': '<(PRODUCT_DIR)/DumpRenderTree_resources', - 'files': [ - '../tools/test_shell/resources/missingImage.gif', - '../tools/test_shell/resources/textAreaResizeCorner.png', - ], - }], - }], - ], - # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. - 'msvs_disabled_warnings': [ 4267, ], - }, - - { - 'target_name': 'webkit_support_common', - 'type': 'static_library', - 'variables': { 'enable_wexit_time_destructors': 1, }, - 'dependencies': [ - '<(DEPTH)/base/base.gyp:base', - '<(DEPTH)/net/net.gyp:net', - '<(DEPTH)/skia/skia.gyp:skia', - '<(DEPTH)/third_party/zlib/zlib.gyp:zlib', - '<(DEPTH)/ui/ui.gyp:ui', - '<(DEPTH)/webkit/common/user_agent/webkit_user_agent.gyp:user_agent', - '<(DEPTH)/webkit/renderer/webkit_renderer.gyp:webkit_renderer', - 'glue', - ], - 'export_dependent_settings': [ - '<(DEPTH)/base/base.gyp:base', - ], - 'sources': [ - '<(DEPTH)/webkit/support/mock_webclipboard_impl.cc', - '<(DEPTH)/webkit/support/mock_webclipboard_impl.h', - ], - # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. - 'msvs_disabled_warnings': [ 4267, ], - }, - ], -} diff --git a/webkit/support/webkit_support.h b/webkit/support/webkit_support.h deleted file mode 100644 index ed09e67..0000000 --- a/webkit/support/webkit_support.h +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef WEBKIT_SUPPORT_WEBKIT_SUPPORT_H_ -#define WEBKIT_SUPPORT_WEBKIT_SUPPORT_H_ - -// This package provides functions used by webkit_unit_tests. -namespace webkit_support { - -// Initializes or terminates a test environment for unit tests. -void SetUpTestEnvironmentForUnitTests(); -void TearDownTestEnvironment(); - -} // namespace webkit_support - -#endif // WEBKIT_SUPPORT_WEBKIT_SUPPORT_H_ diff --git a/webkit/support/webkit_support_glue.cc b/webkit/support/webkit_support_glue.cc deleted file mode 100644 index b49522d..0000000 --- a/webkit/support/webkit_support_glue.cc +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "webkit/glue/webkit_glue.h" - -#include "base/base_paths.h" -#include "base/path_service.h" - -// Functions needed by webkit_glue. - -namespace webkit_glue { - -void AppendToLog(const char*, int, const char*) { -} - -bool GetPluginFinderURL(std::string* plugin_finder_url) { - return false; -} - -#if defined(OS_WIN) -bool DownloadUrl(const std::string& url, HWND caller_window) { - return false; -} -#endif - -void EnableSpdy(bool enable) { -} - -void UserMetricsRecordAction(const std::string& action) { -} - -} // namespace webkit_glue diff --git a/webkit/support/weburl_loader_mock.cc b/webkit/support/weburl_loader_mock.cc deleted file mode 100644 index 06aff4d..0000000 --- a/webkit/support/weburl_loader_mock.cc +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "webkit/support/weburl_loader_mock.h" - -#include "base/logging.h" -#include "third_party/WebKit/public/platform/WebData.h" -#include "third_party/WebKit/public/platform/WebURLError.h" -#include "third_party/WebKit/public/platform/WebURLLoaderClient.h" -#include "webkit/support/weburl_loader_mock_factory.h" - -WebURLLoaderMock::WebURLLoaderMock(WebURLLoaderMockFactory* factory, - WebKit::WebURLLoader* default_loader) - : factory_(factory), - client_(NULL), - default_loader_(default_loader), - using_default_loader_(false), - is_deferred_(false) { -} - -WebURLLoaderMock::~WebURLLoaderMock() { -} - -void WebURLLoaderMock::ServeAsynchronousRequest( - const WebKit::WebURLResponse& response, - const WebKit::WebData& data, - const WebKit::WebURLError& error) { - DCHECK(!using_default_loader_); - if (!client_) - return; - - client_->didReceiveResponse(this, response); - - if (error.reason) { - client_->didFail(this, error); - return; - } - client_->didReceiveData(this, data.data(), data.size(), data.size()); - client_->didFinishLoading(this, 0); -} - -WebKit::WebURLRequest WebURLLoaderMock::ServeRedirect( - const WebKit::WebURLResponse& redirectResponse) { - WebKit::WebURLRequest newRequest; - newRequest.initialize(); - GURL redirectURL(redirectResponse.httpHeaderField("Location")); - newRequest.setURL(redirectURL); - client_->willSendRequest(this, newRequest, redirectResponse); - return newRequest; -} - -void WebURLLoaderMock::loadSynchronously(const WebKit::WebURLRequest& request, - WebKit::WebURLResponse& response, - WebKit::WebURLError& error, - WebKit::WebData& data) { - if (factory_->IsMockedURL(request.url())) { - factory_->LoadSynchronously(request, &response, &error, &data); - return; - } - DCHECK(static_cast<const GURL&>(request.url()).SchemeIs("data")) - << "loadSynchronously shouldn't be falling back: " - << request.url().spec().data(); - using_default_loader_ = true; - default_loader_->loadSynchronously(request, response, error, data); -} - -void WebURLLoaderMock::loadAsynchronously(const WebKit::WebURLRequest& request, - WebKit::WebURLLoaderClient* client) { - if (factory_->IsMockedURL(request.url())) { - client_ = client; - factory_->LoadAsynchronouly(request, this); - return; - } - DCHECK(static_cast<const GURL&>(request.url()).SchemeIs("data")) - << "loadAsynchronously shouldn't be falling back: " - << request.url().spec().data(); - using_default_loader_ = true; - default_loader_->loadAsynchronously(request, client); -} - -void WebURLLoaderMock::cancel() { - if (using_default_loader_) { - default_loader_->cancel(); - return; - } - client_ = NULL; - factory_->CancelLoad(this); -} - -void WebURLLoaderMock::setDefersLoading(bool deferred) { - is_deferred_ = deferred; - if (using_default_loader_) { - default_loader_->setDefersLoading(deferred); - return; - } - NOTIMPLEMENTED(); -} diff --git a/webkit/support/weburl_loader_mock.h b/webkit/support/weburl_loader_mock.h deleted file mode 100644 index 46de7be..0000000 --- a/webkit/support/weburl_loader_mock.h +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef WEBKIT_SUPPORT_WEBURL_LOADER_MOCK_H_ -#define WEBKIT_SUPPORT_WEBURL_LOADER_MOCK_H_ - -#include "base/basictypes.h" -#include "base/memory/scoped_ptr.h" -#include "third_party/WebKit/public/platform/WebURLLoader.h" - -namespace WebKit { -class WebData; -struct WebURLError; -class WebURLLoaderClient; -class WebURLRequest; -class WebURLResponse; -} - -class WebURLLoaderMockFactory; - -// A simple class for mocking WebURLLoader. -// If the WebURLLoaderMockFactory it is associated with has been configured to -// mock the request it gets, it serves the mocked resource. Otherwise it just -// forwards it to the default loader. -class WebURLLoaderMock : public WebKit::WebURLLoader { - public: - // This object becomes the owner of |default_loader|. - WebURLLoaderMock(WebURLLoaderMockFactory* factory, - WebKit::WebURLLoader* default_loader); - virtual ~WebURLLoaderMock(); - - // Simulates the asynchronous request being served. - void ServeAsynchronousRequest(const WebKit::WebURLResponse& response, - const WebKit::WebData& data, - const WebKit::WebURLError& error); - - // Simulates the redirect being served. - WebKit::WebURLRequest ServeRedirect( - const WebKit::WebURLResponse& redirectResponse); - - // WebURLLoader methods: - virtual void loadSynchronously(const WebKit::WebURLRequest& request, - WebKit::WebURLResponse& response, - WebKit::WebURLError& error, - WebKit::WebData& data); - virtual void loadAsynchronously(const WebKit::WebURLRequest& request, - WebKit::WebURLLoaderClient* client); - virtual void cancel(); - virtual void setDefersLoading(bool defer); - - bool isDeferred() { return is_deferred_; } - - private: - WebURLLoaderMockFactory* factory_; - WebKit::WebURLLoaderClient* client_; - scoped_ptr<WebKit::WebURLLoader> default_loader_; - bool using_default_loader_; - bool is_deferred_; - - DISALLOW_COPY_AND_ASSIGN(WebURLLoaderMock); -}; - -#endif // WEBKIT_SUPPORT_WEBURL_LOADER_MOCK_H_ diff --git a/webkit/support/weburl_loader_mock_factory.cc b/webkit/support/weburl_loader_mock_factory.cc deleted file mode 100644 index f459211..0000000 --- a/webkit/support/weburl_loader_mock_factory.cc +++ /dev/null @@ -1,192 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "webkit/support/weburl_loader_mock_factory.h" - -#include "base/file_util.h" -#include "base/logging.h" -#include "base/run_loop.h" -#include "third_party/WebKit/public/platform/WebString.h" -#include "third_party/WebKit/public/platform/WebURLError.h" -#include "third_party/WebKit/public/platform/WebURLRequest.h" -#include "third_party/WebKit/public/platform/WebURLResponse.h" -#include "third_party/WebKit/public/web/WebCache.h" -#include "webkit/support/webkit_support.h" -#include "webkit/support/weburl_loader_mock.h" - -using WebKit::WebCache; -using WebKit::WebData; -using WebKit::WebString; -using WebKit::WebURL; -using WebKit::WebURLError; -using WebKit::WebURLLoader; -using WebKit::WebURLRequest; -using WebKit::WebURLResponse; - -WebURLLoaderMockFactory::WebURLLoaderMockFactory() {} - -WebURLLoaderMockFactory::~WebURLLoaderMockFactory() {} - -void WebURLLoaderMockFactory::RegisterURL(const WebURL& url, - const WebURLResponse& response, - const WebString& file_path) { - ResponseInfo response_info; - response_info.response = response; - if (!file_path.isNull() && !file_path.isEmpty()) { -#if defined(OS_POSIX) - // TODO(jcivelli): On Linux, UTF8 might not be correct. - response_info.file_path = - base::FilePath(static_cast<std::string>(file_path.utf8())); -#elif defined(OS_WIN) - string16 file_path_16 = file_path; - response_info.file_path = base::FilePath(std::wstring( - file_path_16.data(), file_path_16.length())); -#endif - DCHECK(base::PathExists(response_info.file_path)) - << response_info.file_path.MaybeAsASCII() << " does not exist."; - } - - DCHECK(url_to_reponse_info_.find(url) == url_to_reponse_info_.end()); - url_to_reponse_info_[url] = response_info; -} - - -void WebURLLoaderMockFactory::RegisterErrorURL(const WebURL& url, - const WebURLResponse& response, - const WebURLError& error) { - DCHECK(url_to_reponse_info_.find(url) == url_to_reponse_info_.end()); - RegisterURL(url, response, WebString()); - url_to_error_info_[url] = error; -} - -void WebURLLoaderMockFactory::UnregisterURL(const WebKit::WebURL& url) { - URLToResponseMap::iterator iter = url_to_reponse_info_.find(url); - DCHECK(iter != url_to_reponse_info_.end()); - url_to_reponse_info_.erase(iter); - - URLToErrorMap::iterator error_iter = url_to_error_info_.find(url); - if (error_iter != url_to_error_info_.end()) - url_to_error_info_.erase(error_iter); -} - -void WebURLLoaderMockFactory::UnregisterAllURLs() { - url_to_reponse_info_.clear(); - url_to_error_info_.clear(); - WebCache::clear(); -} - -void WebURLLoaderMockFactory::ServeAsynchronousRequests() { - last_handled_asynchronous_request_.reset(); - // Serving a request might trigger more requests, so we cannot iterate on - // pending_loaders_ as it might get modified. - while (!pending_loaders_.empty()) { - LoaderToRequestMap::iterator iter = pending_loaders_.begin(); - WebURLLoaderMock* loader = iter->first; - const WebURLRequest& request = iter->second; - WebURLResponse response; - WebURLError error; - WebData data; - last_handled_asynchronous_request_ = request; - LoadRequest(request, &response, &error, &data); - // Follow any redirects while the loader is still active. - while (response.httpStatusCode() >= 300 && - response.httpStatusCode() < 400) { - WebURLRequest newRequest = loader->ServeRedirect(response); - if (!IsPending(loader) || loader->isDeferred()) - break; - last_handled_asynchronous_request_ = newRequest; - LoadRequest(newRequest, &response, &error, &data); - } - // Serve the request if the loader is still active. - if (IsPending(loader) && !loader->isDeferred()) - loader->ServeAsynchronousRequest(response, data, error); - // The loader might have already been removed. - pending_loaders_.erase(loader); - } - base::RunLoop().RunUntilIdle(); -} - -WebKit::WebURLRequest -WebURLLoaderMockFactory::GetLastHandledAsynchronousRequest() { - return last_handled_asynchronous_request_; -} - -bool WebURLLoaderMockFactory::IsMockedURL(const WebKit::WebURL& url) { - return url_to_reponse_info_.find(url) != url_to_reponse_info_.end(); -} - -void WebURLLoaderMockFactory::CancelLoad(WebURLLoaderMock* loader) { - LoaderToRequestMap::iterator iter = pending_loaders_.find(loader); - DCHECK(iter != pending_loaders_.end()); - pending_loaders_.erase(iter); -} - -WebURLLoader* WebURLLoaderMockFactory::CreateURLLoader( - WebURLLoader* default_loader) { - DCHECK(default_loader); - return new WebURLLoaderMock(this, default_loader); -} - -void WebURLLoaderMockFactory::LoadSynchronously(const WebURLRequest& request, - WebURLResponse* response, - WebURLError* error, - WebData* data) { - LoadRequest(request, response, error, data); -} - -void WebURLLoaderMockFactory::LoadAsynchronouly(const WebURLRequest& request, - WebURLLoaderMock* loader) { - LoaderToRequestMap::iterator iter = pending_loaders_.find(loader); - DCHECK(iter == pending_loaders_.end()); - pending_loaders_[loader] = request; -} - -void WebURLLoaderMockFactory::LoadRequest(const WebURLRequest& request, - WebURLResponse* response, - WebURLError* error, - WebData* data) { - URLToErrorMap::const_iterator error_iter = - url_to_error_info_.find(request.url()); - if (error_iter != url_to_error_info_.end()) - *error = error_iter->second; - - URLToResponseMap::const_iterator iter = - url_to_reponse_info_.find(request.url()); - if (iter == url_to_reponse_info_.end()) { - // Non mocked URLs should not have been passed to the default URLLoader. - NOTREACHED(); - return; - } - - if (!error->reason && !ReadFile(iter->second.file_path, data)) { - NOTREACHED(); - return; - } - - *response = iter->second.response; -} - -bool WebURLLoaderMockFactory::IsPending(WebURLLoaderMock* loader) { - LoaderToRequestMap::iterator iter = pending_loaders_.find(loader); - return iter != pending_loaders_.end(); -} - -// static -bool WebURLLoaderMockFactory::ReadFile(const base::FilePath& file_path, - WebData* data) { - int64 file_size = 0; - if (!file_util::GetFileSize(file_path, &file_size)) - return false; - - int size = static_cast<int>(file_size); - scoped_ptr<char[]> buffer(new char[size]); - data->reset(); - int read_count = file_util::ReadFile(file_path, buffer.get(), size); - if (read_count == -1) - return false; - DCHECK(read_count == size); - data->assign(buffer.get(), size); - - return true; -} diff --git a/webkit/support/weburl_loader_mock_factory.h b/webkit/support/weburl_loader_mock_factory.h deleted file mode 100644 index 8f00fc0..0000000 --- a/webkit/support/weburl_loader_mock_factory.h +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef WEBKIT_SUPPORT_WEBURL_LOADER_MOCK_FACTORY_H_ -#define WEBKIT_SUPPORT_WEBURL_LOADER_MOCK_FACTORY_H_ - -#include <map> - -#include "base/files/file_path.h" -#include "third_party/WebKit/public/platform/WebURL.h" -#include "third_party/WebKit/public/platform/WebURLError.h" -#include "third_party/WebKit/public/platform/WebURLRequest.h" -#include "third_party/WebKit/public/platform/WebURLResponse.h" - -namespace WebKit { -class WebData; -class WebURLLoader; -} - -class WebURLLoaderMock; - -// A factory that creates WebURLLoaderMock to simulate resource loading in -// tests. -// You register files for specific URLs, the content of the file is then served -// when these URLs are loaded. -// In order to serve the asynchronous requests, you need to invoke -// ServeAsynchronousRequest. -class WebURLLoaderMockFactory { - public: - WebURLLoaderMockFactory(); - virtual ~WebURLLoaderMockFactory(); - - // Called by TestWebKitPlatformSupport to create a WebURLLoader. - // Non-mocked request are forwarded to |default_loader| which should not be - // NULL. - virtual WebKit::WebURLLoader* CreateURLLoader( - WebKit::WebURLLoader* default_loader); - - // Registers a response and the contents to be served when the specified URL - // is loaded. - void RegisterURL(const WebKit::WebURL& url, - const WebKit::WebURLResponse& response, - const WebKit::WebString& filePath); - - // Registers an error to be served when the specified URL is requested. - void RegisterErrorURL(const WebKit::WebURL& url, - const WebKit::WebURLResponse& response, - const WebKit::WebURLError& error); - - // Unregisters |url| so it will no longer be mocked. - void UnregisterURL(const WebKit::WebURL& url); - - // Unregister all URLs so no URL will be mocked anymore. - void UnregisterAllURLs(); - - // Serves all the pending asynchronous requests. - void ServeAsynchronousRequests(); - - // Returns the last request handled by |ServeAsynchronousRequests()|. - WebKit::WebURLRequest GetLastHandledAsynchronousRequest(); - - // Returns true if |url| was registered for being mocked. - bool IsMockedURL(const WebKit::WebURL& url); - - // Called by the loader to load a resource. - void LoadSynchronously(const WebKit::WebURLRequest& request, - WebKit::WebURLResponse* response, - WebKit::WebURLError* error, - WebKit::WebData* data); - void LoadAsynchronouly(const WebKit::WebURLRequest& request, - WebURLLoaderMock* loader); - - // Removes the loader from the list of pending loaders. - void CancelLoad(WebURLLoaderMock* loader); - - private: - struct ResponseInfo { - WebKit::WebURLResponse response; - base::FilePath file_path; - }; - - - // Loads the specified request and populates the response, error and data - // accordingly. - void LoadRequest(const WebKit::WebURLRequest& request, - WebKit::WebURLResponse* response, - WebKit::WebURLError* error, - WebKit::WebData* data); - - // Checks if the loader is pending. Otherwise, it may have been deleted. - bool IsPending(WebURLLoaderMock* loader); - - // Reads |m_filePath| and puts its content in |data|. - // Returns true if it successfully read the file. - static bool ReadFile(const base::FilePath& file_path, WebKit::WebData* data); - - // The loaders that have not being served data yet. - typedef std::map<WebURLLoaderMock*, WebKit::WebURLRequest> LoaderToRequestMap; - LoaderToRequestMap pending_loaders_; - - typedef std::map<GURL, WebKit::WebURLError> URLToErrorMap; - URLToErrorMap url_to_error_info_; - - // Table of the registered URLs and the responses that they should receive. - typedef std::map<GURL, ResponseInfo> URLToResponseMap; - URLToResponseMap url_to_reponse_info_; - - WebKit::WebURLRequest last_handled_asynchronous_request_; - - DISALLOW_COPY_AND_ASSIGN(WebURLLoaderMockFactory); -}; - -#endif // WEBKIT_SUPPORT_WEBURL_LOADER_MOCK_FACTORY_H_ - |