Bug 613562 - VKB will stay open in portrait mode when going to the preference panel [r=mfinkle]
authorVivien Nicolas <21@vingtetun.org>
Wed, 24 Nov 2010 14:54:42 +0100
changeset 67067 8ace02c105b4ccd0da0ce8fd9024e3aeec623050
parent 67066 6b8fc7b792d414c77f62793ba19dc5a649637517
child 67068 2f79401a0dfe195580a27144811d00cfe0250e7b
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs613562
Bug 613562 - VKB will stay open in portrait mode when going to the preference panel [r=mfinkle]
mobile/chrome/content/browser-ui.js
mobile/chrome/tests/Makefile.in
mobile/chrome/tests/browser_vkb.js
mobile/chrome/tests/remote_vkb.js
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -636,18 +636,17 @@ var BrowserUI = {
     Util.forceOnline();
 
     let engine = Services.search.getEngineByName(aName);
     let submission = engine.getSubmission(searchValue, null);
     Browser.loadURI(submission.uri.spec, { postData: submission.postData });
   },
 
   updateUIFocus: function _updateUIFocus() {
-    let state = (Elements.contentShowing.getAttribute("disabled") == "true") ? "Blur" : "Focus";
-    Browser.selectedBrowser.messageManager.sendAsyncMessage("Browser:" + state, {});
+    Browser.selectedBrowser.active = !(Elements.contentShowing.getAttribute("disabled") == "true");
   },
 
   updateStar: function() {
     if (PlacesUtils.getMostRecentBookmarkForURI(Browser.selectedBrowser.currentURI) != -1)
       this.starButton.setAttribute("starred", "true");
     else
       this.starButton.removeAttribute("starred");
   },
--- a/mobile/chrome/tests/Makefile.in
+++ b/mobile/chrome/tests/Makefile.in
@@ -45,16 +45,17 @@ ADDONSRC = $(srcdir)/addons
 
 include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/rules.mk
 
 _BROWSER_FILES = \
   head.js \
   remote_head.js \
   remote_forms.js \
+  remote_vkb.js \
   browser_awesomescreen.js \
   browser_blank_01.html \
   browser_blank_02.html \
   browser_bookmarks.js \
   browser_bookmarks_star.js \
   browser_bookmarks_tags.js \
   browser_click_content.html \
   browser_click_content.js \
@@ -71,16 +72,17 @@ include $(topsrcdir)/config/rules.mk
   browser_rememberPassword.js \
   browser_select.html \
   browser_select.js \
   browser_sessionstore.js \
   browser_tabs.js \
   browser_tapping.js \
   browser_tap_content.html \
   browser_test.js \
+  browser_vkb.js \
   browser_viewport.js \
   browser_viewport.sjs \
   browser_no_title.html \
   browser_english_title.html \
   browser_install.xml \
   browser_upgrade.rdf\
   $(NULL)
 
