Bug 769435 - Convert test_openLocationLastURL.js from a xpcshell test to a mochitest r=ehsan
authorAndres Hernandez <andres@appcoast.com>
Wed, 18 Jul 2012 10:44:51 -0600
changeset 99791 775c7786a753aaf332c8e1b635b3b1dffe2535e1
parent 99790 a85081e2fbff0d10b4bbd9bfc9d729f16acffe07
child 99792 7bd28eb29f440d6585ab97d7a01da64f8e15ebeb
push id23151
push useremorley@mozilla.com
push dateFri, 20 Jul 2012 13:33:35 +0000
treeherdermozilla-central@3337f0685b75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs769435
milestone17.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 769435 - Convert test_openLocationLastURL.js from a xpcshell test to a mochitest r=ehsan
browser/components/privatebrowsing/test/browser/Makefile.in
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_openLocationLastURL.js
browser/components/privatebrowsing/test/unit/test_openLocationLastURL.js
browser/components/privatebrowsing/test/unit/xpcshell.ini
--- a/browser/components/privatebrowsing/test/browser/Makefile.in
+++ b/browser/components/privatebrowsing/test/browser/Makefile.in
@@ -9,16 +9,18 @@ VPATH		= @srcdir@
 relativesrcdir  = browser/components/privatebrowsing/test/browser
 
 include $(DEPTH)/config/autoconf.mk
 
 MOCHITEST_BROWSER_FILES =  \
 		head.js \
 		browser_console_clear.js \
 		browser_privatebrowsing_certexceptionsui.js \
+		browser_privatebrowsing_clearplugindata.js \
+		browser_privatebrowsing_clearplugindata.html \
 		browser_privatebrowsing_commandline_toggle.js \
 		browser_privatebrowsing_concurrent.js \
 		browser_privatebrowsing_concurrent_page.html \
 		browser_privatebrowsing_crh.js \
 		browser_privatebrowsing_fastswitch.js \
 		browser_privatebrowsing_findbar.js \
 		browser_privatebrowsing_forgetthissite.js \
 		browser_privatebrowsing_geoprompt.js \
@@ -29,16 +31,17 @@ MOCHITEST_BROWSER_FILES =  \
 		browser_privatebrowsing_localStorage_before_after.js \
 		browser_privatebrowsing_localStorage_before_after_page.html \
 		browser_privatebrowsing_localStorage_before_after_page2.html \
 		browser_privatebrowsing_localStorage_page1.html \
 		browser_privatebrowsing_localStorage_page2.html \
 		browser_privatebrowsing_newwindow_stopcmd.js \
 		browser_privatebrowsing_opendir.js \
 		browser_privatebrowsing_openlocation.js \
+		browser_privatebrowsing_openLocationLastURL.js \
 		browser_privatebrowsing_pageinfo.js \
 		browser_privatebrowsing_placestitle.js \
 		browser_privatebrowsing_popupblocker.js \
 		browser_privatebrowsing_popupmode.js \
 		browser_privatebrowsing_protocolhandler.js \
 		browser_privatebrowsing_protocolhandler_page.html \
 		browser_privatebrowsing_searchbar.js \
 		browser_privatebrowsing_sslsite_transition.js \
@@ -47,18 +50,16 @@ MOCHITEST_BROWSER_FILES =  \
 		browser_privatebrowsing_ui.js \
 		browser_privatebrowsing_urlbarfocus.js \
 		browser_privatebrowsing_urlbarundo.js \
 		browser_privatebrowsing_viewsource.js \
 		browser_privatebrowsing_windowtitle.js \
 		browser_privatebrowsing_windowtitle_page.html \
 		browser_privatebrowsing_zoom.js \
 		browser_privatebrowsing_zoomrestore.js \
-		browser_privatebrowsing_clearplugindata.js \
-		browser_privatebrowsing_clearplugindata.html \
 		ctxmenu.html \
 		ctxmenu-image.png \
 		popup.html \
 		staller.sjs \
 		title.sjs \
 		$(NULL)
 
 # Disabled until bug 564934 is fixed:
