Chromium Code Reviews| Index: chrome/browser/media/webrtc/webrtc_browsertest_common.cc |
| diff --git a/chrome/browser/media/webrtc/webrtc_browsertest_common.cc b/chrome/browser/media/webrtc/webrtc_browsertest_common.cc |
| index 00105e363ba0f961391277f04219199772625b02..568d12160374add109f602c1921b145194942c71 100644 |
| --- a/chrome/browser/media/webrtc/webrtc_browsertest_common.cc |
| +++ b/chrome/browser/media/webrtc/webrtc_browsertest_common.cc |
| @@ -119,7 +119,6 @@ bool SleepInJavascript(content::WebContents* tab_contents, int timeout_msec) { |
| tab_contents, javascript, &result); |
| return ok && result == "sleep-ok"; |
| } |
| - |
| bool PollingWaitUntil(const std::string& javascript, |
| const std::string& evaluates_to, |
| content::WebContents* tab_contents) { |
| @@ -136,7 +135,6 @@ bool PollingWaitUntil(const std::string& javascript, |
| std::string result; |
| while (base::Time::Now() - start_time < timeout) { |
| - std::string result; |
| if (!content::ExecuteScriptAndExtractString(tab_contents, javascript, |
| &result)) { |
| LOG(ERROR) << "Failed to execute javascript " << javascript; |
| @@ -164,4 +162,33 @@ bool PollingWaitUntil(const std::string& javascript, |
| return false; |
| } |
| +bool PollingWaitUntil(const std::string& javascript, |
| + content::WebContents* tab_contents, |
| + int poll_interval_msec) { |
| + base::Time start_time = base::Time::Now(); |
| + base::TimeDelta timeout = TestTimeouts::action_max_timeout(); |
| + bool result; |
| + |
| + while (base::Time::Now() - start_time < timeout) { |
| + if (!content::ExecuteScriptAndExtractBool(tab_contents, javascript, |
| + &result)) { |
| + LOG(ERROR) << "Failed to execute javascript " << javascript; |
| + return false; |
| + } |
| + |
| + if (result) { |
| + return true; |
| + } |
| + |
| + // Sleep a bit here to keep this loop from spinlocking too badly. |
| + if (!SleepInJavascript(tab_contents, poll_interval_msec)) { |
| + // TODO(phoglund): Figure out why this fails every now and then. |
| + // It's not a huge deal if it does though. |
| + LOG(ERROR) << "Failed to sleep."; |
| + } |
| + } |
| + LOG(ERROR) << "Timed out while waiting for " << javascript; |
| + return false; |
| +} |
|
mcasas
2017/03/22 17:54:14
This code is very similar to l.129-163. Either ref
|
| + |
| } // namespace test |