OLD | NEW |
---|---|
(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/string16.h" | |
8 #include "base/utf_string_conversions.h" | |
9 #include "chrome/browser/sessions/session_types.h" | |
10 #include "googleurl/src/gurl.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 class TabNavigationMock : public TabNavigation { | |
14 public: | |
15 TabNavigationMock(const char* url, const char* title) | |
16 : TabNavigation(0, // index | |
17 GURL(string16(ASCIIToUTF16(url))), // virtual_url | |
18 GURL(), // referrer | |
19 string16(ASCIIToUTF16(title)), // title | |
20 "", // state | |
21 PageTransition::FROM_ADDRESS_BAR) { | |
22 } | |
23 }; | |
24 | |
25 class SessionUtilsTest : public testing::Test { | |
26 protected: | |
27 class TabMock : public TabRestoreService::Tab { | |
28 public: | |
29 TabMock(const char* url, const char* title) { | |
30 navigations.push_back(TabNavigationMock(url, title)); | |
31 current_navigation_index = 0; | |
32 } | |
33 }; | |
34 | |
35 virtual void SetUp() { | |
36 // prefill the entries | |
37 | |
38 // Two identical | |
39 entries_.push_back(new TabMock("http://a", "a")); | |
40 entries_.push_back(new TabMock("http://a", "a")); | |
41 | |
42 // Different URL | |
43 entries_.push_back(new TabMock("http://b", "b")); | |
44 entries_.push_back(new TabMock("http://c", "b")); | |
45 | |
46 // Different Title | |
47 entries_.push_back(new TabMock("http://d", "d")); | |
48 entries_.push_back(new TabMock("http://d", "e")); | |
49 | |
50 // Nothing in common | |
51 entries_.push_back(new TabMock("http://f", "f")); | |
52 entries_.push_back(new TabMock("http://g", "g")); | |
53 } | |
54 | |
55 void TearDown() { | |
56 std::list<TabRestoreService::Entry*>::iterator iter = entries_.begin(); | |
sky
2011/09/20 22:10:28
STLDeleteElements
noyau (Ping after 24h)
2011/09/20 22:43:58
Didn't even knew this existed. Thanks.
| |
57 while (iter != entries_.end()) { | |
58 delete(*iter); | |
59 iter = entries_.erase(iter); | |
60 } | |
61 } | |
62 | |
63 TabRestoreService::Entries entries_; | |
64 }; | |
65 | |
66 TEST_F(SessionUtilsTest, SessionUtilsFilter) { | |
67 TabRestoreService::Entries filtered_entries; | |
68 | |
69 SessionUtils::FilteredEntries(entries_, &filtered_entries); | |
70 ASSERT_EQ(7U, filtered_entries.size()); | |
71 | |
72 // The filtering should have removed the second item | |
73 TabRestoreService::Entries expected = entries_; | |
74 TabRestoreService::Entry* first = expected.front(); | |
75 expected.pop_front(); | |
76 expected.pop_front(); | |
77 expected.push_front(first); | |
78 ASSERT_EQ(expected, filtered_entries); | |
79 } | |
OLD | NEW |