Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: webkit/support/test_webkit_platform_support.cc

Issue 11038027: Revert 160044 - Implement hyphenation for DumpRenderTree. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/support/test_webkit_platform_support.h ('k') | webkit/support/webkit_support.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebAudioDevi ce.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebAudioDevi ce.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSyste m.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSyste m.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads. h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads. h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBFactory.h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBFactory.h"
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h"
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h " 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h "
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 #include "base/mac/mac_util.h" 61 #include "base/mac/mac_util.h"
63 #elif defined(OS_POSIX) && !defined(OS_ANDROID) 62 #elif defined(OS_POSIX) && !defined(OS_ANDROID)
64 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/linux/WebThe meEngine.h" 63 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/linux/WebThe meEngine.h"
65 #endif 64 #endif
66 65
67 using WebKit::WebScriptController; 66 using WebKit::WebScriptController;
68 67
69 TestWebKitPlatformSupport::TestWebKitPlatformSupport(bool unit_test_mode, 68 TestWebKitPlatformSupport::TestWebKitPlatformSupport(bool unit_test_mode,
70 WebKit::Platform* shadow_platform_delegate) 69 WebKit::Platform* shadow_platform_delegate)
71 : unit_test_mode_(unit_test_mode), 70 : unit_test_mode_(unit_test_mode),
72 shadow_platform_delegate_(shadow_platform_delegate), 71 shadow_platform_delegate_(shadow_platform_delegate) {
73 hyphen_dictionary_(NULL) {
74 v8::V8::SetCounterFunction(base::StatsTable::FindLocation); 72 v8::V8::SetCounterFunction(base::StatsTable::FindLocation);
75 73
76 WebKit::initialize(this); 74 WebKit::initialize(this);
77 WebKit::setLayoutTestMode(true); 75 WebKit::setLayoutTestMode(true);
78 WebKit::WebSecurityPolicy::registerURLSchemeAsLocal( 76 WebKit::WebSecurityPolicy::registerURLSchemeAsLocal(
79 WebKit::WebString::fromUTF8("test-shell-resource")); 77 WebKit::WebString::fromUTF8("test-shell-resource"));
80 WebKit::WebSecurityPolicy::registerURLSchemeAsNoAccess( 78 WebKit::WebSecurityPolicy::registerURLSchemeAsNoAccess(
81 WebKit::WebString::fromUTF8("test-shell-resource")); 79 WebKit::WebString::fromUTF8("test-shell-resource"));
82 WebKit::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated( 80 WebKit::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(
83 WebKit::WebString::fromUTF8("test-shell-resource")); 81 WebKit::WebString::fromUTF8("test-shell-resource"));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // and no support for directory listings. 143 // and no support for directory listings.
146 SimpleResourceLoaderBridge::Init(FilePath(), cache_mode, true); 144 SimpleResourceLoaderBridge::Init(FilePath(), cache_mode, true);
147 145
148 // Test shell always exposes the GC. 146 // Test shell always exposes the GC.
149 webkit_glue::SetJavaScriptFlags(" --expose-gc"); 147 webkit_glue::SetJavaScriptFlags(" --expose-gc");
150 // Expose GCController to JavaScript. 148 // Expose GCController to JavaScript.
151 WebScriptController::registerExtension(extensions_v8::GCExtension::Get()); 149 WebScriptController::registerExtension(extensions_v8::GCExtension::Get());
152 } 150 }
153 151
154 TestWebKitPlatformSupport::~TestWebKitPlatformSupport() { 152 TestWebKitPlatformSupport::~TestWebKitPlatformSupport() {
155 if (hyphen_dictionary_)
156 hnj_hyphen_free(hyphen_dictionary_);
157 } 153 }
158 154
159 WebKit::WebMimeRegistry* TestWebKitPlatformSupport::mimeRegistry() { 155 WebKit::WebMimeRegistry* TestWebKitPlatformSupport::mimeRegistry() {
160 return &mime_registry_; 156 return &mime_registry_;
161 } 157 }
162 158
163 WebKit::WebClipboard* TestWebKitPlatformSupport::clipboard() { 159 WebKit::WebClipboard* TestWebKitPlatformSupport::clipboard() {
164 // Mock out clipboard calls so that tests don't mess 160 // Mock out clipboard calls so that tests don't mess
165 // with each other's copies/pastes when running in parallel. 161 // with each other's copies/pastes when running in parallel.
166 return &mock_clipboard_; 162 return &mock_clipboard_;
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 489
494 WebKit::WebRTCPeerConnectionHandler* 490 WebKit::WebRTCPeerConnectionHandler*
495 TestWebKitPlatformSupport::createRTCPeerConnectionHandler( 491 TestWebKitPlatformSupport::createRTCPeerConnectionHandler(
496 WebKit::WebRTCPeerConnectionHandlerClient* client) { 492 WebKit::WebRTCPeerConnectionHandlerClient* client) {
497 if (shadow_platform_delegate_) 493 if (shadow_platform_delegate_)
498 return shadow_platform_delegate_->createRTCPeerConnectionHandler(client); 494 return shadow_platform_delegate_->createRTCPeerConnectionHandler(client);
499 495
500 return webkit_glue::WebKitPlatformSupportImpl::createRTCPeerConnectionHandler( 496 return webkit_glue::WebKitPlatformSupportImpl::createRTCPeerConnectionHandler(
501 client); 497 client);
502 } 498 }
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))
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))
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 while (length && !IsAsciiAlpha(characters[length - 1]))
536 --length;
537 if (!length)
538 return 0;
539 std::string word = UTF16ToASCII(string16(characters, length));
540 scoped_array<char> hyphens(new char[word.length() + 5]);
541 char** rep = NULL;
542 int* pos = NULL;
543 int* cut = NULL;
544 int error = hnj_hyphen_hyphenate2(hyphen_dictionary_,
545 word.data(),
546 static_cast<int>(word.length()),
547 hyphens.get(),
548 NULL,
549 &rep,
550 &pos,
551 &cut);
552 if (error)
553 return 0;
554
555 // Release all resources allocated by the hyphen library now because they are
556 // not used when hyphenating English words.
557 if (rep) {
558 for (size_t i = 0; i < word.length(); ++i) {
559 if (rep[i])
560 free(rep[i]);
561 }
562 free(rep);
563 }
564 if (pos)
565 free(pos);
566 if (cut)
567 free(cut);
568
569 // Retrieve the last position where we can insert a hyphen before the given
570 // index.
571 if (before_index >= 2) {
572 for (size_t index = before_index - 2; index > 0; --index) {
573 if (hyphens[index] & 1)
574 return index + 1;
575 }
576 }
577 return 0;
578 }
OLDNEW
« no previous file with comments | « webkit/support/test_webkit_platform_support.h ('k') | webkit/support/webkit_support.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698