Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / renderer / external_popup_menu_browsertest.cc
index c29306c..cadb51f 100644 (file)
@@ -3,8 +3,9 @@
 // found in the LICENSE file.
 
 #include "base/strings/utf_string_conversions.h"
-#include "content/common/view_messages.h"
+#include "content/common/frame_messages.h"
 #include "content/public/test/render_view_test.h"
+#include "content/renderer/render_frame_impl.h"
 #include "content/renderer/render_view_impl.h"
 #include "testing/gtest/include/gtest/gtest.h"
 #include "third_party/WebKit/public/web/WebView.h"
@@ -28,6 +29,10 @@ class ExternalPopupMenuTest : public RenderViewTest {
     return static_cast<RenderViewImpl*>(view_);
   }
 
+  RenderFrameImpl* frame() {
+    return view()->GetMainRenderFrame();
+  }
+
   virtual void SetUp() {
     RenderViewTest::SetUp();
     // We need to set this explictly as RenderMain is not run.
@@ -79,28 +84,28 @@ TEST_F(ExternalPopupMenuTest, NormalCase) {
 
   // We should have sent a message to the browser to show the popup menu.
   const IPC::Message* message =
-      sink.GetUniqueMessageMatching(ViewHostMsg_ShowPopup::ID);
+      sink.GetUniqueMessageMatching(FrameHostMsg_ShowPopup::ID);
   ASSERT_TRUE(message != NULL);
-  Tuple1<ViewHostMsg_ShowPopup_Params> param;
-  ViewHostMsg_ShowPopup::Read(message, &param);
+  Tuple1<FrameHostMsg_ShowPopup_Params> param;
+  FrameHostMsg_ShowPopup::Read(message, &param);
   ASSERT_EQ(3U, param.a.popup_items.size());
   EXPECT_EQ(1, param.a.selected_item);
 
-  // Simulate the user canceling the popup, the index should not have changed.
-  view()->OnSelectPopupMenuItem(-1);
+  // Simulate the user canceling the popup; the index should not have changed.
+  frame()->OnSelectPopupMenuItem(-1);
   EXPECT_EQ(1, GetSelectedIndex());
 
   // Show the pop-up again and this time make a selection.
   EXPECT_TRUE(SimulateElementClick(kSelectID));
-  view()->OnSelectPopupMenuItem(0);
+  frame()->OnSelectPopupMenuItem(0);
   EXPECT_EQ(0, GetSelectedIndex());
 
   // Show the pop-up again and make another selection.
   sink.ClearMessages();
   EXPECT_TRUE(SimulateElementClick(kSelectID));
-  message = sink.GetUniqueMessageMatching(ViewHostMsg_ShowPopup::ID);
+  message = sink.GetUniqueMessageMatching(FrameHostMsg_ShowPopup::ID);
   ASSERT_TRUE(message != NULL);
-  ViewHostMsg_ShowPopup::Read(message, &param);
+  FrameHostMsg_ShowPopup::Read(message, &param);
   ASSERT_EQ(3U, param.a.popup_items.size());
   EXPECT_EQ(0, param.a.selected_item);
 }
@@ -114,7 +119,7 @@ TEST_F(ExternalPopupMenuTest, ShowPopupThenNavigate) {
   LoadHTML("<blink>Awesome page!</blink>");
 
   // Now the user selects something, we should not crash.
-  view()->OnSelectPopupMenuItem(-1);
+  frame()->OnSelectPopupMenuItem(-1);
 }
 
 // An empty select should not cause a crash when clicked.
@@ -128,7 +133,7 @@ class ExternalPopupMenuRemoveTest : public ExternalPopupMenuTest {
   ExternalPopupMenuRemoveTest() {}
 
  protected:
-  virtual bool ShouldRemoveSelectOnChange() const OVERRIDE { return true; }
+  bool ShouldRemoveSelectOnChange() const override { return true; }
 };
 
 // Tests that nothing bad happen when the page removes the select when it
@@ -138,7 +143,7 @@ TEST_F(ExternalPopupMenuRemoveTest, RemoveOnChange) {
   EXPECT_TRUE(SimulateElementClick(kSelectID));
 
   // Select something, it causes the select to be removed from the page.
-  view()->OnSelectPopupMenuItem(0);
+  frame()->OnSelectPopupMenuItem(0);
 
   // Just to check the soundness of the test, call SimulateElementClick again.
   // It should return false as the select has been removed.
@@ -175,14 +180,26 @@ class ExternalPopupMenuDisplayNoneTest : public ExternalPopupMenuTest {
 };
 
 TEST_F(ExternalPopupMenuDisplayNoneTest, SelectItem) {
+  IPC::TestSink& sink = render_thread_->sink();
+
   // Click the text field once to show the popup.
   EXPECT_TRUE(SimulateElementClick(kSelectID));
 
+  // Read the message sent to browser to show the popup menu.
+  const IPC::Message* message =
+      sink.GetUniqueMessageMatching(FrameHostMsg_ShowPopup::ID);
+  ASSERT_TRUE(message != NULL);
+  Tuple1<FrameHostMsg_ShowPopup_Params> param;
+  FrameHostMsg_ShowPopup::Read(message, &param);
+  // Number of items should match item count minus the number
+  // of "display: none" items.
+  ASSERT_EQ(5U, param.a.popup_items.size());
+
   // Select index 1 item. This should select item with index 2,
   // skipping the item with 'display: none'
-  view()->OnSelectPopupMenuItem(1);
+  frame()->OnSelectPopupMenuItem(1);
 
-  EXPECT_EQ(2,GetSelectedIndex());
+  EXPECT_EQ(2, GetSelectedIndex());
 }
 
 }  // namespace content