Title: [205212] trunk
Revision
205212
Author
[email protected]
Date
2016-08-30 17:34:39 -0700 (Tue, 30 Aug 2016)

Log Message

YouTubePluginReplacementTest's URL transformation logic should have tests
https://bugs.webkit.org/show_bug.cgi?id=161406
<rdar://problem/28050847>

Patch by Ricky Mondello <[email protected]> on 2016-08-30
Reviewed by Eric Carlson.

Source/WebCore:

Refactor most of YouTubePluginReplacement::youTubeURL into a static method that can be used by TestWebKitAPI.

* Modules/plugins/YouTubePluginReplacement.cpp:
(WebCore::YouTubePluginReplacement::youTubeURL): Now implemented in terms of youTubeURLFromAbsoluteURL.
(WebCore::YouTubePluginReplacement::youTubeURLFromAbsoluteURL): Absorbs most of youTubeURL.
* Modules/plugins/YouTubePluginReplacement.h: Declare a public method, for the benefit of testing.
* WebCore.xcodeproj/project.pbxproj: Make some heads private for TestWebKitAPI's benefit.

Tools:

Add some very basic tests. Future patches should expand on these to find and fix bugs.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Add YouTubePluginReplacement.cpp.
* TestWebKitAPI/Tests/WebCore/YouTubePluginReplacement.cpp: Added.
(TestWebKitAPI::test): Added.
(TestWebKitAPI::TEST_F): Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (205211 => 205212)


--- trunk/Source/WebCore/ChangeLog	2016-08-31 00:27:27 UTC (rev 205211)
+++ trunk/Source/WebCore/ChangeLog	2016-08-31 00:34:39 UTC (rev 205212)
@@ -1,3 +1,19 @@
+2016-08-30  Ricky Mondello  <[email protected]>
+
+        YouTubePluginReplacementTest's URL transformation logic should have tests
+        https://bugs.webkit.org/show_bug.cgi?id=161406
+        <rdar://problem/28050847>
+
+        Reviewed by Eric Carlson.
+
+        Refactor most of YouTubePluginReplacement::youTubeURL into a static method that can be used by TestWebKitAPI.
+
+        * Modules/plugins/YouTubePluginReplacement.cpp:
+        (WebCore::YouTubePluginReplacement::youTubeURL): Now implemented in terms of youTubeURLFromAbsoluteURL.
+        (WebCore::YouTubePluginReplacement::youTubeURLFromAbsoluteURL): Absorbs most of youTubeURL.
+        * Modules/plugins/YouTubePluginReplacement.h: Declare a public method, for the benefit of testing.
+        * WebCore.xcodeproj/project.pbxproj: Make some heads private for TestWebKitAPI's benefit.
+
 2016-08-30  Frederic Wang  <[email protected]>
 
         Move some code from MathMLElement to MathMLPresentationElement

Modified: trunk/Source/WebCore/Modules/plugins/YouTubePluginReplacement.cpp (205211 => 205212)


--- trunk/Source/WebCore/Modules/plugins/YouTubePluginReplacement.cpp	2016-08-31 00:27:27 UTC (rev 205211)
+++ trunk/Source/WebCore/Modules/plugins/YouTubePluginReplacement.cpp	2016-08-31 00:34:39 UTC (rev 205212)
@@ -283,7 +283,11 @@
 String YouTubePluginReplacement::youTubeURL(const String& srcString)
 {
     URL srcURL = m_parentElement->document().completeURL(stripLeadingAndTrailingHTMLSpaces(srcString));
+    return youTubeURLFromAbsoluteURL(srcURL, srcString);
+}
 
