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" |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 size_t TestWebKitPlatformSupport::audioHardwareBufferSize() { | 399 size_t TestWebKitPlatformSupport::audioHardwareBufferSize() { |
400 return 128; | 400 return 128; |
401 } | 401 } |
402 | 402 |
403 WebKit::WebAudioDevice* TestWebKitPlatformSupport::createAudioDevice( | 403 WebKit::WebAudioDevice* TestWebKitPlatformSupport::createAudioDevice( |
404 size_t bufferSize, unsigned numberOfChannels, double sampleRate, | 404 size_t bufferSize, unsigned numberOfChannels, double sampleRate, |
405 WebKit::WebAudioDevice::RenderCallback*) { | 405 WebKit::WebAudioDevice::RenderCallback*) { |
406 return new WebAudioDeviceMock(sampleRate); | 406 return new WebAudioDeviceMock(sampleRate); |
407 } | 407 } |
408 | 408 |
| 409 bool TestWebKitPlatformSupport::canHyphenate(const WebKit::WebString& locale) { |
| 410 // As of February 2012, DumpRenderTree needs to support English only. |
| 411 return locale.isEmpty() || locale.equals("en") || locale.equals("en_US") || |
| 412 locale.equals("en_GB"); |
| 413 } |
| 414 |
| 415 size_t TestWebKitPlatformSupport::lastHyphenLocation( |
| 416 const char16* characters, |
| 417 size_t length, |
| 418 size_t index, |
| 419 const WebKit::WebString& locale) { |
| 420 // A list of hyphenation queries and their results used by DumpRenderTree. To |
| 421 // emulate Mac Safari, this list is created with the following steps: |
| 422 // 1. Run LayoutTests of Mac Safari; |
| 423 // 2. collect its hyphenation queries, and; |
| 424 // 3. Pack the results for the same text. |
| 425 // (When a query always returns 0, its indices becomes an empty string.) |
| 426 // Therefore, these results do not always represent gramatically-correct |
| 427 // locations. For example, we can insert two hyphens to a word "ev-i-dence" |
| 428 // even though this list does not allow inserting them. |
| 429 static const struct { |
| 430 const char* query; |
| 431 const char* results; |
| 432 } kQueries[] = { |
| 433 { " and", "" }, |
| 434 { " concupiscent,", "" }, |
| 435 { " evidence.", "" }, |
| 436 { " first", "" }, |
| 437 { " getting", "\x04" }, |
| 438 { " hedgehog", "\x06" }, |
| 439 { " remarkable", "\x03\x07" }, |
| 440 { " straightened", "\x09" }, |
| 441 { " undid", "\x03" }, |
| 442 { " were", "" }, |
| 443 { "Simply", "\x03" }, |
| 444 { "Undone.", "" }, |
| 445 { "comfortably", "\x03" }, |
| 446 { "declination", "\x03" }, |
| 447 { "flamingo:", "" }, |
| 448 { "lination", "\x04" }, |
| 449 { "reciprocity", "\x04" }, |
| 450 { "throughout", "\x07" }, |
| 451 { "undid", "\x02" }, |
| 452 { "undone.", "" }, |
| 453 { "unnecessary", "\x02" }, |
| 454 }; |
| 455 |
| 456 // Find a matching query. If we have a matching query, we return the largest |
| 457 // index in the indices less than the given index. |
| 458 WebKit::WebString word(characters, length); |
| 459 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kQueries); ++i) { |
| 460 if (word != WebKit::WebString::fromUTF8(kQueries[i].query)) |
| 461 continue; |
| 462 const char* results = kQueries[i].results; |
| 463 size_t previous = 0; |
| 464 size_t next = 0; |
| 465 while ((next = *results++) != '\0') { |
| 466 if (next >= index) |
| 467 break; |
| 468 previous = next; |
| 469 } |
| 470 return previous; |
| 471 } |
| 472 |
| 473 // DumpRenderTree sends a query not supported by this function. This case |
| 474 // happens probably when WebKit adds new layout tests that needs hyphenation. |
| 475 NOTIMPLEMENTED(); |
| 476 return 0; |
| 477 } |
| 478 |
409 void TestWebKitPlatformSupport::sampleGamepads(WebKit::WebGamepads& data) { | 479 void TestWebKitPlatformSupport::sampleGamepads(WebKit::WebGamepads& data) { |
410 data = gamepad_data_; | 480 data = gamepad_data_; |
411 } | 481 } |
412 | 482 |
413 void TestWebKitPlatformSupport::setGamepadData( | 483 void TestWebKitPlatformSupport::setGamepadData( |
414 const WebKit::WebGamepads& data) { | 484 const WebKit::WebGamepads& data) { |
415 gamepad_data_ = data; | 485 gamepad_data_ = data; |
416 } | 486 } |
417 | 487 |
418 void TestWebKitPlatformSupport::GetPlugins( | 488 void TestWebKitPlatformSupport::GetPlugins( |
(...skipping 23 matching lines...) Expand all Loading... |
442 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { | 512 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { |
443 return SimpleResourceLoaderBridge::Create(request_info); | 513 return SimpleResourceLoaderBridge::Create(request_info); |
444 } | 514 } |
445 | 515 |
446 webkit_glue::WebSocketStreamHandleBridge* | 516 webkit_glue::WebSocketStreamHandleBridge* |
447 TestWebKitPlatformSupport::CreateWebSocketBridge( | 517 TestWebKitPlatformSupport::CreateWebSocketBridge( |
448 WebKit::WebSocketStreamHandle* handle, | 518 WebKit::WebSocketStreamHandle* handle, |
449 webkit_glue::WebSocketStreamHandleDelegate* delegate) { | 519 webkit_glue::WebSocketStreamHandleDelegate* delegate) { |
450 return SimpleSocketStreamBridge::Create(handle, delegate); | 520 return SimpleSocketStreamBridge::Create(handle, delegate); |
451 } | 521 } |
OLD | NEW |