Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: chrome/browser/tabs/tab_strip_model_unittest.cc

Issue 100210: Relanding in-progress download bug fix (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/tabs/tab_strip_model.cc ('k') | chrome/browser/views/tabs/tab_strip.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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) {} 25 : dummy_contents_(dummy), can_close_(true) {}
26 virtual ~TabStripDummyDelegate() {} 26 virtual ~TabStripDummyDelegate() {}
27 27
28 void set_can_close(bool value) { can_close_ = value; }
29
28 // Overridden from TabStripModelDelegate: 30 // Overridden from TabStripModelDelegate:
29 virtual TabContents* AddBlankTab(bool foreground) { return NULL; } 31 virtual TabContents* AddBlankTab(bool foreground) { return NULL; }
30 virtual TabContents* AddBlankTabAt(int index, bool foreground) { 32 virtual TabContents* AddBlankTabAt(int index, bool foreground) {
31 return NULL; 33 return NULL;
32 } 34 }
33 virtual Browser* CreateNewStripWithContents(TabContents* contents, 35 virtual Browser* CreateNewStripWithContents(TabContents* contents,
34 const gfx::Rect& window_bounds, 36 const gfx::Rect& window_bounds,
35 const DockInfo& dock_info) { 37 const DockInfo& dock_info) {
36 return NULL; 38 return NULL;
37 } 39 }
(...skipping 11 matching lines...) Expand all
49 } 51 }
50 virtual bool CanDuplicateContentsAt(int index) { return false; } 52 virtual bool CanDuplicateContentsAt(int index) { return false; }
51 virtual void DuplicateContentsAt(int index) {} 53 virtual void DuplicateContentsAt(int index) {}
52 virtual void CloseFrameAfterDragSession() {} 54 virtual void CloseFrameAfterDragSession() {}
53 virtual void CreateHistoricalTab(TabContents* contents) {} 55 virtual void CreateHistoricalTab(TabContents* contents) {}
54 virtual bool RunUnloadListenerBeforeClosing(TabContents* contents) { 56 virtual bool RunUnloadListenerBeforeClosing(TabContents* contents) {
55 return false; 57 return false;
56 } 58 }
57 virtual bool CanRestoreTab() { return false; } 59 virtual bool CanRestoreTab() { return false; }
58 virtual void RestoreTab() {} 60 virtual void RestoreTab() {}
61 virtual bool CanCloseContentsAt(int index) { return can_close_ ; }
59 62
60 private: 63 private:
61 // A dummy TabContents we give to callers that expect us to actually build a 64 // A dummy TabContents we give to callers that expect us to actually build a
62 // Destinations tab for them. 65 // Destinations tab for them.
63 TabContents* dummy_contents_; 66 TabContents* dummy_contents_;
64 67
68 // Whether tabs can be closed.
69 bool can_close_;
70
65 DISALLOW_EVIL_CONSTRUCTORS(TabStripDummyDelegate); 71 DISALLOW_EVIL_CONSTRUCTORS(TabStripDummyDelegate);
66 }; 72 };
67 73
68 class TabStripModelTest : public RenderViewHostTestHarness { 74 class TabStripModelTest : public RenderViewHostTestHarness {
69 public: 75 public:
70 TabContents* CreateTabContents() { 76 TabContents* CreateTabContents() {
71 return new WebContents(profile(), NULL, 0, NULL); 77 return new WebContents(profile(), NULL, 0, NULL);
72 } 78 }
73 79
74 // Forwards a URL "load" request through to our dummy TabContents 80 // Forwards a URL "load" request through to our dummy TabContents
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 EXPECT_TRUE(observer.StateEquals(2, s3)); 310 EXPECT_TRUE(observer.StateEquals(2, s3));
305 State s4(detached, 2, MockTabStripModelObserver::SELECT); 311 State s4(detached, 2, MockTabStripModelObserver::SELECT);
306 s4.src_contents = contents2; 312 s4.src_contents = contents2;
307 s4.user_gesture = false; 313 s4.user_gesture = false;
308 EXPECT_TRUE(observer.StateEquals(3, s4)); 314 EXPECT_TRUE(observer.StateEquals(3, s4));
309 observer.ClearStates(); 315 observer.ClearStates();
310 } 316 }
311 317
312 // Test CloseTabContentsAt 318 // Test CloseTabContentsAt
313 { 319 {
314 tabstrip.CloseTabContentsAt(2); 320 // Let's test nothing happens when the delegate veto the close.
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));
315 EXPECT_EQ(2, tabstrip.count()); 329 EXPECT_EQ(2, tabstrip.count());
316 330
317 EXPECT_EQ(3, observer.GetStateCount()); 331 EXPECT_EQ(3, observer.GetStateCount());
318 State s1(contents3, 2, MockTabStripModelObserver::CLOSE); 332 State s1(contents3, 2, MockTabStripModelObserver::CLOSE);
319 EXPECT_TRUE(observer.StateEquals(0, s1)); 333 EXPECT_TRUE(observer.StateEquals(0, s1));
320 State s2(contents3, 2, MockTabStripModelObserver::DETACH); 334 State s2(contents3, 2, MockTabStripModelObserver::DETACH);
321 EXPECT_TRUE(observer.StateEquals(1, s2)); 335 EXPECT_TRUE(observer.StateEquals(1, s2));
322 State s3(contents2, 1, MockTabStripModelObserver::SELECT); 336 State s3(contents2, 1, MockTabStripModelObserver::SELECT);
323 s3.src_contents = contents3; 337 s3.src_contents = contents3;
324 s3.user_gesture = false; 338 s3.user_gesture = false;
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
1178 1192
1179 // Now select the last tab. 1193 // Now select the last tab.
1180 strip.SelectTabContentsAt(strip.count() - 1, true); 1194 strip.SelectTabContentsAt(strip.count() - 1, true);
1181 1195
1182 // Now close the last tab. The next adjacent should be selected. 1196 // Now close the last tab. The next adjacent should be selected.
1183 strip.CloseTabContentsAt(strip.count() - 1); 1197 strip.CloseTabContentsAt(strip.count() - 1);
1184 EXPECT_EQ(page_d_contents, strip.GetTabContentsAt(strip.selected_index())); 1198 EXPECT_EQ(page_d_contents, strip.GetTabContentsAt(strip.selected_index()));
1185 1199
1186 strip.CloseAllTabs(); 1200 strip.CloseAllTabs();
1187 } 1201 }
OLDNEW
« no previous file with comments | « chrome/browser/tabs/tab_strip_model.cc ('k') | chrome/browser/views/tabs/tab_strip.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698