// 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"
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.
// 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, ¶m);
+ Tuple1<FrameHostMsg_ShowPopup_Params> param;
+ FrameHostMsg_ShowPopup::Read(message, ¶m);
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, ¶m);
+ FrameHostMsg_ShowPopup::Read(message, ¶m);
ASSERT_EQ(3U, param.a.popup_items.size());
EXPECT_EQ(0, param.a.selected_item);
}
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.
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
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.
};
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, ¶m);
+ // 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