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

Side by Side Diff: chrome/browser/ui/app_list/search/launcher_search/launcher_search_icon_image_loader_unittest.cc

Issue 1865213004: Convert //chrome/browser/ui from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "chrome/browser/ui/app_list/search/launcher_search/launcher_search_icon _image_loader.h" 5 #include "chrome/browser/ui/app_list/search/launcher_search/launcher_search_icon _image_loader.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h"
8 #include "chrome/browser/chromeos/launcher_search_provider/error_reporter.h" 9 #include "chrome/browser/chromeos/launcher_search_provider/error_reporter.h"
9 #include "extensions/common/manifest_constants.h" 10 #include "extensions/common/manifest_constants.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/gfx/canvas.h" 12 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/geometry/rect.h" 13 #include "ui/gfx/geometry/rect.h"
13 #include "ui/gfx/geometry/size.h" 14 #include "ui/gfx/geometry/size.h"
14 #include "ui/gfx/image/canvas_image_source.h" 15 #include "ui/gfx/image/canvas_image_source.h"
15 #include "ui/gfx/image/image_skia.h" 16 #include "ui/gfx/image/image_skia.h"
16 #include "ui/gfx/image/image_unittest_util.h" 17 #include "ui/gfx/image/image_unittest_util.h"
17 #include "url/gurl.h" 18 #include "url/gurl.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 explicit FakeErrorReporter(const linked_ptr<std::string>& last_message) 90 explicit FakeErrorReporter(const linked_ptr<std::string>& last_message)
90 : ErrorReporter(nullptr), last_message_(last_message) {} 91 : ErrorReporter(nullptr), last_message_(last_message) {}
91 ~FakeErrorReporter() override {} 92 ~FakeErrorReporter() override {}
92 void Warn(const std::string& message) override { 93 void Warn(const std::string& message) override {
93 last_message_->clear(); 94 last_message_->clear();
94 last_message_->append(message); 95 last_message_->append(message);
95 } 96 }
96 97
97 const std::string& GetLastWarningMessage() { return *last_message_.get(); } 98 const std::string& GetLastWarningMessage() { return *last_message_.get(); }
98 99
99 scoped_ptr<ErrorReporter> Duplicate() override { 100 std::unique_ptr<ErrorReporter> Duplicate() override {
100 return make_scoped_ptr(new FakeErrorReporter(last_message_)); 101 return base::WrapUnique(new FakeErrorReporter(last_message_));
101 } 102 }
102 103
103 private: 104 private:
104 linked_ptr<std::string> last_message_; 105 linked_ptr<std::string> last_message_;
105 106
106 DISALLOW_COPY_AND_ASSIGN(FakeErrorReporter); 107 DISALLOW_COPY_AND_ASSIGN(FakeErrorReporter);
107 }; 108 };
108 109
109 // Creates a test extension with |extension_id|. 110 // Creates a test extension with |extension_id|.
110 scoped_refptr<extensions::Extension> CreateTestExtension( 111 scoped_refptr<extensions::Extension> CreateTestExtension(
(...skipping 16 matching lines...) Expand all
127 expected_image.GetRepresentation(1.0).sk_bitmap(), 128 expected_image.GetRepresentation(1.0).sk_bitmap(),
128 result_image.GetRepresentation(1.0).sk_bitmap()); 129 result_image.GetRepresentation(1.0).sk_bitmap());
129 } 130 }
130 131
131 } // namespace 132 } // namespace
132 133
133 class LauncherSearchIconImageLoaderTest : public testing::Test { 134 class LauncherSearchIconImageLoaderTest : public testing::Test {
134 protected: 135 protected:
135 void SetUp() override { extension_ = CreateTestExtension(kTestExtensionId); } 136 void SetUp() override { extension_ = CreateTestExtension(kTestExtensionId); }
136 137
137 scoped_ptr<FakeErrorReporter> GetFakeErrorReporter() { 138 std::unique_ptr<FakeErrorReporter> GetFakeErrorReporter() {
138 return make_scoped_ptr(new FakeErrorReporter()); 139 return base::WrapUnique(new FakeErrorReporter());
139 } 140 }
140 141
141 scoped_refptr<extensions::Extension> extension_; 142 scoped_refptr<extensions::Extension> extension_;
142 }; 143 };
143 144
144 TEST_F(LauncherSearchIconImageLoaderTest, WithoutCustomIconSuccessCase) { 145 TEST_F(LauncherSearchIconImageLoaderTest, WithoutCustomIconSuccessCase) {
145 GURL icon_url; // No custom icon. 146 GURL icon_url; // No custom icon.
146 LauncherSearchIconImageLoaderTestImpl impl(icon_url, nullptr, nullptr, 32, 147 LauncherSearchIconImageLoaderTestImpl impl(icon_url, nullptr, nullptr, 32,
147 GetFakeErrorReporter()); 148 GetFakeErrorReporter());
148 impl.LoadResources(); 149 impl.LoadResources();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 208
208 TEST_F(LauncherSearchIconImageLoaderTest, InvalidCustomIconUrl) { 209 TEST_F(LauncherSearchIconImageLoaderTest, InvalidCustomIconUrl) {
209 // Use a really long URL (for testing the string truncation). 210 // Use a really long URL (for testing the string truncation).
210 // The URL is from the wrong extension (foo2), so should be rejected. 211 // The URL is from the wrong extension (foo2), so should be rejected.
211 std::string invalid_url = 212 std::string invalid_url =
212 "chrome-extension://foo2/bar/" 213 "chrome-extension://foo2/bar/"
213 "901234567890123456789012345678901234567890123456789012345678901234567890" 214 "901234567890123456789012345678901234567890123456789012345678901234567890"
214 "1"; 215 "1";
215 ASSERT_EQ(101U, invalid_url.size()); 216 ASSERT_EQ(101U, invalid_url.size());
216 217
217 scoped_ptr<FakeErrorReporter> fake_error_reporter = GetFakeErrorReporter(); 218 std::unique_ptr<FakeErrorReporter> fake_error_reporter =
219 GetFakeErrorReporter();
218 GURL icon_url(invalid_url); 220 GURL icon_url(invalid_url);
219 LauncherSearchIconImageLoaderTestImpl impl(icon_url, nullptr, 221 LauncherSearchIconImageLoaderTestImpl impl(icon_url, nullptr,
220 extension_.get(), 32, 222 extension_.get(), 32,
221 fake_error_reporter->Duplicate()); 223 fake_error_reporter->Duplicate());
222 impl.LoadResources(); 224 impl.LoadResources();
223 225
224 // Warning message should be provided. 226 // Warning message should be provided.
225 ASSERT_EQ( 227 ASSERT_EQ(
226 "[chrome.launcherSearchProvider.setSearchResults] Invalid icon URL: " 228 "[chrome.launcherSearchProvider.setSearchResults] Invalid icon URL: "
227 "chrome-extension://foo2/bar/" 229 "chrome-extension://foo2/bar/"
228 "901234567890123456789012345678901234567890123456789012345678901234567..." 230 "901234567890123456789012345678901234567890123456789012345678901234567..."
229 ". Must have a valid URL within chrome-extension://foo.", 231 ". Must have a valid URL within chrome-extension://foo.",
230 fake_error_reporter->GetLastWarningMessage()); 232 fake_error_reporter->GetLastWarningMessage());
231 233
232 // LoadExtensionIconResource should not be called. 234 // LoadExtensionIconResource should not be called.
233 ASSERT_FALSE(impl.IsLoadExtensionIconResourceCalled()); 235 ASSERT_FALSE(impl.IsLoadExtensionIconResourceCalled());
234 } 236 }
235 237
236 TEST_F(LauncherSearchIconImageLoaderTest, FailedToLoadCustomIcon) { 238 TEST_F(LauncherSearchIconImageLoaderTest, FailedToLoadCustomIcon) {
237 scoped_ptr<FakeErrorReporter> fake_error_reporter = GetFakeErrorReporter(); 239 std::unique_ptr<FakeErrorReporter> fake_error_reporter =
240 GetFakeErrorReporter();
238 GURL icon_url(kTestCustomIconURL); 241 GURL icon_url(kTestCustomIconURL);
239 LauncherSearchIconImageLoaderTestImpl impl(icon_url, nullptr, 242 LauncherSearchIconImageLoaderTestImpl impl(icon_url, nullptr,
240 extension_.get(), 32, 243 extension_.get(), 32,
241 fake_error_reporter->Duplicate()); 244 fake_error_reporter->Duplicate());
242 impl.LoadResources(); 245 impl.LoadResources();
243 ASSERT_TRUE(impl.IsLoadExtensionIconResourceCalled()); 246 ASSERT_TRUE(impl.IsLoadExtensionIconResourceCalled());
244 247
245 // Fails to load custom icon by passing an empty image. 248 // Fails to load custom icon by passing an empty image.
246 gfx::ImageSkia custom_icon; 249 gfx::ImageSkia custom_icon;
247 impl.CallOnCustomIconLoaded(custom_icon); 250 impl.CallOnCustomIconLoaded(custom_icon);
248 251
249 // Warning message should be shown. 252 // Warning message should be shown.
250 ASSERT_EQ( 253 ASSERT_EQ(
251 "[chrome.launcherSearchProvider.setSearchResults] Failed to load icon " 254 "[chrome.launcherSearchProvider.setSearchResults] Failed to load icon "
252 "URL: chrome-extension://foo/bar", 255 "URL: chrome-extension://foo/bar",
253 fake_error_reporter->GetLastWarningMessage()); 256 fake_error_reporter->GetLastWarningMessage());
254 257
255 // Assert that extension icon image is set to icon image and badge icon image 258 // Assert that extension icon image is set to icon image and badge icon image
256 // is null. 259 // is null.
257 gfx::Size icon_size(32, 32); 260 gfx::Size icon_size(32, 32);
258 gfx::ImageSkia expected_image( 261 gfx::ImageSkia expected_image(
259 new FillColorImageSource(icon_size, SK_ColorBLACK), icon_size); 262 new FillColorImageSource(icon_size, SK_ColorBLACK), icon_size);
260 ASSERT_TRUE(IsEqual(expected_image, impl.GetIconImage())); 263 ASSERT_TRUE(IsEqual(expected_image, impl.GetIconImage()));
261 264
262 ASSERT_TRUE(impl.GetBadgeIconImage().isNull()); 265 ASSERT_TRUE(impl.GetBadgeIconImage().isNull());
263 } 266 }
264 267
265 } // namespace app_list 268 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698