Remove dead 'sizes' parsing code in chrome/renderer/web_apps.cc

It looks like the code in question uses WebIconSizesParser - which
provide the same functionality. Remove the code and transplant relevant
(non-duplicate) tests to WebIconSizesParserTest.

Change-Id: I7b7c4e0140268eddccf858174ee6fd78395a0010
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1545051
Commit-Queue: Jochen Eisinger <jochen@chromium.org>
Auto-Submit: Fredrik Söderquist <fs@opera.com>
Reviewed-by: Jochen Eisinger <jochen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#646010}
diff --git a/chrome/renderer/web_apps.cc b/chrome/renderer/web_apps.cc
index 9598fa0..2be769c 100644
--- a/chrome/renderer/web_apps.cc
+++ b/chrome/renderer/web_apps.cc
@@ -9,13 +9,7 @@
 #include <string>
 #include <vector>
 
-#include "base/json/json_reader.h"
 #include "base/strings/string16.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/string_split.h"
-#include "base/strings/string_util.h"
-#include "base/strings/utf_string_conversions.h"
-#include "base/values.h"
 #include "build/build_config.h"
 #include "chrome/common/web_application_info.h"
 #include "third_party/blink/public/platform/web_icon_sizes_parser.h"
@@ -37,38 +31,6 @@
 namespace web_apps {
 namespace {
 
-// Sizes a single size (the width or height) from a 'sizes' attribute. A size
-// matches must match the following regex: [1-9][0-9]*.
-int ParseSingleIconSize(const base::StringPiece16& text) {
-  // Size must not start with 0, and be between 0 and 9.
-  if (text.empty() || !(text[0] >= L'1' && text[0] <= L'9'))
-    return 0;
-
-  // Make sure all chars are from 0-9.
-  for (size_t i = 1; i < text.length(); ++i) {
-    if (!(text[i] >= L'0' && text[i] <= L'9'))
-      return 0;
-  }
-  int output;
-  if (!base::StringToInt(text, &output))
-    return 0;
-  return output;
-}
-
-// Parses an icon size. An icon size must match the following regex:
-// [1-9][0-9]*x[1-9][0-9]*.
-// If the input couldn't be parsed, a size with a width/height == 0 is returned.
-gfx::Size ParseIconSize(const base::string16& text) {
-  std::vector<base::StringPiece16> sizes = base::SplitStringPiece(
-      text, base::string16(1, 'x'),
-      base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
-  if (sizes.size() != 2)
-    return gfx::Size();
-
-  return gfx::Size(ParseSingleIconSize(sizes[0]),
-                   ParseSingleIconSize(sizes[1]));
-}
-
 void AddInstallIcon(const WebElement& link,
                     std::vector<WebApplicationInfo::IconInfo>* icons) {
   WebString href = link.GetAttribute("href");
@@ -97,30 +59,6 @@
 
 }  // namespace
 
-bool ParseIconSizes(const base::string16& text,
-                    std::vector<gfx::Size>* sizes,
-                    bool* is_any) {
-  *is_any = false;
-  std::vector<base::string16> size_strings = base::SplitString(
-      text, base::kWhitespaceASCIIAs16,
-      base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
-  for (size_t i = 0; i < size_strings.size(); ++i) {
-    if (base::EqualsASCII(size_strings[i], "any")) {
-      *is_any = true;
-    } else {
-      gfx::Size size = ParseIconSize(size_strings[i]);
-      if (size.width() <= 0 || size.height() <= 0)
-        return false;  // Bogus size.
-      sizes->push_back(size);
-    }
-  }
-  if (*is_any && !sizes->empty()) {
-    // If is_any is true, it must occur by itself.
-    return false;
-  }
-  return (*is_any || !sizes->empty());
-}
-
 void ParseWebAppFromWebDocument(WebLocalFrame* frame,
                                 WebApplicationInfo* app_info) {
   WebDocument document = frame->GetDocument();
diff --git a/chrome/renderer/web_apps_unittest.cc b/chrome/renderer/web_apps_unittest.cc
deleted file mode 100644
index 44c3008..0000000
--- a/chrome/renderer/web_apps_unittest.cc
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/renderer/web_apps.h"
-
-#include <stddef.h>
-
-#include "base/stl_util.h"
-#include "base/strings/utf_string_conversions.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-// Tests ParseIconSizes with various input.
-TEST(WebAppInfo, ParseIconSizes) {
-  struct TestData {
-    const char* input;
-    const bool expected_result;
-    const bool is_any;
-    const size_t expected_size_count;
-    const int width1;
-    const int height1;
-    const int width2;
-    const int height2;
-  } data[] = {
-    // Bogus input cases.
-    { "10",         false, false, 0, 0, 0, 0, 0 },
-    { "10 10",      false, false, 0, 0, 0, 0, 0 },
-    { "010",        false, false, 0, 0, 0, 0, 0 },
-    { " 010 ",      false, false, 0, 0, 0, 0, 0 },
-    { " 10x ",      false, false, 0, 0, 0, 0, 0 },
-    { " x10 ",      false, false, 0, 0, 0, 0, 0 },
-    { "any 10x10",  false, false, 0, 0, 0, 0, 0 },
-    { "",           false, false, 0, 0, 0, 0, 0 },
-    { "10ax11",     false, false, 0, 0, 0, 0, 0 },
-
-    // Any.
-    { "any",        true, true, 0, 0, 0, 0, 0 },
-    { " any",       true, true, 0, 0, 0, 0, 0 },
-    { " any ",      true, true, 0, 0, 0, 0, 0 },
-
-    // Sizes.
-    { "10x11",      true, false, 1, 10, 11, 0, 0 },
-    { " 10x11 ",    true, false, 1, 10, 11, 0, 0 },
-    { " 10x11 1x2", true, false, 2, 10, 11, 1, 2 },
-  };
-  for (size_t i = 0; i < base::size(data); ++i) {
-    bool is_any;
-    std::vector<gfx::Size> sizes;
-    bool result = web_apps::ParseIconSizes(
-        base::ASCIIToUTF16(data[i].input), &sizes, &is_any);
-    ASSERT_EQ(result, data[i].expected_result);
-    if (result) {
-      ASSERT_EQ(data[i].is_any, is_any);
-      ASSERT_EQ(data[i].expected_size_count, sizes.size());
-      if (!sizes.empty()) {
-        ASSERT_EQ(data[i].width1, sizes[0].width());
-        ASSERT_EQ(data[i].height1, sizes[0].height());
-      }
-      if (sizes.size() > 1) {
-        ASSERT_EQ(data[i].width2, sizes[1].width());
-        ASSERT_EQ(data[i].height2, sizes[1].height());
-      }
-    }
-  }
-}
diff --git a/chrome/test/BUILD.gn b/chrome/test/BUILD.gn
index d4480fa..6772e1e 100644
--- a/chrome/test/BUILD.gn
+++ b/chrome/test/BUILD.gn
@@ -3000,7 +3000,6 @@
     "../renderer/page_load_metrics/page_timing_metrics_sender_unittest.cc",
     "../renderer/plugins/plugin_uma_unittest.cc",
     "../renderer/prerender/prerender_dispatcher_unittest.cc",
-    "../renderer/web_apps_unittest.cc",
     "../test/base/chrome_render_view_test.cc",
     "../test/base/chrome_render_view_test.h",
     "../test/base/menu_model_test.cc",
diff --git a/third_party/blink/renderer/platform/web_icon_sizes_parser_test.cc b/third_party/blink/renderer/platform/web_icon_sizes_parser_test.cc
index a9807a5..53959c6c 100644
--- a/third_party/blink/renderer/platform/web_icon_sizes_parser_test.cc
+++ b/third_party/blink/renderer/platform/web_icon_sizes_parser_test.cc
@@ -21,6 +21,12 @@
   EXPECT_EQ(32, sizes[0].width);
   EXPECT_EQ(33, sizes[0].height);
 
+  sizes_attribute = " 10x11 ";
+  sizes = WebIconSizesParser::ParseIconSizes(sizes_attribute);
+  ASSERT_EQ(1u, sizes.size());
+  EXPECT_EQ(10, sizes[0].width);
+  EXPECT_EQ(11, sizes[0].height);
+
   sizes_attribute = "0x33";
   sizes = WebIconSizesParser::ParseIconSizes(sizes_attribute);
   ASSERT_EQ(0U, sizes.size());
@@ -60,10 +66,66 @@
   sizes = WebIconSizesParser::ParseIconSizes(sizes_attribute);
   ASSERT_EQ(1U, sizes.size());
 
+  sizes_attribute = " any";
+  sizes = WebIconSizesParser::ParseIconSizes(sizes_attribute);
+  ASSERT_EQ(1U, sizes.size());
+  EXPECT_EQ(0, sizes[0].width);
+  EXPECT_EQ(0, sizes[0].height);
+
+  sizes_attribute = " any ";
+  sizes = WebIconSizesParser::ParseIconSizes(sizes_attribute);
+  ASSERT_EQ(1U, sizes.size());
+  EXPECT_EQ(0, sizes[0].width);
+  EXPECT_EQ(0, sizes[0].height);
+
+  sizes_attribute = "any 10x10";
+  sizes = WebIconSizesParser::ParseIconSizes(sizes_attribute);
+  ASSERT_EQ(2u, sizes.size());
+  EXPECT_EQ(0, sizes[0].width);
+  EXPECT_EQ(0, sizes[0].height);
+  EXPECT_EQ(10, sizes[1].width);
+  EXPECT_EQ(10, sizes[1].height);
+
   sizes_attribute = "an";
   sizes = WebIconSizesParser::ParseIconSizes(sizes_attribute);
   ASSERT_EQ(0U, sizes.size());
 
+  sizes_attribute = "10";
+  sizes = WebIconSizesParser::ParseIconSizes(sizes_attribute);
+  ASSERT_EQ(0U, sizes.size());
+
+  sizes_attribute = "10";
+  sizes = WebIconSizesParser::ParseIconSizes(sizes_attribute);
+  EXPECT_EQ(0u, sizes.size());
+
+  sizes_attribute = "10 10";
+  sizes = WebIconSizesParser::ParseIconSizes(sizes_attribute);
+  EXPECT_EQ(0u, sizes.size());
+
+  sizes_attribute = "010";
+  sizes = WebIconSizesParser::ParseIconSizes(sizes_attribute);
+  EXPECT_EQ(0u, sizes.size());
+
+  sizes_attribute = " 010 ";
+  sizes = WebIconSizesParser::ParseIconSizes(sizes_attribute);
+  EXPECT_EQ(0u, sizes.size());
+
+  sizes_attribute = " 10x ";
+  sizes = WebIconSizesParser::ParseIconSizes(sizes_attribute);
+  EXPECT_EQ(0u, sizes.size());
+
+  sizes_attribute = " x10 ";
+  sizes = WebIconSizesParser::ParseIconSizes(sizes_attribute);
+  EXPECT_EQ(0u, sizes.size());
+
+  sizes_attribute = "";
+  sizes = WebIconSizesParser::ParseIconSizes(sizes_attribute);
+  EXPECT_EQ(0u, sizes.size());
+
+  sizes_attribute = "10ax11";
+  sizes = WebIconSizesParser::ParseIconSizes(sizes_attribute);
+  EXPECT_EQ(0u, sizes.size());
+
   sizes_attribute = "32x33 32";
   sizes = WebIconSizesParser::ParseIconSizes(sizes_attribute);
   ASSERT_EQ(1U, sizes.size());