new file mode 100644
--- /dev/null
+++ b/mobile/chrome/tests/browser_vkb.js
@@ -0,0 +1,146 @@
+/* 
+ * Check VKB show/hide behavior
+ */
+let testURL_01 = chromeRoot + "browser_forms.html";
+messageManager.loadFrameScript(chromeRoot + "remote_vkb.js", true);
+
+/* ============================= Tests Utils =============================== */
+let gTests = [];
+let gCurrentTest = null;
+
+// Iterating tests by shifting test out one by one as runNextTest is called.
+function runNextTest() {
+  // Run the next test until all tests completed
+  if (gTests.length > 0) {
+    gCurrentTest = gTests.shift();
+    info(gCurrentTest.desc);
+    gCurrentTest.run();
+  }
+  else {
+    // Close the awesome panel just in case
+    BrowserUI.activePanel = null;
+    finish();
+  }
+}
+
+function test() {
+  // The "runNextTest" approach is async, so we need to call "waitForExplicitFinish()"
+  // We call "finish()" when the tests are finished
+  waitForExplicitFinish();
+
+  // Start the tests
+  if ("gTimeout" in window)
+    setTimeout(runNextTest, gTimeout);
+  else
+    runNextTest();
+}
+/* ============================ End Utils ================================== */
+
+Components.utils.import("resource://gre/modules/Services.jsm");
+let VKBStateHasChanged = false;
+let VKBObserver = {
+  _enabled: false,
+  observe: function(aTopic, aSubject, aData) {
+    if (this._enabled != parseInt(aData)) {
+      this._enabled = parseInt(aData);
+      VKBstateHasChanged = true;
+    }
+  }
+};
+Services.obs.addObserver(VKBObserver, "ime-enabled-state-changed", false);
+
+function waitForVKBChange(aCallback, aState) {
+  waitForAndContinue(aCallback, function() {
+    if (VKBStateHasChanged) {
+      VKBStateHasChanged = false;
+      return true;
+    }
+      
+    return VKBStateHasChanged;
+  });
+}
+
+
+let newTab = null;
+
+let isLoading = function() {
+  return !newTab.isLoading() && newTab.browser.currentURI.spec != "about:blank";
+};
+
+function dragElement(element, x1, y1, x2, y2) {
+  EventUtils.synthesizeMouse(element, x1, y1, { type: "mousedown" });
+  EventUtils.synthesizeMouse(element, x2, y2, { type: "mousemove" });
+  EventUtils.synthesizeMouse(element, x2, y2, { type: "mouseup" });
+}
+
+//------------------------------------------------------------------------------
+// Case: Test interactions with a VKB from content
+gTests.push({
+  desc: "Test interactions with a VKB from content",
+
+  run: function() {
+    newTab = Browser.addTab(testURL_01, true);
+    ok(newTab, "Tab Opened");	
+    waitFor(gCurrentTest.focusContentInputField, isLoading);
+  },
+
+  focusContentInputField: function() {
+    is(VKBObserver._enabled, false, "Initially the VKB should be closed");
+
+    AsyncTests.waitFor("Test:Focus", {}, function(json) {
+      waitForVKBChange(gCurrentTest.showLeftSidebar);
+    })
+  },
+
+  showLeftSidebar: function() {
+    is(VKBObserver._enabled, true, "When focusing an input field the VKB should be opened");
+
+    let browsers = document.getElementById("browsers");
+    dragElement(browsers, window.innerWidth / 2, window.innerHeight / 2, 1000, 1000);
+    waitForVKBChange(gCurrentTest.showRightSidebar);
+  },
+
+  showRightSidebar: function() {
+    is(VKBObserver._enabled, true, "When pannning to the leftSidebar the VKB state should not changed");
+
+    let browsers = document.getElementById("browsers");
+    dragElement(browsers, window.innerWidth / 2, window.innerHeight / 2, -1000, -1000);
+    waitForVKBChange(gCurrentTest.changeTab);
+  },
+
+  changeTab: function() {
+    is(VKBObserver._enabled, true, "When panning to the right sidebar the VKB state should not changed");
+
+    let firstTab = document.getElementById("tabs").children.firstChild;
+    BrowserUI.selectTab(firstTab);
+    waitForVKBChange(gCurrentTest.prepareOpenRightPanel);
+  },
+
+  prepareOpenRightPanel: function() {
+    is(VKBObserver._enabled, false, "Switching tab should close the VKB");
+
+    BrowserUI.selectTab(newTab);
+
+    // Give back the focus to the content input and launch and check
+    // interaction with the right panel
+    AsyncTests.waitFor("Test:Focus", {}, function(json) {
+      waitForVKBChange(gCurrentTest.openRightPanel);
+    });
+  },
+
+  openRightPanel: function() {
+    is(VKBObserver._enabled, true, "Re-cliking on an input field should re-open the VKB");
+
+    let toolsButton = document.getElementById("tool-panel-open");
+    let rect = toolsButton.getBoundingClientRect();
+    EventUtils.synthesizeMouse(toolsButton, rect.width / 2, rect.height / 2, {});
+    waitForVKBChange(function() {
+      is(VKBObserver._enabled, false, "Opening the right panel should close the VKB");
+      BrowserUI.hidePanel();
+      Browser.hideSidebars();
+      BrowserUI.closeTab(newTab);
+      Services.obs.removeObserver(VKBObserver, "ime-enabled-state-changed");
+      runNextTest();
+    });
+  }
+});
new file mode 100644
--- /dev/null
+++ b/mobile/chrome/tests/remote_vkb.js
@@ -0,0 +1,6 @@
+dump("====================== Content Script Loaded =======================\n");
+
+AsyncTests.add("Test:Focus", function(aMessage, aJson) {
+  content.document.getElementById("root").focus();
+  return true;
+});