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