Chromium Code Reviews| 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/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/metrics/stats_counters.h" | 8 #include "base/metrics/stats_counters.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "media/base/media.h" | 13 #include "media/base/media.h" |
| 14 #include "net/cookies/cookie_monster.h" | 14 #include "net/cookies/cookie_monster.h" |
| 15 #include "net/http/http_cache.h" | 15 #include "net/http/http_cache.h" |
| 16 #include "net/test/test_server.h" | 16 #include "net/test/test_server.h" |
| 17 #include "third_party/hyphen/hyphen.h" | |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebAudioDevi ce.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebAudioDevi ce.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSyste m.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSyste m.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads. h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads. h" |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBFactory.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBFactory.h" |
| 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h " | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h " |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 #include "base/mac/mac_util.h" | 62 #include "base/mac/mac_util.h" |
| 62 #elif defined(OS_POSIX) && !defined(OS_ANDROID) | 63 #elif defined(OS_POSIX) && !defined(OS_ANDROID) |
| 63 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/linux/WebThe meEngine.h" | 64 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/linux/WebThe meEngine.h" |
| 64 #endif | 65 #endif |
| 65 | 66 |
| 66 using WebKit::WebScriptController; | 67 using WebKit::WebScriptController; |
| 67 | 68 |
| 68 TestWebKitPlatformSupport::TestWebKitPlatformSupport(bool unit_test_mode, | 69 TestWebKitPlatformSupport::TestWebKitPlatformSupport(bool unit_test_mode, |
| 69 WebKit::Platform* shadow_platform_delegate) | 70 WebKit::Platform* shadow_platform_delegate) |
| 70 : unit_test_mode_(unit_test_mode), | 71 : unit_test_mode_(unit_test_mode), |
| 71 shadow_platform_delegate_(shadow_platform_delegate) { | 72 shadow_platform_delegate_(shadow_platform_delegate), |
| 73 hyphen_dictionary_(NULL) { | |
| 72 v8::V8::SetCounterFunction(base::StatsTable::FindLocation); | 74 v8::V8::SetCounterFunction(base::StatsTable::FindLocation); |
| 73 | 75 |
| 74 WebKit::initialize(this); | 76 WebKit::initialize(this); |
| 75 WebKit::setLayoutTestMode(true); | 77 WebKit::setLayoutTestMode(true); |
| 76 WebKit::WebSecurityPolicy::registerURLSchemeAsLocal( | 78 WebKit::WebSecurityPolicy::registerURLSchemeAsLocal( |
| 77 WebKit::WebString::fromUTF8("test-shell-resource")); | 79 WebKit::WebString::fromUTF8("test-shell-resource")); |
| 78 WebKit::WebSecurityPolicy::registerURLSchemeAsNoAccess( | 80 WebKit::WebSecurityPolicy::registerURLSchemeAsNoAccess( |
| 79 WebKit::WebString::fromUTF8("test-shell-resource")); | 81 WebKit::WebString::fromUTF8("test-shell-resource")); |
| 80 WebKit::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated( | 82 WebKit::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated( |
| 81 WebKit::WebString::fromUTF8("test-shell-resource")); | 83 WebKit::WebString::fromUTF8("test-shell-resource")); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 // and no support for directory listings. | 145 // and no support for directory listings. |
| 144 SimpleResourceLoaderBridge::Init(FilePath(), cache_mode, true); | 146 SimpleResourceLoaderBridge::Init(FilePath(), cache_mode, true); |
| 145 | 147 |
| 146 // Test shell always exposes the GC. | 148 // Test shell always exposes the GC. |
| 147 webkit_glue::SetJavaScriptFlags(" --expose-gc"); | 149 webkit_glue::SetJavaScriptFlags(" --expose-gc"); |
| 148 // Expose GCController to JavaScript. | 150 // Expose GCController to JavaScript. |
| 149 WebScriptController::registerExtension(extensions_v8::GCExtension::Get()); | 151 WebScriptController::registerExtension(extensions_v8::GCExtension::Get()); |
| 150 } | 152 } |
| 151 | 153 |
| 152 TestWebKitPlatformSupport::~TestWebKitPlatformSupport() { | 154 TestWebKitPlatformSupport::~TestWebKitPlatformSupport() { |
| 155 if (hyphen_dictionary_) | |
| 156 hnj_hyphen_free(hyphen_dictionary_); | |
| 153 } | 157 } |
| 154 | 158 |
| 155 WebKit::WebMimeRegistry* TestWebKitPlatformSupport::mimeRegistry() { | 159 WebKit::WebMimeRegistry* TestWebKitPlatformSupport::mimeRegistry() { |
| 156 return &mime_registry_; | 160 return &mime_registry_; |
| 157 } | 161 } |
| 158 | 162 |
| 159 WebKit::WebClipboard* TestWebKitPlatformSupport::clipboard() { | 163 WebKit::WebClipboard* TestWebKitPlatformSupport::clipboard() { |
| 160 // Mock out clipboard calls so that tests don't mess | 164 // Mock out clipboard calls so that tests don't mess |
| 161 // with each other's copies/pastes when running in parallel. | 165 // with each other's copies/pastes when running in parallel. |
| 162 return &mock_clipboard_; | 166 return &mock_clipboard_; |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 | 493 |
| 490 WebKit::WebRTCPeerConnectionHandler* | 494 WebKit::WebRTCPeerConnectionHandler* |
| 491 TestWebKitPlatformSupport::createRTCPeerConnectionHandler( | 495 TestWebKitPlatformSupport::createRTCPeerConnectionHandler( |
| 492 WebKit::WebRTCPeerConnectionHandlerClient* client) { | 496 WebKit::WebRTCPeerConnectionHandlerClient* client) { |
| 493 if (shadow_platform_delegate_) | 497 if (shadow_platform_delegate_) |
| 494 return shadow_platform_delegate_->createRTCPeerConnectionHandler(client); | 498 return shadow_platform_delegate_->createRTCPeerConnectionHandler(client); |
| 495 | 499 |
| 496 return webkit_glue::WebKitPlatformSupportImpl::createRTCPeerConnectionHandler( | 500 return webkit_glue::WebKitPlatformSupportImpl::createRTCPeerConnectionHandler( |
| 497 client); | 501 client); |
| 498 } | 502 } |
| 503 | |
| 504 bool TestWebKitPlatformSupport::canHyphenate(const WebKit::WebString& locale) { | |
| 505 return locale.isEmpty() || locale.equals("en_US"); | |
| 506 } | |
| 507 | |
| 508 size_t TestWebKitPlatformSupport::computeLastHyphenLocation( | |
| 509 const char16* characters, | |
| 510 size_t length, | |
| 511 size_t before_index, | |
| 512 const WebKit::WebString& locale) { | |
| 513 DCHECK(locale.isEmpty() || locale.equals("en_US")); | |
| 514 if (!hyphen_dictionary_) { | |
| 515 // Initialize the hyphen library with a sample dictionary. To avoid test | |
| 516 // flakiness, this code synchronously loads the dictionary. | |
| 517 FilePath path; | |
| 518 if (!PathService::Get(base::DIR_SOURCE_ROOT, &path)) | |
|
Nico
2013/01/20 04:45:11
This is possibly not correct on linux for standalo
| |
| 519 return 0; | |
| 520 path = path.AppendASCII("third_party"); | |
| 521 path = path.AppendASCII("hyphen"); | |
| 522 path = path.AppendASCII("hyph_en_US.dic"); | |
| 523 std::string dictionary; | |
| 524 if (!file_util::ReadFileToString(path, &dictionary)) | |
|
Nico
2013/01/20 04:45:11
Relatedly, should this be DCHECK()ed?
| |
| 525 return 0; | |
| 526 hyphen_dictionary_ = hnj_hyphen_load( | |
| 527 reinterpret_cast<const unsigned char*>(dictionary.data()), | |
| 528 dictionary.length()); | |
| 529 if (!hyphen_dictionary_) | |
| 530 return 0; | |
| 531 } | |
| 532 // Retrieve the positions where we can insert hyphens. This function assumes | |
| 533 // the input word is an English word so it can use the position returned by | |
| 534 // the hyphen library without conversion. | |
| 535 string16 word_utf16(characters, length); | |
| 536 if (!IsStringASCII(word_utf16)) | |
| 537 return 0; | |
| 538 std::string word = UTF16ToASCII(word_utf16); | |
| 539 scoped_array<char> hyphens(new char[word.length() + 5]); | |
| 540 char** rep = NULL; | |
| 541 int* pos = NULL; | |
| 542 int* cut = NULL; | |
| 543 int error = hnj_hyphen_hyphenate2(hyphen_dictionary_, | |
| 544 word.data(), | |
| 545 static_cast<int>(word.length()), | |
| 546 hyphens.get(), | |
| 547 NULL, | |
| 548 &rep, | |
| 549 &pos, | |
| 550 &cut); | |
| 551 if (error) | |
| 552 return 0; | |
| 553 | |
| 554 // Release all resources allocated by the hyphen library now because they are | |
| 555 // not used when hyphenating English words. | |
| 556 if (rep) { | |
| 557 for (size_t i = 0; i < word.length(); ++i) { | |
| 558 if (rep[i]) | |
| 559 free(rep[i]); | |
| 560 } | |
| 561 free(rep); | |
| 562 } | |
| 563 if (pos) | |
| 564 free(pos); | |
| 565 if (cut) | |
| 566 free(cut); | |
| 567 | |
| 568 // Retrieve the last position where we can insert a hyphen before the given | |
| 569 // index. | |
| 570 if (before_index >= 2) { | |
| 571 for (size_t index = before_index - 2; index > 0; --index) { | |
| 572 if (hyphens[index] & 1) | |
| 573 return index + 1; | |
| 574 } | |
| 575 } | |
| 576 return 0; | |
| 577 } | |
| OLD | NEW |