vibrate function have to return boolean value.
authorkihong.kwon@samsung.com <kihong.kwon@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 8 Jul 2013 07:39:23 +0000 (07:39 +0000)
committerkihong.kwon@samsung.com <kihong.kwon@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 8 Jul 2013 07:39:23 +0000 (07:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=118288

Reviewed by Gyuyoung Kim.

Source/WebCore:

According to latest Vibration API which is LC, vibrate() needs to return boolean value
and exception code is removed also. In addition, remove condition for canceling vibration
can be called when visibility state is hidden.
http://www.w3.org/TR/vibration/

No new tests. vibration/navigator-vibration.html is changed.

* Modules/vibration/NavigatorVibration.cpp:
(WebCore::NavigatorVibration::vibrate):
* Modules/vibration/NavigatorVibration.h:
* Modules/vibration/NavigatorVibration.idl:
* Modules/vibration/Vibration.cpp:
(WebCore::Vibration::vibrate):
* Modules/vibration/Vibration.h:

LayoutTests:

Update navigator-vibration.html to adjust latest spec.
Add vibration/cancelVibration-during-pattern-vibrating.html to TestExpactations
until Vibration API support visibilitychane event.

* platform/efl/TestExpectations:
* vibration/navigator-vibration-expected.txt:
* vibration/navigator-vibration.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@152441 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/platform/efl/TestExpectations
LayoutTests/vibration/navigator-vibration-expected.txt
LayoutTests/vibration/navigator-vibration.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/vibration/NavigatorVibration.cpp
Source/WebCore/Modules/vibration/NavigatorVibration.h
Source/WebCore/Modules/vibration/NavigatorVibration.idl
Source/WebCore/Modules/vibration/Vibration.cpp
Source/WebCore/Modules/vibration/Vibration.h

index 3f44be8..c8bd061 100644 (file)
@@ -1,3 +1,18 @@
+2013-07-08  Kihong Kwon  <kihong.kwon@samsung.com>
+
+        vibrate function have to return boolean value.
+        https://bugs.webkit.org/show_bug.cgi?id=118288
+
+        Reviewed by Gyuyoung Kim.
+
+        Update navigator-vibration.html to adjust latest spec.
+        Add vibration/cancelVibration-during-pattern-vibrating.html to TestExpactations
+        until Vibration API support visibilitychane event.
+
+        * platform/efl/TestExpectations:
+        * vibration/navigator-vibration-expected.txt:
+        * vibration/navigator-vibration.html:
+
 2013-07-06  Rob Buis  <rbuis@rim.com>
 
         createElement("image") creates an HTMLImageElement, although this hack should exist in parser only
index f774066..d0a37a6 100644 (file)
@@ -1760,3 +1760,6 @@ webkit.org/b/116587 http/tests/websocket/tests/hybi/reload-crash.html [ Skip ]
 
 # Synthesized italics not supported
 fast/text/international/synthesized-italic-vertical-latin.html [ Skip ]
+
+# vibration api doesn't support visibilitychange event.
+webkit.org/b/118378 vibration/cancelVibration-after-pagevisibility-changed-to-hidden.html [ Skip ]
index 475be69..e7fc643 100644 (file)
@@ -3,12 +3,13 @@ Test for the Vibration API.
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS navigator.vibrate(0); is undefined
-PASS navigator.vibrate([]); is undefined
-PASS navigator.vibrate(1000); is undefined
-PASS navigator.vibrate([1000, 300, 500]); is undefined
-PASS navigator.vibrate(4294967295); is undefined
+PASS navigator.vibrate(0); is true
+PASS navigator.vibrate([]); is true
+PASS navigator.vibrate(1); is true
+PASS navigator.vibrate([1, 2]); is true
+PASS navigator.vibrate([1, 2, 3]); is true
 PASS navigator.vibrate(); threw exception TypeError: Not enough arguments.
+PASS navigator.vibrate([1], [2]); threw exception TypeError: Type error.
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 6514d87..b2f13e7 100644 (file)
@@ -6,12 +6,13 @@
 <script>
 description('Test for the Vibration API.');
 
-shouldBe("navigator.vibrate(0);", "undefined");
-shouldBe("navigator.vibrate([]);", "undefined");
-shouldBe("navigator.vibrate(1000);", "undefined");
-shouldBe("navigator.vibrate([1000, 300, 500]);", "undefined");
-shouldBe("navigator.vibrate(4294967295);", "undefined");
+shouldBeTrue("navigator.vibrate(0);");
+shouldBeTrue("navigator.vibrate([]);");
+shouldBeTrue("navigator.vibrate(1);");
+shouldBeTrue("navigator.vibrate([1, 2]);");
+shouldBeTrue("navigator.vibrate([1, 2, 3]);");
 shouldThrow("navigator.vibrate();");
+shouldThrow("navigator.vibrate([1], [2]);");
 </script>
 <script src="../fast/js/resources/js-test-post.js"></script>
 </body>
index 2c3e90e..fb9dc98 100644 (file)
@@ -1,3 +1,25 @@
+2013-07-08  Kihong Kwon  <kihong.kwon@samsung.com>
+
+        vibrate function have to return boolean value.
+        https://bugs.webkit.org/show_bug.cgi?id=118288
+
+        Reviewed by Gyuyoung Kim.
+
+        According to latest Vibration API which is LC, vibrate() needs to return boolean value
+        and exception code is removed also. In addition, remove condition for canceling vibration
+        can be called when visibility state is hidden.
+        http://www.w3.org/TR/vibration/
+
+        No new tests. vibration/navigator-vibration.html is changed.
+
+        * Modules/vibration/NavigatorVibration.cpp:
+        (WebCore::NavigatorVibration::vibrate):
+        * Modules/vibration/NavigatorVibration.h:
+        * Modules/vibration/NavigatorVibration.idl:
+        * Modules/vibration/Vibration.cpp:
+        (WebCore::Vibration::vibrate):
+        * Modules/vibration/Vibration.h:
+
 2013-07-07  Kangil Han  <kangil.han@samsung.com>
 
         Adopt is/toHTMLTableElement for code cleanup
index e170470..96e97a9 100644 (file)
@@ -22,7 +22,6 @@
 
 #if ENABLE(VIBRATION)
 
-#include "ExceptionCode.h"
 #include "Frame.h"
 #include "Navigator.h"
 #include "Page.h"
@@ -39,40 +38,22 @@ NavigatorVibration::~NavigatorVibration()
 {
 }
 
-void NavigatorVibration::vibrate(Navigator* navigator, unsigned time, ExceptionCode& ec)
+bool NavigatorVibration::vibrate(Navigator* navigator, unsigned time)
 {
-    if (!navigator->frame()->page())
-        return;
-
-#if ENABLE(PAGE_VISIBILITY_API)
-    if (navigator->frame()->page()->visibilityState() == PageVisibilityStateHidden && time)
-        return;
-#endif
-
-    if (!Vibration::isActive(navigator->frame()->page())) {
-        ec = NOT_SUPPORTED_ERR;
-        return;
-    }
-
-    Vibration::from(navigator->frame()->page())->vibrate(time);
+    return NavigatorVibration::vibrate(navigator, VibrationPattern(time));
 }
 
-void NavigatorVibration::vibrate(Navigator* navigator, const VibrationPattern& pattern, ExceptionCode& ec)
+bool NavigatorVibration::vibrate(Navigator* navigator, const VibrationPattern& pattern)
 {
     if (!navigator->frame()->page())
-        return;
+        return false;
 
 #if ENABLE(PAGE_VISIBILITY_API)
     if (navigator->frame()->page()->visibilityState() == PageVisibilityStateHidden)
-        return;
+        return false;
 #endif
 
-    if (!Vibration::isActive(navigator->frame()->page())) {
-        ec = NOT_SUPPORTED_ERR;
-        return;
-    }
-
-    Vibration::from(navigator->frame()->page())->vibrate(pattern);
+    return Vibration::from(navigator->frame()->page())->vibrate(pattern);
 }
 
 } // namespace WebCore
