1// Use of this source code is governed by a BSD-style license that can be 2// Copyright 2014 The Chromium Authors. All rights reserved. 3// found in the LICENSE file. 4 5#include "config.h" 6#include "core/css/MediaValues.h" 7 8#include "core/css/CSSPrimitiveValue.h" 9#include "wtf/text/StringBuilder.h" 10 11#include <gtest/gtest.h> 12 13namespace blink { 14 15struct TestCase { 16 double value; 17 CSSPrimitiveValue::UnitType type; 18 unsigned fontSize; 19 unsigned viewportWidth; 20 unsigned viewportHeight; 21 bool success; 22 int output; 23}; 24 25TEST(MediaValuesTest, Basic) 26{ 27 TestCase testCases[] = { 28 { 40.0, CSSPrimitiveValue::CSS_PX, 16, 300, 300, true, 40 }, 29 { 40.0, CSSPrimitiveValue::CSS_EMS, 16, 300, 300, true, 640 }, 30 { 40.0, CSSPrimitiveValue::CSS_REMS, 16, 300, 300, true, 640 }, 31 { 40.0, CSSPrimitiveValue::CSS_EXS, 16, 300, 300, true, 320 }, 32 { 40.0, CSSPrimitiveValue::CSS_CHS, 16, 300, 300, true, 320 }, 33 { 43.0, CSSPrimitiveValue::CSS_VW, 16, 848, 976, true, 364 }, 34 { 43.0, CSSPrimitiveValue::CSS_VH, 16, 848, 976, true, 419 }, 35 { 43.0, CSSPrimitiveValue::CSS_VMIN, 16, 848, 976, true, 364 }, 36 { 43.0, CSSPrimitiveValue::CSS_VMAX, 16, 848, 976, true, 419 }, 37 { 1.3, CSSPrimitiveValue::CSS_CM, 16, 300, 300, true, 49 }, 38 { 1.3, CSSPrimitiveValue::CSS_MM, 16, 300, 300, true, 4 }, 39 { 1.3, CSSPrimitiveValue::CSS_IN, 16, 300, 300, true, 124 }, 40 { 13, CSSPrimitiveValue::CSS_PT, 16, 300, 300, true, 17 }, 41 { 1.3, CSSPrimitiveValue::CSS_PC, 16, 300, 300, true, 20 }, 42 { 1.3, CSSPrimitiveValue::CSS_UNKNOWN, 16, 300, 300, false, 20 }, 43 { 0.0, CSSPrimitiveValue::CSS_UNKNOWN, 0, 0, 0, false, 0.0 } // Do not remove the terminating line. 44 }; 45 46 47 for (unsigned i = 0; testCases[i].viewportWidth; ++i) { 48 int output = 0; 49 bool success = MediaValues::computeLength(testCases[i].value, 50 testCases[i].type, 51 testCases[i].fontSize, 52 testCases[i].viewportWidth, 53 testCases[i].viewportHeight, 54 output); 55 ASSERT_EQ(testCases[i].success, success); 56 if (success) 57 ASSERT_EQ(testCases[i].output, output); 58 } 59} 60 61} // namespace 62