Commit 64015fe0 authored by samuong's avatar samuong Committed by Commit bot

[chromedriver] Add JavaScript fallback for GoBack/GoForward if DevTools commands aren't available

BUG=chromedriver:980

Review URL: https://codereview.chromium.org/783593003

Cr-Commit-Position: refs/heads/master@{#307102}
parent 68b55cd3
......@@ -170,8 +170,20 @@ Status WebViewImpl::TraverseHistory(int delta) {
scoped_ptr<base::DictionaryValue> result;
Status status = client_->SendCommandAndGetResult(
"Page.getNavigationHistory", params, &result);
if (status.IsError())
return status;
if (status.IsError()) {
// TODO(samuong): remove this once we stop supporting WebView on KitKat.
// Older versions of WebView on Android (on KitKat and earlier) do not have
// the Page.getNavigationHistory DevTools command handler, so fall back to
// using JavaScript to navigate back and forward. WebView reports its build
// number as 0, so use the error message to detect if we can't use the
// DevTools command.
std::string message;
result->GetString("message", &message);
if (message == "'Page.getNavigationHistory' wasn't found")
return TraverseHistoryWithJavaScript(delta);
else
return status;
}
int current_index;
if (!result->GetInteger("currentIndex", &current_index))
......@@ -197,6 +209,16 @@ Status WebViewImpl::TraverseHistory(int delta) {
return client_->SendCommand("Page.navigateToHistoryEntry", params);
}
Status WebViewImpl::TraverseHistoryWithJavaScript(int delta) {
scoped_ptr<base::Value> value;
if (delta == -1)
return EvaluateScript(std::string(), "window.history.back();", &value);
else if (delta == 1)
return EvaluateScript(std::string(), "window.history.forward();", &value);
else
return Status(kUnknownError, "expected delta to be 1 or -1");
}
Status WebViewImpl::EvaluateScript(const std::string& frame,
const std::string& expression,
scoped_ptr<base::Value>* result) {
......
......@@ -96,6 +96,7 @@ class WebViewImpl : public WebView {
Status EndProfile(scoped_ptr<base::Value>* profile_data) override;
private:
Status TraverseHistoryWithJavaScript(int delta);
Status CallAsyncFunctionInternal(const std::string& frame,
const std::string& function,
const base::ListValue& args,
......
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