1b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 2b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// found in the LICENSE file. 4b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 5b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "chrome/renderer/web_apps.h" 6b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 8b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 9b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 10b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Tests ParseIconSizes with various input. 11b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)TEST(WebAppInfo, ParseIconSizes) { 12b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) struct TestData { 13b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) const char* input; 14b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) const bool expected_result; 15b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) const bool is_any; 16b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) const size_t expected_size_count; 17b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) const int width1; 18b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) const int height1; 19b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) const int width2; 20b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) const int height2; 21b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) } data[] = { 22b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // Bogus input cases. 23b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) { "10", false, false, 0, 0, 0, 0, 0 }, 24b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) { "10 10", false, false, 0, 0, 0, 0, 0 }, 25b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) { "010", false, false, 0, 0, 0, 0, 0 }, 26b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) { " 010 ", false, false, 0, 0, 0, 0, 0 }, 27b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) { " 10x ", false, false, 0, 0, 0, 0, 0 }, 28b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) { " x10 ", false, false, 0, 0, 0, 0, 0 }, 29b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) { "any 10x10", false, false, 0, 0, 0, 0, 0 }, 30b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) { "", false, false, 0, 0, 0, 0, 0 }, 31b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) { "10ax11", false, false, 0, 0, 0, 0, 0 }, 32b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 33b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // Any. 34b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) { "any", true, true, 0, 0, 0, 0, 0 }, 35b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) { " any", true, true, 0, 0, 0, 0, 0 }, 36b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) { " any ", true, true, 0, 0, 0, 0, 0 }, 37b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 38b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // Sizes. 39b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) { "10x11", true, false, 1, 10, 11, 0, 0 }, 40b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) { " 10x11 ", true, false, 1, 10, 11, 0, 0 }, 41b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) { " 10x11 1x2", true, false, 2, 10, 11, 1, 2 }, 42b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) }; 43b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { 44b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) bool is_any; 45b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) std::vector<gfx::Size> sizes; 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool result = web_apps::ParseIconSizes( 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::ASCIIToUTF16(data[i].input), &sizes, &is_any); 48b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) ASSERT_EQ(result, data[i].expected_result); 49b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) if (result) { 50b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) ASSERT_EQ(data[i].is_any, is_any); 51b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) ASSERT_EQ(data[i].expected_size_count, sizes.size()); 52b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) if (!sizes.empty()) { 53b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) ASSERT_EQ(data[i].width1, sizes[0].width()); 54b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) ASSERT_EQ(data[i].height1, sizes[0].height()); 55b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) } 56b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) if (sizes.size() > 1) { 57b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) ASSERT_EQ(data[i].width2, sizes[1].width()); 58b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) ASSERT_EQ(data[i].height2, sizes[1].height()); 59b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) } 60b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) } 61b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) } 62b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)} 63