[GTK] Use a different user agent string depending on the site
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Jun 2014 07:38:35 +0000 (07:38 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Jun 2014 07:38:35 +0000 (07:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=132681

Reviewed by Anders Carlsson.

Source/WebCore:
We have changed the user agent string several times to try to fix
broken websites that require specific things in the UA string to
properly work. But everytime we change the UA string to fix a
website we break others. We could use different UA string
depending on the website. UserAgentGtk code has also been cleaned
up, using NeverDestroyed instead of DEPRECATED_DEFINE_STATIC_LOCAL
and avoiding unneeded conversions to UTF-8.

* platform/gtk/UserAgentGtk.cpp:
(WebCore::UserAgentQuirks::UserAgentQuirks): New helper private
class to handle user agent quirks.
(WebCore::UserAgentQuirks::add):
(WebCore::UserAgentQuirks::contains):
(WebCore::UserAgentQuirks::isEmpty):
(WebCore::platformForUAString): Bring back this method that was
removed to always pretend to be Macintosh.
(WebCore::platformVersionForUAString): Return a different platform
version depending on the actual platform.
(WebCore::versionForUAString): Return the WebKit version.
(WebCore::buildUserAgentString): Helper function to build the user
agent taking into account the UserAgentQuirks received.
(WebCore::standardUserAgentStatic): Standard user agent string
when no quirks are present.
(WebCore::standardUserAgent):
(WebCore::standardUserAgentForURL): New method that returns the
user agent string for the given URL.
* platform/gtk/UserAgentGtk.h:

Source/WebKit2:
* UIProcess/API/gtk/WebKitSettings.cpp:
(webkit_settings_class_init): Enable site specific quirks setting
by default.
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::userAgent): Pass the given URL to WebPage.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::userAgent): Try to get the user agent for the
URL received falling back to the current one otherwise.
* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::platformUserAgent): Added.
* WebProcess/WebPage/efl/WebPageEfl.cpp:
(WebKit::WebPage::platformUserAgent): Return null String.
* WebProcess/WebPage/gtk/WebPageGtk.cpp:
(WebKit::WebPage::platformUserAgent): Use WebCore::standardUserAgentForURL() when site specific quirks
setting is enabled.
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::platformUserAgent): Return null String.
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::platformUserAgent): Return null String.

Tools:
Add a unit test to check user agent quirks.

