Chromium Code Reviews| Index: webkit/glue/user_agent_unittest.cc |
| diff --git a/webkit/glue/user_agent_unittest.cc b/webkit/glue/user_agent_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b79afe9ee134585c3ba73e0059a2dbf246ea966a |
| --- /dev/null |
| +++ b/webkit/glue/user_agent_unittest.cc |
| @@ -0,0 +1,60 @@ |
| +// 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 "webkit/glue/user_agent.h" |
| + |
| +#include <string> |
| + |
| +#include "googleurl/src/gurl.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "webkit/tools/test_shell/test_shell_test.h" |
| + |
| +namespace { |
| + |
| +class WebkitGlueUserAgentTest : public TestShellTest { |
|
tony
2012/08/27 17:58:36
Nit: If you wanted to put this into content_unitte
stuartmorgan
2012/08/28 08:02:12
The test currently relies on the user agent being
|
| +}; |
| + |
| +bool IsSpoofedUserAgent(const std::string& user_agent) { |
| + return user_agent.find("TestShell") == std::string::npos; |
| +} |
| + |
| +TEST_F(WebkitGlueUserAgentTest, UserAgentSpoofingHack) { |
| + enum Platform { |
| + NONE = 0, |
| + MACOSX = 1, |
| + WIN = 2, |
| + OTHER = 4, |
| + }; |
| + |
| + struct Expected { |
| + const char* url; |
| + int os_mask; |
| + }; |
| + |
| + Expected expected[] = { |
| + { "http://wwww.google.com", NONE }, |
| + { "http://www.microsoft.com/getsilverlight", MACOSX }, |
| + { "http://headlines.yahoo.co.jp/videonews/", MACOSX | WIN }, |
| + { "http://downloads.yahoo.co.jp/docs/silverlight/", MACOSX }, |
| + { "http://gyao.yahoo.co.jp/", MACOSX }, |
| + { "http://weather.yahoo.co.jp/weather/zoomradar/", WIN }, |
| + { "http://promotion.shopping.yahoo.co.jp/", WIN }, |
| + { "http://pokemon.kids.yahoo.co.jp", WIN }, |
| + }; |
| +#if defined(OS_MACOSX) |
| + int os_bit = MACOSX; |
| +#elif defined(OS_WIN) |
| + int os_bit = WIN; |
| +#else |
| + int os_bit = OTHER; |
| +#endif |
| + |
| + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(expected); ++i) { |
| + EXPECT_EQ((expected[i].os_mask & os_bit) != 0, |
| + IsSpoofedUserAgent( |
| + webkit_glue::GetUserAgent(GURL(expected[i].url)))); |
| + } |
| +} |
| + |
| +} // namespace |