| OLD | NEW |
| 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 <tuple> | 7 #include <tuple> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 " document.getElementById('input').select();" | 46 " document.getElementById('input').select();" |
| 47 "}" | 47 "}" |
| 48 "function get_input_text() {" | 48 "function get_input_text() {" |
| 49 " window.domAutomationController.send(" | 49 " window.domAutomationController.send(" |
| 50 " document.getElementById('input').value);" | 50 " document.getElementById('input').value);" |
| 51 "}" | 51 "}" |
| 52 "function get_selection() {" | 52 "function get_selection() {" |
| 53 " window.domAutomationController.send(" | 53 " window.domAutomationController.send(" |
| 54 " window.getSelection().toString());" | 54 " window.getSelection().toString());" |
| 55 "}" | 55 "}" |
| 56 "function set_selection_change_listener() {" |
| 57 " document.addEventListener('selectionchange'," |
| 58 " function() { document.title='SELECTION_CHANGED'; })" |
| 59 "}" |
| 56 "</script>" | 60 "</script>" |
| 57 "</head>" | 61 "</head>" |
| 58 "<body>original body text</body>" | 62 "<body>original body text</body>" |
| 59 "</html>"; | 63 "</html>"; |
| 60 } | 64 } |
| 61 }; | 65 }; |
| 62 | 66 |
| 63 // A title watcher for interstitial pages. The existing TitleWatcher does not | 67 // A title watcher for interstitial pages. The existing TitleWatcher does not |
| 64 // work for interstitial pages. Note that this title watcher waits for the | 68 // work for interstitial pages. Note that this title watcher waits for the |
| 65 // title update IPC message not the actual title update. So, the new title is | 69 // 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 Loading... |
| 274 bool GetSelection(std::string* input_text) { | 278 bool GetSelection(std::string* input_text) { |
| 275 return ExecuteScriptAndExtractString(interstitial_->GetMainFrame(), | 279 return ExecuteScriptAndExtractString(interstitial_->GetMainFrame(), |
| 276 "get_selection()", input_text); | 280 "get_selection()", input_text); |
| 277 } | 281 } |
| 278 | 282 |
| 279 bool CreateInputAndSetText(const std::string& text) { | 283 bool CreateInputAndSetText(const std::string& text) { |
| 280 return ExecuteScript(interstitial_->GetMainFrame(), | 284 return ExecuteScript(interstitial_->GetMainFrame(), |
| 281 "create_input_and_set_text('" + text + "')"); | 285 "create_input_and_set_text('" + text + "')"); |
| 282 } | 286 } |
| 283 | 287 |
| 288 bool SetSelectionChangeListener() { |
| 289 return ExecuteScript(interstitial_->GetMainFrame(), |
| 290 "set_selection_change_listener()"); |
| 291 } |
| 292 |
| 284 std::string PerformCut() { | 293 std::string PerformCut() { |
| 285 clipboard_message_watcher_->InitWait(); | 294 clipboard_message_watcher_->InitWait(); |
| 286 title_update_watcher_->InitWait("TEXT_CHANGED"); | 295 title_update_watcher_->InitWait("TEXT_CHANGED"); |
| 287 RenderFrameHostImpl* rfh = | 296 RenderFrameHostImpl* rfh = |
| 288 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame()); | 297 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame()); |
| 289 rfh->GetRenderWidgetHost()->delegate()->Cut(); | 298 rfh->GetRenderWidgetHost()->delegate()->Cut(); |
| 290 clipboard_message_watcher_->WaitForWriteCommit(); | 299 clipboard_message_watcher_->WaitForWriteCommit(); |
| 291 title_update_watcher_->Wait(); | 300 title_update_watcher_->Wait(); |
| 292 return clipboard_message_watcher_->last_text(); | 301 return clipboard_message_watcher_->last_text(); |
| 293 } | 302 } |
| 294 | 303 |
| 295 std::string PerformCopy() { | 304 std::string PerformCopy() { |
| 296 clipboard_message_watcher_->InitWait(); | 305 clipboard_message_watcher_->InitWait(); |
| 297 RenderFrameHostImpl* rfh = | 306 RenderFrameHostImpl* rfh = |
| 298 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame()); | 307 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame()); |
| 299 rfh->GetRenderWidgetHost()->delegate()->Copy(); | 308 rfh->GetRenderWidgetHost()->delegate()->Copy(); |
| 300 clipboard_message_watcher_->WaitForWriteCommit(); | 309 clipboard_message_watcher_->WaitForWriteCommit(); |
| 301 return clipboard_message_watcher_->last_text(); | 310 return clipboard_message_watcher_->last_text(); |
| 302 } | 311 } |
| 303 | 312 |
| 304 void PerformPaste() { | 313 void PerformPaste() { |
| 305 title_update_watcher_->InitWait("TEXT_CHANGED"); | 314 title_update_watcher_->InitWait("TEXT_CHANGED"); |
| 306 RenderFrameHostImpl* rfh = | 315 RenderFrameHostImpl* rfh = |
| 307 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame()); | 316 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame()); |
| 308 rfh->GetRenderWidgetHost()->delegate()->Paste(); | 317 rfh->GetRenderWidgetHost()->delegate()->Paste(); |
| 309 title_update_watcher_->Wait(); | 318 title_update_watcher_->Wait(); |
| 310 } | 319 } |
| 311 | 320 |
| 312 void PerformSelectAll() { | 321 void PerformSelectAll() { |
| 322 title_update_watcher_->InitWait("SELECTION_CHANGED"); |
| 313 RenderFrameHostImpl* rfh = | 323 RenderFrameHostImpl* rfh = |
| 314 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame()); | 324 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame()); |
| 315 rfh->GetRenderWidgetHost()->delegate()->SelectAll(); | 325 rfh->GetRenderWidgetHost()->delegate()->SelectAll(); |
| 326 title_update_watcher_->Wait(); |
| 316 } | 327 } |
| 317 | 328 |
| 318 private: | 329 private: |
| 319 void RunTaskOnIOThreadAndWait(const base::Closure& task) { | 330 void RunTaskOnIOThreadAndWait(const base::Closure& task) { |
| 320 base::WaitableEvent completion( | 331 base::WaitableEvent completion( |
| 321 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 332 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 322 base::WaitableEvent::InitialState::NOT_SIGNALED); | 333 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 323 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 334 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 324 base::Bind(&InterstitialPageImplTest::RunTask, this, | 335 base::Bind(&InterstitialPageImplTest::RunTask, this, |
| 325 task, &completion)); | 336 task, &completion)); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 std::string input_text; | 395 std::string input_text; |
| 385 ASSERT_TRUE(GetInputText(&input_text)); | 396 ASSERT_TRUE(GetInputText(&input_text)); |
| 386 EXPECT_EQ("text-to-paste", input_text); | 397 EXPECT_EQ("text-to-paste", input_text); |
| 387 | 398 |
| 388 TearDownInterstitialPage(); | 399 TearDownInterstitialPage(); |
| 389 TearDownTestClipboard(); | 400 TearDownTestClipboard(); |
| 390 } | 401 } |
| 391 | 402 |
| 392 IN_PROC_BROWSER_TEST_F(InterstitialPageImplTest, SelectAll) { | 403 IN_PROC_BROWSER_TEST_F(InterstitialPageImplTest, SelectAll) { |
| 393 SetUpInterstitialPage(); | 404 SetUpInterstitialPage(); |
| 405 ASSERT_TRUE(SetSelectionChangeListener()); |
| 394 | 406 |
| 395 std::string input_text; | 407 std::string input_text; |
| 396 ASSERT_TRUE(GetSelection(&input_text)); | 408 ASSERT_TRUE(GetSelection(&input_text)); |
| 397 EXPECT_EQ(std::string(), input_text); | 409 EXPECT_EQ(std::string(), input_text); |
| 398 | 410 |
| 399 PerformSelectAll(); | 411 PerformSelectAll(); |
| 412 |
| 400 ASSERT_TRUE(GetSelection(&input_text)); | 413 ASSERT_TRUE(GetSelection(&input_text)); |
| 401 EXPECT_EQ("original body text", input_text); | 414 EXPECT_EQ("original body text", input_text); |
| 402 | 415 |
| 403 TearDownInterstitialPage(); | 416 TearDownInterstitialPage(); |
| 404 } | 417 } |
| 405 | 418 |
| 406 } // namespace content | 419 } // namespace content |
| OLD | NEW |