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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sessions/session_utils.h"
6
7 #include "base/stl_util.h"
8 #include "base/string16.h"
9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/sessions/session_types.h"
11 #include "googleurl/src/gurl.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 class TabNavigationMock : public TabNavigation {
15 public:
16 TabNavigationMock(const char* url, const char* title)
17 : TabNavigation(0, // index
18 GURL(string16(ASCIIToUTF16(url))), // virtual_url
19 GURL(), // referrer
20 string16(ASCIIToUTF16(title)), // title
21 "", // state
22 PageTransition::FROM_ADDRESS_BAR) {
23 }
24 };
25
26 class SessionUtilsTest : public testing::Test {
27 protected:
28 class TabMock : public TabRestoreService::Tab {
29 public:
30 TabMock(const char* url, const char* title) {
31 navigations.push_back(TabNavigationMock(url, title));
32 current_navigation_index = 0;
33 }
34 };
35
36 virtual void SetUp() {
37 // prefill the entries
38
39 // Two identical
40 entries_.push_back(new TabMock("http://a", "a"));
41 entries_.push_back(new TabMock("http://a", "a"));
42
43 // Different URL
44 entries_.push_back(new TabMock("http://b", "b"));
45 entries_.push_back(new TabMock("http://c", "b"));
46
47 // Different Title
48 entries_.push_back(new TabMock("http://d", "d"));
49 entries_.push_back(new TabMock("http://d", "e"));
50
51 // Nothing in common
52 entries_.push_back(new TabMock("http://f", "f"));
53 entries_.push_back(new TabMock("http://g", "g"));
54 }
55
56 void TearDown() {
57 STLDeleteElements(&entries_);
58 }
59
60 TabRestoreService::Entries entries_;
61 };
62
63 TEST_F(SessionUtilsTest, SessionUtilsFilter) {
64 TabRestoreService::Entries filtered_entries;
65
66 SessionUtils::FilteredEntries(entries_, &filtered_entries);
67 ASSERT_EQ(7U, filtered_entries.size());
68
69 // The filtering should have removed the second item
70 TabRestoreService::Entries expected = entries_;
71 TabRestoreService::Entry* first = expected.front();
72 expected.pop_front();
73 expected.pop_front();
74 expected.push_front(first);
75 ASSERT_EQ(expected, filtered_entries);
76 }
OLDNEW
« 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