+String YouTubePluginReplacement::youTubeURLFromAbsoluteURL(const URL& srcURL, const String& srcString)
+{
     bool isYouTubeShortenedURL = false;
     URL youTubeURL = processAndCreateYouTubeURL(srcURL, isYouTubeShortenedURL);
     if (srcURL.isEmpty() || youTubeURL.isEmpty())

Modified: trunk/Source/WebCore/Modules/plugins/YouTubePluginReplacement.h (205211 => 205212)


--- trunk/Source/WebCore/Modules/plugins/YouTubePluginReplacement.h	2016-08-31 00:27:27 UTC (rev 205211)
+++ trunk/Source/WebCore/Modules/plugins/YouTubePluginReplacement.h	2016-08-31 00:34:39 UTC (rev 205212)
@@ -38,6 +38,8 @@
 
     typedef HashMap<String, String> KeyValueMap;
 
+    WEBCORE_EXPORT static String youTubeURLFromAbsoluteURL(const URL& srcURL, const String& srcString);
+
 private:
     YouTubePluginReplacement(HTMLPlugInElement&, const Vector<String>& paramNames, const Vector<String>& paramValues);
     static Ref<PluginReplacement> create(HTMLPlugInElement&, const Vector<String>& paramNames, const Vector<String>& paramValues);

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (205211 => 205212)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-08-31 00:27:27 UTC (rev 205211)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-08-31 00:34:39 UTC (rev 205212)
@@ -139,7 +139,7 @@
 		07297FA71C1881C5003F0735 /* UserMediaPermissionCheck.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07297FA51C1881C5003F0735 /* UserMediaPermissionCheck.cpp */; };
 		07297FA81C1881C5003F0735 /* UserMediaPermissionCheck.h in Headers */ = {isa = PBXBuildFile; fileRef = 07297FA61C1881C5003F0735 /* UserMediaPermissionCheck.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		072A70401D6E8F6200DF0AFC /* OverconstrainedErrorEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 072A703E1D6E8F6200DF0AFC /* OverconstrainedErrorEvent.h */; };
-		072AE1E5183C0741000A5988 /* PluginReplacement.h in Headers */ = {isa = PBXBuildFile; fileRef = 072AE1DF183C0741000A5988 /* PluginReplacement.h */; };
+		072AE1E5183C0741000A5988 /* PluginReplacement.h in Headers */ = {isa = PBXBuildFile; fileRef = 072AE1DF183C0741000A5988 /* PluginReplacement.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		072AE1E6183C0741000A5988 /* QuickTimePluginReplacement.mm in Sources */ = {isa = PBXBuildFile; fileRef = 072AE1E0183C0741000A5988 /* QuickTimePluginReplacement.mm */; };
 		072AE1E8183C0741000A5988 /* QuickTimePluginReplacement.h in Headers */ = {isa = PBXBuildFile; fileRef = 072AE1E2183C0741000A5988 /* QuickTimePluginReplacement.h */; };
 		072C8B11131C518600A4FCE9 /* MediaPlayerPrivateAVFoundation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 076F0D0912B8192700C26AA4 /* MediaPlayerPrivateAVFoundation.cpp */; };
@@ -2678,7 +2678,7 @@
 		7A54858014E02D51006AE05A /* InspectorHistory.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A54857E14E02D51006AE05A /* InspectorHistory.h */; };
 		7A54881714E432A1006AE05A /* DOMPatchSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A54881514E432A1006AE05A /* DOMPatchSupport.h */; };
 		7A54881814E432A1006AE05A /* DOMPatchSupport.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A54881614E432A1006AE05A /* DOMPatchSupport.cpp */; };
-		7A5515F5191830A3009687D2 /* YouTubePluginReplacement.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A5515F3191830A3009687D2 /* YouTubePluginReplacement.h */; };
+		7A5515F5191830A3009687D2 /* YouTubePluginReplacement.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A5515F3191830A3009687D2 /* YouTubePluginReplacement.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		7A5515F6191830A3009687D2 /* YouTubePluginReplacement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A5515F4191830A3009687D2 /* YouTubePluginReplacement.cpp */; };
 		7A674BDB0F9EBF4E006CF099 /* PageGroupLoadDeferrer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A674BD90F9EBF4E006CF099 /* PageGroupLoadDeferrer.cpp */; };
 		7A674BDC0F9EBF4E006CF099 /* PageGroupLoadDeferrer.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A674BDA0F9EBF4E006CF099 /* PageGroupLoadDeferrer.h */; };

