Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "webkit/glue/user_agent.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "googleurl/src/gurl.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 #include "webkit/tools/test_shell/test_shell_test.h" | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 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
| |
| 16 }; | |
| 17 | |
| 18 bool IsSpoofedUserAgent(const std::string& user_agent) { | |
| 19 return user_agent.find("TestShell") == std::string::npos; | |
| 20 } | |
| 21 | |
| 22 TEST_F(WebkitGlueUserAgentTest, UserAgentSpoofingHack) { | |
| 23 enum Platform { | |
| 24 NONE = 0, | |
| 25 MACOSX = 1, | |
| 26 WIN = 2, | |
| 27 OTHER = 4, | |
| 28 }; | |
| 29 | |
| 30 struct Expected { | |
| 31 const char* url; | |
| 32 int os_mask; | |
| 33 }; | |
| 34 | |
| 35 Expected expected[] = { | |
| 36 { "http://wwww.google.com", NONE }, | |
| 37 { "http://www.microsoft.com/getsilverlight", MACOSX }, | |
| 38 { "http://headlines.yahoo.co.jp/videonews/", MACOSX | WIN }, | |
| 39 { "http://downloads.yahoo.co.jp/docs/silverlight/", MACOSX }, | |
| 40 { "http://gyao.yahoo.co.jp/", MACOSX }, | |
| 41 { "http://weather.yahoo.co.jp/weather/zoomradar/", WIN }, | |
| 42 { "http://promotion.shopping.yahoo.co.jp/", WIN }, | |
| 43 { "http://pokemon.kids.yahoo.co.jp", WIN }, | |
| 44 }; | |
| 45 #if defined(OS_MACOSX) | |
| 46 int os_bit = MACOSX; | |
| 47 #elif defined(OS_WIN) | |
| 48 int os_bit = WIN; | |
| 49 #else | |
| 50 int os_bit = OTHER; | |
| 51 #endif | |
| 52 | |
| 53 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(expected); ++i) { | |
| 54 EXPECT_EQ((expected[i].os_mask & os_bit) != 0, | |
| 55 IsSpoofedUserAgent( | |
| 56 webkit_glue::GetUserAgent(GURL(expected[i].url)))); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 } // namespace | |
| OLD | NEW |