Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10029)

Unified Diff: chrome/test/chromedriver/chrome/web_view_impl.cc

Issue 783593003: [chromedriver] Add JavaScript fallback for GoBack/GoForward if DevTools commands aren't available (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@back-forward
Patch Set: fix nits Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/chromedriver/chrome/web_view_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/chromedriver/chrome/web_view_impl.cc
diff --git a/chrome/test/chromedriver/chrome/web_view_impl.cc b/chrome/test/chromedriver/chrome/web_view_impl.cc
index 9a366c5d2819a238764c64207f3b12017d84233a..806a82c7145d6f26c7679ced3c221bfb44e3384c 100644
--- a/chrome/test/chromedriver/chrome/web_view_impl.cc
+++ b/chrome/test/chromedriver/chrome/web_view_impl.cc
@@ -172,8 +172,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))
@@ -199,6 +211,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) {
« no previous file with comments | « chrome/test/chromedriver/chrome/web_view_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698