OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/strings/string16.h" | 5 #include "base/strings/string16.h" |
6 #include "base/strings/string_util.h" | 6 #include "base/strings/string_util.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "content/public/browser/native_web_keyboard_event.h" | 8 #include "content/public/browser/native_web_keyboard_event.h" |
9 #include "content/public/test/render_view_test.h" | 9 #include "content/public/test/render_view_test.h" |
10 #include "content/renderer/render_view_impl.h" | 10 #include "content/renderer/render_view_impl.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 const char* kArrowUpNoScroll = "38,false,false,true,false\n100\np1"; | 133 const char* kArrowUpNoScroll = "38,false,false,true,false\n100\np1"; |
134 view->OnSetEditCommandsForNextKeyEvent( | 134 view->OnSetEditCommandsForNextKeyEvent( |
135 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); | 135 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); |
136 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); | 136 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); |
137 ProcessPendingMessages(); | 137 ProcessPendingMessages(); |
138 ExecuteJavaScript("scroll.textContent = window.pageYOffset"); | 138 ExecuteJavaScript("scroll.textContent = window.pageYOffset"); |
139 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); | 139 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); |
140 EXPECT_EQ(kArrowUpNoScroll, base::UTF16ToASCII(output)); | 140 EXPECT_EQ(kArrowUpNoScroll, base::UTF16ToASCII(output)); |
141 } | 141 } |
142 | 142 |
143 TEST_F(RenderViewTest, OnTtsForEmptySelection) { | |
144 #define HTML(s) #s | |
145 const char* kRawHtml = HTML( | |
146 <!DOCTYPE html> | |
147 <style> | |
148 /* Add a vertical scrollbar */ | |
149 body { height: 10128px; } | |
150 </style> | |
151 <div id='text'> | |
152 <p> A "Hello World" program has become the traditional first program that | |
153 many people learn. In general it is simple enough so that people who | |
154 experience with computer programming can easily understand it especially | |
155 the guidance of a teacher a written guide. Using this simple program | |
156 basis computer science principles elements of a specific programming | |
157 language can be explained to novice programmers. Experienced programmers | |
158 learning languages can also gain a lot of information about a given | |
159 languages syntax structure from a hello world program. </p> | |
160 </div> | |
161 ); | |
162 #undef HTML | |
163 | |
164 RenderViewImpl* view = static_cast<RenderViewImpl*>(view_); | |
165 view->set_send_content_state_immediately(true); | |
166 LoadHTML(kRawHtml); | |
167 render_thread_->sink().ClearMessages(); | |
168 // contentAsText doesn't depend on scroll position or focussed frame location | |
169 // hence the returned value would be same throughout. | |
170 // Scroll down further. | |
171 ExecuteJavaScript("window.scrollTo(0, 9030)"); | |
jamesr
2014/07/18 06:05:04
hmm, why do we need to scroll? i don't think that
sarka
2014/07/19 06:28:36
Done.
| |
172 // Execute a command to Select all text in DOM. | |
173 ExecuteJavaScript("document.execCommand('SelectAll', false, null)"); | |
174 | |
175 const int kMaxOutputCharacters = 1024; | |
176 base::string16 output = GetMainFrame()->contentAsText(kMaxOutputCharacters); | |
177 base::string16 select_all_text = GetMainFrame()->selectionAsText(); | |
178 EXPECT_EQ(output, select_all_text); | |
179 } | |
180 | |
143 } // namespace content | 181 } // namespace content |
OLD | NEW |