diff --git a/cpp/iedriver/CommandHandlers/SwitchToParentFrameCommandHandler.h b/cpp/iedriver/CommandHandlers/SwitchToParentFrameCommandHandler.h new file mode 100644 index 0000000000000..1d51c44a85a70 --- /dev/null +++ b/cpp/iedriver/CommandHandlers/SwitchToParentFrameCommandHandler.h @@ -0,0 +1,49 @@ +// Copyright 2014 Software Freedom Conservancy +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef WEBDRIVER_IE_SWITCHTOPARENTFRAMECOMMANDHANDLER_H_ +#define WEBDRIVER_IE_SWITCHTOPARENTFRAMECOMMANDHANDLER_H_ + +#include "../Browser.h" +#include "../IECommandHandler.h" +#include "../IECommandExecutor.h" + +namespace webdriver { + +class SwitchToParentFrameCommandHandler : public IECommandHandler { + public: + SwitchToParentFrameCommandHandler(void) { + } + + virtual ~SwitchToParentFrameCommandHandler(void) { + } + + protected: + void ExecuteInternal(const IECommandExecutor& executor, + const LocatorMap& locator_parameters, + const ParametersMap& command_parameters, + Response* response) { + BrowserHandle browser_wrapper; + int status_code = executor.GetCurrentBrowser(&browser_wrapper); + if (status_code != WD_SUCCESS) { + response->SetErrorResponse(status_code, "Unable to get browser"); + return; + } + browser_wrapper->SetFocusedFrameToParent(); + response->SetSuccessResponse(Json::Value::null); + } +}; + +} // namespace webdriver + +#endif // WEBDRIVER_IE_SWITCHTOPARENTFRAMECOMMANDHANDLER_H_ diff --git a/cpp/iedriver/DocumentHost.cpp b/cpp/iedriver/DocumentHost.cpp index 6cc1ab043330c..a01fb53ed8b84 100644 --- a/cpp/iedriver/DocumentHost.cpp +++ b/cpp/iedriver/DocumentHost.cpp @@ -156,6 +156,34 @@ int DocumentHost::SetFocusedFrameByIndex(const int frame_index) { return this->SetFocusedFrameByIdentifier(frame_identifier); } +void DocumentHost::SetFocusedFrameToParent() { + LOG(TRACE) << "Entering DocumentHost::SetFocusedFrameToParent"; + // Three possible outcomes. + // Outcome 1: Already at top-level browsing context. No-op. + if (this->focused_frame_window_ != NULL) { + CComPtr parent_window; + HRESULT hr = this->focused_frame_window_->get_parent(&parent_window); + if (FAILED(hr)) { + LOGHR(WARN, hr) << "IHTMLWindow2::get_parent call failed."; + } + CComPtr top_window; + hr = this->focused_frame_window_->get_top(&top_window); + if (FAILED(hr)) { + LOGHR(WARN, hr) << "IHTMLWindow2::get_top call failed."; + } + if (top_window.IsEqualObject(parent_window)) { + // Outcome 2: Focus is on a frame one level deep, making the + // parent the top-level browsing context. Set focused frame + // pointer to NULL. + this->focused_frame_window_ = NULL; + } else { + // Outcome 3: Focus is on a frame more than one level deep. + // Set focused frame pointer to parent frame. + this->focused_frame_window_ = parent_window; + } + } +} + int DocumentHost::SetFocusedFrameByIdentifier(VARIANT frame_identifier) { LOG(TRACE) << "Entering DocumentHost::SetFocusedFrameByIdentifier"; diff --git a/cpp/iedriver/DocumentHost.h b/cpp/iedriver/DocumentHost.h index 1c3e85674b145..2d96e1728e827 100644 --- a/cpp/iedriver/DocumentHost.h +++ b/cpp/iedriver/DocumentHost.h @@ -67,6 +67,7 @@ class DocumentHost { int SetFocusedFrameByIndex(const int frame_index); int SetFocusedFrameByName(const std::string& frame_name); int SetFocusedFrameByElement(IHTMLElement* frame_element); + void SetFocusedFrameToParent(void); bool wait_required(void) const { return this->wait_required_; } void set_wait_required(const bool value) { this->wait_required_ = value; } diff --git a/cpp/iedriver/IECommandExecutor.cpp b/cpp/iedriver/IECommandExecutor.cpp index 5b20479297e2a..8e3cf3470c09b 100755 --- a/cpp/iedriver/IECommandExecutor.cpp +++ b/cpp/iedriver/IECommandExecutor.cpp @@ -72,6 +72,7 @@ #include "CommandHandlers/SetWindowSizeCommandHandler.h" #include "CommandHandlers/SubmitElementCommandHandler.h" #include "CommandHandlers/SwitchToFrameCommandHandler.h" +#include "CommandHandlers/SwitchToParentFrameCommandHandler.h" #include "CommandHandlers/SwitchToWindowCommandHandler.h" #include "StringUtilities.h" @@ -766,6 +767,7 @@ void IECommandExecutor::PopulateCommandHandlers() { this->command_handlers_[webdriver::CommandType::GetWindowHandles] = CommandHandlerHandle(new GetAllWindowHandlesCommandHandler); this->command_handlers_[webdriver::CommandType::SwitchToWindow] = CommandHandlerHandle(new SwitchToWindowCommandHandler); this->command_handlers_[webdriver::CommandType::SwitchToFrame] = CommandHandlerHandle(new SwitchToFrameCommandHandler); + this->command_handlers_[webdriver::CommandType::SwitchToParentFrame] = CommandHandlerHandle(new SwitchToParentFrameCommandHandler); this->command_handlers_[webdriver::CommandType::Get] = CommandHandlerHandle(new GoToUrlCommandHandler); this->command_handlers_[webdriver::CommandType::GoForward] = CommandHandlerHandle(new GoForwardCommandHandler); this->command_handlers_[webdriver::CommandType::GoBack] = CommandHandlerHandle(new GoBackCommandHandler); diff --git a/cpp/iedriver/IEDriver.vcxproj b/cpp/iedriver/IEDriver.vcxproj index 2ee46869349ff..840e74aea2a03 100644 --- a/cpp/iedriver/IEDriver.vcxproj +++ b/cpp/iedriver/IEDriver.vcxproj @@ -262,6 +262,7 @@ + diff --git a/cpp/iedriver/IEDriver.vcxproj.filters b/cpp/iedriver/IEDriver.vcxproj.filters index af9bc99739821..ee72a9883089a 100644 --- a/cpp/iedriver/IEDriver.vcxproj.filters +++ b/cpp/iedriver/IEDriver.vcxproj.filters @@ -349,6 +349,9 @@ Header Files + + Header Files\CommandHandlers + diff --git a/cpp/iedriverserver/CHANGELOG b/cpp/iedriverserver/CHANGELOG index d0a7caaaa821d..2a8973b4e257b 100644 --- a/cpp/iedriverserver/CHANGELOG +++ b/cpp/iedriverserver/CHANGELOG @@ -9,6 +9,10 @@ available via the project downloads page. Changes in "revision" field indicate private releases checked into the prebuilts directory of the source tree, but not made generally available on the downloads page. +v2.42.0.1 +========= + * Implemented switchToParentFrame command. + v2.42.0.0 ========= * Release to synchronize with release of Selenium project. diff --git a/cpp/iedriverserver/IEDriverServer.rc b/cpp/iedriverserver/IEDriverServer.rc index 8008085afbce4..b4933657ecbbe 100644 Binary files a/cpp/iedriverserver/IEDriverServer.rc and b/cpp/iedriverserver/IEDriverServer.rc differ diff --git a/cpp/prebuilt/Win32/Release/IEDriverServer.exe b/cpp/prebuilt/Win32/Release/IEDriverServer.exe index 415561f9b8f60..652399e04f2b9 100644 Binary files a/cpp/prebuilt/Win32/Release/IEDriverServer.exe and b/cpp/prebuilt/Win32/Release/IEDriverServer.exe differ diff --git a/cpp/prebuilt/x64/Release/IEDriverServer.exe b/cpp/prebuilt/x64/Release/IEDriverServer.exe index e8d94d0473d1f..6c8483ca00c1c 100644 Binary files a/cpp/prebuilt/x64/Release/IEDriverServer.exe and b/cpp/prebuilt/x64/Release/IEDriverServer.exe differ diff --git a/dotnet/test/common/FrameSwitchingTest.cs b/dotnet/test/common/FrameSwitchingTest.cs index bef626ec379fb..edf0ceae34567 100644 --- a/dotnet/test/common/FrameSwitchingTest.cs +++ b/dotnet/test/common/FrameSwitchingTest.cs @@ -197,7 +197,6 @@ public void ShouldThrowAnExceptionWhenAFrameCannotBeFoundByIndex() [Test] [IgnoreBrowser(Browser.Chrome, "Browser does not support parent frame navigation")] - [IgnoreBrowser(Browser.IE, "Browser does not support parent frame navigation")] [IgnoreBrowser(Browser.PhantomJS, "Browser does not support parent frame navigation")] [IgnoreBrowser(Browser.Safari, "Browser does not support parent frame navigation")] [IgnoreBrowser(Browser.Android, "Browser does not support parent frame navigation")] @@ -212,7 +211,6 @@ public void ShouldBeAbleToSwitchToParentFrame() [Test] [IgnoreBrowser(Browser.Chrome, "Browser does not support parent frame navigation")] - [IgnoreBrowser(Browser.IE, "Browser does not support parent frame navigation")] [IgnoreBrowser(Browser.PhantomJS, "Browser does not support parent frame navigation")] [IgnoreBrowser(Browser.Safari, "Browser does not support parent frame navigation")] [IgnoreBrowser(Browser.Android, "Browser does not support parent frame navigation")] @@ -228,7 +226,6 @@ public void ShouldBeAbleToSwitchToParentFrameFromASecondLevelFrame() [Test] [IgnoreBrowser(Browser.Chrome, "Browser does not support parent frame navigation")] - [IgnoreBrowser(Browser.IE, "Browser does not support parent frame navigation")] [IgnoreBrowser(Browser.PhantomJS, "Browser does not support parent frame navigation")] [IgnoreBrowser(Browser.Safari, "Browser does not support parent frame navigation")] [IgnoreBrowser(Browser.Android, "Browser does not support parent frame navigation")] @@ -243,7 +240,6 @@ public void SwitchingToParentFrameFromDefaultContextIsNoOp() [Test] [IgnoreBrowser(Browser.Chrome, "Browser does not support parent frame navigation")] - [IgnoreBrowser(Browser.IE, "Browser does not support parent frame navigation")] [IgnoreBrowser(Browser.PhantomJS, "Browser does not support parent frame navigation")] [IgnoreBrowser(Browser.Safari, "Browser does not support parent frame navigation")] [IgnoreBrowser(Browser.Android, "Browser does not support parent frame navigation")]