Chromium Code Reviews| Index: chrome/common/chrome_content_client_unittest.cc |
| diff --git a/chrome/common/chrome_content_client_unittest.cc b/chrome/common/chrome_content_client_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..66006b52eda33a0484d922d28b9a32e14adaf6a9 |
| --- /dev/null |
| +++ b/chrome/common/chrome_content_client_unittest.cc |
| @@ -0,0 +1,77 @@ |
| +// Copyright (c) 2012 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/common/chrome_content_client.h" |
| + |
| +#include "base/command_line.h" |
| +#include "base/string_split.h" |
| +#include "content/public/common/content_switches.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace chrome { |
|
tony
2012/08/28 18:51:25
Nit: This should be in the chrome_common namespace
gone
2012/08/28 20:25:53
I've moved the test into the chrome_common::, but
|
| + |
| +void CheckUserAgentStringOrdering(bool mobile_device) { |
|
tony
2012/08/28 18:51:25
Nit: Maybe use an anonymous namespace for this hel
gone
2012/08/28 20:25:53
Done.
|
| + std::vector<std::string> pieces; |
| + |
| + // Check if the pieces of the user agent string come in the correct order. |
| + 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]; |
| + |
| + // Not sure what can be done to better check the OS string, since it's highly |
| + // platform-dependent. |
| + EXPECT_TRUE(os_str.size() > 0); |
| + |
| + // Check that the version numbers match. |
| + 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) { |
| + // "Mobile" gets tacked on to the end for mobile devices, like phones. |
| + const std::string kMobileStr = " Mobile"; |
| + EXPECT_EQ(kMobileStr, |
| + product_str.substr(product_str.size() - kMobileStr.size())); |
| + } |
| +} |
| + |
| +TEST(ChromeContentClientTest, Basic) { |
| +#if !defined(OS_ANDROID) |
| + CheckUserAgentStringOrdering(false); |
| +#else |
| + // Do it once for mobile devices and once for other devices. |
| + const char* kArguments[] = {"chrome"}; |
| + CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| + command_line->Reset(); |
| + command_line->Init(1, kArguments); |
| + ASSERT_FALSE(command_line->HasSwitch(switches::kUseMobileUserAgent)); |
| + CheckUserAgentStringOrdering(false); |
| + |
| + command_line->AppendSwitch(switches::kUseMobileUserAgent); |
| + ASSERT_TRUE(command_line->HasSwitch(switches::kUseMobileUserAgent)); |
| + CheckUserAgentStringOrdering(true); |
| +#endif |
| +} |
| + |
| +}; |