Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Unified Diff: chrome/browser/sessions/session_utils_unittest.cc

Issue 7931027: Refactoring recently closed tab filtering (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Long live the STL Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sessions/session_utils_unittest.cc
diff --git a/chrome/browser/sessions/session_utils_unittest.cc b/chrome/browser/sessions/session_utils_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2d38fa1c8c2a8f384399f9620d79f2c27e639191
--- /dev/null
+++ b/chrome/browser/sessions/session_utils_unittest.cc
@@ -0,0 +1,76 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/sessions/session_utils.h"
+
+#include "base/stl_util.h"
+#include "base/string16.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/sessions/session_types.h"
+#include "googleurl/src/gurl.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class TabNavigationMock : public TabNavigation {
+ public:
+ TabNavigationMock(const char* url, const char* title)
+ : TabNavigation(0, // index
+ GURL(string16(ASCIIToUTF16(url))), // virtual_url
+ GURL(), // referrer
+ string16(ASCIIToUTF16(title)), // title
+ "", // state
+ PageTransition::FROM_ADDRESS_BAR) {
+ }
+};
+
+class SessionUtilsTest : public testing::Test {
+ protected:
+ class TabMock : public TabRestoreService::Tab {
+ public:
+ TabMock(const char* url, const char* title) {
+ navigations.push_back(TabNavigationMock(url, title));
+ current_navigation_index = 0;
+ }
+ };
+
+ virtual void SetUp() {
+ // prefill the entries
+
+ // Two identical
+ entries_.push_back(new TabMock("http://a", "a"));
+ entries_.push_back(new TabMock("http://a", "a"));
+
+ // Different URL
+ entries_.push_back(new TabMock("http://b", "b"));
+ entries_.push_back(new TabMock("http://c", "b"));
+
+ // Different Title
+ entries_.push_back(new TabMock("http://d", "d"));
+ entries_.push_back(new TabMock("http://d", "e"));
+
+ // Nothing in common
+ entries_.push_back(new TabMock("http://f", "f"));
+ entries_.push_back(new TabMock("http://g", "g"));
+ }
+
+ void TearDown() {
+ STLDeleteElements(&entries_);
+ }
+
+ TabRestoreService::Entries entries_;
+};
+
+TEST_F(SessionUtilsTest, SessionUtilsFilter) {
+ TabRestoreService::Entries filtered_entries;
+
+ SessionUtils::FilteredEntries(entries_, &filtered_entries);
+ ASSERT_EQ(7U, filtered_entries.size());
+
+ // The filtering should have removed the second item
+ TabRestoreService::Entries expected = entries_;
+ TabRestoreService::Entry* first = expected.front();
+ expected.pop_front();
+ expected.pop_front();
+ expected.push_front(first);
+ ASSERT_EQ(expected, filtered_entries);
+}
« no previous file with comments | « chrome/browser/sessions/session_utils.cc ('k') | chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698