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 "content/public/test/browser_test_utils.h" | 5 #include "content/public/test/browser_test_utils.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <tuple> | 8 #include <tuple> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
406 } | 406 } |
407 | 407 |
408 // Queries for video input devices on the current system using the getSources | 408 // Queries for video input devices on the current system using the getSources |
409 // API. | 409 // API. |
410 // | 410 // |
411 // This does not guarantee that a getUserMedia with video will succeed, as the | 411 // This does not guarantee that a getUserMedia with video will succeed, as the |
412 // camera could be busy for instance. | 412 // camera could be busy for instance. |
413 // | 413 // |
414 // Returns has-video-input-device to the test if there is a webcam available, | 414 // Returns has-video-input-device to the test if there is a webcam available, |
415 // no-video-input-devices otherwise. | 415 // no-video-input-devices otherwise. |
416 const char kHasVideoInputDeviceOnSystem[] = | 416 const char kHasVideoInputDeviceOnSystem[] = R"( |
417 "(function() {" | 417 (function() { |
418 "navigator.mediaDevices.enumerateDevices()" | 418 navigator.mediaDevices.enumerateDevices() |
419 ".then(function(devices) {" | 419 .then(function(devices) { |
420 "devices.forEach(function(device) {" | 420 var found = false; |
421 "if (device.kind == 'videoinput') {" | 421 devices.forEach(function(device) { |
422 "window.domAutomationController.send('has-video-input-device');" | 422 if (device.kind == 'videoinput') { |
423 "return;" | 423 window.domAutomationController.send('has-video-input-device'); |
ncarter (slow)
2017/07/05 20:30:44
looks like there could still be multiple sends() h
Łukasz Anforowicz
2017/07/06 15:48:02
Good catch. Thanks for the "devices.some" suggest
| |
424 "}" | 424 found = true; |
425 "});" | 425 } |
426 "window.domAutomationController.send('no-video-input-devices');" | 426 }); |
427 "});" | 427 if (!found) { |
428 "})()"; | 428 window.domAutomationController.send('no-video-input-devices'); |
429 } | |
430 }); | |
431 })() | |
432 )"; | |
429 | 433 |
430 const char kHasVideoInputDevice[] = "has-video-input-device"; | 434 const char kHasVideoInputDevice[] = "has-video-input-device"; |
431 | 435 |
432 } // namespace | 436 } // namespace |
433 | 437 |
434 bool NavigateIframeToURL(WebContents* web_contents, | 438 bool NavigateIframeToURL(WebContents* web_contents, |
435 std::string iframe_id, | 439 std::string iframe_id, |
436 const GURL& url) { | 440 const GURL& url) { |
437 std::string script = base::StringPrintf( | 441 std::string script = base::StringPrintf( |
438 "setTimeout(\"" | 442 "setTimeout(\"" |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
809 RenderFrameHost* ConvertToRenderFrameHost(RenderViewHost* render_view_host) { | 813 RenderFrameHost* ConvertToRenderFrameHost(RenderViewHost* render_view_host) { |
810 return render_view_host->GetMainFrame(); | 814 return render_view_host->GetMainFrame(); |
811 } | 815 } |
812 | 816 |
813 RenderFrameHost* ConvertToRenderFrameHost(RenderFrameHost* render_frame_host) { | 817 RenderFrameHost* ConvertToRenderFrameHost(RenderFrameHost* render_frame_host) { |
814 return render_frame_host; | 818 return render_frame_host; |
815 } | 819 } |
816 | 820 |
817 bool ExecuteScript(const ToRenderFrameHost& adapter, | 821 bool ExecuteScript(const ToRenderFrameHost& adapter, |
818 const std::string& script) { | 822 const std::string& script) { |
823 // TODO(lukasza): ExecuteScript should just call | |
824 // ExecuteJavaScriptWithUserGestureForTests and avoid modifying the original | |
825 // script (and at that point we should remove ExecuteUnmodifiedScript). This | |
826 // is difficult to change, because many tests depend on the message loop | |
827 // pumping done by ExecuteScriptHelper below (this is fragile - these tests | |
828 // should wait on a more specific thing instead). | |
ncarter (slow)
2017/07/05 20:30:44
We could make this more robust by generating a GUI
Łukasz Anforowicz
2017/07/06 15:48:02
Done.
| |
819 std::string new_script = | 829 std::string new_script = |
820 script + ";window.domAutomationController.send(0);"; | 830 script + ";window.domAutomationController.send(0);"; |
821 return ExecuteScriptHelper(adapter.render_frame_host(), new_script, true, | 831 return ExecuteScriptHelper(adapter.render_frame_host(), new_script, true, |
822 nullptr); | 832 nullptr); |
823 } | 833 } |
824 | 834 |
825 bool ExecuteScriptWithoutUserGesture(const ToRenderFrameHost& adapter, | 835 bool ExecuteScriptWithoutUserGesture(const ToRenderFrameHost& adapter, |
826 const std::string& script) { | 836 const std::string& script) { |
827 std::string new_script = script + ";window.domAutomationController.send(0);"; | 837 std::string new_script = script + ";window.domAutomationController.send(0);"; |
828 return ExecuteScriptHelper(adapter.render_frame_host(), new_script, false, | 838 return ExecuteScriptHelper(adapter.render_frame_host(), new_script, false, |
829 nullptr); | 839 nullptr); |
830 } | 840 } |
831 | 841 |
842 void ExecuteUnmodifiedScript(const ToRenderFrameHost& adapter, | |
843 const std::string& script) { | |
844 adapter.render_frame_host()->ExecuteJavaScriptWithUserGestureForTests( | |
845 base::UTF8ToUTF16(script)); | |
846 } | |
847 | |
832 bool ExecuteScriptAndExtractDouble(const ToRenderFrameHost& adapter, | 848 bool ExecuteScriptAndExtractDouble(const ToRenderFrameHost& adapter, |
833 const std::string& script, double* result) { | 849 const std::string& script, double* result) { |
834 DCHECK(result); | 850 DCHECK(result); |
835 std::unique_ptr<base::Value> value; | 851 std::unique_ptr<base::Value> value; |
836 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, true, &value) || | 852 if (!ExecuteScriptHelper(adapter.render_frame_host(), script, true, &value) || |
837 !value.get()) { | 853 !value.get()) { |
838 return false; | 854 return false; |
839 } | 855 } |
840 | 856 |
841 return value->GetAsDouble(result); | 857 return value->GetAsDouble(result); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
996 AppendGzippedResource(*bytes, &script); | 1012 AppendGzippedResource(*bytes, &script); |
997 else | 1013 else |
998 script.append(bytes->front_as<char>(), bytes->size()); | 1014 script.append(bytes->front_as<char>(), bytes->size()); |
999 | 1015 |
1000 script.append("\n"); | 1016 script.append("\n"); |
1001 } | 1017 } |
1002 if (!ExecuteScript(web_contents, script)) | 1018 if (!ExecuteScript(web_contents, script)) |
1003 return false; | 1019 return false; |
1004 | 1020 |
1005 DOMMessageQueue message_queue; | 1021 DOMMessageQueue message_queue; |
1006 if (!ExecuteScript(web_contents, "runTests()")) | 1022 ExecuteUnmodifiedScript(web_contents, "runTests()"); |
1007 return false; | |
1008 | 1023 |
1009 std::string message; | 1024 std::string message; |
1010 do { | 1025 do { |
1011 if (!message_queue.WaitForMessage(&message)) | 1026 if (!message_queue.WaitForMessage(&message)) |
1012 return false; | 1027 return false; |
1013 } while (message.compare("\"PENDING\"") == 0); | 1028 } while (message.compare("\"PENDING\"") == 0); |
1014 | 1029 |
1015 return message.compare("\"SUCCESS\"") == 0; | 1030 return message.compare("\"SUCCESS\"") == 0; |
1016 } | 1031 } |
1017 | 1032 |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1485 Source<WebContents>(web_contents)); | 1500 Source<WebContents>(web_contents)); |
1486 } | 1501 } |
1487 | 1502 |
1488 DOMMessageQueue::~DOMMessageQueue() {} | 1503 DOMMessageQueue::~DOMMessageQueue() {} |
1489 | 1504 |
1490 void DOMMessageQueue::Observe(int type, | 1505 void DOMMessageQueue::Observe(int type, |
1491 const NotificationSource& source, | 1506 const NotificationSource& source, |
1492 const NotificationDetails& details) { | 1507 const NotificationDetails& details) { |
1493 Details<std::string> dom_op_result(details); | 1508 Details<std::string> dom_op_result(details); |
1494 message_queue_.push(*dom_op_result.ptr()); | 1509 message_queue_.push(*dom_op_result.ptr()); |
1495 if (message_loop_runner_.get()) | 1510 if (message_loop_runner_) |
1496 message_loop_runner_->Quit(); | 1511 message_loop_runner_->Quit(); |
1497 } | 1512 } |
1498 | 1513 |
1499 void DOMMessageQueue::RenderProcessGone(base::TerminationStatus status) { | 1514 void DOMMessageQueue::RenderProcessGone(base::TerminationStatus status) { |
1500 VLOG(0) << "DOMMessageQueue::RenderProcessGone " << status; | 1515 VLOG(0) << "DOMMessageQueue::RenderProcessGone " << status; |
1501 switch (status) { | 1516 switch (status) { |
1502 case base::TERMINATION_STATUS_NORMAL_TERMINATION: | 1517 case base::TERMINATION_STATUS_NORMAL_TERMINATION: |
1503 case base::TERMINATION_STATUS_STILL_RUNNING: | 1518 case base::TERMINATION_STATUS_STILL_RUNNING: |
1504 break; | 1519 break; |
1505 default: | 1520 default: |
1521 renderer_crashed_ = true; | |
1506 if (message_loop_runner_.get()) | 1522 if (message_loop_runner_.get()) |
1507 message_loop_runner_->Quit(); | 1523 message_loop_runner_->Quit(); |
1508 break; | 1524 break; |
1509 } | 1525 } |
1510 } | 1526 } |
1511 | 1527 |
1512 void DOMMessageQueue::ClearQueue() { | 1528 void DOMMessageQueue::ClearQueue() { |
1513 message_queue_ = std::queue<std::string>(); | 1529 message_queue_ = std::queue<std::string>(); |
1514 } | 1530 } |
1515 | 1531 |
1516 bool DOMMessageQueue::WaitForMessage(std::string* message) { | 1532 bool DOMMessageQueue::WaitForMessage(std::string* message) { |
1517 DCHECK(message); | 1533 DCHECK(message); |
1518 if (message_queue_.empty()) { | 1534 if (!renderer_crashed_ && message_queue_.empty()) { |
1519 // This will be quit when a new message comes in. | 1535 // This will be quit when a new message comes in. |
1520 message_loop_runner_ = | 1536 message_loop_runner_ = |
1521 new MessageLoopRunner(MessageLoopRunner::QuitMode::IMMEDIATE); | 1537 new MessageLoopRunner(MessageLoopRunner::QuitMode::IMMEDIATE); |
1522 message_loop_runner_->Run(); | 1538 message_loop_runner_->Run(); |
1523 } | 1539 } |
1524 return PopMessage(message); | 1540 return PopMessage(message); |
1525 } | 1541 } |
1526 | 1542 |
1527 bool DOMMessageQueue::PopMessage(std::string* message) { | 1543 bool DOMMessageQueue::PopMessage(std::string* message) { |
1528 DCHECK(message); | 1544 DCHECK(message); |
1529 if (message_queue_.empty()) | 1545 if (renderer_crashed_ || message_queue_.empty()) |
1530 return false; | 1546 return false; |
1531 *message = message_queue_.front(); | 1547 *message = message_queue_.front(); |
1532 message_queue_.pop(); | 1548 message_queue_.pop(); |
1533 return true; | 1549 return true; |
1534 } | 1550 } |
1535 | 1551 |
1536 class WebContentsAddedObserver::RenderViewCreatedObserver | 1552 class WebContentsAddedObserver::RenderViewCreatedObserver |
1537 : public WebContentsObserver { | 1553 : public WebContentsObserver { |
1538 public: | 1554 public: |
1539 explicit RenderViewCreatedObserver(WebContents* web_contents) | 1555 explicit RenderViewCreatedObserver(WebContents* web_contents) |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2104 RenderWidgetHostViewAura* rwhva = | 2120 RenderWidgetHostViewAura* rwhva = |
2105 static_cast<RenderWidgetHostViewAura*>(rwhv); | 2121 static_cast<RenderWidgetHostViewAura*>(rwhv); |
2106 rwhva->SetOverscrollControllerForTesting(std::move(mock)); | 2122 rwhva->SetOverscrollControllerForTesting(std::move(mock)); |
2107 | 2123 |
2108 return raw_mock; | 2124 return raw_mock; |
2109 } | 2125 } |
2110 | 2126 |
2111 #endif // defined(USE_AURA) | 2127 #endif // defined(USE_AURA) |
2112 | 2128 |
2113 } // namespace content | 2129 } // namespace content |
OLD | NEW |