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

Side by Side Diff: content/browser/frame_host/interstitial_page_impl_browsertest.cc

Issue 2060713002: Respect the order of input messages from browser to renderer (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@2743
Patch Set: Created 4 years, 6 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
« no previous file with comments | « no previous file | content/browser/renderer_host/ime_adapter_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/browser/frame_host/interstitial_page_impl.h" 5 #include "content/browser/frame_host/interstitial_page_impl.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 " document.getElementById('input').select();" 44 " document.getElementById('input').select();"
45 "}" 45 "}"
46 "function get_input_text() {" 46 "function get_input_text() {"
47 " window.domAutomationController.send(" 47 " window.domAutomationController.send("
48 " document.getElementById('input').value);" 48 " document.getElementById('input').value);"
49 "}" 49 "}"
50 "function get_selection() {" 50 "function get_selection() {"
51 " window.domAutomationController.send(" 51 " window.domAutomationController.send("
52 " window.getSelection().toString());" 52 " window.getSelection().toString());"
53 "}" 53 "}"
54 "function set_selection_change_listener() {"
55 " document.addEventListener('selectionchange',"
56 " function() { document.title='SELECTION_CHANGED'; })"
57 "}"
54 "</script>" 58 "</script>"
55 "</head>" 59 "</head>"
56 "<body>original body text</body>" 60 "<body>original body text</body>"
57 "</html>"; 61 "</html>";
58 } 62 }
59 }; 63 };
60 64
61 // A title watcher for interstitial pages. The existing TitleWatcher does not 65 // A title watcher for interstitial pages. The existing TitleWatcher does not
62 // work for interstitial pages. Note that this title watcher waits for the 66 // work for interstitial pages. Note that this title watcher waits for the
63 // title update IPC message not the actual title update. So, the new title is 67 // title update IPC message not the actual title update. So, the new title is
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 bool GetSelection(std::string* input_text) { 276 bool GetSelection(std::string* input_text) {
273 return ExecuteScriptAndExtractString(interstitial_->GetMainFrame(), 277 return ExecuteScriptAndExtractString(interstitial_->GetMainFrame(),
274 "get_selection()", input_text); 278 "get_selection()", input_text);
275 } 279 }
276 280
277 bool CreateInputAndSetText(const std::string& text) { 281 bool CreateInputAndSetText(const std::string& text) {
278 return ExecuteScript(interstitial_->GetMainFrame(), 282 return ExecuteScript(interstitial_->GetMainFrame(),
279 "create_input_and_set_text('" + text + "')"); 283 "create_input_and_set_text('" + text + "')");
280 } 284 }
281 285
286 bool SetSelectionChangeListener() {
287 return ExecuteScript(interstitial_->GetMainFrame(),
288 "set_selection_change_listener()");
289 }
290
282 std::string PerformCut() { 291 std::string PerformCut() {
283 clipboard_message_watcher_->InitWait(); 292 clipboard_message_watcher_->InitWait();
284 title_update_watcher_->InitWait("TEXT_CHANGED"); 293 title_update_watcher_->InitWait("TEXT_CHANGED");
285 RenderFrameHostImpl* rfh = 294 RenderFrameHostImpl* rfh =
286 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame()); 295 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame());
287 rfh->GetRenderWidgetHost()->delegate()->Cut(); 296 rfh->GetRenderWidgetHost()->delegate()->Cut();
288 clipboard_message_watcher_->WaitForWriteCommit(); 297 clipboard_message_watcher_->WaitForWriteCommit();
289 title_update_watcher_->Wait(); 298 title_update_watcher_->Wait();
290 return clipboard_message_watcher_->last_text(); 299 return clipboard_message_watcher_->last_text();
291 } 300 }
292 301
293 std::string PerformCopy() { 302 std::string PerformCopy() {
294 clipboard_message_watcher_->InitWait(); 303 clipboard_message_watcher_->InitWait();
295 RenderFrameHostImpl* rfh = 304 RenderFrameHostImpl* rfh =
296 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame()); 305 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame());
297 rfh->GetRenderWidgetHost()->delegate()->Copy(); 306 rfh->GetRenderWidgetHost()->delegate()->Copy();
298 clipboard_message_watcher_->WaitForWriteCommit(); 307 clipboard_message_watcher_->WaitForWriteCommit();
299 return clipboard_message_watcher_->last_text(); 308 return clipboard_message_watcher_->last_text();
300 } 309 }
301 310
302 void PerformPaste() { 311 void PerformPaste() {
303 title_update_watcher_->InitWait("TEXT_CHANGED"); 312 title_update_watcher_->InitWait("TEXT_CHANGED");
304 RenderFrameHostImpl* rfh = 313 RenderFrameHostImpl* rfh =
305 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame()); 314 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame());
306 rfh->GetRenderWidgetHost()->delegate()->Paste(); 315 rfh->GetRenderWidgetHost()->delegate()->Paste();
307 title_update_watcher_->Wait(); 316 title_update_watcher_->Wait();
308 } 317 }
309 318
310 void PerformSelectAll() { 319 void PerformSelectAll() {
320 title_update_watcher_->InitWait("SELECTION_CHANGED");
311 RenderFrameHostImpl* rfh = 321 RenderFrameHostImpl* rfh =
312 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame()); 322 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame());
313 rfh->GetRenderWidgetHost()->delegate()->SelectAll(); 323 rfh->GetRenderWidgetHost()->delegate()->SelectAll();
324 title_update_watcher_->Wait();
314 } 325 }
315 326
316 private: 327 private:
317 void RunTaskOnIOThreadAndWait(const base::Closure& task) { 328 void RunTaskOnIOThreadAndWait(const base::Closure& task) {
318 base::WaitableEvent completion(false, false); 329 base::WaitableEvent completion(false, false);
319 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 330 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
320 base::Bind(&InterstitialPageImplTest::RunTask, this, 331 base::Bind(&InterstitialPageImplTest::RunTask, this,
321 task, &completion)); 332 task, &completion));
322 completion.Wait(); 333 completion.Wait();
323 } 334 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 std::string input_text; 391 std::string input_text;
381 ASSERT_TRUE(GetInputText(&input_text)); 392 ASSERT_TRUE(GetInputText(&input_text));
382 EXPECT_EQ("text-to-paste", input_text); 393 EXPECT_EQ("text-to-paste", input_text);
383 394
384 TearDownInterstitialPage(); 395 TearDownInterstitialPage();
385 TearDownTestClipboard(); 396 TearDownTestClipboard();
386 } 397 }
387 398
388 IN_PROC_BROWSER_TEST_F(InterstitialPageImplTest, SelectAll) { 399 IN_PROC_BROWSER_TEST_F(InterstitialPageImplTest, SelectAll) {
389 SetUpInterstitialPage(); 400 SetUpInterstitialPage();
401 ASSERT_TRUE(SetSelectionChangeListener());
390 402
391 std::string input_text; 403 std::string input_text;
392 ASSERT_TRUE(GetSelection(&input_text)); 404 ASSERT_TRUE(GetSelection(&input_text));
393 EXPECT_EQ(std::string(), input_text); 405 EXPECT_EQ(std::string(), input_text);
394 406
395 PerformSelectAll(); 407 PerformSelectAll();
408
396 ASSERT_TRUE(GetSelection(&input_text)); 409 ASSERT_TRUE(GetSelection(&input_text));
397 EXPECT_EQ("original body text", input_text); 410 EXPECT_EQ("original body text", input_text);
398 411
399 TearDownInterstitialPage(); 412 TearDownInterstitialPage();
400 } 413 }
401 414
402 } // namespace content 415 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/ime_adapter_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698