Modified: trunk/Tools/ChangeLog (205211 => 205212)


--- trunk/Tools/ChangeLog	2016-08-31 00:27:27 UTC (rev 205211)
+++ trunk/Tools/ChangeLog	2016-08-31 00:34:39 UTC (rev 205212)
@@ -1,3 +1,18 @@
+2016-08-30  Ricky Mondello  <[email protected]>
+
+        YouTubePluginReplacementTest's URL transformation logic should have tests
+        https://bugs.webkit.org/show_bug.cgi?id=161406
+        <rdar://problem/28050847>
+
+        Reviewed by Eric Carlson.
+
+        Add some very basic tests. Future patches should expand on these to find and fix bugs.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Add YouTubePluginReplacement.cpp.
+        * TestWebKitAPI/Tests/WebCore/YouTubePluginReplacement.cpp: Added.
+        (TestWebKitAPI::test): Added.
+        (TestWebKitAPI::TEST_F): Added.
+
 2016-08-30  Brady Eidson  <[email protected]>
 
         GameController.framework backend for gamepad API.

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (205211 => 205212)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-08-31 00:27:27 UTC (rev 205211)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-08-31 00:34:39 UTC (rev 205212)
@@ -387,6 +387,7 @@
 		9B0786A51C5885C300D159E3 /* InjectedBundleMakeAllShadowRootOpen_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9B0786A41C5885C300D159E3 /* InjectedBundleMakeAllShadowRootOpen_Bundle.cpp */; };
 		9B26FCCA159D16DE00CC3765 /* HTMLFormCollectionNamedItem.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B26FCB4159D15E700CC3765 /* HTMLFormCollectionNamedItem.html */; };
 		9B4F8FA7159D52DD002D9F94 /* HTMLCollectionNamedItem.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B4F8FA6159D52CA002D9F94 /* HTMLCollectionNamedItem.html */; };
+		9C64DC321D76198A004B598E /* YouTubePluginReplacement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9C64DC311D76198A004B598E /* YouTubePluginReplacement.cpp */; };
 		A1146A8D1D2D7115000FE710 /* ContentFiltering.mm in Sources */ = {isa = PBXBuildFile; fileRef = A1146A8A1D2D704F000FE710 /* ContentFiltering.mm */; };
 		A13EBBAA1B87428D00097110 /* WebProcessPlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = A13EBBA91B87428D00097110 /* WebProcessPlugIn.mm */; };
 		A13EBBAB1B87434600097110 /* PlatformUtilitiesCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F139E721A423A2B00F590F5 /* PlatformUtilitiesCocoa.mm */; };
@@ -954,6 +955,7 @@
 		9B4F8FA3159D52B1002D9F94 /* HTMLCollectionNamedItem.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = HTMLCollectionNamedItem.mm; sourceTree = "<group>"; };
 		9B4F8FA6159D52CA002D9F94 /* HTMLCollectionNamedItem.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = HTMLCollectionNamedItem.html; sourceTree = "<group>"; };
 		9B79164F1BD89D0D00D50B8F /* FirstResponderScrollingPosition.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FirstResponderScrollingPosition.mm; sourceTree = "<group>"; };
+		9C64DC311D76198A004B598E /* YouTubePluginReplacement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YouTubePluginReplacement.cpp; sourceTree = "<group>"; };
 		A1146A8A1D2D704F000FE710 /* ContentFiltering.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ContentFiltering.mm; sourceTree = "<group>"; };
 		A13EBB491B87339E00097110 /* TestWebKitAPI.wkbundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TestWebKitAPI.wkbundle; sourceTree = BUILT_PRODUCTS_DIR; };
 		A13EBB521B87346600097110 /* WebProcessPlugIn.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = WebProcessPlugIn.xcconfig; sourceTree = "<group>"; };
@@ -1347,6 +1349,7 @@
 				7AD3FE8D1D75FB8D00B169A4 /* TransformationMatrix.cpp */,
 				440A1D3814A0103A008A66F2 /* URL.cpp */,
 				5C6E65411D5CEF8500F7862E /* URLParser.cpp */,