* TestWebKitAPI/PlatformGTK.cmake:
* TestWebKitAPI/Tests/WebCore/gtk/UserAgentQuirks.cpp: Added.
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSettings.cpp:
(testWebKitSettings): Site specific quirks setting is now enabled
by default.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@169799 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/gtk/UserAgentGtk.cpp
Source/WebCore/platform/gtk/UserAgentGtk.h
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/efl/WebPageEfl.cpp
Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp
Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm
Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm
Tools/ChangeLog
Tools/TestWebKitAPI/PlatformGTK.cmake
Tools/TestWebKitAPI/Tests/WebCore/gtk/UserAgentQuirks.cpp [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSettings.cpp

index f2af9b5..319f101 100644 (file)
@@ -1,3 +1,38 @@
+2014-06-11  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Use a different user agent string depending on the site
+        https://bugs.webkit.org/show_bug.cgi?id=132681
+
+        Reviewed by Anders Carlsson.
+
+        We have changed the user agent string several times to try to fix
+        broken websites that require specific things in the UA string to
+        properly work. But everytime we change the UA string to fix a
+        website we break others. We could use different UA string
+        depending on the website. UserAgentGtk code has also been cleaned
+        up, using NeverDestroyed instead of DEPRECATED_DEFINE_STATIC_LOCAL
+        and avoiding unneeded conversions to UTF-8.
+
+        * platform/gtk/UserAgentGtk.cpp:
+        (WebCore::UserAgentQuirks::UserAgentQuirks): New helper private
+        class to handle user agent quirks.
+        (WebCore::UserAgentQuirks::add):
+        (WebCore::UserAgentQuirks::contains):
+        (WebCore::UserAgentQuirks::isEmpty):
+        (WebCore::platformForUAString): Bring back this method that was
+        removed to always pretend to be Macintosh.
+        (WebCore::platformVersionForUAString): Return a different platform
+        version depending on the actual platform.
+        (WebCore::versionForUAString): Return the WebKit version.
+        (WebCore::buildUserAgentString): Helper function to build the user
+        agent taking into account the UserAgentQuirks received.
+        (WebCore::standardUserAgentStatic): Standard user agent string
+        when no quirks are present.
+        (WebCore::standardUserAgent):
+        (WebCore::standardUserAgentForURL): New method that returns the
+        user agent string for the given URL.
+        * platform/gtk/UserAgentGtk.h:
+
 2014-06-11  Alex Christensen  <achristensen@webkit.org>
 
         [Win] Unreviewed build fix.
index e1cc0b5..4d5800d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Igalia S.L.
+ * Copyright (C) 2012, 2014 Igalia S.L.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,7 +26,9 @@
 #include "config.h"
 #include "UserAgentGtk.h"
 
-#include <glib.h>
+#include "URL.h"
+#include <wtf/NeverDestroyed.h>
+#include <wtf/text/StringBuilder.h>
 
 #if OS(UNIX)
 #include <sys/utsname.h>
 
 namespace WebCore {
 
+class UserAgentQuirks {
+public:
+    enum UserAgentQuirk {
+        NeedsSafariVersion6,
+        NeedsMacintoshPlatform,
+
+        NumUserAgentQuirks
+    };
+
+    UserAgentQuirks()
+        : m_quirks(0)
+    {
+        COMPILE_ASSERT(sizeof(m_quirks) * 8 >= NumUserAgentQuirks, not_enough_room_for_quirks);
+    }
+
+    void add(UserAgentQuirk quirk)
+    {
+        ASSERT(quirk >= 0);
+        ASSERT_WITH_SECURITY_IMPLICATION(quirk < NumUserAgentQuirks);
+
+        m_quirks |= (1 << quirk);
+    }
+
+    bool contains(UserAgentQuirk quirk) const
+    {
+        return m_quirks & (1 << quirk);
+    }
+
+    bool isEmpty() const { return !m_quirks; }
+
+private:
+    uint32_t m_quirks;
+};
+
 static const char* cpuDescriptionForUAString()
 {
 #if CPU(PPC) || CPU(PPC64)
@@ -47,16 +83,75 @@ static const char* cpuDescriptionForUAString()
 #endif
 }
 
-static String platformVersionForUAString()
+static const char* platformForUAString()
 {
-    DEPRECATED_DEFINE_STATIC_LOCAL(String, uaOSVersion, (String()));
-    if (!uaOSVersion.isEmpty())
-        return uaOSVersion;
+#if PLATFORM(X11)
+    return "X11";
+#elif OS(WINDOWS)
+    return "";
+#elif PLATFORM(MAC)
+    return "Macintosh";
+#elif defined(GDK_WINDOWING_DIRECTFB)
+    return "DirectFB";
+#else
+    return "Unknown";
+#endif
+}
 
-    // We will always claim to be Safari in Mac OS X, since Safari in Linux triggers the iOS path on
-    // some websites.
-    uaOSVersion = String::format("%s Mac OS X", cpuDescriptionForUAString());
+static const String platformVersionForUAString()
+{
+#if OS(UNIX)
+    struct utsname name;
+    uname(&name);
+    static NeverDestroyed<const String> uaOSVersion(String::format("%s %s", name.sysname, name.machine));
     return uaOSVersion;
+#else
+    // We will always claim to be Safari in Mac OS X, since Safari in Linux triggers the iOS path on some websites.
+    static NeverDestroyed<const String> uaOSVersion(String::format("%s Mac OS X", cpuDescriptionForUAString()));
+    return uaOSVersion;
+#endif
+}
+
+static const String versionForUAString()
+{
+    static NeverDestroyed<const String> uaVersion(String::format("%i.%i", USER_AGENT_GTK_MAJOR_VERSION, USER_AGENT_GTK_MINOR_VERSION));
+    return uaVersion;
+}
+
+static String buildUserAgentString(const UserAgentQuirks& quirks)
+{
+    StringBuilder uaString;
+    uaString.appendLiteral("Mozilla/5.0 ");
+    uaString.append('(');
+
+    if (quirks.contains(UserAgentQuirks::NeedsMacintoshPlatform))
+        uaString.appendLiteral("Macintosh");
+    else
+        uaString.append(platformForUAString());
+
+    uaString.appendLiteral("; ");
+
+    if (quirks.contains(UserAgentQuirks::NeedsMacintoshPlatform)) {
+        uaString.append(cpuDescriptionForUAString());
+        uaString.appendLiteral(" Mac OS X");
+    } else
+        uaString.append(platformVersionForUAString());
+
+    uaString.appendLiteral(") AppleWebKit/");
+    uaString.append(versionForUAString());
+    uaString.appendLiteral(" (KHTML, like Gecko) Safari/");
+    uaString.append(versionForUAString());
+
+    if (quirks.contains(UserAgentQuirks::NeedsSafariVersion6))
+        uaString.appendLiteral(" Version/6.0");
+
+    return uaString.toString();
+}
+
+static const String standardUserAgentStatic()
+{
+    static NeverDestroyed<const String> uaStatic(buildUserAgentString(UserAgentQuirks()));
+    return uaStatic;
 }
 
 String standardUserAgent(const String& applicationName, const String& applicationVersion)
@@ -69,18 +164,32 @@ String standardUserAgent(const String& applicationName, const String& applicatio
     // browsers that are "Safari" but not running on OS X are the Safari iOS browse. Getting this
     // wrong can cause sites to load the wrong JavaScript, CSS, or custom fonts. In some cases
     // sites won't load resources at all.
-    DEPRECATED_DEFINE_STATIC_LOCAL(const CString, uaVersion, (String::format("%i.%i", USER_AGENT_GTK_MAJOR_VERSION, USER_AGENT_GTK_MINOR_VERSION).utf8()));
-    DEPRECATED_DEFINE_STATIC_LOCAL(const String, staticUA, (String::format("Mozilla/5.0 (Macintosh; %s) AppleWebKit/%s (KHTML, like Gecko) Safari/%s Version/6.0",
-        platformVersionForUAString().utf8().data(), uaVersion.data(), uaVersion.data())));
-
     if (applicationName.isEmpty())
-        return staticUA;
+        return standardUserAgentStatic();
 
     String finalApplicationVersion = applicationVersion;
     if (finalApplicationVersion.isEmpty())
-        finalApplicationVersion = uaVersion.data();
+        finalApplicationVersion = versionForUAString();
+
+    return standardUserAgentStatic() + applicationName + '/' + finalApplicationVersion;
+}
+
+String standardUserAgentForURL(const URL& url)
+{
+    ASSERT(!url.isNull());
+    UserAgentQuirks quirks;
+    if (url.host().endsWith(".yahoo.com")) {
+        // www.yahoo.com redirects to the mobile version when Linux is present in the UA,
+        // use always Macintosh as platform. See https://bugs.webkit.org/show_bug.cgi?id=125444.
+        quirks.add(UserAgentQuirks::NeedsMacintoshPlatform);
+    } else if (url.host().endsWith(".globalforestwatch.org")) {
+        // www.globalforestwatch.org fails to redirect when Safari Version 6 is not present in the UA.
+        // See https://bugs.webkit.org/show_bug.cgi?id=129681.
+        quirks.add(UserAgentQuirks::NeedsSafariVersion6);
+    }
 
-    return String::format("%s %s/%s", staticUA.utf8().data(), applicationName.utf8().data(), finalApplicationVersion.utf8().data());
+    // The null string means we don't need a specific UA for the given URL.
+    return quirks.isEmpty() ? String() : buildUserAgentString(quirks);
 }
 
 } // namespace WebCore
index 164dd36..48aca29 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Igalia S.L.
+ * Copyright (C) 2012, 2014 Igalia S.L.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #ifndef UserAgentGtk_h
 #define UserAgentGtk_h
 
-#include <wtf/text/CString.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
+class URL;
 
-String standardUserAgent(const String& applicationName = "", const String& applicationVersion = "");
+String standardUserAgent(const String& applicationName = emptyString(), const String& applicationVersion = emptyString());
+String standardUserAgentForURL(const URL&);
 
 }
 
