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

Side by Side Diff: third_party/WebKit/Source/core/css/MediaValuesTest.cpp

Issue 1904523002: Fix double comparisons for Media Queries (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unreachable build error Created 4 years, 8 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
« no previous file with comments | « third_party/WebKit/Source/core/css/MediaValues.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Use of this source code is governed by a BSD-style license that can be 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. 2 // Copyright 2014 The Chromium Authors. All rights reserved.
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/css/MediaValues.h" 5 #include "core/css/MediaValues.h"
6 6
7 #include "core/css/CSSPrimitiveValue.h" 7 #include "core/css/CSSPrimitiveValue.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "wtf/text/StringBuilder.h" 9 #include "wtf/text/StringBuilder.h"
10 10
11 namespace blink { 11 namespace blink {
12 12
13 struct TestCase { 13 struct TestCase {
14 double value; 14 double value;
15 CSSPrimitiveValue::UnitType type; 15 CSSPrimitiveValue::UnitType type;
16 unsigned fontSize; 16 unsigned fontSize;
17 unsigned viewportWidth; 17 unsigned viewportWidth;
18 unsigned viewportHeight; 18 unsigned viewportHeight;
19 bool success; 19 bool success;
20 int output; 20 double output;
21 }; 21 };
22 22
23 TEST(MediaValuesTest, Basic) 23 TEST(MediaValuesTest, Basic)
24 { 24 {
25 TestCase testCases[] = { 25 TestCase testCases[] = {
26 { 40.0, CSSPrimitiveValue::UnitType::Pixels, 16, 300, 300, true, 40 }, 26 { 40.0, CSSPrimitiveValue::UnitType::Pixels, 16, 300, 300, true, 40 },
27 { 40.0, CSSPrimitiveValue::UnitType::Ems, 16, 300, 300, true, 640 }, 27 { 40.0, CSSPrimitiveValue::UnitType::Ems, 16, 300, 300, true, 640 },
28 { 40.0, CSSPrimitiveValue::UnitType::Rems, 16, 300, 300, true, 640 }, 28 { 40.0, CSSPrimitiveValue::UnitType::Rems, 16, 300, 300, true, 640 },
29 { 40.0, CSSPrimitiveValue::UnitType::Exs, 16, 300, 300, true, 320 }, 29 { 40.0, CSSPrimitiveValue::UnitType::Exs, 16, 300, 300, true, 320 },
30 { 40.0, CSSPrimitiveValue::UnitType::Chs, 16, 300, 300, true, 320 }, 30 { 40.0, CSSPrimitiveValue::UnitType::Chs, 16, 300, 300, true, 320 },
31 { 43.0, CSSPrimitiveValue::UnitType::ViewportWidth, 16, 848, 976, true, 364 }, 31 { 43.0, CSSPrimitiveValue::UnitType::ViewportWidth, 16, 848, 976, true, 364.64 },
32 { 43.0, CSSPrimitiveValue::UnitType::ViewportHeight, 16, 848, 976, true, 419 }, 32 { 100.0, CSSPrimitiveValue::UnitType::ViewportWidth, 16, 821, 976, true, 821 },
33 { 43.0, CSSPrimitiveValue::UnitType::ViewportMin, 16, 848, 976, true, 36 4 }, 33 { 43.0, CSSPrimitiveValue::UnitType::ViewportHeight, 16, 848, 976, true, 419.68 },
34 { 43.0, CSSPrimitiveValue::UnitType::ViewportMax, 16, 848, 976, true, 41 9 }, 34 { 43.0, CSSPrimitiveValue::UnitType::ViewportMin, 16, 848, 976, true, 36 4.64 },
35 { 1.3, CSSPrimitiveValue::UnitType::Centimeters, 16, 300, 300, true, 49 }, 35 { 43.0, CSSPrimitiveValue::UnitType::ViewportMax, 16, 848, 976, true, 41 9.68 },
36 { 1.3, CSSPrimitiveValue::UnitType::Millimeters, 16, 300, 300, true, 4 } , 36 { 1.3, CSSPrimitiveValue::UnitType::Centimeters, 16, 300, 300, true, 49. 133858 },
37 { 1.3, CSSPrimitiveValue::UnitType::Inches, 16, 300, 300, true, 124 }, 37 { 1.3, CSSPrimitiveValue::UnitType::Millimeters, 16, 300, 300, true, 4.9 13386 },
38 { 13, CSSPrimitiveValue::UnitType::Points, 16, 300, 300, true, 17 }, 38 { 1.3, CSSPrimitiveValue::UnitType::Inches, 16, 300, 300, true, 124.8 },
39 { 1.3, CSSPrimitiveValue::UnitType::Picas, 16, 300, 300, true, 20 }, 39 { 13, CSSPrimitiveValue::UnitType::Points, 16, 300, 300, true, 17.333333 },
40 { 1.3, CSSPrimitiveValue::UnitType::Picas, 16, 300, 300, true, 20.8 },
40 { 40.0, CSSPrimitiveValue::UnitType::UserUnits, 16, 300, 300, true, 40 } , 41 { 40.0, CSSPrimitiveValue::UnitType::UserUnits, 16, 300, 300, true, 40 } ,
41 { 1.3, CSSPrimitiveValue::UnitType::Unknown, 16, 300, 300, false, 20 }, 42 { 1.3, CSSPrimitiveValue::UnitType::Unknown, 16, 300, 300, false, 20 },
42 { 0.0, CSSPrimitiveValue::UnitType::Unknown, 0, 0, 0, false, 0.0 } // Do not remove the terminating line. 43 { 0.0, CSSPrimitiveValue::UnitType::Unknown, 0, 0, 0, false, 0.0 } // Do not remove the terminating line.
43 }; 44 };
44 45
45 46
46 for (unsigned i = 0; testCases[i].viewportWidth; ++i) { 47 for (unsigned i = 0; testCases[i].viewportWidth; ++i) {
47 int output = 0; 48 double output = 0;
48 bool success = MediaValues::computeLength(testCases[i].value, 49 bool success = MediaValues::computeLength(testCases[i].value,
49 testCases[i].type, 50 testCases[i].type,
50 testCases[i].fontSize, 51 testCases[i].fontSize,
51 testCases[i].viewportWidth, 52 testCases[i].viewportWidth,
52 testCases[i].viewportHeight, 53 testCases[i].viewportHeight,
53 output); 54 output);
54 ASSERT_EQ(testCases[i].success, success); 55 EXPECT_EQ(testCases[i].success, success);
55 if (success) 56 if (success)
56 ASSERT_EQ(testCases[i].output, output); 57 EXPECT_FLOAT_EQ(testCases[i].output, output);
57 } 58 }
58 } 59 }
59 60
60 } // namespace blink 61 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/MediaValues.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698