summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sessions
diff options
context:
space:
mode:
authorjerrica@google.com <jerrica@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-17 17:16:56 +0000
committerjerrica@google.com <jerrica@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-17 17:16:56 +0000
commit6cc93378b95958438fb0095a94d362da1ef89af7 (patch)
treea77c1bb9a1aef5f9a8741649f120e0154c9fd5e0 /chrome/browser/sessions
parent5253c609143203efd367bde34aca8b01891b4f60 (diff)
downloadchromium_src-6cc93378b95958438fb0095a94d362da1ef89af7.zip
chromium_src-6cc93378b95958438fb0095a94d362da1ef89af7.tar.gz
chromium_src-6cc93378b95958438fb0095a94d362da1ef89af7.tar.bz2
Created notification for when a session is saved.
Created a notification for when a session is saved, so that later we can observe this notification and sync a session. BUG=30519 TEST=session_service_unittest.cc Review URL: http://codereview.chromium.org/2858005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50119 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sessions')
-rw-r--r--chrome/browser/sessions/session_service.cc7
-rw-r--r--chrome/browser/sessions/session_service_unittest.cc29
2 files changed, 32 insertions, 4 deletions
diff --git a/chrome/browser/sessions/session_service.cc b/chrome/browser/sessions/session_service.cc
index da7508b..1669218 100644
--- a/chrome/browser/sessions/session_service.cc
+++ b/chrome/browser/sessions/session_service.cc
@@ -431,8 +431,13 @@ SessionService::Handle SessionService::GetCurrentSession(
void SessionService::Save() {
bool had_commands = !pending_commands().empty();
BaseSessionService::Save();
- if (had_commands)
+ if (had_commands) {
RecordSaveHistogramData();
+ NotificationService::current()->Notify(
+ NotificationType::SESSION_SERVICE_SAVED,
+ NotificationService::AllSources(),
+ NotificationService::NoDetails());
+ }
}
diff --git a/chrome/browser/sessions/session_service_unittest.cc b/chrome/browser/sessions/session_service_unittest.cc
index 83793bf..5b30328 100644
--- a/chrome/browser/sessions/session_service_unittest.cc
+++ b/chrome/browser/sessions/session_service_unittest.cc
@@ -16,13 +16,18 @@
#include "chrome/browser/sessions/session_types.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/common/chrome_paths.h"
+#include "chrome/common/notification_observer.h"
+#include "chrome/common/notification_registrar.h"
+#include "chrome/common/notification_service.h"
+#include "chrome/common/notification_type.h"
#include "chrome/test/browser_with_test_window_test.h"
#include "chrome/test/file_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
-class SessionServiceTest : public BrowserWithTestWindowTest {
+class SessionServiceTest : public BrowserWithTestWindowTest,
+ public NotificationObserver {
public:
- SessionServiceTest() : window_bounds(0, 1, 2, 3) {}
+ SessionServiceTest() : window_bounds(0, 1, 2, 3), sync_save_count_(0){}
protected:
virtual void SetUp() {
@@ -42,6 +47,14 @@ class SessionServiceTest : public BrowserWithTestWindowTest {
service()->SetWindowBounds(window_id, window_bounds, false);
}
+ // Upon notification, increment the sync_save_count variable
+ void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ ASSERT_EQ(type.value, NotificationType::SESSION_SERVICE_SAVED);
+ sync_save_count_++;
+ }
+
virtual void TearDown() {
helper_.set_service(NULL);
path_deleter_.reset();
@@ -80,7 +93,6 @@ class SessionServiceTest : public BrowserWithTestWindowTest {
// and the pinned state of the read back tab is returned.
bool CreateAndWriteSessionWithOneTab(bool pinned_state, bool write_always) {
SessionID tab_id;
-
TabNavigation nav1(0, GURL("http://google.com"),
GURL("http://www.referrer.com"),
ASCIIToUTF16("abc"), "def",
@@ -116,6 +128,8 @@ class SessionServiceTest : public BrowserWithTestWindowTest {
SessionID window_id;
+ int sync_save_count_;
+
// Path used in testing.
FilePath path_;
scoped_ptr<FileAutoDeleter> path_deleter_;
@@ -618,6 +632,15 @@ TEST_F(SessionServiceTest, GetCurrentSession) {
NewCallback(&handler, &GetCurrentSessionCallbackHandler::OnGotSession));
}
+// Test that the notification for SESSION_SERVICE_SAVED is working properly.
+TEST_F(SessionServiceTest, SavedSessionNotification) {
+ NotificationRegistrar registrar_;
+ registrar_.Add(this, NotificationType::SESSION_SERVICE_SAVED,
+ NotificationService::AllSources());
+ service()->Save();
+ EXPECT_EQ(sync_save_count_, 1);
+}
+
// Makes sure a tab closed by a user gesture is not restored.
TEST_F(SessionServiceTest, CloseTabUserGesture) {
SessionID tab_id;