index 13f0b2b..599344c 100644 (file)
@@ -34,12 +34,13 @@ class NavigatorVibration {
 public:
     typedef Vector<unsigned> VibrationPattern;
 
-    static void vibrate(Navigator*, unsigned time, ExceptionCode&);
-    static void vibrate(Navigator*, const VibrationPattern&, ExceptionCode&);
+    ~NavigatorVibration();
+
+    static bool vibrate(Navigator*, unsigned time);
+    static bool vibrate(Navigator*, const VibrationPattern&);
 
 private:
     NavigatorVibration();
-    ~NavigatorVibration();
 };
 
 } // namespace WebCore
index 09ef38e..9215014 100644 (file)
@@ -20,7 +20,7 @@
 [
     Conditional=VIBRATION,
 ] partial interface Navigator {
-    [RaisesException] void vibrate(sequence<unsigned long> pattern);
-    [RaisesException] void vibrate(unsigned long time);
+    boolean vibrate(sequence<unsigned long> pattern);
+    boolean vibrate(unsigned long time);
 };
 
index d67535e..e035fb7 100644 (file)
@@ -44,36 +44,25 @@ PassOwnPtr<Vibration> Vibration::create(VibrationClient* client)
     return adoptPtr(new Vibration(client));
 }
 
-void Vibration::vibrate(const unsigned& time)
+bool Vibration::vibrate(const VibrationPattern& pattern)
 {
-    if (!time) {
-        cancelVibration();
-        return;
-    }
-    m_pattern.append(time);
-    m_timerStart.startOneShot(0);
-    m_isVibrating = true;
-}
-
-void Vibration::vibrate(const VibrationPattern& pattern)
-{
-    int length = pattern.size();
+    size_t length = pattern.size();
 
-    // Cancel the pre-existing instance of vibration patterns, if the pattern is 0 or an empty list.
-    if (!length || (length == 1 && !pattern[0])) {
-        cancelVibration();
-        return;
-    }
+    m_pattern = pattern;
+    if (length && !(length % 2))
+        m_pattern.removeLast();
 
-    if (m_isVibrating)
+    // Pre-exsiting instance need to be canceled when vibration is called.
+    // And if time is 0, vibration have to be canceled also.
+    if (m_isVibrating || (m_pattern.size() == 1 && !m_pattern[0]))
         cancelVibration();
 
-    if (m_timerStart.isActive())
-        m_timerStart.stop();
+    if (!m_pattern.size())
+        return true;
 
-    m_pattern = pattern;
     m_timerStart.startOneShot(0);
     m_isVibrating = true;
+    return true;
 }
 
 void Vibration::cancelVibration()
index 58ff421..c0be574 100644 (file)
@@ -39,8 +39,7 @@ public:
 
     static PassOwnPtr<Vibration> create(VibrationClient*);
 
-    void vibrate(const unsigned& time);
-    void vibrate(const VibrationPattern&);
+    bool vibrate(const VibrationPattern&);
     void cancelVibration();
 
     // FIXME : Add suspendVibration() and resumeVibration() to the page visibility feature, when the document.hidden attribute is changed.