Commit bf89045b authored by jamescook's avatar jamescook Committed by Commit bot

app_shell: Add version number in user agent

Some sites sniff the Chrome version number, so app_shell needs to
provide one.

BUG=407236
TEST=app_shell_unittests ShellContentClientTest.UserAgentFormat

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

Cr-Commit-Position: refs/heads/master@{#292063}
parent e1608a4f
...@@ -204,6 +204,7 @@ ...@@ -204,6 +204,7 @@
'../test/extensions_unittests_main.cc', '../test/extensions_unittests_main.cc',
'browser/shell_desktop_controller_unittest.cc', 'browser/shell_desktop_controller_unittest.cc',
'browser/shell_nacl_browser_delegate_unittest.cc', 'browser/shell_nacl_browser_delegate_unittest.cc',
'common/shell_content_client_unittest.cc'
], ],
'conditions': [ 'conditions': [
['disable_nacl==1', { ['disable_nacl==1', {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "content/public/common/user_agent.h" #include "content/public/common/user_agent.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "extensions/shell/common/version.h" // Generated file.
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
...@@ -83,9 +84,9 @@ void ShellContentClient::AddAdditionalSchemes( ...@@ -83,9 +84,9 @@ void ShellContentClient::AddAdditionalSchemes(
} }
std::string ShellContentClient::GetUserAgent() const { std::string ShellContentClient::GetUserAgent() const {
// TODO(derat): Figure out what this should be for app_shell and determine // Must contain a user agent string for version sniffing. For example,
// whether we need to include a version number to placate browser sniffing. // pluginless WebRTC Hangouts checks the Chrome version number.
return content::BuildUserAgentFromProduct("Chrome"); return content::BuildUserAgentFromProduct("Chrome/" PRODUCT_VERSION);
} }
base::string16 ShellContentClient::GetLocalizedString(int message_id) const { base::string16 ShellContentClient::GetLocalizedString(int message_id) const {
......
// Copyright 2014 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 "extensions/shell/common/shell_content_client.h"
#include <string>
#include "base/strings/string_util.h"
#include "testing/gtest/include/gtest/gtest.h"
typedef testing::Test ShellContentClientTest;
namespace extensions {
// Tests that the app_shell user agent looks like a Chrome user agent.
TEST_F(ShellContentClientTest, UserAgentFormat) {
ShellContentClient client;
std::string user_agent = client.GetUserAgent();
// Must start with the usual Mozilla-compatibility string.
EXPECT_TRUE(StartsWithASCII(user_agent, "Mozilla/5.0", false)) << user_agent;
// Must contain a substring like "Chrome/1.2.3.4".
EXPECT_TRUE(MatchPattern(user_agent, "*Chrome/*.*.*.*")) << user_agent;
}
} // namespace extensions
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