Chromium Code Reviews| 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..b8b932157e022012a1c6ec67af390396a346d259 |
| --- /dev/null |
| +++ b/chrome/browser/sessions/session_utils_unittest.cc |
| @@ -0,0 +1,91 @@ |
| +// 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 "testing/gtest/include/gtest/gtest.h" |
|
sky
2011/09/20 16:24:46
test files have a similar include layout to that o
noyau (Ping after 24h)
2011/09/20 17:09:35
Done.
|
| + |
| +#include "base/string16.h" |
| +#include "base/utf_string_conversions.h" |
| +#include "chrome/browser/sessions/session_types.h" |
| +#include "chrome/browser/sessions/session_utils.h" |
| +#include "googleurl/src/gurl.h" |
| + |
| +class TabNavigationMock : public TabNavigation { |
| + public: |
| + TabNavigationMock(const GURL& url, const string16& title) |
| + : TabNavigation(0, // index |
|
sky
2011/09/20 16:24:46
indent this by 4.
noyau (Ping after 24h)
2011/09/20 17:09:35
Done.
|
| + url, // virtual_url |
| + GURL(), // referrer |
| + title, // title |
| + "", // state |
| + PageTransition::FROM_ADDRESS_BAR) { |
| + } |
| +}; |
| + |
| +class TabRestoreServiceMock : public TabRestoreService { |
|
sky
2011/09/20 16:24:46
When you change FilteredEntries to not take a TabR
noyau (Ping after 24h)
2011/09/20 17:09:35
Done.
|
| + public: |
| + class TabMock : public TabRestoreService::Tab { |
| + public: |
| + TabMock(const char* url, const char* title) { |
| + |
| + navigations.push_back(TabNavigationMock( |
| + GURL(string16(ASCIIToUTF16(url))), string16(ASCIIToUTF16(title)))); |
| + current_navigation_index = 0; |
| + } |
| + |
| + }; |
| + |
| + TabRestoreServiceMock() : TabRestoreService(NULL) { |
| + // 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")); |
| + } |
| + |
| +}; |
| + |
|
sky
2011/09/20 16:24:46
remove one of these.
noyau (Ping after 24h)
2011/09/20 17:09:35
Done.
|
| + |
| +class SessionUtilsTest : public testing::Test { |
| + protected: |
| + virtual void SetUp() { |
| + service = new TabRestoreServiceMock(); |
| + } |
| + |
| + void TearDown() { |
| + delete(service); |
| + } |
| + |
| + TabRestoreService* service; |
| +}; |
| + |
| + |
| +TEST_F(SessionUtilsTest, SessionUtilsFilter) { |
| + TabRestoreService::Entries filteredEntries; |
|
sky
2011/09/20 16:24:46
filtered_entries.
noyau (Ping after 24h)
2011/09/20 17:09:35
Done.
|
| + |
| + SessionUtils::FilteredEntries(service, &filteredEntries); |
| + ASSERT_EQ(7U, filteredEntries.size()); |
| + |
| + // The filtering should have removed the second item |
| + TabRestoreService::Entries expected = service->entries(); |
| + TabRestoreService::Entry* first = expected.front(); |
| + expected.pop_front(); |
| + expected.pop_front(); |
| + expected.push_front(first); |
| + ASSERT_EQ(expected, filteredEntries); |
| +}; |
| + |
|
sky
2011/09/20 16:24:46
remove these newlines.
noyau (Ping after 24h)
2011/09/20 17:09:35
Done.
|
| + |
| + |