MemoryCache::addImageToCache should return the result of add().
authormhock@apple.com <mhock@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 May 2014 17:07:09 +0000 (17:07 +0000)
committermhock@apple.com <mhock@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 May 2014 17:07:09 +0000 (17:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=132928
<rdar://problem/16651547>

Reviewed by Alexey Proskuryakov.

Source/WebCore:
API test: WebKit1.MemoryCacheADdImageToCache (MemoryCacheAddImageToCacheIOS.mm)

* loader/cache/MemoryCache.cpp:
(WebCore::MemoryCache::addImageToCache):

Tools:
* TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/ios/MemoryCacheAddImageToCacheIOS.mm: Added.
(TestWebKitAPI::TEST):

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

Source/WebCore/ChangeLog
Source/WebCore/loader/cache/MemoryCache.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/ios/MemoryCacheAddImageToCacheIOS.mm [new file with mode: 0644]

index 54d3b24..81eb632 100644 (file)
@@ -1,3 +1,16 @@
+2014-05-16  Martin Hock  <mhock@apple.com>
+
+        MemoryCache::addImageToCache should return the result of add().
+        https://bugs.webkit.org/show_bug.cgi?id=132928
+        <rdar://problem/16651547>
+
+        Reviewed by Alexey Proskuryakov.
+
+        API test: WebKit1.MemoryCacheADdImageToCache (MemoryCacheAddImageToCacheIOS.mm)
+
+        * loader/cache/MemoryCache.cpp:
+        (WebCore::MemoryCache::addImageToCache):
+
 2014-05-16  Andrei Bucur  <abucur@adobe.com>
 
         [CSS Regions] Reduce the RenderRegion invasiveness in rendering code
index 4241afe..928d2ee 100644 (file)
@@ -266,7 +266,7 @@ bool MemoryCache::addImageToCache(NativeImagePtr image, const URL& url, const St
 #if ENABLE(CACHE_PARTITIONING)
     cachedImage->resourceRequest().setCachePartition(cachePartition);
 #endif
-    return true;
+    return add(cachedImage.release());
 }
 
 void MemoryCache::removeImageFromCache(const URL& url, const String& cachePartition)
index a7911b4..7083848 100644 (file)
@@ -1,3 +1,16 @@
+2014-05-16  Martin Hock  <mhock@apple.com>
+
+        MemoryCache::addImageToCache should return the result of add().
+        https://bugs.webkit.org/show_bug.cgi?id=132928
+        <rdar://problem/16651547>
+
+        Reviewed by Alexey Proskuryakov.
+
+        * TestWebKitAPI/Configurations/TestWebKitAPI.xcconfig:
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/ios/MemoryCacheAddImageToCacheIOS.mm: Added.
+        (TestWebKitAPI::TEST):
+
 2014-05-15  David Farler  <dfarler@apple.com>
 
         old-run-webkit-tests: allow specifying a simulator app path
index 9409261..e205179 100644 (file)
@@ -25,6 +25,6 @@ PRODUCT_NAME = TestWebKitAPI;
 GCC_ENABLE_OBJC_EXCEPTIONS = YES;
 
 OTHER_LDFLAGS = $(inherited) -lgtest -framework JavaScriptCore -framework WebKit -framework WebKit2 $(OTHER_LDFLAGS_$(PLATFORM_NAME));
-OTHER_LDFLAGS_iphoneos = -framework WebCore;
+OTHER_LDFLAGS_iphoneos = -framework WebCore -framework CoreGraphics;
 OTHER_LDFLAGS_iphonesimulator = $(OTHER_LDFLAGS_iphoneos);
 OTHER_LDFLAGS_macosx = -framework Cocoa -framework Carbon;
index 38d2729..bc58138 100644 (file)
                52CB47411448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52CB47401448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp */; };
                52E5CE4614D21E9D003B2BD8 /* ParentFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52E5CE4514D21E9D003B2BD8 /* ParentFrame.cpp */; };
                52E5CE4914D21EAB003B2BD8 /* ParentFrame_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52E5CE4814D21EAB003B2BD8 /* ParentFrame_Bundle.cpp */; };
