| 98 | } |
| 99 | |
| 100 | int InputManager::PerformInputSequence(BrowserHandle browser_wrapper, |
| 101 | const Json::Value& sequences, |
| 102 | std::string* error_info) { |
| 103 | LOG(TRACE) << "Entering InputManager::PerformInputSequence"; |
| 104 | if (!sequences.isArray()) { |
| 105 | return EUNHANDLEDERROR; |
| 106 | } |
| 107 | |
| 108 | int status_code = WD_SUCCESS; |
| 109 | // Use a single mutex, so that all instances synchronize on the same object |
| 110 | // for focus purposes. |
| 111 | HANDLE mutex_handle = this->AcquireMutex(); |
| 112 | |
| 113 | Json::Value ticks(Json::arrayValue); |
| 114 | status_code = this->GetTicks(sequences, &ticks); |
| 115 | if (status_code != WD_SUCCESS) { |
| 116 | this->ReleaseMutex(mutex_handle); |
| 117 | return status_code; |
| 118 | } |
| 119 | |
| 120 | this->inputs_.clear(); |
| 121 | this->current_input_state_.last_click_time = 0; |
| 122 | InputState current_input_state = this->CloneCurrentInputState(); |
| 123 | for (size_t i = 0; i < ticks.size(); ++i) { |
| 124 | Json::UInt tick_index = static_cast<Json::UInt>(i); |
| 125 | Json::Value tick = ticks[tick_index]; |
| 126 | for (size_t j = 0; j < tick.size(); ++j) { |
| 127 | Json::UInt action_index = static_cast<Json::UInt>(j); |
| 128 | Json::Value action = tick[action_index]; |
| 129 | std::string action_subtype = action["type"].asString(); |
| 130 | if (action_subtype == "pointerMove") { |
| 131 | status_code = this->PointerMoveTo(browser_wrapper, action, ¤t_input_state); |
| 132 | } else if (action_subtype == "pointerDown") { |
| 133 | status_code = this->PointerDown(browser_wrapper, action, ¤t_input_state); |
| 134 | } else if (action_subtype == "pointerUp") { |
| 135 | status_code = this->PointerUp(browser_wrapper, action, ¤t_input_state); |
| 136 | } else if (action_subtype == "keyDown") { |
| 137 | status_code = this->KeyDown(browser_wrapper, action, ¤t_input_state); |
| 138 | } else if (action_subtype == "keyUp") { |
| 139 | status_code = this->KeyUp(browser_wrapper, action, ¤t_input_state); |
| 140 | } else if (action_subtype == "pause") { |
| 141 | status_code = this->Pause(browser_wrapper, action); |
| 142 | } |
| 143 | |
| 144 | if (status_code != WD_SUCCESS) { |
| 145 | this->ReleaseMutex(mutex_handle); |
| 146 | *error_info = current_input_state.error_info; |
| 147 | return status_code; |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | // If there are inputs in the array, then we've queued up input actions |
| 153 | // to be played back. So play them back. |
| 154 | if (this->inputs_.size() > 0) { |
| 155 | LOG(DEBUG) << "Processing a total of " << this->inputs_.size() << " input events"; |
| 156 | this->action_simulator_->SimulateActions(browser_wrapper, |
| 157 | this->inputs_, |
no test coverage detected