Commit 6cc2c589 authored by Shengfa Lin's avatar Shengfa Lin Committed by Commit Bot

[chromedriver] Improve WindowMinimize robustness

After setting window bounds, could potentially wait for 1 second
using retries for window state to reflect.

Bug: chromium:1068467
Change-Id: I94cd7919487dcda3faf3b39b87b9378057bb192c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2209898
Commit-Queue: Shengfa Lin <shengfa@google.com>
Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#770767}
parent 140848d9
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <stddef.h> #include <stddef.h>
#include <utility> #include <utility>
#include "base/strings/string_number_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/test/chromedriver/chrome/devtools_client.h" #include "chrome/test/chromedriver/chrome/devtools_client.h"
#include "chrome/test/chromedriver/chrome/devtools_event_listener.h" #include "chrome/test/chromedriver/chrome/devtools_event_listener.h"
...@@ -316,10 +317,14 @@ Status ChromeImpl::SetWindowBounds( ...@@ -316,10 +317,14 @@ Status ChromeImpl::SetWindowBounds(
return status; return status;
} }
if (state.empty())
return Status(kOk);
status = GetWindowBounds(window->id, window); status = GetWindowBounds(window->id, window);
if (status.IsError()) if (status.IsError())
return status; return status;
if (window->state == state || state == "")
if (window->state == state)
return Status(kOk); return Status(kOk);
if (state == "maximized" && window->state == "normal") { if (state == "maximized" && window->state == "normal") {
...@@ -354,10 +359,23 @@ Status ChromeImpl::SetWindowBounds( ...@@ -354,10 +359,23 @@ Status ChromeImpl::SetWindowBounds(
params.Set("bounds", bounds->CreateDeepCopy()); params.Set("bounds", bounds->CreateDeepCopy());
return devtools_websocket_client_->SendCommand("Browser.setWindowBounds", return devtools_websocket_client_->SendCommand("Browser.setWindowBounds",
params); params);
} else {
return Status(kUnknownError, "failed to change window state to " + state +
", current state is " + window->state);
} }
int retries = 0;
// Wait and retry for 1 second
for (; retries < 10; ++retries) {
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
status = GetWindowBounds(window->id, window);
if (status.IsError())
return status;
if (window->state == state)
return Status(kOk);
}
return Status(kUnknownError, "failed to change window state to '" + state +
"', current state is '" + window->state +
"'");
} }
Status ChromeImpl::ParseWindow(std::unique_ptr<base::DictionaryValue> params, Status ChromeImpl::ParseWindow(std::unique_ptr<base::DictionaryValue> params,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment