[Power] Fix Power API failures on tct test suites.
authorAlexis Menard <alexis@webkit.org>
Tue, 17 Sep 2013 18:21:50 +0000 (15:21 -0300)
committerAlexis Menard <alexis@webkit.org>
Tue, 17 Sep 2013 18:54:53 +0000 (15:54 -0300)
-Remove workaround of glib callback as it is not needed anymore : the
extensions run in a separate process.
-Remove commented code in the examples as now switching on and off doesn't
background crosswalk behind the launcher.

examples/power.html
power/power_context_mobile.cc

index 54a2843..13c34f3 100644 (file)
@@ -76,18 +76,13 @@ shouldNotThrow("tizen.power.request('SCREEN', 'SCREEN_NORMAL')");
 shouldNotThrow("tizen.power.request('SCREEN', 'SCREEN_BRIGHT')");
 shouldThrow("tizen.power.release(1)", "new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR)");
 shouldThrow("tizen.power.release('MOUSE')", "new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR)");
-// FIXME : For now deactivate the test of turning off the screen as it will lead to the lock screen but afer unlocking Xwalk is
-// not in foreground so you can't check the results. When #313 is fixed we can turn it on.
-//shouldNotThrow("tizen.power.release('CPU')");
+shouldNotThrow("tizen.power.release('CPU')");
 shouldNotThrow("tizen.power.release('SCREEN')");
 
 var screenBrightness = tizen.power.getScreenBrightness();
 shouldThrow("tizen.power.setScreenBrightness('1')", "new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR)");
 shouldThrow("tizen.power.setScreenBrightness(2)", "new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR)");
 tizen.power.setScreenBrightness(0.5);
-// FIXME : Getter needs sync and uses vconf which can't be called from the extensions thread. When the extensions are
-// in their own process we can enable the test and fix the getter to work.
-//shouldBe("tizen.power.getScreenBrightness()", "0.5");
 
 tizen.power.restoreScreenBrightness();
 shouldBeTrue("tizen.power.getScreenBrightness() == screenBrightness");
@@ -115,10 +110,8 @@ function switchOffScreen() {
   tizen.power.unsetScreenStateChangeListener(ScreenStateChangeListener);
   tizen.power.restoreScreenBrightness();
   shouldBeTrue("tizen.power.isScreenOn()");
-  // FIXME : For now deactivate the test of turning off the screen as it will lead to the lock screen but afer unlocking Xwalk is
-  // not in foreground so you can't check the results. When #313 is fixed we can turn it on.
-  //shouldNotThrow("tizen.power.turnScreenOff()");
-  //setTimeout(waitForScreenOff, 100);
+  shouldNotThrow("tizen.power.turnScreenOff()");
+  setTimeout(waitForScreenOff, 100);
 }
 
 function waitForScreenOff() {
index 34072d5..bc33f96 100644 (file)
@@ -120,36 +120,21 @@ void PowerContext::HandleRelease(const picojson::value& msg) {
   // FIXME: Check return value and throw exception if needed.
 }
 
-// FIXME : This callback can be removed when extensions are moved to
-// their own process. For now it is needed for vconf to function correctly.
-// This callback actually make sure that the code is run in the main thread.
-static gboolean set_brightness_callback(gpointer data) {
-  double* brightness = static_cast<double*>(data);
-  if (*brightness < 0) {
+void PowerContext::HandleSetScreenBrightness(const picojson::value& msg) {
+  double brightness = msg.get("value").get<double>();
+  if (brightness < 0)
     // Resource brightness.
     device_set_brightness_from_settings(0);
-    delete brightness;
-    return false;
-  }
 
   int maxBrightness;
   power_wakeup(false);
   int ret = device_get_max_brightness(0, &maxBrightness);
   if (ret != 0) {
     fprintf(stderr, "Can't get the max brightness from the platform. \n");
-    device_set_brightness(0, static_cast<int>(*brightness * 100.0));
+    device_set_brightness(0, static_cast<int>(brightness * 100.0));
   } else {
-    device_set_brightness(0, static_cast<int>(*brightness * maxBrightness));
+    device_set_brightness(0, static_cast<int>(brightness * maxBrightness));
   }
-  delete brightness;
-  return false;
-}
-
-void PowerContext::HandleSetScreenBrightness(const picojson::value& msg) {
-  double* requested_brightness = new double[1];
-  *requested_brightness = msg.get("value").get<double>();
-  g_timeout_add(0, set_brightness_callback,
-                static_cast<gpointer>(requested_brightness));
 }
 
 void PowerContext::HandleGetScreenState() {
@@ -161,10 +146,11 @@ void PowerContext::HandleGetScreenState() {
 }
 
 void PowerContext::HandleGetScreenBrightness() {
-  // FIXME : This need to be called from the main thread, when extensions are
-  // moved to their own process the code should work.
   int platformBrightness;
-  vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &platformBrightness);
+  int ret = device_get_brightness(0, &platformBrightness);
+  if (ret != 0)
+    fprintf(stderr, "Can't get the brightness from the platform. \n");
+
   double brightness = platformBrightness / 100.0;
   char brightnessAsString[32];
   snprintf(brightnessAsString, sizeof(brightnessAsString), "%g", brightness);