index 58c85d6..131b3c2 100644 (file)
@@ -1,3 +1,30 @@
+2014-06-11  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Use a different user agent string depending on the site
+        https://bugs.webkit.org/show_bug.cgi?id=132681
+
+        Reviewed by Anders Carlsson.
+
+        * UIProcess/API/gtk/WebKitSettings.cpp:
+        (webkit_settings_class_init): Enable site specific quirks setting
+        by default.
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebKit::WebFrameLoaderClient::userAgent): Pass the given URL to WebPage.
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::userAgent): Try to get the user agent for the
+        URL received falling back to the current one otherwise.
+        * WebProcess/WebPage/WebPage.h:
+        (WebKit::WebPage::platformUserAgent): Added.
+        * WebProcess/WebPage/efl/WebPageEfl.cpp:
+        (WebKit::WebPage::platformUserAgent): Return null String.
+        * WebProcess/WebPage/gtk/WebPageGtk.cpp:
+        (WebKit::WebPage::platformUserAgent): Use WebCore::standardUserAgentForURL() when site specific quirks
+        setting is enabled.
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::platformUserAgent): Return null String.
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::platformUserAgent): Return null String.
+
 2014-06-10  Benjamin Poulain  <benjamin@webkit.org>
 
         [iOS][WK2] ScrollingTreeOverflowScrollingNode does not use asynchronous touch dispatch
