Title: [122853] branches/chromium/1180
Revision
122853
Author
[email protected]
Date
2012-07-17 10:35:25 -0700 (Tue, 17 Jul 2012)

Log Message

Merge 122552 - REGRESSION(r119948): [Forms] Spin button Up/Down actions make value to zero for input type "number" when step mismatched
https://bugs.webkit.org/show_bug.cgi?id=91197

Reviewed by Kent Tamura.

Source/WebCore:

This patch fixes implementation of Decimal::ceiling() and floor().
They return wrong value for small fractional numbers.

The bug is occurred when:
  - Step-able input type, e.g. number, date, datetime, and so on.
  - Current value is step mismatched
  - Current value is smaller than step
  - Step up/down by spin button
because spin button up/down actions are implemented in InputType::setpUpFromRenderer
which calls Decimal::ceiling() and floor() for step mismatched case.

Tests: fast/forms/number/number-stepup-stepdown-from-renderer.html: Added test cases
       WebKit/chromium/tests/DecimalTest.cpp: Added test cases

* platform/Decimal.cpp:
(WebCore::Decimal::ceiling): Changed to return 1 for positive small fractional number.
(WebCore::Decimal::floor): Changed to return -1 for negative small fractional number.

Source/WebKit/chromium:

This patch adds test cases for Decimal::ceiling() and floor() of
positive/negative small fractional numbers.

* tests/DecimalTest.cpp:
(TEST_F):

LayoutTests:

This patch adds new test cases.

* fast/forms/number/number-stepup-stepdown-from-renderer-expected.txt: Updated for new test cases.
* fast/forms/number/number-stepup-stepdown-from-renderer.html: Added new test cases.

[email protected]
Review URL: https://chromiumcodereview.appspot.com/10786036

Modified Paths

Diff

Modified: branches/chromium/1180/LayoutTests/fast/forms/number/number-stepup-stepdown-from-renderer-expected.txt (122852 => 122853)


--- branches/chromium/1180/LayoutTests/fast/forms/number/number-stepup-stepdown-from-renderer-expected.txt	2012-07-17 17:32:59 UTC (rev 122852)
+++ branches/chromium/1180/LayoutTests/fast/forms/number/number-stepup-stepdown-from-renderer-expected.txt	2012-07-17 17:35:25 UTC (rev 122853)
@@ -49,6 +49,10 @@
 PASS input.min = "0"; stepUp("9", "10", "") is "10"
 PASS stepDown("19", "10", "0") is "10"
 PASS stepUp("89", "10", "99") is "90"
+PASS stepUp("7", "300", "") is "300"
+PASS stepUp("-7", "300", "") is "0"
+PASS stepDown("7", "300", "") is "0"
+PASS stepDown("-7", "300", "") is "-300"
 Huge value and small step
 PASS input.min = ""; stepUp("1e+38", "1", "", 999) is "1e+38"
 PASS input.max = ""; stepDown("1e+38", "1", "", 999) is "1e+38"

Modified: branches/chromium/1180/LayoutTests/fast/forms/number/number-stepup-stepdown-from-renderer.html (122852 => 122853)


--- branches/chromium/1180/LayoutTests/fast/forms/number/number-stepup-stepdown-from-renderer.html	2012-07-17 17:32:59 UTC (rev 122852)
+++ branches/chromium/1180/LayoutTests/fast/forms/number/number-stepup-stepdown-from-renderer.html	2012-07-17 17:35:25 UTC (rev 122853)
@@ -131,6 +131,10 @@
 shouldBe('input.min = "0"; stepUp("9", "10", "")', '"10"');
 shouldBe('stepDown("19", "10", "0")', '"10"');
 shouldBe('stepUp("89", "10", "99")', '"90"');
+shouldBe('stepUp("7", "300", "")', '"300"');
+shouldBe('stepUp("-7", "300", "")', '"0"');
+shouldBe('stepDown("7", "300", "")', '"0"');
+shouldBe('stepDown("-7", "300", "")', '"-300"');
 debug('Huge value and small step');
 shouldBe('input.min = ""; stepUp("1e+38", "1", "", 999)', '"1e+38"');
 shouldBe('input.max = ""; stepDown("1e+38", "1", "", 999)', '"1e+38"');

