| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "chrome/browser/dock_info.h" | 7 #include "chrome/browser/dock_info.h" |
| 8 #include "chrome/browser/dom_ui/new_tab_ui.h" | 8 #include "chrome/browser/dom_ui/new_tab_ui.h" |
| 9 #include "chrome/browser/profile.h" | 9 #include "chrome/browser/profile.h" |
| 10 #include "chrome/browser/profile_manager.h" | 10 #include "chrome/browser/profile_manager.h" |
| 11 #include "chrome/browser/renderer_host/test_render_view_host.h" | 11 #include "chrome/browser/renderer_host/test_render_view_host.h" |
| 12 #include "chrome/browser/tab_contents/navigation_controller.h" | 12 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 13 #include "chrome/browser/tab_contents/navigation_entry.h" | 13 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 14 #include "chrome/browser/tab_contents/tab_contents.h" | 14 #include "chrome/browser/tab_contents/tab_contents.h" |
| 15 #include "chrome/browser/tabs/tab_strip_model.h" | 15 #include "chrome/browser/tabs/tab_strip_model.h" |
| 16 #include "chrome/browser/tabs/tab_strip_model_order_controller.h" | 16 #include "chrome/browser/tabs/tab_strip_model_order_controller.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/common/stl_util-inl.h" | 18 #include "chrome/common/stl_util-inl.h" |
| 19 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 21 |
| 22 class TabStripDummyDelegate : public TabStripModelDelegate { | 22 class TabStripDummyDelegate : public TabStripModelDelegate { |
| 23 public: | 23 public: |
| 24 explicit TabStripDummyDelegate(TabContents* dummy) | 24 explicit TabStripDummyDelegate(TabContents* dummy) |
| 25 : dummy_contents_(dummy), can_close_(true) {} | 25 : dummy_contents_(dummy) {} |
| 26 virtual ~TabStripDummyDelegate() {} | 26 virtual ~TabStripDummyDelegate() {} |
| 27 | 27 |
| 28 void set_can_close(bool value) { can_close_ = value; } | |
| 29 | |
| 30 // Overridden from TabStripModelDelegate: | 28 // Overridden from TabStripModelDelegate: |
| 31 virtual TabContents* AddBlankTab(bool foreground) { return NULL; } | 29 virtual TabContents* AddBlankTab(bool foreground) { return NULL; } |
| 32 virtual TabContents* AddBlankTabAt(int index, bool foreground) { | 30 virtual TabContents* AddBlankTabAt(int index, bool foreground) { |
| 33 return NULL; | 31 return NULL; |
| 34 } | 32 } |
| 35 virtual Browser* CreateNewStripWithContents(TabContents* contents, | 33 virtual Browser* CreateNewStripWithContents(TabContents* contents, |
| 36 const gfx::Rect& window_bounds, | 34 const gfx::Rect& window_bounds, |
| 37 const DockInfo& dock_info) { | 35 const DockInfo& dock_info) { |
| 38 return NULL; | 36 return NULL; |
| 39 } | 37 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 51 } | 49 } |
| 52 virtual bool CanDuplicateContentsAt(int index) { return false; } | 50 virtual bool CanDuplicateContentsAt(int index) { return false; } |
| 53 virtual void DuplicateContentsAt(int index) {} | 51 virtual void DuplicateContentsAt(int index) {} |
| 54 virtual void CloseFrameAfterDragSession() {} | 52 virtual void CloseFrameAfterDragSession() {} |
| 55 virtual void CreateHistoricalTab(TabContents* contents) {} | 53 virtual void CreateHistoricalTab(TabContents* contents) {} |
| 56 virtual bool RunUnloadListenerBeforeClosing(TabContents* contents) { | 54 virtual bool RunUnloadListenerBeforeClosing(TabContents* contents) { |
| 57 return false; | 55 return false; |
| 58 } | 56 } |
| 59 virtual bool CanRestoreTab() { return false; } | 57 virtual bool CanRestoreTab() { return false; } |
| 60 virtual void RestoreTab() {} | 58 virtual void RestoreTab() {} |
| 61 virtual bool CanCloseContentsAt(int index) { return can_close_ ; } | |
| 62 | 59 |
| 63 private: | 60 private: |
| 64 // A dummy TabContents we give to callers that expect us to actually build a | 61 // A dummy TabContents we give to callers that expect us to actually build a |
| 65 // Destinations tab for them. | 62 // Destinations tab for them. |
| 66 TabContents* dummy_contents_; | 63 TabContents* dummy_contents_; |
| 67 | 64 |
| 68 // Whether tabs can be closed. | |
| 69 bool can_close_; | |
| 70 | |
| 71 DISALLOW_EVIL_CONSTRUCTORS(TabStripDummyDelegate); | 65 DISALLOW_EVIL_CONSTRUCTORS(TabStripDummyDelegate); |
| 72 }; | 66 }; |
| 73 | 67 |
| 74 class TabStripModelTest : public RenderViewHostTestHarness { | 68 class TabStripModelTest : public RenderViewHostTestHarness { |
| 75 public: | 69 public: |
| 76 TabContents* CreateTabContents() { | 70 TabContents* CreateTabContents() { |
| 77 return new WebContents(profile(), NULL, 0, NULL); | 71 return new WebContents(profile(), NULL, 0, NULL); |
| 78 } | 72 } |
| 79 | 73 |
| 80 // Forwards a URL "load" request through to our dummy TabContents | 74 // Forwards a URL "load" request through to our dummy TabContents |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 EXPECT_TRUE(observer.StateEquals(2, s3)); | 304 EXPECT_TRUE(observer.StateEquals(2, s3)); |
| 311 State s4(detached, 2, MockTabStripModelObserver::SELECT); | 305 State s4(detached, 2, MockTabStripModelObserver::SELECT); |
| 312 s4.src_contents = contents2; | 306 s4.src_contents = contents2; |
| 313 s4.user_gesture = false; | 307 s4.user_gesture = false; |
| 314 EXPECT_TRUE(observer.StateEquals(3, s4)); | 308 EXPECT_TRUE(observer.StateEquals(3, s4)); |
| 315 observer.ClearStates(); | 309 observer.ClearStates(); |
| 316 } | 310 } |
| 317 | 311 |
| 318 // Test CloseTabContentsAt | 312 // Test CloseTabContentsAt |
| 319 { | 313 { |
| 320 // Let's test nothing happens when the delegate veto the close. | 314 tabstrip.CloseTabContentsAt(2); |
| 321 delegate.set_can_close(false); | |
| 322 EXPECT_FALSE(tabstrip.CloseTabContentsAt(2)); | |
| 323 EXPECT_EQ(3, tabstrip.count()); | |
| 324 EXPECT_EQ(0, observer.GetStateCount()); | |
| 325 | |
| 326 // Now let's close for real. | |
| 327 delegate.set_can_close(true); | |
| 328 EXPECT_TRUE(tabstrip.CloseTabContentsAt(2)); | |
| 329 EXPECT_EQ(2, tabstrip.count()); | 315 EXPECT_EQ(2, tabstrip.count()); |
| 330 | 316 |
| 331 EXPECT_EQ(3, observer.GetStateCount()); | 317 EXPECT_EQ(3, observer.GetStateCount()); |
| 332 State s1(contents3, 2, MockTabStripModelObserver::CLOSE); | 318 State s1(contents3, 2, MockTabStripModelObserver::CLOSE); |
| 333 EXPECT_TRUE(observer.StateEquals(0, s1)); | 319 EXPECT_TRUE(observer.StateEquals(0, s1)); |
| 334 State s2(contents3, 2, MockTabStripModelObserver::DETACH); | 320 State s2(contents3, 2, MockTabStripModelObserver::DETACH); |
| 335 EXPECT_TRUE(observer.StateEquals(1, s2)); | 321 EXPECT_TRUE(observer.StateEquals(1, s2)); |
| 336 State s3(contents2, 1, MockTabStripModelObserver::SELECT); | 322 State s3(contents2, 1, MockTabStripModelObserver::SELECT); |
| 337 s3.src_contents = contents3; | 323 s3.src_contents = contents3; |
| 338 s3.user_gesture = false; | 324 s3.user_gesture = false; |
| (...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 | 1178 |
| 1193 // Now select the last tab. | 1179 // Now select the last tab. |
| 1194 strip.SelectTabContentsAt(strip.count() - 1, true); | 1180 strip.SelectTabContentsAt(strip.count() - 1, true); |
| 1195 | 1181 |
| 1196 // Now close the last tab. The next adjacent should be selected. | 1182 // Now close the last tab. The next adjacent should be selected. |
| 1197 strip.CloseTabContentsAt(strip.count() - 1); | 1183 strip.CloseTabContentsAt(strip.count() - 1); |
| 1198 EXPECT_EQ(page_d_contents, strip.GetTabContentsAt(strip.selected_index())); | 1184 EXPECT_EQ(page_d_contents, strip.GetTabContentsAt(strip.selected_index())); |
| 1199 | 1185 |
| 1200 strip.CloseAllTabs(); | 1186 strip.CloseAllTabs(); |
| 1201 } | 1187 } |
| OLD | NEW |