Path: blob/trunk/cpp/iedriver/CommandHandlers/ElementEqualsCommandHandler.cpp
2868 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the "License");5// you may not use this file except in compliance with the License.6// You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing, software11// distributed under the License is distributed on an "AS IS" BASIS,12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13// See the License for the specific language governing permissions and14// limitations under the License.1516#include "ElementEqualsCommandHandler.h"17#include "errorcodes.h"18#include "../Browser.h"19#include "../Element.h"20#include "../IECommandExecutor.h"2122namespace webdriver {2324ElementEqualsCommandHandler::ElementEqualsCommandHandler(void) {25}2627ElementEqualsCommandHandler::~ElementEqualsCommandHandler(void) {28}2930void ElementEqualsCommandHandler::ExecuteInternal(31const IECommandExecutor& executor,32const ParametersMap& command_parameters,33Response* response) {34ParametersMap::const_iterator id_parameter_iterator = command_parameters.find("id");35ParametersMap::const_iterator other_parameter_iterator = command_parameters.find("other");36if (id_parameter_iterator == command_parameters.end()) {37response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter in URL: id");38return;39}40else if (other_parameter_iterator == command_parameters.end()) {41response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Missing parameter in URL: other");42return;43} else {44std::string element_id = id_parameter_iterator->second.asString();45std::string other_element_id = other_parameter_iterator->second.asString();4647BrowserHandle browser_wrapper;48int status_code = executor.GetCurrentBrowser(&browser_wrapper);49if (status_code != WD_SUCCESS) {50response->SetErrorResponse(status_code, "Unable to get browser");51return;52}5354ElementHandle element_wrapper;55status_code = this->GetElement(executor, element_id, &element_wrapper);56if (status_code == WD_SUCCESS)57{58ElementHandle other_element_wrapper;59status_code = this->GetElement(executor,60other_element_id,61&other_element_wrapper);62if (status_code == WD_SUCCESS) {63response->SetSuccessResponse((element_wrapper->element() == other_element_wrapper->element()));64return;65} else {66response->SetErrorResponse(status_code,67"Element specified by 'other' is no longer valid");68return;69}70} else {71response->SetErrorResponse(status_code,72"Element specified by 'id' is no longer valid");73return;74}75}7677}7879} // namespace webdriver808182