| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // Tests for displaying context menus in corner cases (and swallowing context | 5 // Tests for displaying context menus in corner cases (and swallowing context |
| 6 // menu events when appropriate) | 6 // menu events when appropriate) |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 11 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 12 #include "webkit/glue/webframe.h" | 13 #include "webkit/glue/webframe.h" |
| 13 #include "webkit/glue/webkit_glue.h" | 14 #include "webkit/glue/webkit_glue.h" |
| 14 #include "webkit/glue/webview.h" | 15 #include "webkit/glue/webview.h" |
| 15 #include "webkit/tools/test_shell/test_shell_test.h" | 16 #include "webkit/tools/test_shell/test_shell_test.h" |
| 16 | 17 |
| 17 using WebKit::WebInputEvent; | 18 using WebKit::WebInputEvent; |
| 18 using WebKit::WebMouseEvent; | 19 using WebKit::WebMouseEvent; |
| 19 | 20 |
| 20 // Right clicking inside on an iframe should produce a context menu | 21 // Right clicking inside on an iframe should produce a context menu |
| 21 class ContextMenuCapturing : public TestShellTest { | 22 class ContextMenuCapturing : public TestShellTest { |
| 22 protected: | 23 protected: |
| 23 void SetUp() { | 24 void SetUp() { |
| 24 TestShellTest::SetUp(); | 25 TestShellTest::SetUp(); |
| 25 | 26 |
| 26 iframes_data_dir_ = data_dir_; | 27 iframes_data_dir_ = data_dir_; |
| 27 file_util::AppendToPath(&iframes_data_dir_, L"test_shell"); | 28 iframes_data_dir_ = iframes_data_dir_.AppendASCII("test_shell"); |
| 28 file_util::AppendToPath(&iframes_data_dir_, L"iframes"); | 29 iframes_data_dir_ = iframes_data_dir_.AppendASCII("iframes"); |
| 29 ASSERT_TRUE(file_util::PathExists(iframes_data_dir_)); | 30 ASSERT_TRUE(file_util::PathExists(iframes_data_dir_)); |
| 30 } | 31 } |
| 31 | 32 |
| 32 std::wstring iframes_data_dir_; | 33 FilePath iframes_data_dir_; |
| 33 }; | 34 }; |
| 34 | 35 |
| 35 | 36 |
| 36 TEST_F(ContextMenuCapturing, ContextMenuCapturing) { | 37 TEST_F(ContextMenuCapturing, ContextMenuCapturing) { |
| 37 // Make sure we have no stored mouse event state | 38 // Make sure we have no stored mouse event state |
| 38 WebViewDelegate* raw_delegate = test_shell_->webView()->GetDelegate(); | 39 WebViewDelegate* raw_delegate = test_shell_->webView()->GetDelegate(); |
| 39 TestWebViewDelegate* test_delegate = static_cast<TestWebViewDelegate*>(raw_del
egate); | 40 TestWebViewDelegate* test_delegate = static_cast<TestWebViewDelegate*>(raw_del
egate); |
| 40 test_delegate->clear_captured_context_menu_events(); | 41 test_delegate->clear_captured_context_menu_events(); |
| 41 EXPECT_EQ(0U, test_delegate->captured_context_menu_events().size()); | 42 EXPECT_EQ(0U, test_delegate->captured_context_menu_events().size()); |
| 42 | 43 |
| 43 std::wstring test_url = GetTestURL(iframes_data_dir_, L"testiframe.html"); | 44 std::wstring test_url = GetTestURL(iframes_data_dir_, "testiframe.html"); |
| 44 test_shell_->LoadURL(test_url.c_str()); | 45 test_shell_->LoadURL(test_url.c_str()); |
| 45 test_shell_->WaitTestFinished(); | 46 test_shell_->WaitTestFinished(); |
| 46 | 47 |
| 47 // Create a right click in the center of the iframe. (I'm hoping this will | 48 // Create a right click in the center of the iframe. (I'm hoping this will |
| 48 // make this a bit more robust in case of some other formatting or other bug.) | 49 // make this a bit more robust in case of some other formatting or other bug.) |
| 49 WebMouseEvent mouse_event; | 50 WebMouseEvent mouse_event; |
| 50 mouse_event.type = WebInputEvent::MouseDown; | 51 mouse_event.type = WebInputEvent::MouseDown; |
| 51 mouse_event.button = WebMouseEvent::ButtonRight; | 52 mouse_event.button = WebMouseEvent::ButtonRight; |
| 52 mouse_event.x = 250; | 53 mouse_event.x = 250; |
| 53 mouse_event.y = 250; | 54 mouse_event.y = 250; |
| 54 mouse_event.globalX = 250; | 55 mouse_event.globalX = 250; |
| 55 mouse_event.globalY = 250; | 56 mouse_event.globalY = 250; |
| 56 | 57 |
| 57 WebView* webview = test_shell_->webView(); | 58 WebView* webview = test_shell_->webView(); |
| 58 webview->HandleInputEvent(&mouse_event); | 59 webview->HandleInputEvent(&mouse_event); |
| 59 | 60 |
| 60 // Now simulate the corresponding up event which should display the menu | 61 // Now simulate the corresponding up event which should display the menu |
| 61 mouse_event.type = WebInputEvent::MouseUp; | 62 mouse_event.type = WebInputEvent::MouseUp; |
| 62 webview->HandleInputEvent(&mouse_event); | 63 webview->HandleInputEvent(&mouse_event); |
| 63 | 64 |
| 64 EXPECT_EQ(1U, test_delegate->captured_context_menu_events().size()); | 65 EXPECT_EQ(1U, test_delegate->captured_context_menu_events().size()); |
| 65 } | 66 } |
| OLD | NEW |