+				9C64DC311D76198A004B598E /* YouTubePluginReplacement.cpp */,
 			);
 			path = WebCore;
 			sourceTree = "<group>";
@@ -2375,6 +2378,7 @@
 				2D00065F1C1F589A0088E6A7 /* WKPDFViewResizeCrash.mm in Sources */,
 				7CCE7F211A411AE600447C4C /* WKPreferences.cpp in Sources */,
 				7C83E0B51D0A649300FEBCF3 /* WKRetainPtr.cpp in Sources */,
+				9C64DC321D76198A004B598E /* YouTubePluginReplacement.cpp in Sources */,
 				5E4B1D2E1D404C6100053621 /* WKScrollViewDelegateCrash.mm in Sources */,
 				7CCE7F221A411AE600447C4C /* WKString.cpp in Sources */,
 				7CCE7F1E1A411AE600447C4C /* WKStringJSString.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebCore/YouTubePluginReplacement.cpp (0 => 205212)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/YouTubePluginReplacement.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/YouTubePluginReplacement.cpp	2016-08-31 00:34:39 UTC (rev 205212)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * 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/YouTubePluginReplacement.h>
+#include <wtf/MainThread.h>
+
+using namespace WebCore;
+
+namespace TestWebKitAPI {
+
+class YouTubePluginReplacementTest : public testing::Test {
+public:
+    void SetUp() final {
+        WTF::initializeMainThread();
+    }
+};
+
+static bool test(const String& inputURLString, const String& expectedURLString)
+{
+    URL inputURL(URL(), inputURLString);
+    String actualURLString = YouTubePluginReplacement::youTubeURLFromAbsoluteURL(inputURL, inputURLString);
+    return actualURLString.utf8() == expectedURLString.utf8();
+}
+
+TEST_F(YouTubePluginReplacementTest, YouTubeURLFromAbsoluteURL)
+{
+    // YouTube non-video URL, not expected to be transformed.
+    EXPECT_TRUE(test("https://www.youtube.com", "https://www.youtube.com"));
+
+    // Basic YouTube video links, expected to be transformed.
+    EXPECT_TRUE(test("https://www.youtube.com/v/dQw4w9WgXcQ", "https://www.youtube.com/embed/dQw4w9WgXcQ?showinfo=0"));
+    EXPECT_TRUE(test("http://www.youtube.com/v/dQw4w9WgXcQ", "http://www.youtube.com/embed/dQw4w9WgXcQ?showinfo=0"));
+    EXPECT_TRUE(test("https://youtube.com/v/dQw4w9WgXcQ", "https://youtube.com/embed/dQw4w9WgXcQ?showinfo=0"));
+    EXPECT_TRUE(test("http://youtube.com/v/dQw4w9WgXcQ", "http://youtube.com/embed/dQw4w9WgXcQ?showinfo=0"));
+
+    // With start time, preserved.
+    EXPECT_TRUE(test("http://www.youtube.com/v/dQw4w9WgXcQ?start=4", "http://www.youtube.com/embed/dQw4w9WgXcQ?start=4&showinfo=0"));
+    EXPECT_TRUE(test("http://www.youtube.com/v/dQw4w9WgXcQ?start=4&fs=1", "http://www.youtube.com/embed/dQw4w9WgXcQ?start=4&fs=1&showinfo=0"));
+
+    // Non-Flash URL is untouched.
+    EXPECT_TRUE(test("https://www.youtube.com/embed/dQw4w9WgXcQ", "https://www.youtube.com/embed/dQw4w9WgXcQ"));
+    // Even with an extra parameter.
+    EXPECT_TRUE(test("http://www.youtube.com/embed/dQw4w9WgXcQ?enablejsapi=1", "http://www.youtube.com/embed/dQw4w9WgXcQ?enablejsapi=1"));
+
+    // Non-YouTube domain whose path looks like a Flash video shouldn't be transformed.
+    EXPECT_TRUE(test("https://www.notyoutube.com/v/dQw4w9WgXcQ", "https://www.notyoutube.com/v/dQw4w9WgXcQ"));
+}
+
+} // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to