index 99bbe29..e96ba13 100644 (file)
@@ -1056,13 +1056,15 @@ static void webkit_settings_class_init(WebKitSettingsClass* klass)
      * workarounds. By turning on site-specific quirks, WebKit will
      * special-case this and other cases to make some specific sites work.
      */
-    g_object_class_install_property(gObjectClass,
-                                    PROP_ENABLE_SITE_SPECIFIC_QUIRKS,
-                                    g_param_spec_boolean("enable-site-specific-quirks",
-                                                         _("Enable Site Specific Quirks"),
-                                                         _("Enables the site-specific compatibility workarounds"),
-                                                         FALSE,
-                                                         readWriteConstructParamFlags));
+    g_object_class_install_property(
+        gObjectClass,
+        PROP_ENABLE_SITE_SPECIFIC_QUIRKS,
+        g_param_spec_boolean(
+            "enable-site-specific-quirks",
+            _("Enable Site Specific Quirks"),
+            _("Enables the site-specific compatibility workarounds"),
+            TRUE,
+            readWriteConstructParamFlags));
 
     /**
      * WebKitSettings:enable-page-cache:
index 0c36f95..d374ca3 100644 (file)
@@ -1181,13 +1181,13 @@ void WebFrameLoaderClient::setTitle(const StringWithDirection& title, const URL&
         title.string(), url.string(), m_frame->frameID()), 0);
 }
 
-String WebFrameLoaderClient::userAgent(const URL&)
+String WebFrameLoaderClient::userAgent(const URL& url)
 {
     WebPage* webPage = m_frame->page();
     if (!webPage)
         return String();
 
-    return webPage->userAgent();
+    return webPage->userAgent(url);
 }
 
 void WebFrameLoaderClient::savePlatformDataToCachedFrame(CachedFrame*)
index d0d917e..01d824f 100644 (file)
@@ -2284,6 +2284,15 @@ void WebPage::setUserAgent(const String& userAgent)
     m_userAgent = userAgent;
 }
 
+String WebPage::userAgent(const URL& url) const
+{
+    String userAgent = platformUserAgent(url);
+    if (!userAgent.isEmpty())
+        return userAgent;
+
+    return m_userAgent;
+}
+
 void WebPage::suspendActiveDOMObjectsAndAnimations()
 {
     m_page->suspendActiveDOMObjectsAndAnimations();
index 0ba7901..4fe225a 100644 (file)
@@ -128,6 +128,7 @@ class ResourceRequest;
 class SharedBuffer;
 class SubstituteData;
 class TextCheckingRequest;
+class URL;
 class VisibleSelection;
 struct KeypressCommand;
 struct TextCheckingResult;
@@ -252,7 +253,8 @@ public:
     void didFinishDocumentLoad(WebFrame*);
     void didFinishLoad(WebFrame*);
     void show();
-    String userAgent() const { return m_userAgent; }
+    String userAgent(const WebCore::URL&) const;
+    String platformUserAgent(const WebCore::URL&) const;
     WebCore::IntRect windowResizerRect() const;
     WebCore::KeyboardUIMode keyboardUIMode();
 
index 74aed37..51c9d8e 100644 (file)
@@ -220,4 +220,9 @@ void WebPage::cancelComposition()
     frame.editor().cancelComposition();
 }
 
+String WebPage::platformUserAgent(const URL&) const
+{
+    return String();
+}
+
 } // namespace WebKit
index bb55088..338cf56 100644 (file)
@@ -42,6 +42,7 @@
 #include <WebCore/PasteboardHelper.h>
 #include <WebCore/PlatformKeyboardEvent.h>
 #include <WebCore/Settings.h>
+#include <WebCore/UserAgentGtk.h>
 #include <wtf/gobject/GUniquePtr.h>
 
 using namespace WebCore;
@@ -168,4 +169,12 @@ void WebPage::setAcceleratedCompositingWindowId(int64_t nativeWindowHandle)
 }
 #endif
 
+String WebPage::platformUserAgent(const URL& url) const
+{
+    if (url.isNull() || !m_page->settings().needsSiteSpecificQuirks())
+        return String();
+
+    return WebCore::standardUserAgentForURL(url);
+}
+
 } // namespace WebKit
index 175a763..35239c7 100644 (file)
@@ -2406,6 +2406,11 @@ void WebPage::contentSizeCategoryDidChange(const String& contentSizeCategory)
     Page::updateStyleForAllPagesAfterGlobalChangeInEnvironment();
 }
 
+String WebPage::platformUserAgent(const URL&) const
+{
+    return String();
+}
+
 } // namespace WebKit
 
 #endif // PLATFORM(IOS)
index 46f655d..d8cc59a 100644 (file)
@@ -761,7 +761,7 @@ WKAccessibilityWebPageObject* WebPage::accessibilityRemoteObject()
 bool WebPage::platformHasLocalDataForURL(const WebCore::URL& url)
 {
     NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:url];
-    [request setValue:(NSString*)userAgent() forHTTPHeaderField:@"User-Agent"];
+    [request setValue:(NSString*)userAgent(url) forHTTPHeaderField:@"User-Agent"];
     NSCachedURLResponse *cachedResponse;
     if (CFURLStorageSessionRef storageSession = corePage()->mainFrame().loader().networkingContext()->storageSession().platformSession())
         cachedResponse = WKCachedResponseForRequest(storageSession, request);
@@ -775,7 +775,7 @@ bool WebPage::platformHasLocalDataForURL(const WebCore::URL& url)
 static NSCachedURLResponse *cachedResponseForURL(WebPage* webPage, const URL& url)
 {
     RetainPtr<NSMutableURLRequest> request = adoptNS([[NSMutableURLRequest alloc] initWithURL:url]);
-    [request setValue:(NSString *)webPage->userAgent() forHTTPHeaderField:@"User-Agent"];
+    [request setValue:(NSString *)webPage->userAgent(url) forHTTPHeaderField:@"User-Agent"];
 
     if (CFURLStorageSessionRef storageSession = webPage->corePage()->mainFrame().loader().networkingContext()->storageSession().platformSession())
         return WKCachedResponseForRequest(storageSession, request.get());
@@ -1043,6 +1043,11 @@ void WebPage::handleSelectionServiceClick(FrameSelection& selection, const IntPo
 }
 #endif
 
+String WebPage::platformUserAgent(const URL&) const
+{
+    return String();
+}
+
 } // namespace WebKit
 
 #endif // PLATFORM(MAC)
index ebdf722..a6b77f6 100644 (file)
@@ -1,3 +1,19 @@
+2014-06-11  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Use a different user agent string depending on the site
+        https://bugs.webkit.org/show_bug.cgi?id=132681
+
+        Reviewed by Anders Carlsson.
+
+        Add a unit test to check user agent quirks.
+
+        * TestWebKitAPI/PlatformGTK.cmake:
+        * TestWebKitAPI/Tests/WebCore/gtk/UserAgentQuirks.cpp: Added.
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSettings.cpp:
+        (testWebKitSettings): Site specific quirks setting is now enabled
+        by default.
+
 2014-06-10  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
 
         Unreviewed, update my list of email addresses in contributors.json.
index 0cbe247..844489e 100644 (file)
@@ -119,6 +119,7 @@ set(TestWebCoreGtk_SOURCES
     ${WEBCORE_DIR}/platform/graphics/gtk/IntRectGtk.cpp
     ${WEBCORE_DIR}/platform/gtk/GtkInputMethodFilter.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/gtk/InputMethodFilter.cpp
+    ${TESTWEBKITAPI_DIR}/Tests/WebCore/gtk/UserAgentQuirks.cpp
 )
 
 add_executable(TestWebCore
diff --git a/Tools/TestWebKitAPI/Tests/WebCore/gtk/UserAgentQuirks.cpp b/Tools/TestWebKitAPI/Tests/WebCore/gtk/UserAgentQuirks.cpp
new file mode 100644 (file)
index 0000000..8c174f7
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include <WebCore/URL.h>
+#include <WebCore/UserAgentGtk.h>
+
+using namespace WebCore;
+
+namespace TestWebKitAPI {
+
+TEST(WebCore, UserAgentQuirksTest)
+{
+    // A site with not quirks should return a null String.
+    String uaString = standardUserAgentForURL(URL(ParsedURLString, "http://www.webkit.org/"));
+    EXPECT_TRUE(uaString.isNull());
+
+    // www.yahoo.com requires MAC OS platform in the UA.
+    uaString = standardUserAgentForURL(URL(ParsedURLString, "http://www.yahoo.com/"));
+    EXPECT_TRUE(uaString.contains("Macintosh"));
+    EXPECT_TRUE(uaString.contains("Mac OS X"));
+    EXPECT_FALSE(uaString.contains("Linux"));
+
+    // www.globalforestwatch.org requires Safari Version 6.
+    uaString = standardUserAgentForURL(URL(ParsedURLString, "http://www.globalforestwatch.org"));
+    EXPECT_TRUE(uaString.endsWith("Version/6.0"));
+}
+
+} // namespace TestWebKitAPI
index 60f964e..a4f7da1 100644 (file)
@@ -233,10 +233,10 @@ static void testWebKitSettings(Test*, gconstpointer)
     webkit_settings_set_draw_compositing_indicators(settings, TRUE);
     g_assert(webkit_settings_get_draw_compositing_indicators(settings));
 
-    // By default, site specific quirks are disabled.
-    g_assert(!webkit_settings_get_enable_site_specific_quirks(settings));
-    webkit_settings_set_enable_site_specific_quirks(settings, TRUE);
+    // By default, site specific quirks are enabled.
     g_assert(webkit_settings_get_enable_site_specific_quirks(settings));
+    webkit_settings_set_enable_site_specific_quirks(settings, FALSE);
+    g_assert(!webkit_settings_get_enable_site_specific_quirks(settings));
 
     // By default, page cache is enabled.
     g_assert(webkit_settings_get_enable_page_cache(settings));