new file mode 100644
--- /dev/null
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_openLocationLastURL.js
@@ -0,0 +1,63 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+function test() {
+  const URL_1 = "mozilla.org";
+  const URL_2 = "mozilla.com";
+
+  let openLocationLastURL = getLocationModule();
+  let privateBrowsingService =
+    Cc["@mozilla.org/privatebrowsing;1"].
+      getService(Ci.nsIPrivateBrowsingService);
+
+  function clearHistory() {
+    Services.obs.notifyObservers(null, "browser:purge-session-history", "");
+  }
+  function testURL(aTestNumber, aValue) {
+    is(openLocationLastURL.value, aValue,
+       "Test: " + aTestNumber + ": Validate last url value.");
+  }
+
+  // Clean to start testing.
+  is(typeof openLocationLastURL, "object", "Validate type of last url.");
+  openLocationLastURL.reset();
+  testURL(1, "");
+
+  // Test without private browsing.
+  openLocationLastURL.value = URL_1;
+  testURL(2, URL_1);
+  openLocationLastURL.value = "";
+  testURL(3, "");
+  openLocationLastURL.value = URL_2;
+  testURL(4, URL_2);
+  clearHistory();
+  testURL(5, "");
+
+  // Test changing private browsing.
+  openLocationLastURL.value = URL_2;
+  privateBrowsingService.privateBrowsingEnabled = true;
+  testURL(6, "");
+  privateBrowsingService.privateBrowsingEnabled = false;
+  testURL(7, URL_2);
+  privateBrowsingService.privateBrowsingEnabled = true;
+  openLocationLastURL.value = URL_1;
+  testURL(8, URL_1);
+  privateBrowsingService.privateBrowsingEnabled = false;
+  testURL(9, URL_2);
+  privateBrowsingService.privateBrowsingEnabled = true;
+  openLocationLastURL.value = URL_1;
+  testURL(10, URL_1);
+
+  // Test cleaning history.
+  clearHistory();
+  testURL(11, "");
+  privateBrowsingService.privateBrowsingEnabled = false;
+  testURL(12, "");
+}
+
+function getLocationModule() {
+  let openLocationModule = {};
+  Cu.import("resource:///modules/openLocationLastURL.jsm", openLocationModule);
+  return new openLocationModule.OpenLocationLastURL(window);
+}
deleted file mode 100644
--- a/browser/components/privatebrowsing/test/unit/test_openLocationLastURL.js
+++ /dev/null
@@ -1,78 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-// Test the correct behavior of the openLocationLastURL.jsm JS module.
-
-function run_test_on_service()
-{
-  let openLocationModule = {};
-  // This variable fakes the window required for getting the PB flag
-  let window = { gPrivateBrowsingUI: { privateWindow: false } };
-  Cu.import("resource:///modules/openLocationLastURL.jsm", openLocationModule);
-  let gOpenLocationLastURL = new openLocationModule.OpenLocationLastURL(window);
-  
-  function clearHistory() {
-    // simulate clearing the private data
-    Cc["@mozilla.org/observer-service;1"].
-    getService(Ci.nsIObserverService).
-    notifyObservers(null, "browser:purge-session-history", "");
-  }
-  
-  let pb = Cc[PRIVATEBROWSING_CONTRACT_ID].
-           getService(Ci.nsIPrivateBrowsingService);
-  let pref = Cc["@mozilla.org/preferences-service;1"].
-             getService(Ci.nsIPrefBranch);
-  gOpenLocationLastURL.reset();
-
-  do_check_eq(typeof gOpenLocationLastURL, "object");
-  do_check_eq(gOpenLocationLastURL.value, "");
-
-  function switchPrivateBrowsing(flag) {
-    pb.privateBrowsingEnabled = flag;
-    window.gPrivateBrowsingUI.privateWindow = flag;
-  }
-
-  const url1 = "mozilla.org";
-  const url2 = "mozilla.com";
-
-  gOpenLocationLastURL.value = url1;
-  do_check_eq(gOpenLocationLastURL.value, url1);
-
-  gOpenLocationLastURL.value = "";
-  do_check_eq(gOpenLocationLastURL.value, "");
-
-  gOpenLocationLastURL.value = url2;
-  do_check_eq(gOpenLocationLastURL.value, url2);
-
-  clearHistory();
-  do_check_eq(gOpenLocationLastURL.value, "");
-  gOpenLocationLastURL.value = url2;
-
-  switchPrivateBrowsing(true);
-  do_check_eq(gOpenLocationLastURL.value, "");
-  
-  switchPrivateBrowsing(false);
-  do_check_eq(gOpenLocationLastURL.value, url2);
-  switchPrivateBrowsing(true);
-
-  gOpenLocationLastURL.value = url1;
-  do_check_eq(gOpenLocationLastURL.value, url1);
-
-  switchPrivateBrowsing(false);
-  do_check_eq(gOpenLocationLastURL.value, url2);
-
-  switchPrivateBrowsing(true);
-  gOpenLocationLastURL.value = url1;
-  do_check_neq(gOpenLocationLastURL.value, "");
-  clearHistory();
-  do_check_eq(gOpenLocationLastURL.value, "");
-
-  switchPrivateBrowsing(false);
-  do_check_eq(gOpenLocationLastURL.value, "");
-}
-
-// Support running tests on both the service itself and its wrapper
-function run_test() {
-  run_test_on_all_services();
-}
--- a/browser/components/privatebrowsing/test/unit/xpcshell.ini
+++ b/browser/components/privatebrowsing/test/unit/xpcshell.ini
@@ -2,17 +2,16 @@
 head = head_privatebrowsing.js
 tail = tail_privatebrowsing.js
 
 [test_0-privatebrowsing.js]
 [test_0-privatebrowsingwrapper.js]
 [test_aboutprivatebrowsing.js]
 [test_geoClearCookie.js]
 [test_httpauth.js]
-[test_openLocationLastURL.js]
 [test_placesTitleNoUpdate.js]
 [test_privatebrowsing_autostart.js]
 [test_privatebrowsing_commandline.js]
 [test_privatebrowsing_exit.js]
 [test_privatebrowsing_telemetry.js]
 [test_privatebrowsingwrapper_autostart.js]
 [test_privatebrowsingwrapper_commandline.js]
 [test_privatebrowsingwrapper_exit.js]