Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(642)

Unified Diff: chrome/renderer/external_popup_menu_unittest.cc

Issue 4078003: Refactoring select popup on Mac.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/external_popup_menu.cc ('k') | chrome/renderer/render_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/external_popup_menu_unittest.cc
===================================================================
--- chrome/renderer/external_popup_menu_unittest.cc (revision 0)
+++ chrome/renderer/external_popup_menu_unittest.cc (revision 0)
@@ -0,0 +1,98 @@
+// Copyright (c) 2010 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 "chrome/common/render_messages.h"
+#include "chrome/common/render_messages_params.h"
+#include "chrome/test/render_view_test.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
+
+// Tests for the external select popup menu (Mac specific).
+
+namespace {
+
+const char* const kSelectID = "mySelect";
+
+} // namespace
+
+class ExternalPopupMenuTest : public RenderViewTest {
+ public:
+ ExternalPopupMenuTest() {}
+
+ virtual void SetUp() {
+ RenderViewTest::SetUp();
+ // We need to set this explictly as RenderMain is not run.
+ WebKit::WebView::setUseExternalPopupMenus(true);
+
+ // Load the test page.
+ LoadHTML("<select id='mySelect'>"
+ " <option>zero</option>"
+ " <option selected='1'>one</option>"
+ " <option>two</option>"
+ "</select>");
+
+ // 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;
+ }
+
+ 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);
+}
« no previous file with comments | « chrome/renderer/external_popup_menu.cc ('k') | chrome/renderer/render_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698