1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/renderer/web_apps.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 // Tests ParseIconSizes with various input.
11 TEST(WebAppInfo
, ParseIconSizes
) {
14 const bool expected_result
;
16 const size_t expected_size_count
;
23 { "10", false, false, 0, 0, 0, 0, 0 },
24 { "10 10", false, false, 0, 0, 0, 0, 0 },
25 { "010", false, false, 0, 0, 0, 0, 0 },
26 { " 010 ", false, false, 0, 0, 0, 0, 0 },
27 { " 10x ", false, false, 0, 0, 0, 0, 0 },
28 { " x10 ", false, false, 0, 0, 0, 0, 0 },
29 { "any 10x10", false, false, 0, 0, 0, 0, 0 },
30 { "", false, false, 0, 0, 0, 0, 0 },
31 { "10ax11", false, false, 0, 0, 0, 0, 0 },
34 { "any", true, true, 0, 0, 0, 0, 0 },
35 { " any", true, true, 0, 0, 0, 0, 0 },
36 { " any ", true, true, 0, 0, 0, 0, 0 },
39 { "10x11", true, false, 1, 10, 11, 0, 0 },
40 { " 10x11 ", true, false, 1, 10, 11, 0, 0 },
41 { " 10x11 1x2", true, false, 2, 10, 11, 1, 2 },
43 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(data
); ++i
) {
45 std::vector
<gfx::Size
> sizes
;
46 bool result
= web_apps::ParseIconSizes(
47 base::ASCIIToUTF16(data
[i
].input
), &sizes
, &is_any
);
48 ASSERT_EQ(result
, data
[i
].expected_result
);
50 ASSERT_EQ(data
[i
].is_any
, is_any
);
51 ASSERT_EQ(data
[i
].expected_size_count
, sizes
.size());
53 ASSERT_EQ(data
[i
].width1
, sizes
[0].width());
54 ASSERT_EQ(data
[i
].height1
, sizes
[0].height());
56 if (sizes
.size() > 1) {
57 ASSERT_EQ(data
[i
].width2
, sizes
[1].width());
58 ASSERT_EQ(data
[i
].height2
, sizes
[1].height());