OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "webkit/support/test_webkit_platform_support.h" | 5 #include "webkit/support/test_webkit_platform_support.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/memory/scoped_handle.h" | |
11 #include "base/metrics/stats_counters.h" | 10 #include "base/metrics/stats_counters.h" |
12 #include "base/path_service.h" | 11 #include "base/path_service.h" |
13 #include "base/string_util.h" | |
14 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
15 #include "cc/thread_impl.h" | 13 #include "cc/thread_impl.h" |
16 #include "media/base/media.h" | 14 #include "media/base/media.h" |
17 #include "net/cookies/cookie_monster.h" | 15 #include "net/cookies/cookie_monster.h" |
18 #include "net/http/http_cache.h" | 16 #include "net/http/http_cache.h" |
19 #include "net/test/test_server.h" | 17 #include "net/test/test_server.h" |
20 #include "third_party/WebKit/Source/Platform/chromium/public/WebAudioDevice.h" | 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebAudioDevice.h" |
21 #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h" | 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h" |
22 #include "third_party/WebKit/Source/Platform/chromium/public/WebFileSystem.h" | 20 #include "third_party/WebKit/Source/Platform/chromium/public/WebFileSystem.h" |
23 #include "third_party/WebKit/Source/Platform/chromium/public/WebGamepads.h" | 21 #include "third_party/WebKit/Source/Platform/chromium/public/WebGamepads.h" |
24 #include "third_party/WebKit/Source/Platform/chromium/public/WebStorageArea.h" | 22 #include "third_party/WebKit/Source/Platform/chromium/public/WebStorageArea.h" |
25 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 23 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
26 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" | 24 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h
" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h
" |
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" |
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageEventDispat
cher.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageEventDispat
cher.h" |
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h
" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h
" |
34 #include "third_party/hyphen/hyphen.h" | |
35 #include "v8/include/v8.h" | 32 #include "v8/include/v8.h" |
36 #include "webkit/appcache/web_application_cache_host_impl.h" | 33 #include "webkit/appcache/web_application_cache_host_impl.h" |
37 #include "webkit/compositor_bindings/web_compositor_support_impl.h" | 34 #include "webkit/compositor_bindings/web_compositor_support_impl.h" |
38 #include "webkit/compositor_bindings/web_layer_tree_view_impl_for_testing.h" | 35 #include "webkit/compositor_bindings/web_layer_tree_view_impl_for_testing.h" |
39 #include "webkit/database/vfs_backend.h" | 36 #include "webkit/database/vfs_backend.h" |
40 #include "webkit/glue/simple_webmimeregistry_impl.h" | 37 #include "webkit/glue/simple_webmimeregistry_impl.h" |
41 #include "webkit/glue/webclipboard_impl.h" | 38 #include "webkit/glue/webclipboard_impl.h" |
42 #include "webkit/glue/webkit_glue.h" | 39 #include "webkit/glue/webkit_glue.h" |
43 #include "webkit/glue/webkitplatformsupport_impl.h" | 40 #include "webkit/glue/webkitplatformsupport_impl.h" |
44 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" | 41 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" |
(...skipping 21 matching lines...) Expand all Loading... |
66 #elif defined(OS_MACOSX) | 63 #elif defined(OS_MACOSX) |
67 #include "base/mac/mac_util.h" | 64 #include "base/mac/mac_util.h" |
68 #endif | 65 #endif |
69 | 66 |
70 using WebKit::WebLayerTreeViewImplForTesting; | 67 using WebKit::WebLayerTreeViewImplForTesting; |
71 using WebKit::WebScriptController; | 68 using WebKit::WebScriptController; |
72 | 69 |
73 TestWebKitPlatformSupport::TestWebKitPlatformSupport(bool unit_test_mode, | 70 TestWebKitPlatformSupport::TestWebKitPlatformSupport(bool unit_test_mode, |
74 WebKit::Platform* shadow_platform_delegate) | 71 WebKit::Platform* shadow_platform_delegate) |
75 : unit_test_mode_(unit_test_mode), | 72 : unit_test_mode_(unit_test_mode), |
76 shadow_platform_delegate_(shadow_platform_delegate), | 73 shadow_platform_delegate_(shadow_platform_delegate) { |
77 hyphen_dictionary_(NULL) { | |
78 v8::V8::SetCounterFunction(base::StatsTable::FindLocation); | 74 v8::V8::SetCounterFunction(base::StatsTable::FindLocation); |
79 | 75 |
80 WebKit::initialize(this); | 76 WebKit::initialize(this); |
81 WebKit::setLayoutTestMode(true); | 77 WebKit::setLayoutTestMode(true); |
82 WebKit::WebSecurityPolicy::registerURLSchemeAsLocal( | 78 WebKit::WebSecurityPolicy::registerURLSchemeAsLocal( |
83 WebKit::WebString::fromUTF8("test-shell-resource")); | 79 WebKit::WebString::fromUTF8("test-shell-resource")); |
84 WebKit::WebSecurityPolicy::registerURLSchemeAsNoAccess( | 80 WebKit::WebSecurityPolicy::registerURLSchemeAsNoAccess( |
85 WebKit::WebString::fromUTF8("test-shell-resource")); | 81 WebKit::WebString::fromUTF8("test-shell-resource")); |
86 WebKit::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated( | 82 WebKit::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated( |
87 WebKit::WebString::fromUTF8("test-shell-resource")); | 83 WebKit::WebString::fromUTF8("test-shell-resource")); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 blob_registry_ = new TestShellWebBlobRegistryImpl(); | 126 blob_registry_ = new TestShellWebBlobRegistryImpl(); |
131 | 127 |
132 file_utilities_.set_sandbox_enabled(false); | 128 file_utilities_.set_sandbox_enabled(false); |
133 | 129 |
134 if (!file_system_root_.CreateUniqueTempDir()) { | 130 if (!file_system_root_.CreateUniqueTempDir()) { |
135 LOG(WARNING) << "Failed to create a temp dir for the filesystem." | 131 LOG(WARNING) << "Failed to create a temp dir for the filesystem." |
136 "FileSystem feature will be disabled."; | 132 "FileSystem feature will be disabled."; |
137 DCHECK(file_system_root_.path().empty()); | 133 DCHECK(file_system_root_.path().empty()); |
138 } | 134 } |
139 | 135 |
| 136 { |
| 137 // Initialize the hyphen library with a sample dictionary. |
| 138 base::FilePath path = webkit_support::GetChromiumRootDirFilePath(); |
| 139 path = path.Append(FILE_PATH_LITERAL("third_party/hyphen/hyph_en_US.dic")); |
| 140 base::PlatformFile dict_file = base::CreatePlatformFile( |
| 141 path, |
| 142 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, |
| 143 NULL, NULL); |
| 144 hyphenator_.LoadDictionary(dict_file); |
| 145 } |
| 146 |
140 #if defined(OS_WIN) | 147 #if defined(OS_WIN) |
141 // Ensure we pick up the default theme engine. | 148 // Ensure we pick up the default theme engine. |
142 SetThemeEngine(NULL); | 149 SetThemeEngine(NULL); |
143 #endif | 150 #endif |
144 | 151 |
145 net::HttpCache::Mode cache_mode = net::HttpCache::NORMAL; | 152 net::HttpCache::Mode cache_mode = net::HttpCache::NORMAL; |
146 net::CookieMonster::EnableFileScheme(); | 153 net::CookieMonster::EnableFileScheme(); |
147 | 154 |
148 // Initializing with a default context, which means no on-disk cookie DB, | 155 // Initializing with a default context, which means no on-disk cookie DB, |
149 // and no support for directory listings. | 156 // and no support for directory listings. |
150 SimpleResourceLoaderBridge::Init(base::FilePath(), cache_mode, true); | 157 SimpleResourceLoaderBridge::Init(base::FilePath(), cache_mode, true); |
151 | 158 |
152 // Test shell always exposes the GC. | 159 // Test shell always exposes the GC. |
153 webkit_glue::SetJavaScriptFlags(" --expose-gc"); | 160 webkit_glue::SetJavaScriptFlags(" --expose-gc"); |
154 // Expose GCController to JavaScript. | 161 // Expose GCController to JavaScript. |
155 WebScriptController::registerExtension(extensions_v8::GCExtension::Get()); | 162 WebScriptController::registerExtension(extensions_v8::GCExtension::Get()); |
156 } | 163 } |
157 | 164 |
158 TestWebKitPlatformSupport::~TestWebKitPlatformSupport() { | 165 TestWebKitPlatformSupport::~TestWebKitPlatformSupport() { |
159 if (hyphen_dictionary_) | |
160 hnj_hyphen_free(hyphen_dictionary_); | |
161 } | 166 } |
162 | 167 |
163 WebKit::WebMimeRegistry* TestWebKitPlatformSupport::mimeRegistry() { | 168 WebKit::WebMimeRegistry* TestWebKitPlatformSupport::mimeRegistry() { |
164 return &mime_registry_; | 169 return &mime_registry_; |
165 } | 170 } |
166 | 171 |
167 WebKit::WebClipboard* TestWebKitPlatformSupport::clipboard() { | 172 WebKit::WebClipboard* TestWebKitPlatformSupport::clipboard() { |
168 // Mock out clipboard calls so that tests don't mess | 173 // Mock out clipboard calls so that tests don't mess |
169 // with each other's copies/pastes when running in parallel. | 174 // with each other's copies/pastes when running in parallel. |
170 return &mock_clipboard_; | 175 return &mock_clipboard_; |
(...skipping 12 matching lines...) Expand all Loading... |
183 } | 188 } |
184 | 189 |
185 WebKit::WebBlobRegistry* TestWebKitPlatformSupport::blobRegistry() { | 190 WebKit::WebBlobRegistry* TestWebKitPlatformSupport::blobRegistry() { |
186 return blob_registry_.get(); | 191 return blob_registry_.get(); |
187 } | 192 } |
188 | 193 |
189 WebKit::WebFileSystem* TestWebKitPlatformSupport::fileSystem() { | 194 WebKit::WebFileSystem* TestWebKitPlatformSupport::fileSystem() { |
190 return &file_system_; | 195 return &file_system_; |
191 } | 196 } |
192 | 197 |
| 198 WebKit::WebHyphenator* TestWebKitPlatformSupport::hyphenator() { |
| 199 return &hyphenator_; |
| 200 } |
| 201 |
193 bool TestWebKitPlatformSupport::sandboxEnabled() { | 202 bool TestWebKitPlatformSupport::sandboxEnabled() { |
194 return true; | 203 return true; |
195 } | 204 } |
196 | 205 |
197 WebKit::Platform::FileHandle | 206 WebKit::Platform::FileHandle |
198 TestWebKitPlatformSupport::databaseOpenFile( | 207 TestWebKitPlatformSupport::databaseOpenFile( |
199 const WebKit::WebString& vfs_file_name, int desired_flags) { | 208 const WebKit::WebString& vfs_file_name, int desired_flags) { |
200 return SimpleDatabaseSystem::GetInstance()->OpenFile( | 209 return SimpleDatabaseSystem::GetInstance()->OpenFile( |
201 vfs_file_name, desired_flags); | 210 vfs_file_name, desired_flags); |
202 } | 211 } |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 TestWebKitPlatformSupport::createRTCPeerConnectionHandler( | 482 TestWebKitPlatformSupport::createRTCPeerConnectionHandler( |
474 WebKit::WebRTCPeerConnectionHandlerClient* client) { | 483 WebKit::WebRTCPeerConnectionHandlerClient* client) { |
475 if (shadow_platform_delegate_) | 484 if (shadow_platform_delegate_) |
476 return shadow_platform_delegate_->createRTCPeerConnectionHandler(client); | 485 return shadow_platform_delegate_->createRTCPeerConnectionHandler(client); |
477 | 486 |
478 return webkit_glue::WebKitPlatformSupportImpl::createRTCPeerConnectionHandler( | 487 return webkit_glue::WebKitPlatformSupportImpl::createRTCPeerConnectionHandler( |
479 client); | 488 client); |
480 } | 489 } |
481 | 490 |
482 bool TestWebKitPlatformSupport::canHyphenate(const WebKit::WebString& locale) { | 491 bool TestWebKitPlatformSupport::canHyphenate(const WebKit::WebString& locale) { |
483 return locale.isEmpty() || locale.equals("en") || locale.equals("en_US") || | 492 return hyphenator()->canHyphenate(locale); |
484 locale.equals("en_GB"); | |
485 } | 493 } |
486 | 494 |
487 size_t TestWebKitPlatformSupport::computeLastHyphenLocation( | 495 size_t TestWebKitPlatformSupport::computeLastHyphenLocation( |
488 const char16* characters, | 496 const char16* characters, |
489 size_t length, | 497 size_t length, |
490 size_t before_index, | 498 size_t before_index, |
491 const WebKit::WebString& locale) { | 499 const WebKit::WebString& locale) { |
492 DCHECK(locale.isEmpty() || locale.equals("en") || locale.equals("en_US") || | 500 return hyphenator()->computeLastHyphenLocation( |
493 locale.equals("en_GB")); | 501 characters, length, before_index, locale); |
494 if (!hyphen_dictionary_) { | |
495 // Initialize the hyphen library with a sample dictionary. To avoid test | |
496 // flakiness, this code synchronously loads the dictionary. | |
497 base::FilePath path = webkit_support::GetChromiumRootDirFilePath(); | |
498 path = path.Append(FILE_PATH_LITERAL("third_party/hyphen/hyph_en_US.dic")); | |
499 base::PlatformFile dict_file = base::CreatePlatformFile( | |
500 path, | |
501 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, | |
502 NULL, NULL); | |
503 if (dict_file == base::kInvalidPlatformFileValue) | |
504 return 0; | |
505 ScopedStdioHandle dict_handle(base::FdopenPlatformFile(dict_file, "r")); | |
506 if (!dict_handle.get()) { | |
507 base::ClosePlatformFile(dict_file); | |
508 return 0; | |
509 } | |
510 hyphen_dictionary_ = hnj_hyphen_load_file(dict_handle.get()); | |
511 if (!hyphen_dictionary_) | |
512 return 0; | |
513 } | |
514 // Retrieve the positions where we can insert hyphens. This function assumes | |
515 // the input word is an English word so it can use the position returned by | |
516 // the hyphen library without conversion. | |
517 string16 word_utf16(characters, length); | |
518 if (!IsStringASCII(word_utf16)) | |
519 return 0; | |
520 std::string word = StringToLowerASCII(UTF16ToASCII(word_utf16)); | |
521 scoped_array<char> hyphens(new char[word.length() + 5]); | |
522 char** rep = NULL; | |
523 int* pos = NULL; | |
524 int* cut = NULL; | |
525 int error = hnj_hyphen_hyphenate2(hyphen_dictionary_, | |
526 word.data(), | |
527 static_cast<int>(word.length()), | |
528 hyphens.get(), | |
529 NULL, | |
530 &rep, | |
531 &pos, | |
532 &cut); | |
533 if (error) | |
534 return 0; | |
535 | |
536 // Release all resources allocated by the hyphen library now because they are | |
537 // not used when hyphenating English words. | |
538 if (rep) { | |
539 for (size_t i = 0; i < word.length(); ++i) { | |
540 if (rep[i]) | |
541 free(rep[i]); | |
542 } | |
543 free(rep); | |
544 } | |
545 if (pos) | |
546 free(pos); | |
547 if (cut) | |
548 free(cut); | |
549 | |
550 // Retrieve the last position where we can insert a hyphen before the given | |
551 // index. | |
552 if (before_index >= 2) { | |
553 for (size_t index = before_index - 2; index > 0; --index) { | |
554 if (hyphens[index] & 1) | |
555 return index + 1; | |
556 } | |
557 } | |
558 return 0; | |
559 } | 502 } |
560 | 503 |
561 WebKit::WebGestureCurve* TestWebKitPlatformSupport::createFlingAnimationCurve( | 504 WebKit::WebGestureCurve* TestWebKitPlatformSupport::createFlingAnimationCurve( |
562 int device_source, | 505 int device_source, |
563 const WebKit::WebFloatPoint& velocity, | 506 const WebKit::WebFloatPoint& velocity, |
564 const WebKit::WebSize& cumulative_scroll) { | 507 const WebKit::WebSize& cumulative_scroll) { |
565 // Caller will retain and release. | 508 // Caller will retain and release. |
566 return new WebGestureCurveMock(velocity, cumulative_scroll); | 509 return new WebGestureCurveMock(velocity, cumulative_scroll); |
567 } | 510 } |
568 | 511 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 return view.release(); | 555 return view.release(); |
613 } | 556 } |
614 | 557 |
615 WebKit::WebLayerTreeView* | 558 WebKit::WebLayerTreeView* |
616 TestWebKitPlatformSupport::createLayerTreeViewForTesting( | 559 TestWebKitPlatformSupport::createLayerTreeViewForTesting( |
617 TestViewType type) { | 560 TestViewType type) { |
618 DCHECK_EQ(TestViewTypeUnitTest, type); | 561 DCHECK_EQ(TestViewTypeUnitTest, type); |
619 return createLayerTreeViewForTesting(); | 562 return createLayerTreeViewForTesting(); |
620 } | 563 } |
621 | 564 |
OLD | NEW |