From 6a9a54c60091a5a36ceb53206ba28d3996f78303 Mon Sep 17 00:00:00 2001 From: Benjamin Stover Date: Wed, 9 Feb 2011 11:46:28 -0800 Subject: [PATCH] Bug 630593 Remove try/catch and test for saving history r=mfinkle --- mobile/chrome/content/content.js | 4 +- mobile/chrome/tests/Makefile.in | 1 + mobile/chrome/tests/browser_history.js | 75 ++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 mobile/chrome/tests/browser_history.js diff --git a/mobile/chrome/content/content.js b/mobile/chrome/content/content.js index daa3ef694e81..929a76030392 100644 --- a/mobile/chrome/content/content.js +++ b/mobile/chrome/content/content.js @@ -261,9 +261,7 @@ let Content = { addEventListener("pagehide", this, false); addEventListener("keypress", this, false, false); - try{ - docShell.QueryInterface(Ci.nsIDocShellHistory).useGlobalHistory = true; - } catch(e) { } + docShell.QueryInterface(Ci.nsIDocShellHistory).useGlobalHistory = true; }, handleEvent: function handleEvent(aEvent) { diff --git a/mobile/chrome/tests/Makefile.in b/mobile/chrome/tests/Makefile.in index 0727260216b6..205d36b93bd6 100644 --- a/mobile/chrome/tests/Makefile.in +++ b/mobile/chrome/tests/Makefile.in @@ -67,6 +67,7 @@ _BROWSER_FILES = \ browser_forms.js \ browser_formsZoom.html \ browser_formsZoom.js \ + browser_history.js \ browser_mainui.js \ browser_navigation.js \ browser_preferences_text.js \ diff --git a/mobile/chrome/tests/browser_history.js b/mobile/chrome/tests/browser_history.js new file mode 100644 index 000000000000..87a3ee03d1b8 --- /dev/null +++ b/mobile/chrome/tests/browser_history.js @@ -0,0 +1,75 @@ +/* + * Make sure history is being recorded when we visit websites. + */ + +var testURL_01 = "http://mochi.test:8888/browser/mobile/chrome/browser_blank_01.html"; + +// A queue to order the tests and a handle for each test +var gTests = []; +var gCurrentTest = null; + +//------------------------------------------------------------------------------ +// Entry point (must be named "test") +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 + runNextTest(); +} + +//------------------------------------------------------------------------------ +// 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 { + // Cleanup. All tests are completed at this point + try { + } + finally { + // We must finialize the tests + finish(); + } + } +} + +/** + * One-time observer callback. + */ +function waitForObserve(name, callback) { + var observerService = Cc["@mozilla.org/observer-service;1"] + .getService(Ci.nsIObserverService); + var observer = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]), + observe: function(subject, topic, data) { + observerService.removeObserver(observer, name); + observer = null; + callback(subject, topic, data); + } + }; + + observerService.addObserver(observer, name, false); +} + +//------------------------------------------------------------------------------ + +gTests.push({ + desc: "Test history being added with page visit", + _currentTab: null, + + run: function() { + this._currentTab = Browser.addTab(testURL_01, true); + waitForObserve("uri-visit-saved", function(subject, topic, data) { + let uri = subject.QueryInterface(Ci.nsIURI); + ok(uri.spec == testURL_01, "URI was saved to history"); + Browser.closeTab(gCurrentTest._currentTab); + runNextTest(); + }); + } +});