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

Side by Side Diff: chrome/browser/profiles/profile_avatar_icon_util_unittest.cc

Issue 1487283005: Implement the new Sync Confirmation dialog on Linux and Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reverted a few sign changes missed in last patchset Created 4 years, 11 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/profiles/profile_avatar_icon_util.h" 5 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
6 6
7 #include "grit/theme_resources.h" 7 #include "grit/theme_resources.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/base/resource/resource_bundle.h" 9 #include "ui/base/resource/resource_bundle.h"
10 #include "ui/gfx/canvas.h" 10 #include "ui/gfx/canvas.h"
11 #include "ui/gfx/image/image_skia.h" 11 #include "ui/gfx/image/image_skia.h"
12 #include "ui/gfx/image/image_skia_rep.h" 12 #include "ui/gfx/image/image_skia_rep.h"
13 #include "ui/gfx/image/image_unittest_util.h" 13 #include "ui/gfx/image/image_unittest_util.h"
14 #include "url/gurl.h"
14 15
15 namespace { 16 namespace {
16 17
17 // Helper function to check that the image is sized properly 18 // Helper function to check that the image is sized properly
18 // and supports multiple pixel densities. 19 // and supports multiple pixel densities.
19 void VerifyScaling(gfx::Image& image, gfx::Size& size) { 20 void VerifyScaling(gfx::Image& image, gfx::Size& size) {
20 gfx::Size canvas_size(100, 100); 21 gfx::Size canvas_size(100, 100);
21 gfx::Canvas canvas(canvas_size, 1.0f, false); 22 gfx::Canvas canvas(canvas_size, 1.0f, false);
22 gfx::Canvas canvas2(canvas_size, 2.0f, false); 23 gfx::Canvas canvas2(canvas_size, 2.0f, false);
23 24
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 // Test that a rectangular picture is changed. 100 // Test that a rectangular picture is changed.
100 gfx::Image rect_picture(gfx::test::CreateImage()); 101 gfx::Image rect_picture(gfx::test::CreateImage());
101 102
102 gfx::Size size(width, height); 103 gfx::Size size(width, height);
103 gfx::Image result2 = profiles::GetAvatarIconForTitleBar( 104 gfx::Image result2 = profiles::GetAvatarIconForTitleBar(
104 rect_picture, true, width, height); 105 rect_picture, true, width, height);
105 106
106 VerifyScaling(result2, size); 107 VerifyScaling(result2, size);
107 } 108 }
108 109
110 TEST(ProfileInfoUtilTest, GetImageURLWithThumbnailSizeNoInitialSize) {
111 GURL initial_url(
112 "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/photo.jpg");
113 const std::string expected_url =
114 "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s128-c/photo.jpg";
115
116 GURL transformed_url;
117 EXPECT_TRUE(profiles::GetImageURLWithThumbnailSize(
118 initial_url, 128, &transformed_url));
119
120 EXPECT_EQ(transformed_url, GURL(expected_url));
121 }
122
123 TEST(ProfileInfoUtilTest, GetImageURLWithThumbnailSizeSizeAlreadySpecified) {
124 // If there's already a size specified in the URL, it should be changed to the
125 // specified size in the resulting URL.
126 GURL initial_url(
127 "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s64-c/photo.jpg");
128 const std::string expected_url =
129 "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s128-c/photo.jpg";
130
131 GURL transformed_url;
132 EXPECT_TRUE(profiles::GetImageURLWithThumbnailSize(
133 initial_url, 128, &transformed_url));
134
135 EXPECT_EQ(transformed_url, GURL(expected_url));
136 }
137
138 TEST(ProfileInfoUtilTest, GetImageURLWithThumbnailSizeSameSize) {
139 // If there's already a size specified in the URL, and it's already the
140 // requested size, true should be returned and the URL should remain
141 // unchanged.
142 GURL initial_url(
143 "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s64-c/photo.jpg");
144 const std::string expected_url =
145 "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s64-c/photo.jpg";
146
147 GURL transformed_url;
148 EXPECT_TRUE(profiles::GetImageURLWithThumbnailSize(
149 initial_url, 64, &transformed_url));
150
151 EXPECT_EQ(transformed_url, GURL(expected_url));
152 }
153
154 TEST(ProfileInfoUtilTest, GetImageURLWithThumbnailSizeNoFileNameInPath) {
155 GURL initial_url(
156 "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/");
157 const std::string expected_url =
158 "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/";
159
160 // If there is no file path component in the URL path, we should fail the
161 // modification, but return true since the URL is still potentially valid and
162 // not modify the input URL.
163 GURL new_url;
164 EXPECT_TRUE(profiles::GetImageURLWithThumbnailSize(
165 initial_url, 64, &new_url));
166
167 EXPECT_EQ(new_url, GURL(expected_url));
168 }
169
170 TEST(ProfileInfoUtilTest, GetImageURLWithThumbnailInvalidURL) {
171 GURL initial_url;
172
173 GURL new_url("http://example.com");
174 EXPECT_FALSE(profiles::GetImageURLWithThumbnailSize(
175 initial_url, 128, &new_url));
176
177 // The new URL should be unchanged since the transformation failed.
178 EXPECT_EQ(new_url, GURL("http://example.com"));
179 }
180
109 } // namespace 181 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698