Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: components/image_fetcher/ios/ios_image_data_fetcher_wrapper_unittest.mm

Issue 2689213010: Add a static method to WebPDecoder to decode WebP (Closed)
Patch Set: Address comment Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h" 5 #import "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h"
6 6
7 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 #include "base/ios/ios_util.h" 9 #include "base/ios/ios_util.h"
10 #include "base/mac/scoped_block.h" 10 #include "base/mac/scoped_block.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 12, 0, 0, 0, 1, 7, 16, 17, 253, 15, 68, 68, 255, 3, 0, 0, 86, 85 12, 0, 0, 0, 1, 7, 16, 17, 253, 15, 68, 68, 255, 3, 0, 0, 86,
86 80, 56, 32, 24, 0, 0, 0, 48, 1, 0, 157, 1, 42, 1, 0, 1, 0, 86 80, 56, 32, 24, 0, 0, 0, 48, 1, 0, 157, 1, 42, 1, 0, 1, 0,
87 3, 0, 52, 37, 164, 0, 3, 112, 0, 254, 251, 253, 80, 0, 87 3, 0, 52, 37, 164, 0, 3, 112, 0, 254, 251, 253, 80, 0,
88 }; 88 };
89 89
90 const char kTestUrl[] = "http://www.img.com"; 90 const char kTestUrl[] = "http://www.img.com";
91 91
92 const char kWEBPHeaderResponse[] = 92 const char kWEBPHeaderResponse[] =
93 "HTTP/1.1 200 OK\0Content-type: image/webp\0\0"; 93 "HTTP/1.1 200 OK\0Content-type: image/webp\0\0";
94 94
95 // TODO(crbug.com/687921): Refactor this.
96 class WebpDecoderDelegate : public webp_transcode::WebpDecoder::Delegate {
97 public:
98 WebpDecoderDelegate() = default;
99 NSData* data() const { return decoded_image_; }
100
101 void OnFinishedDecoding(bool success) override {}
102 void SetImageFeatures(
103 size_t total_size,
104 webp_transcode::WebpDecoder::DecodedImageFormat format) override {
105 decoded_image_ = [[NSMutableData alloc] initWithCapacity:total_size];
106 }
107 void OnDataDecoded(NSData* data) override {
108 [decoded_image_ appendData:data];
109 }
110
111 private:
112 ~WebpDecoderDelegate() override {}
113 NSMutableData* decoded_image_;
114
115 DISALLOW_COPY_AND_ASSIGN(WebpDecoderDelegate);
116 };
117
118 // Returns a NSData object containing the decoded image. 95 // Returns a NSData object containing the decoded image.
119 NSData* DecodedWebpImage() { 96 NSData* DecodedWebpImage() {
120 scoped_refptr<WebpDecoderDelegate> delegate(new WebpDecoderDelegate); 97 return webp_transcode::WebpDecoder::DecodeWebpImage([NSData
121 scoped_refptr<webp_transcode::WebpDecoder> decoder(
122 new webp_transcode::WebpDecoder(delegate.get()));
123 decoder->OnDataReceived([NSData
124 dataWithBytes:reinterpret_cast<const char*>(kWEBPImage) 98 dataWithBytes:reinterpret_cast<const char*>(kWEBPImage)
125 length:sizeof(kWEBPImage)]); 99 length:sizeof(kWEBPImage)]);
126 return delegate->data();
127 } 100 }
128 101
129 } // namespace 102 } // namespace
130 103
131 namespace image_fetcher { 104 namespace image_fetcher {
132 105
133 class IOSImageDataFetcherWrapperTest : public PlatformTest { 106 class IOSImageDataFetcherWrapperTest : public PlatformTest {
134 protected: 107 protected:
135 IOSImageDataFetcherWrapperTest() 108 IOSImageDataFetcherWrapperTest()
136 : callback_([^(NSData* data) { 109 : callback_([^(NSData* data) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 EXPECT_TRUE(called_); 219 EXPECT_TRUE(called_);
247 } 220 }
248 221
249 TEST_F(IOSImageDataFetcherWrapperTest, TestCallbacksNotCalledDuringDeletion) { 222 TEST_F(IOSImageDataFetcherWrapperTest, TestCallbacksNotCalledDuringDeletion) {
250 image_fetcher_->FetchImageDataWebpDecoded(GURL(kTestUrl), callback_); 223 image_fetcher_->FetchImageDataWebpDecoded(GURL(kTestUrl), callback_);
251 image_fetcher_.reset(); 224 image_fetcher_.reset();
252 EXPECT_FALSE(called_); 225 EXPECT_FALSE(called_);
253 } 226 }
254 227
255 } // namespace image_fetcher 228 } // namespace image_fetcher
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698