Chromium Code Reviews| 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 entries_.empty(); | |
|
sky
2011/09/20 17:21:30
. empty is better thought of IsEmpty, meaning it d
noyau (Ping after 24h)
2011/09/20 21:53:31
Ooops! A clear case of typing before thinking.
| |
| 57 } | |
| 58 | |
| 59 TabRestoreService::Entries entries_; | |
| 60 }; | |
| 61 | |
| 62 TEST_F(SessionUtilsTest, SessionUtilsFilter) { | |
| 63 TabRestoreService::Entries filtered_entries; | |
| 64 | |
| 65 SessionUtils::FilteredEntries(entries_, &filtered_entries); | |
| 66 ASSERT_EQ(7U, filtered_entries.size()); | |
| 67 | |
| 68 // The filtering should have removed the second item | |
| 69 TabRestoreService::Entries expected = entries_; | |
| 70 TabRestoreService::Entry* first = expected.front(); | |
| 71 expected.pop_front(); | |
| 72 expected.pop_front(); | |
| 73 expected.push_front(first); | |
| 74 ASSERT_EQ(expected, filtered_entries); | |
| 75 }; | |
|
sky
2011/09/20 17:21:30
no semicolon.
noyau (Ping after 24h)
2011/09/20 21:53:31
Done.
| |
| OLD | NEW |