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

Side by Side Diff: chrome/renderer/external_popup_menu_unittest.cc

Issue 5275001: Adding a test to validate that we don't crash on empty selects. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 10 years, 1 month 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "chrome/common/render_messages.h" 6 #include "chrome/common/render_messages.h"
7 #include "chrome/common/render_messages_params.h" 7 #include "chrome/common/render_messages_params.h"
8 #include "chrome/test/render_view_test.h" 8 #include "chrome/test/render_view_test.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/WebKit/WebKit/chromium/public/WebSize.h" 10 #include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
11 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" 11 #include "third_party/WebKit/WebKit/chromium/public/WebView.h"
12 12
13 // Tests for the external select popup menu (Mac specific). 13 // Tests for the external select popup menu (Mac specific).
14 14
15 namespace { 15 namespace {
16 16
17 const char* const kSelectID = "mySelect"; 17 const char* const kSelectID = "mySelect";
18 const char* const kEmptySelectID = "myEmptySelect";
18 19
19 } // namespace 20 } // namespace
20 21
21 class ExternalPopupMenuTest : public RenderViewTest { 22 class ExternalPopupMenuTest : public RenderViewTest {
22 public: 23 public:
23 ExternalPopupMenuTest() {} 24 ExternalPopupMenuTest() {}
24 25
25 virtual void SetUp() { 26 virtual void SetUp() {
26 RenderViewTest::SetUp(); 27 RenderViewTest::SetUp();
27 // We need to set this explictly as RenderMain is not run. 28 // We need to set this explictly as RenderMain is not run.
28 WebKit::WebView::setUseExternalPopupMenus(true); 29 WebKit::WebView::setUseExternalPopupMenus(true);
29 30
30 std::string html = "<select id='mySelect' onchange='selectChanged(this)'>" 31 std::string html = "<select id='mySelect' onchange='selectChanged(this)'>"
31 " <option>zero</option>" 32 " <option>zero</option>"
32 " <option selected='1'>one</option>" 33 " <option selected='1'>one</option>"
33 " <option>two</option>" 34 " <option>two</option>"
35 "</select>"
36 "<select id='myEmptySelect'>"
34 "</select>"; 37 "</select>";
35 if (ShouldRemoveSelectOnChange()) { 38 if (ShouldRemoveSelectOnChange()) {
36 html += "<script>" 39 html += "<script>"
37 " function selectChanged(select) {" 40 " function selectChanged(select) {"
38 " select.parentNode.removeChild(select);" 41 " select.parentNode.removeChild(select);"
39 " }" 42 " }"
40 "</script>"; 43 "</script>";
41 } 44 }
42 45
43 // Load the test page. 46 // Load the test page.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // Click the text field once. 105 // Click the text field once.
103 EXPECT_TRUE(SimulateElementClick(kSelectID)); 106 EXPECT_TRUE(SimulateElementClick(kSelectID));
104 107
105 // Now we navigate to another pager. 108 // Now we navigate to another pager.
106 LoadHTML("<blink>Awesome page!</blink>"); 109 LoadHTML("<blink>Awesome page!</blink>");
107 110
108 // Now the user selects something, we should not crash. 111 // Now the user selects something, we should not crash.
109 view_->OnSelectPopupMenuItem(-1); 112 view_->OnSelectPopupMenuItem(-1);
110 } 113 }
111 114
115 // An empty select should not cause a crash when clicked.
116 // http://crbug.com/63774
117 TEST_F(ExternalPopupMenuTest, EmptySelect) {
118 EXPECT_TRUE(SimulateElementClick(kEmptySelectID));
119 }
120
112 class ExternalPopupMenuRemoveTest : public ExternalPopupMenuTest { 121 class ExternalPopupMenuRemoveTest : public ExternalPopupMenuTest {
113 public: 122 public:
114 ExternalPopupMenuRemoveTest() {} 123 ExternalPopupMenuRemoveTest() {}
115 124
116 protected: 125 protected:
117 virtual bool ShouldRemoveSelectOnChange() const { return true; } 126 virtual bool ShouldRemoveSelectOnChange() const { return true; }
118 }; 127 };
119 128
120 // Tests that nothing bad happen when the page removes the select when it 129 // Tests that nothing bad happen when the page removes the select when it
121 // changes. (http://crbug.com/61997) 130 // changes. (http://crbug.com/61997)
122 TEST_F(ExternalPopupMenuRemoveTest, RemoveOnChange) { 131 TEST_F(ExternalPopupMenuRemoveTest, RemoveOnChange) {
123 // Click the text field once to show the popup. 132 // Click the text field once to show the popup.
124 EXPECT_TRUE(SimulateElementClick(kSelectID)); 133 EXPECT_TRUE(SimulateElementClick(kSelectID));
125 134
126 // Select something, it causes the select to be removed from the page. 135 // Select something, it causes the select to be removed from the page.
127 view_->OnSelectPopupMenuItem(0); 136 view_->OnSelectPopupMenuItem(0);
128 137
129 // Just to check the soundness of the test, call SimulateElementClick again. 138 // Just to check the soundness of the test, call SimulateElementClick again.
130 // It should return false as the select has been removed. 139 // It should return false as the select has been removed.
131 EXPECT_FALSE(SimulateElementClick(kSelectID)); 140 EXPECT_FALSE(SimulateElementClick(kSelectID));
132 } 141 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698