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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/external_popup_menu.cc ('k') | chrome/renderer/render_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 #include "base/utf_string_conversions.h"
6 #include "chrome/common/render_messages.h"
7 #include "chrome/common/render_messages_params.h"
8 #include "chrome/test/render_view_test.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
11 #include "third_party/WebKit/WebKit/chromium/public/WebView.h"
12
13 // Tests for the external select popup menu (Mac specific).
14
15 namespace {
16
17 const char* const kSelectID = "mySelect";
18
19 } // namespace
20
21 class ExternalPopupMenuTest : public RenderViewTest {
22 public:
23 ExternalPopupMenuTest() {}
24
25 virtual void SetUp() {
26 RenderViewTest::SetUp();
27 // We need to set this explictly as RenderMain is not run.
28 WebKit::WebView::setUseExternalPopupMenus(true);
29
30 // Load the test page.
31 LoadHTML("<select id='mySelect'>"
32 " <option>zero</option>"
33 " <option selected='1'>one</option>"
34 " <option>two</option>"
35 "</select>");
36
37 // Set a minimum size and give focus so simulated events work.
38 view_->webwidget()->resize(WebKit::WebSize(500, 500));
39 view_->webwidget()->setFocus(true);
40 }
41
42 int GetSelectedIndex() {
43 string16 script(ASCIIToUTF16(kSelectID));
44 script.append(ASCIIToUTF16(".selectedIndex"));
45 int selected_index = -1;
46 ExecuteJavaScriptAndReturnIntValue(script, &selected_index);
47 return selected_index;
48 }
49
50 DISALLOW_COPY_AND_ASSIGN(ExternalPopupMenuTest);
51 };
52
53 // Normal case: test showing a select popup, canceling/selecting an item.
54 TEST_F(ExternalPopupMenuTest, NormalCase) {
55 IPC::TestSink& sink = render_thread_.sink();
56
57 // Click the text field once.
58 EXPECT_TRUE(SimulateElementClick(kSelectID));
59
60 // We should have sent a message to the browser to show the popup menu.
61 const IPC::Message* message =
62 sink.GetUniqueMessageMatching(ViewHostMsg_ShowPopup::ID);
63 ASSERT_TRUE(message != NULL);
64 Tuple1<ViewHostMsg_ShowPopup_Params> param;
65 ViewHostMsg_ShowPopup::Read(message, &param);
66 ASSERT_EQ(3U, param.a.popup_items.size());
67 EXPECT_EQ(1, param.a.selected_item);
68
69 // Simulate the user canceling the popup, the index should not have changed.
70 view_->OnSelectPopupMenuItem(-1);
71 EXPECT_EQ(1, GetSelectedIndex());
72
73 // Show the pop-up again and this time make a selection.
74 EXPECT_TRUE(SimulateElementClick(kSelectID));
75 view_->OnSelectPopupMenuItem(0);
76 EXPECT_EQ(0, GetSelectedIndex());
77
78 // Show the pop-up again and make another selection.
79 sink.ClearMessages();
80 EXPECT_TRUE(SimulateElementClick(kSelectID));
81 message = sink.GetUniqueMessageMatching(ViewHostMsg_ShowPopup::ID);
82 ASSERT_TRUE(message != NULL);
83 ViewHostMsg_ShowPopup::Read(message, &param);
84 ASSERT_EQ(3U, param.a.popup_items.size());
85 EXPECT_EQ(0, param.a.selected_item);
86 }
87
88 // Page shows popup, then navigates away while popup showing, then select.
89 TEST_F(ExternalPopupMenuTest, ShowPopupThenNavigate) {
90 // Click the text field once.
91 EXPECT_TRUE(SimulateElementClick(kSelectID));
92
93 // Now we navigate to another pager.
94 LoadHTML("<blink>Awesome page!</blink>");
95
96 // Now the user selects something, we should not crash.
97 view_->OnSelectPopupMenuItem(-1);
98 }
OLDNEW
« 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