This source file includes following definitions.
- CheckUserAgentStringOrdering
- TEST
#include "chrome/common/chrome_content_client.h"
#include "base/command_line.h"
#include "base/strings/string_split.h"
#include "content/public/common/content_switches.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
void CheckUserAgentStringOrdering(bool mobile_device) {
std::vector<std::string> pieces;
ChromeContentClient content_client;
std::string buffer = content_client.GetUserAgent();
base::SplitStringUsingSubstr(buffer, "Mozilla/5.0 (", &pieces);
ASSERT_EQ(2u, pieces.size());
buffer = pieces[1];
EXPECT_EQ("", pieces[0]);
base::SplitStringUsingSubstr(buffer, ") AppleWebKit/", &pieces);
ASSERT_EQ(2u, pieces.size());
buffer = pieces[1];
std::string os_str = pieces[0];
base::SplitStringUsingSubstr(buffer, " (KHTML, like Gecko) ", &pieces);
ASSERT_EQ(2u, pieces.size());
buffer = pieces[1];
std::string webkit_version_str = pieces[0];
base::SplitStringUsingSubstr(buffer, " Safari/", &pieces);
ASSERT_EQ(2u, pieces.size());
std::string product_str = pieces[0];
std::string safari_version_str = pieces[1];
EXPECT_TRUE(os_str.size() > 0);
EXPECT_TRUE(webkit_version_str.size() > 0);
EXPECT_TRUE(safari_version_str.size() > 0);
EXPECT_EQ(webkit_version_str, safari_version_str);
EXPECT_EQ(0u, product_str.find("Chrome/"));
if (mobile_device) {
const std::string kMobileStr = " Mobile";
EXPECT_EQ(kMobileStr,
product_str.substr(product_str.size() - kMobileStr.size()));
}
}
}
namespace chrome_common {
TEST(ChromeContentClientTest, Basic) {
#if !defined(OS_ANDROID)
CheckUserAgentStringOrdering(false);
#else
const char* kArguments[] = {"chrome"};
CommandLine::Reset();
CommandLine::Init(1, kArguments);
CommandLine* command_line = CommandLine::ForCurrentProcess();
ASSERT_FALSE(command_line->HasSwitch(switches::kUseMobileUserAgent));
CheckUserAgentStringOrdering(false);
command_line->AppendSwitch(switches::kUseMobileUserAgent);
ASSERT_TRUE(command_line->HasSwitch(switches::kUseMobileUserAgent));
CheckUserAgentStringOrdering(true);
#endif
}
}