Add headless chrome as an accepted browser string in chromedriver.

This is working towards selenium support for headless see https://bugs.chromium.org/p/chromium/issues/detail?id=604324

BUG=699382,604324

Review-Url: https://codereview.chromium.org/2731403008
Cr-Commit-Position: refs/heads/master@{#456660}
diff --git a/chrome/test/chromedriver/chrome/browser_info.cc b/chrome/test/chromedriver/chrome/browser_info.cc
index c790bfd..5ec042d 100644
--- a/chrome/test/chromedriver/chrome/browser_info.cc
+++ b/chrome/test/chromedriver/chrome/browser_info.cc
@@ -19,6 +19,9 @@
 const char kVersionPrefix[] = "Chrome/";
 const size_t kVersionPrefixLen = sizeof(kVersionPrefix) - 1;
 
+const char kHeadlessVersionPrefix[] = "HeadlessChrome/";
+const size_t kHeadlessVersionPrefixLen = sizeof(kHeadlessVersionPrefix) - 1;
+
 }  // namespace
 
 BrowserInfo::BrowserInfo()
@@ -86,10 +89,21 @@
     return Status(kOk);
   }
 
+  const Status error =
+      Status(kUnknownError, "unrecognized Chrome version: " + browser_string);
+
   int build_no = 0;
   if (base::StartsWith(browser_string, kVersionPrefix,
+                       base::CompareCase::SENSITIVE) ||
+      base::StartsWith(browser_string, kHeadlessVersionPrefix,
                        base::CompareCase::SENSITIVE)) {
     std::string version = browser_string.substr(kVersionPrefixLen);
+    bool headless = false;
+    if (base::StartsWith(browser_string, kHeadlessVersionPrefix,
+                         base::CompareCase::SENSITIVE)) {
+      version = browser_string.substr(kHeadlessVersionPrefixLen);
+      headless = true;
+    }
 
     Status status = ParseBrowserVersionString(
         version, &browser_info->major_version, &build_no);
@@ -97,7 +111,10 @@
       return status;
 
     if (build_no != 0) {
-      browser_info->browser_name = "chrome";
+      if (headless)
+        browser_info->browser_name = "headless chrome";
+      else
+        browser_info->browser_name = "chrome";
       browser_info->browser_version = version;
       browser_info->build_no = build_no;
       return Status(kOk);
@@ -118,8 +135,7 @@
     return Status(kOk);
   }
 
-  return Status(kUnknownError,
-                "unrecognized Chrome version: " + browser_string);
+  return error;
 }
 
 Status ParseBrowserVersionString(const std::string& browser_version,
diff --git a/chrome/test/chromedriver/chrome/browser_info_unittest.cc b/chrome/test/chromedriver/chrome/browser_info_unittest.cc
index c33f771..b131d0a 100644
--- a/chrome/test/chromedriver/chrome/browser_info_unittest.cc
+++ b/chrome/test/chromedriver/chrome/browser_info_unittest.cc
@@ -103,6 +103,18 @@
   ASSERT_FALSE(browser_info.is_android);
 }
 
+TEST(ParseBrowserString, HeadlessChrome) {
+  BrowserInfo browser_info;
+  Status status =
+      ParseBrowserString(false, "HeadlessChrome/39.0.2171.59", &browser_info);
+  ASSERT_TRUE(status.IsOk());
+  ASSERT_EQ("headless chrome", browser_info.browser_name);
+  ASSERT_EQ("39.0.2171.59", browser_info.browser_version);
+  ASSERT_EQ(39, browser_info.major_version);
+  ASSERT_EQ(2171, browser_info.build_no);
+  ASSERT_FALSE(browser_info.is_android);
+}
+
 TEST(ParseBlinkVersionString, GitHash) {
   int rev = -1;
   Status status = ParseBlinkVersionString(