Home | History | Annotate | Download | only in renderer
      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.
      4 
      5 #include "chrome/renderer/web_apps.h"
      6 
      7 #include "base/strings/utf_string_conversions.h"
      8 #include "testing/gtest/include/gtest/gtest.h"
      9 
     10 // Tests ParseIconSizes with various input.
     11 TEST(WebAppInfo, ParseIconSizes) {
     12   struct TestData {
     13     const char* input;
     14     const bool expected_result;
     15     const bool is_any;
     16     const size_t expected_size_count;
     17     const int width1;
     18     const int height1;
     19     const int width2;
     20     const int height2;
     21   } data[] = {
     22     // Bogus input cases.
     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 },
     32 
     33     // Any.
     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 },
     37 
     38     // Sizes.
     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 },
     42   };
     43   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
     44     bool is_any;
     45     std::vector<gfx::Size> sizes;
     46     bool result = web_apps::ParseIconSizes(ASCIIToUTF16(data[i].input), &sizes,
     47                                            &is_any);
     48     ASSERT_EQ(result, data[i].expected_result);
     49     if (result) {
     50       ASSERT_EQ(data[i].is_any, is_any);
     51       ASSERT_EQ(data[i].expected_size_count, sizes.size());
     52       if (!sizes.empty()) {
     53         ASSERT_EQ(data[i].width1, sizes[0].width());
     54         ASSERT_EQ(data[i].height1, sizes[0].height());
     55       }
     56       if (sizes.size() > 1) {
     57         ASSERT_EQ(data[i].width2, sizes[1].width());
     58         ASSERT_EQ(data[i].height2, sizes[1].height());
     59       }
     60     }
     61   }
     62 }
     63