Commit 976561c8 authored by Alexey Baskakov's avatar Alexey Baskakov Committed by Commit Bot

WebApp: Use base::StrCat and StringPiece in GenerateApplicationNameFromURL

Modernize it.
Add unit test.

Bug: 860581
Change-Id: I136f85f234a843321b49976659f37aa2865ba318
Reviewed-on: https://chromium-review.googlesource.com/1139844
Commit-Queue: Alexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575581}
parent 33663564
...@@ -60,5 +60,6 @@ source_set("unit_tests") { ...@@ -60,5 +60,6 @@ source_set("unit_tests") {
deps = [ deps = [
":web_applications_unit_tests", ":web_applications_unit_tests",
"//chrome/browser/web_applications/bookmark_apps:unit_tests", "//chrome/browser/web_applications/bookmark_apps:unit_tests",
"//chrome/browser/web_applications/components:components_unit_tests",
] ]
} }
...@@ -12,3 +12,17 @@ source_set("components") { ...@@ -12,3 +12,17 @@ source_set("components") {
"//base", "//base",
] ]
} }
source_set("components_unit_tests") {
testonly = true
sources = [
"web_app_helpers_unittest.cc",
]
deps = [
":components",
"//testing/gtest",
"//url",
]
}
...@@ -4,16 +4,13 @@ ...@@ -4,16 +4,13 @@
#include "chrome/browser/web_applications/components/web_app_helpers.h" #include "chrome/browser/web_applications/components/web_app_helpers.h"
#include "base/strings/strcat.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace web_app { namespace web_app {
std::string GenerateApplicationNameFromURL(const GURL& url) { std::string GenerateApplicationNameFromURL(const GURL& url) {
std::string t; return base::StrCat({url.host_piece(), "_", url.path_piece()});
t.append(url.host());
t.append("_");
t.append(url.path());
return t;
} }
} // namespace web_app } // namespace web_app
// Copyright 2018 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/browser/web_applications/components/web_app_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
namespace web_app {
TEST(WebAppHelpers, GenerateApplicationNameFromURL) {
EXPECT_EQ("_", GenerateApplicationNameFromURL(GURL()));
EXPECT_EQ("example.com_/",
GenerateApplicationNameFromURL(GURL("http://example.com")));
EXPECT_EQ("example.com_/path",
GenerateApplicationNameFromURL(GURL("https://example.com/path")));
}
} // namespace web_app
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