Home | History | Annotate | Download | only in user_agent
      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/common/user_agent/user_agent.h"
      6 
      7 #include <string>
      8 
      9 #include "testing/gtest/include/gtest/gtest.h"
     10 #include "url/gurl.h"
     11 
     12 namespace {
     13 
     14 typedef testing::Test WebkitGlueUserAgentTest;
     15 
     16 bool IsSpoofedUserAgent(const std::string& user_agent) {
     17   return user_agent.find("TestContentClient") == std::string::npos;
     18 }
     19 
     20 TEST_F(WebkitGlueUserAgentTest, UserAgentSpoofingHack) {
     21   enum Platform {
     22     NONE = 0,
     23     MACOSX = 1,
     24     WIN = 2,
     25     OTHER = 4,
     26   };
     27 
     28   struct Expected {
     29     const char* url;
     30     int os_mask;
     31   };
     32 
     33   Expected expected[] = {
     34       { "http://wwww.google.com", NONE },
     35       { "http://www.microsoft.com/getsilverlight", MACOSX },
     36       { "http://downloads.yahoo.co.jp/docs/silverlight/", MACOSX },
     37       { "http://gyao.yahoo.co.jp/", MACOSX },
     38       { "http://promotion.shopping.yahoo.co.jp/", WIN },
     39   };
     40 #if defined(OS_MACOSX)
     41   int os_bit = MACOSX;
     42 #elif defined(OS_WIN)
     43   int os_bit = WIN;
     44 #else
     45   int os_bit = OTHER;
     46 #endif
     47 
     48   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(expected); ++i) {
     49     EXPECT_EQ((expected[i].os_mask & os_bit) != 0,
     50               IsSpoofedUserAgent(
     51                   webkit_glue::GetUserAgent(GURL(expected[i].url))));
     52   }
     53 }
     54 
     55 }  // namespace
     56