+               7560917819259C59009EF06E /* MemoryCacheAddImageToCacheIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7560917719259C59009EF06E /* MemoryCacheAddImageToCacheIOS.mm */; };
                75F3134018C171B70041CAEC /* EphemeralSessionPushStateNoHistoryCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 75F3133F18C171B70041CAEC /* EphemeralSessionPushStateNoHistoryCallback.cpp */; };
                76E182DA1547550100F1FADD /* WillSendSubmitEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76E182D91547550100F1FADD /* WillSendSubmitEvent.cpp */; };
                76E182DD1547569100F1FADD /* WillSendSubmitEvent_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76E182DC1547569100F1FADD /* WillSendSubmitEvent_Bundle.cpp */; };
                52CB47401448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoadAlternateHTMLStringWithNonDirectoryURL.cpp; sourceTree = "<group>"; };
                52E5CE4514D21E9D003B2BD8 /* ParentFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParentFrame.cpp; sourceTree = "<group>"; };
                52E5CE4814D21EAB003B2BD8 /* ParentFrame_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParentFrame_Bundle.cpp; sourceTree = "<group>"; };
+               7560917719259C59009EF06E /* MemoryCacheAddImageToCacheIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MemoryCacheAddImageToCacheIOS.mm; sourceTree = "<group>"; };
                75F3133F18C171B70041CAEC /* EphemeralSessionPushStateNoHistoryCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EphemeralSessionPushStateNoHistoryCallback.cpp; sourceTree = "<group>"; };
                76E182D91547550100F1FADD /* WillSendSubmitEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillSendSubmitEvent.cpp; sourceTree = "<group>"; };
                76E182DC1547569100F1FADD /* WillSendSubmitEvent_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillSendSubmitEvent_Bundle.cpp; sourceTree = "<group>"; };
                        path = Cocoa;
                        sourceTree = "<group>";
                };
+               7560917619259C59009EF06E /* ios */ = {
+                       isa = PBXGroup;
+                       children = (
+                               7560917719259C59009EF06E /* MemoryCacheAddImageToCacheIOS.mm */,
+                       );
+                       path = ios;
+                       sourceTree = "<group>";
+               };
                BC029B1A1486B23800817DA9 /* ns */ = {
                        isa = PBXGroup;
                        children = (
                        children = (
                                44A82E7B19251B3500C1C8C4 /* Cocoa */,
                                FE217ECB1640A54A0052988B /* JavaScriptCore */,
+                               7560917619259C59009EF06E /* ios */,
                                C07E6CAD13FD67650038B22B /* mac */,
                                C08587F913FEC39B001EF4E5 /* TestWebKitAPI */,
                                440A1D3614A01000008A66F2 /* WebCore */,
                                939BA91714103412001A01BD /* DeviceScaleFactorOnBack.mm in Sources */,
                                BCB68040126FBFE100642A61 /* DocumentStartUserScriptAlertCrash.cpp in Sources */,
                                37E1064D16976C8500B78BD0 /* DOMHTMLTableCellCellAbove.mm in Sources */,
+                               7560917819259C59009EF06E /* MemoryCacheAddImageToCacheIOS.mm in Sources */,
                                3751AF7C169518F800764319 /* DOMNodeFromJSObject.mm in Sources */,
                                37DC678D140D7C5000ABCCDB /* DOMRangeOfString.mm in Sources */,
                                51393E201523944A005F39C5 /* DOMWindowExtensionBasic.cpp in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/ios/MemoryCacheAddImageToCacheIOS.mm b/Tools/TestWebKitAPI/Tests/ios/MemoryCacheAddImageToCacheIOS.mm
new file mode 100644 (file)
index 0000000..c17dd81
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+#import "config.h"
+#import "PlatformUtilities.h"
+#import <WebKit/WebCache.h>
+
+namespace TestWebKitAPI {
+
+TEST(WebKit1, MemoryCacheAddImageToCache)
+{
+    CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
+    uint32_t pixel = 0;
+    CGDataProviderRef provider = CGDataProviderCreateWithData(nullptr, &pixel, 4, nullptr);
+    CGImageRef image = CGImageCreate(1, 1, 8, 32, 4, rgb, kCGImageAlphaFirst | kCGBitmapByteOrderDefault, provider, nullptr, false, kCGRenderingIntentDefault);
+    NSURL *url = [NSURL URLWithString:@"about:blank"];
+    EXPECT_TRUE([WebCache addImageToCache:image forURL:url]);
+    EXPECT_EQ(image, [WebCache imageForURL:url]);
+    // By design, removeImageFromCacheForURL doesn't necessarily remove the resource from the cache,
+    // just makes it pruneable, so we can't really test remove.
+    CGImageRelease(image);
+    CGDataProviderRelease(provider);
+    CGColorSpaceRelease(rgb);
+}
+
+} // namespace TestWebKitAPI