summaryrefslogtreecommitdiffstats
path: root/content/renderer/external_popup_menu_browsertest.cc
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-28 22:00:14 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-28 22:00:14 +0000
commit3e751c042ee3718c7b43cf8d642d7f6623b25b5b (patch)
tree736e5afb7b0ee0a8c1a7f0ca7899a307de2d91f9 /content/renderer/external_popup_menu_browsertest.cc
parentd705f79135a19909773c6c080001639ba5d833c9 (diff)
downloadchromium_src-3e751c042ee3718c7b43cf8d642d7f6623b25b5b.zip
chromium_src-3e751c042ee3718c7b43cf8d642d7f6623b25b5b.tar.gz
chromium_src-3e751c042ee3718c7b43cf8d642d7f6623b25b5b.tar.bz2
Rename the external popup menu test from unittest to browsertest, as it is a browsertest
BUG=90443 TEST=none Review URL: http://codereview.chromium.org/8659013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111781 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer/external_popup_menu_browsertest.cc')
-rw-r--r--content/renderer/external_popup_menu_browsertest.cc145
1 files changed, 145 insertions, 0 deletions
diff --git a/content/renderer/external_popup_menu_browsertest.cc b/content/renderer/external_popup_menu_browsertest.cc
new file mode 100644
index 0000000..a1eeed0
--- /dev/null
+++ b/content/renderer/external_popup_menu_browsertest.cc
@@ -0,0 +1,145 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/utf_string_conversions.h"
+#include "content/common/view_messages.h"
+#include "content/renderer/render_view_impl.h"
+#include "content/test/render_view_test.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
+
+// Tests for the external select popup menu (Mac specific).
+
+namespace {
+
+const char* const kSelectID = "mySelect";
+const char* const kEmptySelectID = "myEmptySelect";
+
+} // namespace
+
+class ExternalPopupMenuTest : public content::RenderViewTest {
+ public:
+ ExternalPopupMenuTest() {}
+
+ RenderViewImpl* view() {
+ return static_cast<RenderViewImpl*>(view_);
+ }
+
+ virtual void SetUp() {
+ content::RenderViewTest::SetUp();
+ // We need to set this explictly as RenderMain is not run.
+ WebKit::WebView::setUseExternalPopupMenus(true);
+
+ std::string html = "<select id='mySelect' onchange='selectChanged(this)'>"
+ " <option>zero</option>"
+ " <option selected='1'>one</option>"
+ " <option>two</option>"
+ "</select>"
+ "<select id='myEmptySelect'>"
+ "</select>";
+ if (ShouldRemoveSelectOnChange()) {
+ html += "<script>"
+ " function selectChanged(select) {"
+ " select.parentNode.removeChild(select);"
+ " }"
+ "</script>";
+ }
+
+ // Load the test page.
+ LoadHTML(html.c_str());
+
+ // Set a minimum size and give focus so simulated events work.
+ view()->webwidget()->resize(WebKit::WebSize(500, 500));
+ view()->webwidget()->setFocus(true);
+ }
+
+ int GetSelectedIndex() {
+ string16 script(ASCIIToUTF16(kSelectID));
+ script.append(ASCIIToUTF16(".selectedIndex"));
+ int selected_index = -1;
+ ExecuteJavaScriptAndReturnIntValue(script, &selected_index);
+ return selected_index;
+ }
+
+ protected:
+ virtual bool ShouldRemoveSelectOnChange() const { return false; }
+
+ DISALLOW_COPY_AND_ASSIGN(ExternalPopupMenuTest);
+};
+
+// Normal case: test showing a select popup, canceling/selecting an item.
+TEST_F(ExternalPopupMenuTest, NormalCase) {
+ IPC::TestSink& sink = render_thread_->sink();
+
+ // Click the text field once.
+ EXPECT_TRUE(SimulateElementClick(kSelectID));
+
+ // We should have sent a message to the browser to show the popup menu.
+ const IPC::Message* message =
+ sink.GetUniqueMessageMatching(ViewHostMsg_ShowPopup::ID);
+ ASSERT_TRUE(message != NULL);
+ Tuple1<ViewHostMsg_ShowPopup_Params> param;
+ ViewHostMsg_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);
+ EXPECT_EQ(1, GetSelectedIndex());
+
+ // Show the pop-up again and this time make a selection.
+ EXPECT_TRUE(SimulateElementClick(kSelectID));
+ view()->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);
+ ASSERT_TRUE(message != NULL);
+ ViewHostMsg_ShowPopup::Read(message, &param);
+ ASSERT_EQ(3U, param.a.popup_items.size());
+ EXPECT_EQ(0, param.a.selected_item);
+}
+
+// Page shows popup, then navigates away while popup showing, then select.
+TEST_F(ExternalPopupMenuTest, ShowPopupThenNavigate) {
+ // Click the text field once.
+ EXPECT_TRUE(SimulateElementClick(kSelectID));
+
+ // Now we navigate to another pager.
+ LoadHTML("<blink>Awesome page!</blink>");
+
+ // Now the user selects something, we should not crash.
+ view()->OnSelectPopupMenuItem(-1);
+}
+
+// An empty select should not cause a crash when clicked.
+// http://crbug.com/63774
+TEST_F(ExternalPopupMenuTest, EmptySelect) {
+ EXPECT_TRUE(SimulateElementClick(kEmptySelectID));
+}
+
+class ExternalPopupMenuRemoveTest : public ExternalPopupMenuTest {
+ public:
+ ExternalPopupMenuRemoveTest() {}
+
+ protected:
+ virtual bool ShouldRemoveSelectOnChange() const { return true; }
+};
+
+// Tests that nothing bad happen when the page removes the select when it
+// changes. (http://crbug.com/61997)
+TEST_F(ExternalPopupMenuRemoveTest, RemoveOnChange) {
+ // Click the text field once to show the popup.
+ EXPECT_TRUE(SimulateElementClick(kSelectID));
+
+ // Select something, it causes the select to be removed from the page.
+ view()->OnSelectPopupMenuItem(0);
+
+ // Just to check the soundness of the test, call SimulateElementClick again.
+ // It should return false as the select has been removed.
+ EXPECT_FALSE(SimulateElementClick(kSelectID));
+}