| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/test/test_webkit_platform_support.h" | 5 #include "content/test/test_webkit_platform_support.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" |
| 7 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 8 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/metrics/stats_counters.h" | 11 #include "base/metrics/stats_counters.h" |
| 10 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 12 #include "content/test/mock_webclipboard_impl.h" | 14 #include "content/test/mock_webclipboard_impl.h" |
| 13 #include "content/test/web_gesture_curve_mock.h" | 15 #include "content/test/web_gesture_curve_mock.h" |
| 14 #include "content/test/web_layer_tree_view_impl_for_testing.h" | 16 #include "content/test/web_layer_tree_view_impl_for_testing.h" |
| 15 #include "content/test/weburl_loader_mock_factory.h" | 17 #include "content/test/weburl_loader_mock_factory.h" |
| 18 #include "media/base/media.h" |
| 19 #include "net/cookies/cookie_monster.h" |
| 20 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 16 #include "third_party/WebKit/public/platform/WebData.h" | 21 #include "third_party/WebKit/public/platform/WebData.h" |
| 22 #include "third_party/WebKit/public/platform/WebFileSystem.h" |
| 23 #include "third_party/WebKit/public/platform/WebStorageArea.h" |
| 24 #include "third_party/WebKit/public/platform/WebStorageNamespace.h" |
| 17 #include "third_party/WebKit/public/platform/WebString.h" | 25 #include "third_party/WebKit/public/platform/WebString.h" |
| 18 #include "third_party/WebKit/public/platform/WebURL.h" | 26 #include "third_party/WebKit/public/platform/WebURL.h" |
| 27 #include "third_party/WebKit/public/web/WebDatabase.h" |
| 19 #include "third_party/WebKit/public/web/WebKit.h" | 28 #include "third_party/WebKit/public/web/WebKit.h" |
| 29 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 30 #include "third_party/WebKit/public/web/WebScriptController.h" |
| 31 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| 32 #include "third_party/WebKit/public/web/WebStorageEventDispatcher.h" |
| 20 #include "v8/include/v8.h" | 33 #include "v8/include/v8.h" |
| 34 #include "webkit/browser/database/vfs_backend.h" |
| 35 #include "webkit/child/webkitplatformsupport_impl.h" |
| 36 #include "webkit/glue/simple_webmimeregistry_impl.h" |
| 21 #include "webkit/glue/webkit_glue.h" | 37 #include "webkit/glue/webkit_glue.h" |
| 22 #include "webkit/renderer/compositor_bindings/web_compositor_support_impl.h" | 38 #include "webkit/renderer/compositor_bindings/web_compositor_support_impl.h" |
| 23 | 39 |
| 24 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
| 25 #include "third_party/WebKit/public/platform/win/WebThemeEngine.h" | 41 #include "third_party/WebKit/public/platform/win/WebThemeEngine.h" |
| 26 #elif defined(OS_MACOSX) | 42 #elif defined(OS_MACOSX) |
| 27 #include "base/mac/mac_util.h" | 43 #include "base/mac/mac_util.h" |
| 28 #endif | 44 #endif |
| 29 | 45 |
| 46 using WebKit::WebScriptController; |
| 30 using webkit::WebLayerTreeViewImplForTesting; | 47 using webkit::WebLayerTreeViewImplForTesting; |
| 31 | 48 |
| 32 namespace content { | 49 namespace content { |
| 33 | 50 |
| 34 TestWebKitPlatformSupport::TestWebKitPlatformSupport() { | 51 TestWebKitPlatformSupport::TestWebKitPlatformSupport() { |
| 35 url_loader_factory_.reset(new WebURLLoaderMockFactory()); | 52 url_loader_factory_.reset(new WebURLLoaderMockFactory()); |
| 36 mock_clipboard_.reset(new MockWebClipboardImpl()); | 53 mock_clipboard_.reset(new MockWebClipboardImpl()); |
| 37 v8::V8::SetCounterFunction(base::StatsTable::FindLocation); | 54 v8::V8::SetCounterFunction(base::StatsTable::FindLocation); |
| 38 | 55 |
| 56 WebKit::initialize(this); |
| 57 WebKit::setLayoutTestMode(true); |
| 58 WebKit::WebSecurityPolicy::registerURLSchemeAsLocal( |
| 59 WebKit::WebString::fromUTF8("test-shell-resource")); |
| 60 WebKit::WebSecurityPolicy::registerURLSchemeAsNoAccess( |
| 61 WebKit::WebString::fromUTF8("test-shell-resource")); |
| 62 WebKit::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated( |
| 63 WebKit::WebString::fromUTF8("test-shell-resource")); |
| 64 WebKit::WebSecurityPolicy::registerURLSchemeAsEmptyDocument( |
| 65 WebKit::WebString::fromUTF8("test-shell-resource")); |
| 66 WebScriptController::enableV8SingleThreadMode(); |
| 67 WebKit::WebRuntimeFeatures::enableApplicationCache(true); |
| 68 WebKit::WebRuntimeFeatures::enableDatabase(true); |
| 69 WebKit::WebRuntimeFeatures::enableNotifications(true); |
| 70 WebKit::WebRuntimeFeatures::enableTouch(true); |
| 71 |
| 72 // Load libraries for media and enable the media player. |
| 73 bool enable_media = false; |
| 74 base::FilePath module_path; |
| 75 if (PathService::Get(base::DIR_MODULE, &module_path)) { |
| 76 #if defined(OS_MACOSX) |
| 77 if (base::mac::AmIBundled()) |
| 78 module_path = module_path.DirName().DirName().DirName(); |
| 79 #endif |
| 80 if (media::InitializeMediaLibrary(module_path)) |
| 81 enable_media = true; |
| 82 } |
| 83 WebKit::WebRuntimeFeatures::enableMediaPlayer(enable_media); |
| 84 LOG_IF(WARNING, !enable_media) << "Failed to initialize the media library.\n"; |
| 85 |
| 86 // TODO(joth): Make a dummy geolocation service implemenation for |
| 87 // test_shell, and set this to true. http://crbug.com/36451 |
| 88 WebKit::WebRuntimeFeatures::enableGeolocation(false); |
| 89 |
| 90 file_utilities_.set_sandbox_enabled(false); |
| 91 |
| 92 if (!file_system_root_.CreateUniqueTempDir()) { |
| 93 LOG(WARNING) << "Failed to create a temp dir for the filesystem." |
| 94 "FileSystem feature will be disabled."; |
| 95 DCHECK(file_system_root_.path().empty()); |
| 96 } |
| 39 | 97 |
| 40 #if defined(OS_WIN) | 98 #if defined(OS_WIN) |
| 41 // Ensure we pick up the default theme engine. | 99 // Ensure we pick up the default theme engine. |
| 42 SetThemeEngine(NULL); | 100 SetThemeEngine(NULL); |
| 43 #endif | 101 #endif |
| 44 | 102 |
| 103 net::CookieMonster::EnableFileScheme(); |
| 104 |
| 45 // Test shell always exposes the GC. | 105 // Test shell always exposes the GC. |
| 46 webkit_glue::SetJavaScriptFlags(" --expose-gc"); | 106 webkit_glue::SetJavaScriptFlags(" --expose-gc"); |
| 47 } | 107 } |
| 48 | 108 |
| 49 TestWebKitPlatformSupport::~TestWebKitPlatformSupport() { | 109 TestWebKitPlatformSupport::~TestWebKitPlatformSupport() { |
| 50 url_loader_factory_.reset(); | 110 url_loader_factory_.reset(); |
| 51 mock_clipboard_.reset(); | 111 mock_clipboard_.reset(); |
| 52 WebKit::shutdown(); | 112 WebKit::shutdown(); |
| 53 } | 113 } |
| 54 | 114 |
| 55 WebKit::WebMimeRegistry* TestWebKitPlatformSupport::mimeRegistry() { | 115 WebKit::WebMimeRegistry* TestWebKitPlatformSupport::mimeRegistry() { |
| 56 return &mime_registry_; | 116 return &mime_registry_; |
| 57 } | 117 } |
| 58 | 118 |
| 59 WebKit::WebClipboard* TestWebKitPlatformSupport::clipboard() { | 119 WebKit::WebClipboard* TestWebKitPlatformSupport::clipboard() { |
| 60 // Mock out clipboard calls so that tests don't mess | 120 // Mock out clipboard calls so that tests don't mess |
| 61 // with each other's copies/pastes when running in parallel. | 121 // with each other's copies/pastes when running in parallel. |
| 62 return mock_clipboard_.get(); | 122 return mock_clipboard_.get(); |
| 63 } | 123 } |
| 64 | 124 |
| 125 WebKit::WebFileUtilities* TestWebKitPlatformSupport::fileUtilities() { |
| 126 return &file_utilities_; |
| 127 } |
| 128 |
| 129 WebKit::WebIDBFactory* TestWebKitPlatformSupport::idbFactory() { |
| 130 NOTREACHED() << |
| 131 "IndexedDB cannot be tested with in-process harnesses."; |
| 132 return NULL; |
| 133 } |
| 134 |
| 65 WebKit::WebURLLoader* TestWebKitPlatformSupport::createURLLoader() { | 135 WebKit::WebURLLoader* TestWebKitPlatformSupport::createURLLoader() { |
| 66 return url_loader_factory_->CreateURLLoader( | 136 return url_loader_factory_->CreateURLLoader( |
| 67 webkit_glue::WebKitPlatformSupportImpl::createURLLoader()); | 137 webkit_glue::WebKitPlatformSupportImpl::createURLLoader()); |
| 68 } | 138 } |
| 69 | 139 |
| 140 WebKit::WebData TestWebKitPlatformSupport::loadResource(const char* name) { |
| 141 if (!strcmp(name, "deleteButton")) { |
| 142 // Create a red 30x30 square. |
| 143 const char red_square[] = |
| 144 "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" |
| 145 "\x00\x00\x00\x1e\x00\x00\x00\x1e\x04\x03\x00\x00\x00\xc9\x1e\xb3" |
| 146 "\x91\x00\x00\x00\x30\x50\x4c\x54\x45\x00\x00\x00\x80\x00\x00\x00" |
| 147 "\x80\x00\x80\x80\x00\x00\x00\x80\x80\x00\x80\x00\x80\x80\x80\x80" |
| 148 "\x80\xc0\xc0\xc0\xff\x00\x00\x00\xff\x00\xff\xff\x00\x00\x00\xff" |
| 149 "\xff\x00\xff\x00\xff\xff\xff\xff\xff\x7b\x1f\xb1\xc4\x00\x00\x00" |
| 150 "\x09\x70\x48\x59\x73\x00\x00\x0b\x13\x00\x00\x0b\x13\x01\x00\x9a" |
| 151 "\x9c\x18\x00\x00\x00\x17\x49\x44\x41\x54\x78\x01\x63\x98\x89\x0a" |
| 152 "\x18\x50\xb9\x33\x47\xf9\xa8\x01\x32\xd4\xc2\x03\x00\x33\x84\x0d" |
| 153 "\x02\x3a\x91\xeb\xa5\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60" |
| 154 "\x82"; |
| 155 return WebKit::WebData(red_square, arraysize(red_square)); |
| 156 } |
| 157 return webkit_glue::WebKitPlatformSupportImpl::loadResource(name); |
| 158 } |
| 159 |
| 70 WebKit::WebString TestWebKitPlatformSupport::queryLocalizedString( | 160 WebKit::WebString TestWebKitPlatformSupport::queryLocalizedString( |
| 71 WebKit::WebLocalizedString::Name name) { | 161 WebKit::WebLocalizedString::Name name) { |
| 72 // Returns placeholder strings to check if they are correctly localized. | 162 // Returns placeholder strings to check if they are correctly localized. |
| 73 switch (name) { | 163 switch (name) { |
| 74 case WebKit::WebLocalizedString::OtherDateLabel: | 164 case WebKit::WebLocalizedString::OtherDateLabel: |
| 75 return ASCIIToUTF16("<<OtherDateLabel>>"); | 165 return ASCIIToUTF16("<<OtherDateLabel>>"); |
| 76 case WebKit::WebLocalizedString::OtherMonthLabel: | 166 case WebKit::WebLocalizedString::OtherMonthLabel: |
| 77 return ASCIIToUTF16("<<OtherMonthLabel>>"); | 167 return ASCIIToUTF16("<<OtherMonthLabel>>"); |
| 78 case WebKit::WebLocalizedString::OtherTimeLabel: | 168 case WebKit::WebLocalizedString::OtherTimeLabel: |
| 79 return ASCIIToUTF16("<<OtherTimeLabel>>"); | 169 return ASCIIToUTF16("<<OtherTimeLabel>>"); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 const WebKit::WebString& path) { | 318 const WebKit::WebString& path) { |
| 229 base::FilePath file_path = base::FilePath::FromUTF16Unsafe(path); | 319 base::FilePath file_path = base::FilePath::FromUTF16Unsafe(path); |
| 230 | 320 |
| 231 std::string buffer; | 321 std::string buffer; |
| 232 base::ReadFileToString(file_path, &buffer); | 322 base::ReadFileToString(file_path, &buffer); |
| 233 | 323 |
| 234 return WebKit::WebData(buffer.data(), buffer.size()); | 324 return WebKit::WebData(buffer.data(), buffer.size()); |
| 235 } | 325 } |
| 236 | 326 |
| 237 } // namespace content | 327 } // namespace content |
| OLD | NEW |