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

Unified Diff: content/browser/renderer_host/render_widget_host_view_mac_unittest.mm

Issue 2596303002: Fix an issue with not clearing |selected_text_| when text selection range is empty (Mac) (Closed)
Patch Set: Added a unit test Created 4 years 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
Index: content/browser/renderer_host/render_widget_host_view_mac_unittest.mm
diff --git a/content/browser/renderer_host/render_widget_host_view_mac_unittest.mm b/content/browser/renderer_host/render_widget_host_view_mac_unittest.mm
index 5f533eafb1b70d2ac8ba91be30b366938fcbafae..a5838a4d1f479dc8d71aaa57b50289dba257d981 100644
--- a/content/browser/renderer_host/render_widget_host_view_mac_unittest.mm
+++ b/content/browser/renderer_host/render_widget_host_view_mac_unittest.mm
@@ -305,6 +305,8 @@ class RenderWidgetHostViewMacTest : public RenderViewHostImplTestHarness {
RenderWidgetHostView* old_rwhv_;
protected:
+ std::string selected_text() const { return rwhv_mac_->selected_text_; }
+
RenderWidgetHostViewMac* rwhv_mac_;
base::scoped_nsobject<RenderWidgetHostViewCocoa> rwhv_cocoa_;
@@ -1328,6 +1330,28 @@ TEST_F(RenderWidgetHostViewMacTest, EventLatencyOSMouseWheelHistogram) {
host->ShutdownAndDestroyWidget(true);
}
+// This test verifies that |selected_text_| is updated accordingly with
+// different variations of RWHVMac::SelectChanged updates.
+TEST_F(RenderWidgetHostViewMacTest, SelectedText) {
+ base::string16 sample_text;
+ base::UTF8ToUTF16("hello world!", 12, &sample_text);
+ gfx::Range range(6, 11);
+
+ // Send a valid selection for the word 'World'.
+ rwhv_mac_->SelectionChanged(sample_text, 0U, range);
+ EXPECT_EQ("world", selected_text());
+
+ // Make the range cover some of the text and extend more.
+ range.set_end(100);
+ rwhv_mac_->SelectionChanged(sample_text, 0U, range);
+ EXPECT_EQ("world!", selected_text());
+
+ // Finally, send an empty range. This should clear the selected text.
+ range.set_start(100);
+ rwhv_mac_->SelectionChanged(sample_text, 0U, range);
+ EXPECT_EQ("", selected_text());
+}
+
// This class is used for IME-related unit tests which verify correctness of IME
// for pages with multiple RWHVs.
class InputMethodMacTest : public RenderWidgetHostViewMacTest {
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.mm ('k') | content/browser/renderer_host/text_input_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698