summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
Diffstat (limited to 'webkit')
-rw-r--r--webkit/tools/layout_tests/test_expectations.txt77
-rw-r--r--webkit/tools/test_shell/mock_spellcheck.cc126
-rw-r--r--webkit/tools/test_shell/mock_spellcheck.h52
-rw-r--r--webkit/tools/test_shell/mock_spellcheck_unittest.cc78
-rw-r--r--webkit/tools/test_shell/test_shell.gyp3
-rw-r--r--webkit/tools/test_shell/test_webview_delegate.cc20
-rw-r--r--webkit/tools/test_shell/test_webview_delegate.h7
7 files changed, 284 insertions, 79 deletions
diff --git a/webkit/tools/layout_tests/test_expectations.txt b/webkit/tools/layout_tests/test_expectations.txt
index 871e8db..718afd5 100644
--- a/webkit/tools/layout_tests/test_expectations.txt
+++ b/webkit/tools/layout_tests/test_expectations.txt
@@ -1697,86 +1697,9 @@ BUG23498 MAC : tables/mozilla_expected_failures/other/test4.html = IMAGE
BUG23498 MAC : webarchive/test-duplicate-resources.html = IMAGE
// Missing "misspelled-word" dotted underline
-BUG23497 MAC : editing/deleting/delete-3928305-fix.html = IMAGE
-BUG23497 MAC : editing/deleting/delete-3959464-fix.html = IMAGE
-BUG23497 MAC : editing/deleting/delete-and-undo.html = IMAGE
-BUG23497 MAC : editing/deleting/delete-block-contents-003.html = IMAGE
-BUG23497 MAC : editing/deleting/delete-contiguous-ws-001.html = IMAGE
-BUG23497 MAC : editing/deleting/delete-tab-002.html = IMAGE
-BUG23497 MAC : editing/deleting/delete-tab-003.html = IMAGE
BUG23497 MAC : editing/deleting/delete-to-select-table.html = IMAGE
-BUG23497 MAC : editing/deleting/delete-trailing-ws-002.html = IMAGE
-BUG23497 MAC : editing/deleting/delete-ws-fixup-001.html = IMAGE
-BUG23497 MAC : editing/deleting/delete-ws-fixup-002.html = IMAGE
-BUG23497 MAC : editing/execCommand/5569741.html = IMAGE
-BUG23497 MAC : editing/execCommand/insert-list-and-stitch.html = IMAGE
-BUG23497 MAC : editing/execCommand/insertHorizontalRule.html = IMAGE
-// BUG23497 MAC : editing/inserting/5418891.html = IMAGE
-BUG23497 MAC : editing/inserting/editing-empty-divs.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-3659587-fix.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-br-004.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-br-005.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-br-007.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-div-007.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-div-012.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-div-013.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-div-014.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-div-015.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-div-016.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-div-017.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-div-018.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-div-019.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-div-020.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-div-021.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-div-022.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-div-025.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-div-027.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-paragraph-02.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-paragraph-03.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-tab-002.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-tab-003.html = IMAGE
-BUG23497 MAC : editing/inserting/insert-text-with-newlines.html = IMAGE
-BUG23497 MAC : editing/inserting/paragraph-separator-01.html = IMAGE
-BUG23497 MAC : editing/inserting/paragraph-separator-02.html = IMAGE
-BUG23497 MAC : editing/inserting/paragraph-separator-03.html = IMAGE
-BUG23497 MAC : editing/inserting/return-key-with-selection-001.html = IMAGE
-BUG23497 MAC : editing/inserting/return-key-with-selection-002.html = IMAGE
-BUG23497 MAC : editing/inserting/return-key-with-selection-003.html = IMAGE
-BUG23497 MAC : editing/inserting/typing-002.html = IMAGE
-BUG23497 MAC : editing/inserting/typing-around-br-001.html = IMAGE
-BUG23497 MAC : editing/pasteboard/8145-2.html = IMAGE
-BUG23497 MAC : editing/pasteboard/cut-text-001.html = IMAGE
-BUG23497 MAC : editing/pasteboard/merge-end-blockquote.html = IMAGE
-BUG23497 MAC : editing/pasteboard/paste-blockquote-3.html = IMAGE
-BUG23497 MAC : editing/pasteboard/paste-text-019.html = IMAGE
-BUG23497 MAC : editing/pasteboard/undoable-fragment-removes.html = IMAGE
-BUG23497 MAC : editing/selection/13804.html = IMAGE
-BUG23497 MAC : editing/selection/5076323-1.html = IMAGE
-BUG23497 MAC : editing/selection/5234383-1.html = IMAGE
-BUG23497 MAC : editing/selection/5234383-2.html = IMAGE
-BUG23497 MAC : editing/selection/extend-by-word-001.html = IMAGE
-BUG23497 MAC : editing/selection/move-backwords-by-word-001.html = IMAGE
-BUG23497 MAC : editing/selection/move-by-character-001.html = IMAGE
-BUG23497 MAC : editing/selection/move-by-line-001.html = IMAGE
-BUG23497 MAC : editing/selection/move-by-word-001.html = IMAGE
-BUG23497 MAC : editing/selection/select-from-textfield-outwards.html = IMAGE
BUG23497 MAC : editing/selection/unrendered-002.html = IMAGE
-BUG23497 MAC : editing/spelling/inline_spelling_markers.html = IMAGE
BUG23497 MAC : editing/spelling/spellcheck-attribute.html = IMAGE
-BUG23497 MAC : editing/spelling/spelling-linebreak.html = IMAGE
-BUG23497 MAC : editing/spelling/spelling.html = IMAGE
-BUG23497 MAC : editing/style/5046875-2.html = IMAGE
-BUG23497 MAC : editing/style/block-styles-007.html = IMAGE
-BUG23497 MAC : editing/style/create-block-for-style-002.html = IMAGE
-BUG23497 MAC : editing/style/create-block-for-style-003.html = IMAGE
-BUG23497 MAC : editing/style/create-block-for-style-004.html = IMAGE
-BUG23497 MAC : editing/style/create-block-for-style-006.html = IMAGE
-BUG23497 MAC : editing/style/create-block-for-style-008.html = IMAGE
-BUG23497 MAC : editing/style/create-block-for-style-009.html = IMAGE
-BUG23497 MAC : editing/style/create-block-for-style-011.html = IMAGE
-BUG23497 MAC : editing/style/create-block-for-style-012.html = IMAGE
-BUG23497 MAC : editing/style/create-block-for-style-013.html = IMAGE
-BUG23497 MAC : fast/dom/blur-contenteditable.html = IMAGE
// Widget location is just slightly off
BUG23496 MAC : css1/box_properties/acid_test.html = IMAGE
diff --git a/webkit/tools/test_shell/mock_spellcheck.cc b/webkit/tools/test_shell/mock_spellcheck.cc
new file mode 100644
index 0000000..518e576
--- /dev/null
+++ b/webkit/tools/test_shell/mock_spellcheck.cc
@@ -0,0 +1,126 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/tools/test_shell/mock_spellcheck.h"
+
+#include <map>
+#include <utility>
+
+#include "base/logging.h"
+#include "base/string16.h"
+#include "base/string_util.h"
+
+MockSpellCheck::MockSpellCheck()
+ : initialized_(false) {
+}
+
+MockSpellCheck::~MockSpellCheck() {
+}
+
+bool MockSpellCheck::SpellCheckWord(const string16& text,
+ int* misspelledOffset,
+ int* misspelledLength) {
+ DCHECK(misspelledOffset && misspelledLength);
+
+ // Initialize this spellchecker.
+ InitializeIfNeeded();
+
+ // Reset the result values as our spellchecker does.
+ *misspelledOffset = 0;
+ *misspelledLength = 0;
+
+ // Extract the first possible English word from the given string.
+ // The given string may include non-ASCII characters or numbers. So, we
+ // should filter out such characters before start looking up our
+ // misspelled-word table.
+ // (This is a simple version of our SpellCheckWordIterator class.)
+ // If the given string doesn't include any ASCII characters, we can treat the
+ // string as valid one.
+ // Unfortunately, This implementation splits a contraction, i.e. "isn't" is
+ // split into two pieces "isn" and "t". This is OK because webkit tests
+ // don't have misspelled contractions.
+ static const char* kWordCharacters =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+ string16 word_characters(ASCIIToUTF16(kWordCharacters));
+
+ size_t word_offset = text.find_first_of(word_characters);
+ if (word_offset == std::string::npos)
+ return true;
+
+ size_t word_end = text.find_first_not_of(word_characters, word_offset);
+ size_t word_length = word_end == std::string::npos ?
+ text.length() - word_offset : word_end - word_offset;
+
+ // Look up our misspelled-word table to check if the extracted word is a
+ // known misspelled word, and return the offset and the length of the
+ // extracted word if this word is a known misspelled word.
+ // (See the comment in MockSpellCheck::InitializeIfNeeded() why we use a
+ // misspelled-word table.)
+ string16 word(text, word_offset, word_length);
+ std::map<string16, bool>::iterator it = misspelled_words_.find(word);
+ if (it == misspelled_words_.end())
+ return true;
+
+ *misspelledOffset = static_cast<int>(word_offset);
+ *misspelledLength = static_cast<int>(word_length);
+ return false;
+}
+
+bool MockSpellCheck::InitializeIfNeeded() {
+ // Exit if we have already initialized this object.
+ if (initialized_)
+ return false;
+
+ // Create a table that consists of misspelled words used in WebKit layout
+ // tests.
+ // Since WebKit layout tests don't have so many misspelled words as
+ // well-spelled words, it is easier to compare the given word with misspelled
+ // ones than to compare with well-spelled ones.
+ static const char* kMisspelledWords[] = {
+ // These words are known misspelled words in webkit tests.
+ // If there are other misspelled words in webkit tests, please add them in
+ // this array.
+ "foo",
+ "Foo",
+ "baz",
+ "fo",
+ "LibertyF",
+ "chello",
+ "xxxtestxxx",
+ "XXxxx",
+ "Textx",
+ "blockquoted",
+ "asd",
+ "Lorem",
+ "Nunc",
+ "Curabitur",
+ "eu",
+ "adlj",
+ "adaasj",
+ "sdklj",
+ "jlkds",
+ "jsaada",
+ "jlda",
+ "zz",
+ "contentEditable",
+ // The following words are used by unit tests.
+ "ifmmp",
+ "qwertyuiopasd",
+ "qwertyuiopasdf",
+ };
+
+ misspelled_words_.clear();
+ for (size_t i = 0; i < arraysize(kMisspelledWords); ++i) {
+ misspelled_words_.insert(std::make_pair<string16, bool>(
+ ASCIIToUTF16(kMisspelledWords[i]), false));
+ }
+
+ // Mark as initialized to prevent this object from being initialized twice
+ // or more.
+ initialized_ = true;
+
+ // Since this MockSpellCheck class doesn't download dictionaries, this
+ // function always returns false.
+ return false;
+}
diff --git a/webkit/tools/test_shell/mock_spellcheck.h b/webkit/tools/test_shell/mock_spellcheck.h
new file mode 100644
index 0000000..0f40675
--- /dev/null
+++ b/webkit/tools/test_shell/mock_spellcheck.h
@@ -0,0 +1,52 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBKIT_TOOLS_TEST_SHELL_MOCK_SPELLCHECK_H_
+#define WEBKIT_TOOLS_TEST_SHELL_MOCK_SPELLCHECK_H_
+
+#include <map>
+
+#include "base/string16.h"
+
+// A mock implementation of a spell-checker used for WebKit tests.
+// This class only implements the minimal functionarities required by WebKit
+// tests, i.e. this class just compares the given string with known misspelled
+// words in webkit tests and mark them as missspelled.
+// Even though this is sufficent for webkit tests, this class is not suitable
+// for any other usages.
+class MockSpellCheck {
+ public:
+ MockSpellCheck();
+ ~MockSpellCheck();
+
+ // Checks the spellings of the specified text.
+ // This function returns true if the text consists of valid words, and
+ // returns false if it includes invalid words.
+ // When the given text includes invalid words, this function sets the
+ // position of the first invalid word to misspelledOffset, and the length of
+ // the first invalid word to misspelledLength, respectively.
+ // For example, when the given text is " zz zz", this function sets 3 to
+ // misspelledOffset and 2 to misspelledLength, respectively.
+ bool SpellCheckWord(const string16& text,
+ int* misspelledOffset,
+ int* misspelledLength);
+
+ private:
+ // Initialize the internal resources if we need to initialize it.
+ // Initializing this object may take long time. To prevent from hurting
+ // the performance of test_shell, we initialize this object when
+ // SpellCheckWord() is called for the first time.
+ // To be compliant with SpellCheck:InitializeIfNeeded(), this function
+ // returns true if this object is downloading a dictionary, otherwise
+ // it returns false.
+ bool InitializeIfNeeded();
+
+ // A table that consists of misspelled words.
+ std::map<string16, bool> misspelled_words_;
+
+ // A flag representing whether or not this object is initialized.
+ bool initialized_;
+};
+
+#endif // WEBKIT_TOOLS_TEST_SHELL_MOCK_SPELLCHECK_H_
diff --git a/webkit/tools/test_shell/mock_spellcheck_unittest.cc b/webkit/tools/test_shell/mock_spellcheck_unittest.cc
new file mode 100644
index 0000000..76ac595
--- /dev/null
+++ b/webkit/tools/test_shell/mock_spellcheck_unittest.cc
@@ -0,0 +1,78 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this
+// source code is governed by a BSD-style license that can be found in the
+// LICENSE file.
+
+#include "base/format_macros.h"
+#include "base/string_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/tools/test_shell/mock_spellcheck.h"
+
+class MockSpellCheckTest : public testing::Test {
+ public:
+ MockSpellCheckTest() {
+ }
+
+ ~MockSpellCheckTest() {
+ }
+};
+
+TEST_F(MockSpellCheckTest, SpellCheckStrings) {
+ // Test cases.
+ // Even though the following test cases are copied from our unit test,
+ // SpellCheckTest.SpellCheckStrings_EN_US, we omit some test cases which
+ // needs to handle non-ASCII characters correctly since our MockSpellCheck
+ // class cannot handle non-ASCII characters. (It just ignores non-ASCII
+ // characters.)
+ static const struct {
+ const wchar_t* input;
+ bool expected_result;
+ int misspelling_start;
+ int misspelling_length;
+ } kTestCases[] = {
+ {L"", true, 0, 0},
+ {L" ", true, 0, 0},
+ {L"\xA0", true, 0, 0},
+ {L"\x3000", true, 0, 0},
+
+ {L"hello", true, 0, 0},
+ {L"\x4F60\x597D", true, 0, 0},
+ {L"\xC548\xB155\xD558\xC138\xC694", true, 0, 0},
+ {L"\x3053\x3093\x306B\x3061\x306F", true, 0, 0},
+ {L"\x0930\x093E\x091C\x0927\x093E\x0928", true, 0, 0},
+ {L"\xFF28\xFF45\xFF4C\xFF4C\xFF4F", true, 0, 0},
+ {L"\x03B3\x03B5\x03B9\x03AC" L" " L"\x03C3\x03BF\x03C5", true, 0, 0},
+ {L"\x0437\x0434\x0440\x0430\x0432\x0441"
+ L"\x0442\x0432\x0443\x0439\x0442\x0435", true, 0, 0},
+
+ {L" " L"hello", true, 0, 0},
+ {L"hello" L" ", true, 0, 0},
+ {L"hello" L" " L"hello", true, 0, 0},
+ {L"hello:hello", true, 0, 0},
+
+ {L"ifmmp", false, 0, 5},
+ {L"_ifmmp_", false, 1, 5},
+
+ {L" " L"ifmmp", false, 1, 5},
+ {L"ifmmp" L" ", false, 0, 5},
+ {L"ifmmp" L" " L"ifmmp", false, 0, 5},
+
+ {L"qwertyuiopasd", false, 0, 13},
+ {L"qwertyuiopasdf", false, 0, 14},
+ };
+
+ MockSpellCheck spellchecker;
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
+ SCOPED_TRACE(StringPrintf("kTestCases[%" PRIuS "]", i));
+
+ std::wstring input(kTestCases[i].input);
+ int misspelling_start;
+ int misspelling_length;
+ bool result = spellchecker.SpellCheckWord(WideToUTF16(input),
+ &misspelling_start,
+ &misspelling_length);
+
+ EXPECT_EQ(kTestCases[i].expected_result, result);
+ EXPECT_EQ(kTestCases[i].misspelling_start, misspelling_start);
+ EXPECT_EQ(kTestCases[i].misspelling_length, misspelling_length);
+ }
+}
diff --git a/webkit/tools/test_shell/test_shell.gyp b/webkit/tools/test_shell/test_shell.gyp
index 9a07898..d837d1f 100644
--- a/webkit/tools/test_shell/test_shell.gyp
+++ b/webkit/tools/test_shell/test_shell.gyp
@@ -65,6 +65,8 @@
'foreground_helper.h',
'layout_test_controller.cc',
'layout_test_controller.h',
+ 'mock_spellcheck.cc',
+ 'mock_spellcheck.h',
'mock_webclipboard_impl.cc',
'mock_webclipboard_impl.h',
'plain_text_controller.cc',
@@ -431,6 +433,7 @@
'layout_test_controller_unittest.cc',
'listener_leak_test.cc',
'media_leak_test.cc',
+ 'mock_spellcheck_unittest.cc',
'node_leak_test.cc',
'plugin_tests.cc',
'run_all_tests.cc',
diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc
index 64fc528..54a1ea3 100644
--- a/webkit/tools/test_shell/test_webview_delegate.cc
+++ b/webkit/tools/test_shell/test_webview_delegate.cc
@@ -52,6 +52,7 @@
#include "webkit/glue/webmediaplayer_impl.h"
#include "webkit/glue/window_open_disposition.h"
#include "webkit/tools/test_shell/accessibility_controller.h"
+#include "webkit/tools/test_shell/mock_spellcheck.h"
#include "webkit/tools/test_shell/test_navigation_controller.h"
#include "webkit/tools/test_shell/test_shell.h"
#include "webkit/tools/test_shell/test_web_worker.h"
@@ -462,9 +463,24 @@ bool TestWebViewDelegate::handleCurrentKeyboardEvent() {
WebString::fromUTF8(edit_command_value_));
}
+void TestWebViewDelegate::spellCheck(const WebString& text,
+ int& misspelledOffset,
+ int& misspelledLength) {
+#if defined(OS_MACOSX)
+ // Check the spelling of the given text.
+ // TODO(hbono): rebaseline layout-test results of Windows and Linux so we
+ // can enable this mock spellchecker on them.
+ string16 word(text);
+ mock_spellcheck_.SpellCheckWord(word, &misspelledOffset, &misspelledLength);
+#endif
+}
+
WebString TestWebViewDelegate::autoCorrectWord(const WebString& word) {
- // Dummy implementation.
- return word;
+ // Returns an empty string as Mac WebKit ('WebKitSupport/WebEditorClient.mm')
+ // does. (If this function returns a non-empty string, WebKit replaces the
+ // given misspelled string with the result one. This process executes some
+ // editor commands and causes layout-test failures.)
+ return WebString();
}
void TestWebViewDelegate::runModalAlertDialog(
diff --git a/webkit/tools/test_shell/test_webview_delegate.h b/webkit/tools/test_shell/test_webview_delegate.h
index e62fab2..cb403fa 100644
--- a/webkit/tools/test_shell/test_webview_delegate.h
+++ b/webkit/tools/test_shell/test_webview_delegate.h
@@ -38,6 +38,7 @@
#include "webkit/tools/test_shell/drag_delegate.h"
#include "webkit/tools/test_shell/drop_delegate.h"
#endif
+#include "webkit/tools/test_shell/mock_spellcheck.h"
#include "webkit/tools/test_shell/test_navigation_controller.h"
struct WebPreferences;
@@ -100,6 +101,9 @@ class TestWebViewDelegate : public WebKit::WebViewClient,
virtual void didChangeContents();
virtual void didEndEditing();
virtual bool handleCurrentKeyboardEvent();
+ virtual void spellCheck(
+ const WebKit::WebString& text, int& misspelledOffset,
+ int& misspelledLength);
virtual WebKit::WebString autoCorrectWord(
const WebKit::WebString& misspelled_word);
virtual void runModalAlertDialog(
@@ -392,6 +396,9 @@ class TestWebViewDelegate : public WebKit::WebViewClient,
std::string edit_command_name_;
std::string edit_command_value_;
+ // The mock spellchecker used in TestWebViewDelegate::spellCheck().
+ MockSpellCheck mock_spellcheck_;
+
DISALLOW_COPY_AND_ASSIGN(TestWebViewDelegate);
};