Index: chrome/browser/ui/tabs/tab_mru_list_manager_unittest.cc |
diff --git a/chrome/browser/ui/tabs/tab_mru_list_manager_unittest.cc b/chrome/browser/ui/tabs/tab_mru_list_manager_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b7689450123572fdae06a2534884a5536c82c98d |
--- /dev/null |
+++ b/chrome/browser/ui/tabs/tab_mru_list_manager_unittest.cc |
@@ -0,0 +1,69 @@ |
+// Copyright (c) 2012 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/ui/tabs/tab_mru_list_manager.h" |
sky
2012/06/15 19:47:39
newline between 5 and 6.
|
+#include "chrome/browser/ui/tabs/tab_strip_model.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+typedef testing::Test TabMRUListManagerTest; |
+ |
+// Swich to MRU tab when list is empty. |
+TEST_F(TabMRUListManagerTest, ListEmpty) { |
+ TabMRUListManager mru_list(NULL); |
+ TabContentsWrapper* contents = mru_list.GetPreviousMRUTab(); |
+ EXPECT_EQ(NULL, contents); |
+} |
+ |
+// Insert 3 tabs and switch between first and 3rd tab |
+TEST_F(TabMRUListManagerTest, ToggleMRUTabs) { |
+ TabMRUListManager mru_list(NULL); |
+ TabContentsWrapper* contents1 = (TabContentsWrapper*) 0xfffffff1; |
sky
2012/06/15 19:47:39
Don't do this.
You can create TabContents in unit
|
+ TabContentsWrapper* contents2 = (TabContentsWrapper*) 0xfffffff2; |
+ TabContentsWrapper* contents3 = (TabContentsWrapper*) 0xfffffff3; |
+ |
+ mru_list.TabInsertedAt(contents1, 0, true); |
+ mru_list.TabInsertedAt(contents2, 1, true); |
+ mru_list.TabInsertedAt(contents3, 2, true); |
+ |
+ // content3 will be the current active tab and contents2 will be |
+ // the most recently used tab. |
+ // Now activate contents1 so that we toggle between contents1 and |
+ // contents3 |
+ mru_list.ActiveTabChanged(contents3, contents1, 0, true); |
+ |
+ // Now calling GetPreviousMRUTab will return contents3 because we |
+ // shifted to contents1 from contents3, |
+ TabContentsWrapper* contents = mru_list.GetPreviousMRUTab(); |
+ EXPECT_EQ(contents, contents3); |
+} |
+ |
+// Detach a MRU tab and check the behaviour |
+// Insert 3 tabs and switch between first and 3rd tab |
+TEST_F(TabMRUListManagerTest, DetachMRUTabs) { |
+ TabMRUListManager mru_list(NULL); |
+ TabContentsWrapper* contents1 = (TabContentsWrapper*) 0xfffffff1; |
+ TabContentsWrapper* contents2 = (TabContentsWrapper*) 0xfffffff2; |
+ TabContentsWrapper* contents3 = (TabContentsWrapper*) 0xfffffff3; |
+ |
+ mru_list.TabInsertedAt(contents1, 0, true); |
+ mru_list.TabInsertedAt(contents2, 1, true); |
+ mru_list.TabInsertedAt(contents3, 2, true); |
+ |
+ // content3 will be the current active tab and contents2 will be |
+ // the most recently used tab. |
+ // Now activate contents1 so that we toggle between contents1 and |
+ // contents3 |
+ mru_list.ActiveTabChanged(contents3, contents1, 0, true); |
+ |
+ // Now calling GetPreviousMRUTab will return contents3 because we |
+ // shifted to contents1 from contents3, |
+ TabContentsWrapper* contents = mru_list.GetPreviousMRUTab(); |
+ EXPECT_EQ(contents, contents3); |
+ |
+ // Detach contents3 and then the next MRU tab should be contents2 |
+ // as per MRU order. |
+ mru_list.TabDetachedAt(contents3, 2); |
+ contents = mru_list.GetPreviousMRUTab(); |
+ EXPECT_EQ(contents, contents2); |
+} |