From effa34a879e8087852074f297bc8b6785cfe2a5a Mon Sep 17 00:00:00 2001 From: Pallani Kumaran Date: Mon, 16 Apr 2012 23:17:54 -0700 Subject: [PATCH] Bug 739866 - Store last accessed timestamp for tabbrowser tabs [r=zpao] --- browser/base/content/tabbrowser.xml | 2 ++ browser/base/content/test/Makefile.in | 1 + .../content/test/browser_lastAccessedTab.js | 24 +++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 browser/base/content/test/browser_lastAccessedTab.js diff --git a/browser/base/content/tabbrowser.xml b/browser/base/content/tabbrowser.xml index d5b63603efca..c80b387b89b5 100644 --- a/browser/base/content/tabbrowser.xml +++ b/browser/base/content/tabbrowser.xml @@ -924,6 +924,7 @@ if (!this._previewMode) { this.mCurrentTab.removeAttribute("unread"); + this.selectedTab.lastAccessed = Date.now(); #ifdef MOZ_E10S_COMPAT // Bug 666816 - TypeAheadFind support for e10s @@ -3816,6 +3817,7 @@ null false false + 0 diff --git a/browser/base/content/test/Makefile.in b/browser/base/content/test/Makefile.in index ee8c325d53e4..f1a257d86409 100644 --- a/browser/base/content/test/Makefile.in +++ b/browser/base/content/test/Makefile.in @@ -273,6 +273,7 @@ _BROWSER_FILES = \ browser_middleMouse_inherit.js \ redirect_bug623155.sjs \ browser_tabDrop.js \ + browser_lastAccessedTab.js \ $(NULL) ifneq (cocoa,$(MOZ_WIDGET_TOOLKIT)) diff --git a/browser/base/content/test/browser_lastAccessedTab.js b/browser/base/content/test/browser_lastAccessedTab.js new file mode 100644 index 000000000000..4d788092a897 --- /dev/null +++ b/browser/base/content/test/browser_lastAccessedTab.js @@ -0,0 +1,24 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Test for bug 739866. + * + * 1. Adds a new tab (but doesn't select it) + * 2. Checks if timestamp on the new tab is 0 + * 3. Selects the new tab, checks that the timestamp is updated (>0) + * 4. Selects the original tab & checks if new tab's timestamp has remained changed + */ + +function test() { + let originalTab = gBrowser.selectedTab; + let newTab = gBrowser.addTab("about:blank", {skipAnimation: true}); + is(newTab.lastAccessed, 0, "Timestamp on the new tab is 0."); + gBrowser.selectedTab = newTab; + let newTabAccessedDate = newTab.lastAccessed; + ok(newTabAccessedDate > 0, "Timestamp on the selected tab is more than 0."); + ok(newTabAccessedDate <= Date.now(), "Timestamp less than or equal current Date."); + gBrowser.selectedTab = originalTab; + is(newTab.lastAccessed, newTabAccessedDate, "New tab's timestamp remains the same."); + gBrowser.removeTab(newTab); +}