Commit b35d9a70 authored by jkereliuk's avatar jkereliuk Committed by Commit Bot

[ChromeDriver] Minimize window implementation

This is an implementation of the minimize window endpoint
It uses the Browser.setWindowBounds protocol method

spec: https://w3c.github.io/webdriver/webdriver-spec.html#minimize-window

Bug: chromedriver:1940
Change-Id: If5e3394b02f107a254d6be8d8b94a1a7f23b97c7
Reviewed-on: https://chromium-review.googlesource.com/964734Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Commit-Queue: Jonathon Kereliuk <kereliuk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543615}
parent eba63433
......@@ -368,6 +368,29 @@ Status ChromeDesktopImpl::MaximizeWindow(const std::string& target_id) {
return SetWindowBounds(window.id, std::move(bounds));
}
Status ChromeDesktopImpl::MinimizeWindow(const std::string& target_id) {
Window window;
Status status = GetWindow(target_id, &window);
if (status.IsError())
return status;
if (window.state == "minimized")
return Status(kOk);
if (window.state != "normal") {
// restore window to normal first
auto bounds = std::make_unique<base::DictionaryValue>();
bounds->SetString("windowState", "normal");
status = SetWindowBounds(window.id, std::move(bounds));
if (status.IsError())
return status;
}
auto bounds = std::make_unique<base::DictionaryValue>();
bounds->SetString("windowState", "minimized");
return SetWindowBounds(window.id, std::move(bounds));
}
Status ChromeDesktopImpl::FullScreenWindow(const std::string& target_id) {
Window window;
Status status = GetWindow(target_id, &window);
......
......@@ -74,6 +74,7 @@ class ChromeDesktopImpl : public ChromeImpl {
Status SetWindowPosition(const std::string& target_id, int x, int y);
Status SetWindowSize(const std::string& target_id, int width, int height);
Status MaximizeWindow(const std::string& target_id);
Status MinimizeWindow(const std::string& target_id);
Status FullScreenWindow(const std::string& target_id);
private:
......
......@@ -484,6 +484,9 @@ class ChromeDriver(object):
def MaximizeWindow(self):
self.ExecuteCommand(Command.MAXIMIZE_WINDOW, {'windowHandle': 'current'})
def MinimizeWindow(self):
return self.ExecuteCommand(Command.MINIMIZE_WINDOW, {'windowHandle': 'current'})
def FullScreenWindow(self):
self.ExecuteCommand(Command.FULLSCREEN_WINDOW)
......
......@@ -92,6 +92,8 @@ class Command(object):
_Method.POST, '/session/:sessionId/window/rect')
MAXIMIZE_WINDOW = (
_Method.POST, '/session/:sessionId/window/:windowHandle/maximize')
MINIMIZE_WINDOW = (
_Method.POST, '/session/:sessionId/window/:windowHandle/minimize')
FULLSCREEN_WINDOW = (
_Method.POST, '/session/:sessionId/window/fullscreen')
CLOSE = (_Method.DELETE, '/session/:sessionId/window')
......
......@@ -146,6 +146,9 @@ HttpHandler::HttpHandler(
CommandMapping(
kPost, "session/:sessionId/window/:windowHandle/maximize",
WrapToCommand("MaximizeWindow", base::Bind(&ExecuteMaximizeWindow))),
CommandMapping(
kPost, "session/:sessionId/window/:windowHandle/minimize",
WrapToCommand("MinimizeWindow", base::Bind(&ExecuteMinimizeWindow))),
CommandMapping(kPost, "session/:sessionId/window/fullscreen",
WrapToCommand("FullscreenWindow",
base::Bind(&ExecuteFullScreenWindow))),
......
......@@ -966,6 +966,22 @@ Status ExecuteMaximizeWindow(Session* session,
return extension->MaximizeWindow();
}
Status ExecuteMinimizeWindow(Session* session,
const base::DictionaryValue& params,
std::unique_ptr<base::Value>* value) {
ChromeDesktopImpl* desktop = NULL;
Status status = session->chrome->GetAsDesktop(&desktop);
if (status.IsError())
return status;
status = desktop->MinimizeWindow(session->window);
if (status.IsError())
return status;
ExecuteGetWindowRect(session, params, value);
return Status(kOk);
}
Status ExecuteFullScreenWindow(Session* session,
const base::DictionaryValue& params,
std::unique_ptr<base::Value>* value) {
......
......@@ -157,6 +157,10 @@ Status ExecuteMaximizeWindow(Session* session,
const base::DictionaryValue& params,
std::unique_ptr<base::Value>* value);
Status ExecuteMinimizeWindow(Session* session,
const base::DictionaryValue& params,
std::unique_ptr<base::Value>* value);
Status ExecuteFullScreenWindow(Session* session,
const base::DictionaryValue& params,
std::unique_ptr<base::Value>* value);
......
......@@ -1019,6 +1019,23 @@ class ChromeDriverTest(ChromeDriverBaseTestWithWebServer):
self.assertEquals([100, 200], self._driver.GetWindowPosition())
self.assertEquals([600, 400], self._driver.GetWindowSize())
def testWindowMinimize(self):
handle_prefix = "CDwindow-"
handle = self._driver.GetCurrentWindowHandle()
target = handle[len(handle_prefix):]
self._driver.SetWindowPosition(100, 200)
self._driver.SetWindowSize(500, 300)
rect = self._driver.MinimizeWindow()
expected_rect = {u'y': 200, u'width': 500, u'height': 300, u'x': 100}
#check it returned the correct rect
for key in expected_rect.keys():
self.assertEquals(expected_rect[key], rect[key])
# check its minimized
res = self._driver.SendCommandAndGetResult('Browser.getWindowForTarget', {'targetId': target})
self.assertEquals('minimized', res['bounds']['windowState'])
def testWindowFullScreen(self):
self._driver.SetWindowPosition(100, 200)
self._driver.SetWindowSize(500, 300)
......
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