Modified: branches/chromium/1180/Source/WebCore/platform/Decimal.cpp (122852 => 122853)


--- branches/chromium/1180/Source/WebCore/platform/Decimal.cpp	2012-07-17 17:32:59 UTC (rev 122852)
+++ branches/chromium/1180/Source/WebCore/platform/Decimal.cpp	2012-07-17 17:35:25 UTC (rev 122853)
@@ -628,7 +628,7 @@
     const int numberOfDigits = countDigits(result);
     const int numberOfDropDigits = -exponent();
     if (numberOfDigits < numberOfDropDigits)
-        return zero(Positive);
+        return isPositive() ? Decimal(1) : zero(Positive);
 
     result = scaleDown(result, numberOfDropDigits - 1);
     if (sign() == Positive && result % 10 > 0)
@@ -670,7 +670,7 @@
     const int numberOfDigits = countDigits(result);
     const int numberOfDropDigits = -exponent();
     if (numberOfDigits < numberOfDropDigits)
-        return zero(Positive);
+        return isPositive() ? zero(Positive) : Decimal(-1);
 
     result = scaleDown(result, numberOfDropDigits - 1);
     if (isNegative() && result % 10 > 0)

Modified: branches/chromium/1180/Source/WebKit/chromium/tests/DecimalTest.cpp (122852 => 122853)


--- branches/chromium/1180/Source/WebKit/chromium/tests/DecimalTest.cpp	2012-07-17 17:32:59 UTC (rev 122852)
+++ branches/chromium/1180/Source/WebKit/chromium/tests/DecimalTest.cpp	2012-07-17 17:35:25 UTC (rev 122853)
@@ -211,12 +211,14 @@
 TEST_F(DecimalTest, Ceiling)
 {
     EXPECT_EQ(Decimal(1), Decimal(1).ceiling());
+    EXPECT_EQ(Decimal(1), encode(1, -10, Positive).ceiling());
     EXPECT_EQ(Decimal(2), encode(11, -1, Positive).ceiling());
     EXPECT_EQ(Decimal(2), encode(13, -1, Positive).ceiling());
     EXPECT_EQ(Decimal(2), encode(15, -1, Positive).ceiling());
     EXPECT_EQ(Decimal(2), encode(19, -1, Positive).ceiling());
 
     EXPECT_EQ(Decimal(-1), Decimal(-1).ceiling());
+    EXPECT_EQ(Decimal(0), encode(1, -10, Negative).ceiling());
     EXPECT_EQ(Decimal(-1), encode(11, -1, Negative).ceiling());
     EXPECT_EQ(Decimal(-1), encode(13, -1, Negative).ceiling());
     EXPECT_EQ(Decimal(-1), encode(15, -1, Negative).ceiling());
@@ -525,12 +527,14 @@
 TEST_F(DecimalTest, Floor)
 {
     EXPECT_EQ(Decimal(1), Decimal(1).floor());
+    EXPECT_EQ(Decimal(0), encode(1, -10, Positive).floor());
     EXPECT_EQ(Decimal(1), encode(11, -1, Positive).floor());
     EXPECT_EQ(Decimal(1), encode(13, -1, Positive).floor());
     EXPECT_EQ(Decimal(1), encode(15, -1, Positive).floor());
     EXPECT_EQ(Decimal(1), encode(19, -1, Positive).floor());
 
     EXPECT_EQ(Decimal(-1), Decimal(-1).floor());
+    EXPECT_EQ(Decimal(-1), encode(1, -10, Negative).floor());
     EXPECT_EQ(Decimal(-2), encode(11, -1, Negative).floor());
     EXPECT_EQ(Decimal(-2), encode(13, -1, Negative).floor());
     EXPECT_EQ(Decimal(-2), encode(15, -1, Negative).floor());
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to