summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authormorrita@chromium.org <morrita@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-29 03:08:50 +0000
committermorrita@chromium.org <morrita@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-29 03:08:50 +0000
commitb12c65870590e68a52fe112526536b118be75f2d (patch)
tree6f2ada70e2518b509a834d019f218f909bb891bb /webkit
parent18066cbe2444db3ea0792a520076c8b332289c42 (diff)
downloadchromium_src-b12c65870590e68a52fe112526536b118be75f2d.zip
chromium_src-b12c65870590e68a52fe112526536b118be75f2d.tar.gz
chromium_src-b12c65870590e68a52fe112526536b118be75f2d.tar.bz2
TestShell: Backported EventSender.contextClick() improvement
to mock menu item strings. This change was once reverted at r67248 due to hitting a webkit bug and is re-landing because the bug was fixed at http://trac.webkit.org/changeset/72721. BUG=63460 TEST=LayoutTest/editing/spelling/context-menu-suggestions.html Review URL: http://codereview.chromium.org/5120002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67505 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/tools/test_shell/event_sending_controller.cc55
-rw-r--r--webkit/tools/test_shell/mock_spellcheck.cc6
-rw-r--r--webkit/tools/test_shell/mock_spellcheck.h5
-rw-r--r--webkit/tools/test_shell/test_webview_delegate.cc7
-rw-r--r--webkit/tools/test_shell/test_webview_delegate.h11
5 files changed, 84 insertions, 0 deletions
diff --git a/webkit/tools/test_shell/event_sending_controller.cc b/webkit/tools/test_shell/event_sending_controller.cc
index 6bf0282..bf02835 100644
--- a/webkit/tools/test_shell/event_sending_controller.cc
+++ b/webkit/tools/test_shell/event_sending_controller.cc
@@ -35,6 +35,7 @@
#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
#include "third_party/WebKit/WebKit/chromium/public/WebTouchPoint.h"
#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebBindings.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/tools/test_shell/test_shell.h"
#include "webkit/tools/test_shell/test_webview_delegate.h"
@@ -770,12 +771,60 @@ void EventSendingController::ReplaySavedEvents() {
replaying_saved_events = false;
}
+// Because actual context menu is implemented by the browser side,
+// this function does only what LayoutTests are expecting:
+// - Many test checks the count of items. So returning non-zero value
+// makes sense.
+// - Some test compares the count before and after some action. So
+// changing the count based on flags also makes sense. This function
+// is doing such for some flags.
+// - Some test even checks actual string content. So providing it
+// would be also helpful.
+static std::vector<WebString>
+MakeMenuItemStringsFor(const WebKit::WebContextMenuData* context_menu,
+ MockSpellCheck* spellcheck) {
+ // These constants are based on Safari's context menu because tests
+ // are made for it.
+ static const char* kNonEditableMenuStrings[] = {
+ "Back", "Reload Page", "Open in Dashbaord", "<separator>",
+ "View Source", "Save Page As", "Print Page", "Inspect Element",
+ 0 };
+ static const char* kEditableMenuStrings[] = {
+ "Cut", "Copy", "<separator>", "Paste", "Spelling and Grammar",
+ "Substitutions, Transformations", "Font", "Speech",
+ "Paragraph Direction", "<separator>", 0 };
+
+ // This is possible because mouse events are cancelleable.
+ if (!context_menu)
+ return std::vector<WebString>();
+
+ std::vector<WebString> strings;
+
+ if (context_menu->isEditable) {
+ for (const char** item = kEditableMenuStrings; *item; ++item)
+ strings.push_back(WebString::fromUTF8(*item));
+ std::vector<string16> suggestions;
+ spellcheck->FillSuggestions(context_menu->misspelledWord, &suggestions);
+ for (size_t i = 0; i < suggestions.size(); ++i)
+ strings.push_back(WebString(suggestions[i]));
+ } else {
+ for (const char** item = kNonEditableMenuStrings; *item; ++item)
+ strings.push_back(WebString::fromUTF8(*item));
+ }
+
+ return strings;
+}
+
void EventSendingController::contextClick(
const CppArgumentList& args, CppVariant* result) {
result->SetNull();
webview()->layout();
+ // Clears last context menu data because we need to know if the
+ // context menu be requested after following mouse events.
+ shell_->delegate()->ClearContextMenuData();
+
UpdateClickCountForButton(WebMouseEvent::ButtonRight);
// Generate right mouse down and up.
@@ -791,6 +840,12 @@ void EventSendingController::contextClick(
webview()->handleInputEvent(event);
pressed_button_ = WebMouseEvent::ButtonNone;
+
+ result->Set(WebKit::WebBindings::makeStringArray(
+ MakeMenuItemStringsFor(
+ shell_->delegate()->last_context_menu_data(),
+ shell_->delegate()->mock_spellcheck())));
+
}
void EventSendingController::scheduleAsynchronousClick(
diff --git a/webkit/tools/test_shell/mock_spellcheck.cc b/webkit/tools/test_shell/mock_spellcheck.cc
index fd53401..cc05c16 100644
--- a/webkit/tools/test_shell/mock_spellcheck.cc
+++ b/webkit/tools/test_shell/mock_spellcheck.cc
@@ -125,3 +125,9 @@ bool MockSpellCheck::InitializeIfNeeded() {
// function always returns false.
return false;
}
+
+void MockSpellCheck::FillSuggestions(const string16& word,
+ std::vector<string16>* suggestions) {
+ if (word == ASCIIToUTF16("wellcome"))
+ suggestions->push_back(ASCIIToUTF16("welcome"));
+}
diff --git a/webkit/tools/test_shell/mock_spellcheck.h b/webkit/tools/test_shell/mock_spellcheck.h
index 0f40675..41b180d 100644
--- a/webkit/tools/test_shell/mock_spellcheck.h
+++ b/webkit/tools/test_shell/mock_spellcheck.h
@@ -6,6 +6,7 @@
#define WEBKIT_TOOLS_TEST_SHELL_MOCK_SPELLCHECK_H_
#include <map>
+#include <vector>
#include "base/string16.h"
@@ -32,6 +33,10 @@ class MockSpellCheck {
int* misspelledOffset,
int* misspelledLength);
+ // Emulates suggestions for misspelled words.
+ // The suggestions are pushed to |suggestions| parameters.
+ void FillSuggestions(const string16& word,
+ std::vector<string16>* suggestions);
private:
// Initialize the internal resources if we need to initialize it.
// Initializing this object may take long time. To prevent from hurting
diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc
index c623afe..4ad7349 100644
--- a/webkit/tools/test_shell/test_webview_delegate.cc
+++ b/webkit/tools/test_shell/test_webview_delegate.cc
@@ -578,8 +578,15 @@ void TestWebViewDelegate::showContextMenu(
data.mousePosition.x,
data.mousePosition.y);
captured_context_menu_events_.push_back(context);
+ last_context_menu_data_.reset(new WebContextMenuData(data));
}
+void TestWebViewDelegate::ClearContextMenuData() {
+ last_context_menu_data_.reset();
+}
+
+
+
void TestWebViewDelegate::setStatusText(const WebString& text) {
if (WebKit::layoutTestMode() &&
diff --git a/webkit/tools/test_shell/test_webview_delegate.h b/webkit/tools/test_shell/test_webview_delegate.h
index c63cb9f..3c7f38d 100644
--- a/webkit/tools/test_shell/test_webview_delegate.h
+++ b/webkit/tools/test_shell/test_webview_delegate.h
@@ -325,6 +325,16 @@ class TestWebViewDelegate : public WebKit::WebViewClient,
void SetGeolocationPermission(bool allowed);
+ void ClearContextMenuData();
+
+ const WebKit::WebContextMenuData* last_context_menu_data() const {
+ return last_context_menu_data_.get();
+ }
+
+ MockSpellCheck* mock_spellcheck() {
+ return &mock_spellcheck_;
+ }
+
private:
// Called the title of the page changes.
@@ -402,6 +412,7 @@ class TestWebViewDelegate : public WebKit::WebViewClient,
std::string GetResourceDescription(uint32 identifier);
CapturedContextMenuEvents captured_context_menu_events_;
+ scoped_ptr<WebKit::WebContextMenuData> last_context_menu_data_;
WebCursor current_cursor_;