| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/common/user_agent/user_agent.h" | 5 #include "content/public/common/user_agent.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "url/gurl.h" | 10 #include "url/gurl.h" |
| 11 | 11 |
| 12 namespace content { |
| 13 |
| 12 namespace { | 14 namespace { |
| 13 | 15 |
| 14 typedef testing::Test WebkitGlueUserAgentTest; | |
| 15 | |
| 16 bool IsSpoofedUserAgent(const std::string& user_agent) { | 16 bool IsSpoofedUserAgent(const std::string& user_agent) { |
| 17 return user_agent.find("TestContentClient") == std::string::npos; | 17 return user_agent.find("TestContentClient") == std::string::npos; |
| 18 } | 18 } |
| 19 | 19 |
| 20 TEST_F(WebkitGlueUserAgentTest, UserAgentSpoofingHack) { | 20 } // namespace |
| 21 |
| 22 TEST(UserAgentTest, UserAgentSpoofingHack) { |
| 21 enum Platform { | 23 enum Platform { |
| 22 NONE = 0, | 24 NONE = 0, |
| 23 MACOSX = 1, | 25 MACOSX = 1, |
| 24 WIN = 2, | 26 WIN = 2, |
| 25 OTHER = 4, | 27 OTHER = 4, |
| 26 }; | 28 }; |
| 27 | 29 |
| 28 struct Expected { | 30 struct Expected { |
| 29 const char* url; | 31 const char* url; |
| 30 int os_mask; | 32 int os_mask; |
| 31 }; | 33 }; |
| 32 | 34 |
| 33 Expected expected[] = { | 35 Expected expected[] = { |
| 34 { "http://wwww.google.com", NONE }, | 36 { "http://wwww.google.com", NONE }, |
| 35 { "http://www.microsoft.com/getsilverlight", MACOSX }, | 37 { "http://www.microsoft.com/getsilverlight", MACOSX }, |
| 36 { "http://downloads.yahoo.co.jp/docs/silverlight/", MACOSX }, | 38 { "http://downloads.yahoo.co.jp/docs/silverlight/", MACOSX }, |
| 37 { "http://gyao.yahoo.co.jp/", MACOSX }, | 39 { "http://gyao.yahoo.co.jp/", MACOSX }, |
| 38 { "http://promotion.shopping.yahoo.co.jp/", WIN }, | 40 { "http://promotion.shopping.yahoo.co.jp/", WIN }, |
| 39 }; | 41 }; |
| 40 #if defined(OS_MACOSX) | 42 #if defined(OS_MACOSX) |
| 41 int os_bit = MACOSX; | 43 int os_bit = MACOSX; |
| 42 #elif defined(OS_WIN) | 44 #elif defined(OS_WIN) |
| 43 int os_bit = WIN; | 45 int os_bit = WIN; |
| 44 #else | 46 #else |
| 45 int os_bit = OTHER; | 47 int os_bit = OTHER; |
| 46 #endif | 48 #endif |
| 47 | 49 |
| 48 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(expected); ++i) { | 50 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(expected); ++i) { |
| 49 EXPECT_EQ((expected[i].os_mask & os_bit) != 0, | 51 EXPECT_EQ((expected[i].os_mask & os_bit) != 0, |
| 50 IsSpoofedUserAgent( | 52 IsSpoofedUserAgent(GetUserAgent(GURL(expected[i].url)))); |
| 51 webkit_glue::GetUserAgent(GURL(expected[i].url)))); | |
| 52 } | 53 } |
| 53 } | 54 } |
| 54 | 55 |
| 55 } // namespace | 56 } // namespace content |
| OLD | NEW |