OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/system_monitor.h" | 5 #include "app/system_monitor.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/stl_util-inl.h" | 12 #include "base/stl_util-inl.h" |
13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/browser/browser.h" |
16 #include "chrome/browser/defaults.h" | 17 #include "chrome/browser/defaults.h" |
17 #include "chrome/browser/dom_ui/new_tab_ui.h" | 18 #include "chrome/browser/dom_ui/new_tab_ui.h" |
18 #include "chrome/browser/profile.h" | 19 #include "chrome/browser/profile.h" |
19 #include "chrome/browser/profile_manager.h" | 20 #include "chrome/browser/profile_manager.h" |
20 #include "chrome/browser/renderer_host/test/test_render_view_host.h" | 21 #include "chrome/browser/renderer_host/test/test_render_view_host.h" |
21 #include "chrome/browser/tab_contents/navigation_controller.h" | 22 #include "chrome/browser/tab_contents/navigation_controller.h" |
22 #include "chrome/browser/tab_contents/navigation_entry.h" | 23 #include "chrome/browser/tab_contents/navigation_entry.h" |
23 #include "chrome/browser/tab_contents/tab_contents.h" | 24 #include "chrome/browser/tab_contents/tab_contents.h" |
| 25 #include "chrome/browser/tab_contents_wrapper.h" |
24 #include "chrome/browser/tabs/tab_strip_model.h" | 26 #include "chrome/browser/tabs/tab_strip_model.h" |
25 #include "chrome/browser/tabs/tab_strip_model_delegate.h" | 27 #include "chrome/browser/tabs/tab_strip_model_delegate.h" |
26 #include "chrome/browser/tabs/tab_strip_model_order_controller.h" | 28 #include "chrome/browser/tabs/tab_strip_model_order_controller.h" |
27 #include "chrome/common/extensions/extension.h" | 29 #include "chrome/common/extensions/extension.h" |
28 #include "chrome/common/notification_observer_mock.h" | 30 #include "chrome/common/notification_observer_mock.h" |
29 #include "chrome/common/notification_registrar.h" | 31 #include "chrome/common/notification_registrar.h" |
30 #include "chrome/common/notification_service.h" | 32 #include "chrome/common/notification_service.h" |
31 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
32 #include "chrome/common/property_bag.h" | 34 #include "chrome/common/property_bag.h" |
33 #include "chrome/common/url_constants.h" | 35 #include "chrome/common/url_constants.h" |
34 #include "chrome/test/testing_profile.h" | 36 #include "chrome/test/testing_profile.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
36 | 38 |
37 using testing::_; | 39 using testing::_; |
38 | 40 |
39 namespace { | 41 namespace { |
40 | 42 |
41 // Class used to delete a TabContents when another TabContents is destroyed. | 43 // Class used to delete a TabContents when another TabContents is destroyed. |
42 class DeleteTabContentsOnDestroyedObserver : public NotificationObserver { | 44 class DeleteTabContentsOnDestroyedObserver : public NotificationObserver { |
43 public: | 45 public: |
44 DeleteTabContentsOnDestroyedObserver(TabContents* source, | 46 DeleteTabContentsOnDestroyedObserver(TabContentsWrapper* source, |
45 TabContents* tab_to_delete) | 47 TabContentsWrapper* tab_to_delete) |
46 : source_(source), | 48 : source_(source), |
47 tab_to_delete_(tab_to_delete) { | 49 tab_to_delete_(tab_to_delete) { |
48 registrar_.Add(this, | 50 registrar_.Add(this, |
49 NotificationType::TAB_CONTENTS_DESTROYED, | 51 NotificationType::TAB_CONTENTS_DESTROYED, |
50 Source<TabContents>(source)); | 52 Source<TabContents>(source->tab_contents())); |
51 } | 53 } |
52 | 54 |
53 virtual void Observe(NotificationType type, | 55 virtual void Observe(NotificationType type, |
54 const NotificationSource& source, | 56 const NotificationSource& source, |
55 const NotificationDetails& details) { | 57 const NotificationDetails& details) { |
56 TabContents* tab_to_delete = tab_to_delete_; | 58 TabContentsWrapper* tab_to_delete = tab_to_delete_; |
57 tab_to_delete_ = NULL; | 59 tab_to_delete_ = NULL; |
58 delete tab_to_delete; | 60 delete tab_to_delete; |
59 } | 61 } |
60 | 62 |
61 private: | 63 private: |
62 TabContents* source_; | 64 TabContentsWrapper* source_; |
63 TabContents* tab_to_delete_; | 65 TabContentsWrapper* tab_to_delete_; |
64 NotificationRegistrar registrar_; | 66 NotificationRegistrar registrar_; |
65 | 67 |
66 DISALLOW_COPY_AND_ASSIGN(DeleteTabContentsOnDestroyedObserver); | 68 DISALLOW_COPY_AND_ASSIGN(DeleteTabContentsOnDestroyedObserver); |
67 }; | 69 }; |
68 | 70 |
69 } // namespace | 71 } // namespace |
70 | 72 |
71 class TabStripDummyDelegate : public TabStripModelDelegate { | 73 class TabStripDummyDelegate : public TabStripModelDelegate { |
72 public: | 74 public: |
73 explicit TabStripDummyDelegate(TabContents* dummy) | 75 explicit TabStripDummyDelegate(TabContentsWrapper* dummy) |
74 : dummy_contents_(dummy), can_close_(true), run_unload_(false) {} | 76 : dummy_contents_(dummy), can_close_(true), run_unload_(false) {} |
75 virtual ~TabStripDummyDelegate() {} | 77 virtual ~TabStripDummyDelegate() {} |
76 | 78 |
77 void set_can_close(bool value) { can_close_ = value; } | 79 void set_can_close(bool value) { can_close_ = value; } |
78 void set_run_unload_listener(bool value) { run_unload_ = value; } | 80 void set_run_unload_listener(bool value) { run_unload_ = value; } |
79 | 81 |
80 // Overridden from TabStripModelDelegate: | 82 // Overridden from TabStripModelDelegate: |
81 virtual TabContents* AddBlankTab(bool foreground) { return NULL; } | 83 virtual TabContentsWrapper* AddBlankTab(bool foreground) { |
82 virtual TabContents* AddBlankTabAt(int index, bool foreground) { | |
83 return NULL; | 84 return NULL; |
84 } | 85 } |
85 virtual Browser* CreateNewStripWithContents(TabContents* contents, | 86 virtual TabContentsWrapper* AddBlankTabAt(int index, bool foreground) { |
| 87 return NULL; |
| 88 } |
| 89 virtual Browser* CreateNewStripWithContents(TabContentsWrapper* contents, |
86 const gfx::Rect& window_bounds, | 90 const gfx::Rect& window_bounds, |
87 const DockInfo& dock_info, | 91 const DockInfo& dock_info, |
88 bool maximize) { | 92 bool maximize) { |
89 return NULL; | 93 return NULL; |
90 } | 94 } |
91 virtual void ContinueDraggingDetachedTab(TabContents* contents, | 95 virtual void ContinueDraggingDetachedTab(TabContentsWrapper* contents, |
92 const gfx::Rect& window_bounds, | 96 const gfx::Rect& window_bounds, |
93 const gfx::Rect& tab_bounds) { | 97 const gfx::Rect& tab_bounds) { |
94 } | 98 } |
95 virtual int GetDragActions() const { return 0; } | 99 virtual int GetDragActions() const { return 0; } |
96 virtual TabContents* CreateTabContentsForURL( | 100 virtual TabContentsWrapper* CreateTabContentsForURL( |
97 const GURL& url, | 101 const GURL& url, |
98 const GURL& referrer, | 102 const GURL& referrer, |
99 Profile* profile, | 103 Profile* profile, |
100 PageTransition::Type transition, | 104 PageTransition::Type transition, |
101 bool defer_load, | 105 bool defer_load, |
102 SiteInstance* instance) const { | 106 SiteInstance* instance) const { |
103 if (url == GURL(chrome::kChromeUINewTabURL)) | 107 if (url == GURL(chrome::kChromeUINewTabURL)) |
104 return dummy_contents_; | 108 return dummy_contents_; |
105 return NULL; | 109 return NULL; |
106 } | 110 } |
107 virtual bool CanDuplicateContentsAt(int index) { return false; } | 111 virtual bool CanDuplicateContentsAt(int index) { return false; } |
108 virtual void DuplicateContentsAt(int index) {} | 112 virtual void DuplicateContentsAt(int index) {} |
109 virtual void CloseFrameAfterDragSession() {} | 113 virtual void CloseFrameAfterDragSession() {} |
110 virtual void CreateHistoricalTab(TabContents* contents) {} | 114 virtual void CreateHistoricalTab(TabContentsWrapper* contents) {} |
111 virtual bool RunUnloadListenerBeforeClosing(TabContents* contents) { | 115 virtual bool RunUnloadListenerBeforeClosing(TabContentsWrapper* contents) { |
112 return run_unload_; | 116 return run_unload_; |
113 } | 117 } |
114 virtual bool CanRestoreTab() { return false; } | 118 virtual bool CanRestoreTab() { return false; } |
115 virtual void RestoreTab() {} | 119 virtual void RestoreTab() {} |
116 virtual bool CanCloseContentsAt(int index) { return can_close_ ; } | 120 virtual bool CanCloseContentsAt(int index) { return can_close_ ; } |
117 virtual bool CanBookmarkAllTabs() const { return false; } | 121 virtual bool CanBookmarkAllTabs() const { return false; } |
118 virtual void BookmarkAllTabs() {} | 122 virtual void BookmarkAllTabs() {} |
119 virtual bool CanCloseTab() const { return true; } | 123 virtual bool CanCloseTab() const { return true; } |
120 virtual bool UseVerticalTabs() const { return false; } | 124 virtual bool UseVerticalTabs() const { return false; } |
121 virtual void ToggleUseVerticalTabs() {} | 125 virtual void ToggleUseVerticalTabs() {} |
122 virtual bool LargeIconsPermitted() const { return true; } | 126 virtual bool LargeIconsPermitted() const { return true; } |
123 | 127 |
124 private: | 128 private: |
125 // A dummy TabContents we give to callers that expect us to actually build a | 129 // A dummy TabContents we give to callers that expect us to actually build a |
126 // Destinations tab for them. | 130 // Destinations tab for them. |
127 TabContents* dummy_contents_; | 131 TabContentsWrapper* dummy_contents_; |
128 | 132 |
129 // Whether tabs can be closed. | 133 // Whether tabs can be closed. |
130 bool can_close_; | 134 bool can_close_; |
131 | 135 |
132 // Whether to report that we need to run an unload listener before closing. | 136 // Whether to report that we need to run an unload listener before closing. |
133 bool run_unload_; | 137 bool run_unload_; |
134 | 138 |
135 DISALLOW_COPY_AND_ASSIGN(TabStripDummyDelegate); | 139 DISALLOW_COPY_AND_ASSIGN(TabStripDummyDelegate); |
136 }; | 140 }; |
137 | 141 |
138 class TabStripModelTest : public RenderViewHostTestHarness { | 142 class TabStripModelTest : public RenderViewHostTestHarness { |
139 public: | 143 public: |
140 TabContents* CreateTabContents() { | 144 TabContentsWrapper* CreateTabContents() { |
141 return new TabContents(profile(), NULL, 0, NULL, NULL); | 145 return Browser::TabContentsFactory(profile(), NULL, 0, NULL, NULL); |
142 } | 146 } |
143 | 147 |
144 TabContents* CreateTabContentsWithSharedRPH(TabContents* tab_contents) { | 148 TabContentsWrapper* CreateTabContentsWithSharedRPH( |
145 TabContents* retval = new TabContents(profile(), | 149 TabContents* tab_contents) { |
| 150 TabContentsWrapper* retval = Browser::TabContentsFactory(profile(), |
146 tab_contents->render_view_host()->site_instance(), MSG_ROUTING_NONE, | 151 tab_contents->render_view_host()->site_instance(), MSG_ROUTING_NONE, |
147 NULL, NULL); | 152 NULL, NULL); |
148 EXPECT_EQ(retval->GetRenderProcessHost(), | 153 EXPECT_EQ(retval->tab_contents()->GetRenderProcessHost(), |
149 tab_contents->GetRenderProcessHost()); | 154 tab_contents->GetRenderProcessHost()); |
150 return retval; | 155 return retval; |
151 } | 156 } |
152 | 157 |
153 // Forwards a URL "load" request through to our dummy TabContents | 158 // Forwards a URL "load" request through to our dummy TabContents |
154 // implementation. | 159 // implementation. |
155 void LoadURL(TabContents* con, const std::wstring& url) { | 160 void LoadURL(TabContents* con, const std::wstring& url) { |
156 controller().LoadURL(GURL(WideToUTF16(url)), GURL(), PageTransition::LINK); | 161 controller().LoadURL(GURL(WideToUTF16(url)), GURL(), PageTransition::LINK); |
157 } | 162 } |
158 | 163 |
(...skipping 22 matching lines...) Expand all Loading... |
181 // Returns the state of the given tab strip as a string. The state consists | 186 // Returns the state of the given tab strip as a string. The state consists |
182 // of the ID of each tab contents followed by a 'p' if pinned. For example, | 187 // of the ID of each tab contents followed by a 'p' if pinned. For example, |
183 // if the model consists of two tabs with ids 2 and 1, with the first | 188 // if the model consists of two tabs with ids 2 and 1, with the first |
184 // tab pinned, this returns "2p 1". | 189 // tab pinned, this returns "2p 1". |
185 std::string GetPinnedState(const TabStripModel& model) { | 190 std::string GetPinnedState(const TabStripModel& model) { |
186 std::string actual; | 191 std::string actual; |
187 for (int i = 0; i < model.count(); ++i) { | 192 for (int i = 0; i < model.count(); ++i) { |
188 if (i > 0) | 193 if (i > 0) |
189 actual += " "; | 194 actual += " "; |
190 | 195 |
191 actual += base::IntToString(GetID(model.GetTabContentsAt(i))); | 196 actual += |
| 197 base::IntToString(GetID(model.GetTabContentsAt(i)->tab_contents())); |
192 | 198 |
193 if (model.IsAppTab(i)) | 199 if (model.IsAppTab(i)) |
194 actual += "a"; | 200 actual += "a"; |
195 | 201 |
196 if (model.IsTabPinned(i)) | 202 if (model.IsTabPinned(i)) |
197 actual += "p"; | 203 actual += "p"; |
198 } | 204 } |
199 return actual; | 205 return actual; |
200 } | 206 } |
201 | 207 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 CLOSE, | 247 CLOSE, |
242 DETACH, | 248 DETACH, |
243 SELECT, | 249 SELECT, |
244 MOVE, | 250 MOVE, |
245 CHANGE, | 251 CHANGE, |
246 PINNED, | 252 PINNED, |
247 REPLACED | 253 REPLACED |
248 }; | 254 }; |
249 | 255 |
250 struct State { | 256 struct State { |
251 State(TabContents* a_dst_contents, | 257 State(TabContentsWrapper* a_dst_contents, |
252 int a_dst_index, | 258 int a_dst_index, |
253 TabStripModelObserverAction a_action) | 259 TabStripModelObserverAction a_action) |
254 : src_contents(NULL), | 260 : src_contents(NULL), |
255 dst_contents(a_dst_contents), | 261 dst_contents(a_dst_contents), |
256 src_index(-1), | 262 src_index(-1), |
257 dst_index(a_dst_index), | 263 dst_index(a_dst_index), |
258 user_gesture(false), | 264 user_gesture(false), |
259 foreground(false), | 265 foreground(false), |
260 action(a_action) { | 266 action(a_action) { |
261 } | 267 } |
262 | 268 |
263 TabContents* src_contents; | 269 TabContentsWrapper* src_contents; |
264 TabContents* dst_contents; | 270 TabContentsWrapper* dst_contents; |
265 int src_index; | 271 int src_index; |
266 int dst_index; | 272 int dst_index; |
267 bool user_gesture; | 273 bool user_gesture; |
268 bool foreground; | 274 bool foreground; |
269 TabStripModelObserverAction action; | 275 TabStripModelObserverAction action; |
270 }; | 276 }; |
271 | 277 |
272 int GetStateCount() const { | 278 int GetStateCount() const { |
273 return static_cast<int>(states_.size()); | 279 return static_cast<int>(states_.size()); |
274 } | 280 } |
(...skipping 15 matching lines...) Expand all Loading... |
290 return (s->src_contents == state.src_contents && | 296 return (s->src_contents == state.src_contents && |
291 s->dst_contents == state.dst_contents && | 297 s->dst_contents == state.dst_contents && |
292 s->src_index == state.src_index && | 298 s->src_index == state.src_index && |
293 s->dst_index == state.dst_index && | 299 s->dst_index == state.dst_index && |
294 s->user_gesture == state.user_gesture && | 300 s->user_gesture == state.user_gesture && |
295 s->foreground == state.foreground && | 301 s->foreground == state.foreground && |
296 s->action == state.action); | 302 s->action == state.action); |
297 } | 303 } |
298 | 304 |
299 // TabStripModelObserver implementation: | 305 // TabStripModelObserver implementation: |
300 virtual void TabInsertedAt(TabContents* contents, | 306 virtual void TabInsertedAt(TabContentsWrapper* contents, |
301 int index, | 307 int index, |
302 bool foreground) { | 308 bool foreground) { |
303 empty_ = false; | 309 empty_ = false; |
304 State* s = new State(contents, index, INSERT); | 310 State* s = new State(contents, index, INSERT); |
305 s->foreground = foreground; | 311 s->foreground = foreground; |
306 states_.push_back(s); | 312 states_.push_back(s); |
307 } | 313 } |
308 virtual void TabSelectedAt(TabContents* old_contents, | 314 virtual void TabSelectedAt(TabContentsWrapper* old_contents, |
309 TabContents* new_contents, | 315 TabContentsWrapper* new_contents, |
310 int index, | 316 int index, |
311 bool user_gesture) { | 317 bool user_gesture) { |
312 State* s = new State(new_contents, index, SELECT); | 318 State* s = new State(new_contents, index, SELECT); |
313 s->src_contents = old_contents; | 319 s->src_contents = old_contents; |
314 s->user_gesture = user_gesture; | 320 s->user_gesture = user_gesture; |
315 states_.push_back(s); | 321 states_.push_back(s); |
316 } | 322 } |
317 virtual void TabMoved( | 323 virtual void TabMoved( |
318 TabContents* contents, int from_index, int to_index) { | 324 TabContentsWrapper* contents, int from_index, int to_index) { |
319 State* s = new State(contents, to_index, MOVE); | 325 State* s = new State(contents, to_index, MOVE); |
320 s->src_index = from_index; | 326 s->src_index = from_index; |
321 states_.push_back(s); | 327 states_.push_back(s); |
322 } | 328 } |
323 | 329 |
324 virtual void TabClosingAt(TabStripModel* tab_strip_model, | 330 virtual void TabClosingAt(TabStripModel* tab_strip_model, |
325 TabContents* contents, | 331 TabContentsWrapper* contents, |
326 int index) { | 332 int index) { |
327 states_.push_back(new State(contents, index, CLOSE)); | 333 states_.push_back(new State(contents, index, CLOSE)); |
328 } | 334 } |
329 virtual void TabDetachedAt(TabContents* contents, int index) { | 335 virtual void TabDetachedAt(TabContentsWrapper* contents, int index) { |
330 states_.push_back(new State(contents, index, DETACH)); | 336 states_.push_back(new State(contents, index, DETACH)); |
331 } | 337 } |
332 virtual void TabChangedAt(TabContents* contents, int index, | 338 virtual void TabChangedAt(TabContentsWrapper* contents, int index, |
333 TabChangeType change_type) { | 339 TabChangeType change_type) { |
334 states_.push_back(new State(contents, index, CHANGE)); | 340 states_.push_back(new State(contents, index, CHANGE)); |
335 } | 341 } |
336 virtual void TabReplacedAt(TabContents* old_contents, | 342 virtual void TabReplacedAt(TabContentsWrapper* old_contents, |
337 TabContents* new_contents, int index) { | 343 TabContentsWrapper* new_contents, int index) { |
338 State* s = new State(new_contents, index, REPLACED); | 344 State* s = new State(new_contents, index, REPLACED); |
339 s ->src_contents = old_contents; | 345 s ->src_contents = old_contents; |
340 states_.push_back(s); | 346 states_.push_back(s); |
341 } | 347 } |
342 virtual void TabPinnedStateChanged(TabContents* contents, int index) { | 348 virtual void TabPinnedStateChanged(TabContentsWrapper* contents, int index) { |
343 states_.push_back(new State(contents, index, PINNED)); | 349 states_.push_back(new State(contents, index, PINNED)); |
344 } | 350 } |
345 virtual void TabStripEmpty() { | 351 virtual void TabStripEmpty() { |
346 empty_ = true; | 352 empty_ = true; |
347 } | 353 } |
348 | 354 |
349 void ClearStates() { | 355 void ClearStates() { |
350 STLDeleteContainerPointers(states_.begin(), states_.end()); | 356 STLDeleteContainerPointers(states_.begin(), states_.end()); |
351 states_.clear(); | 357 states_.clear(); |
352 } | 358 } |
(...skipping 11 matching lines...) Expand all Loading... |
364 TEST_F(TabStripModelTest, TestBasicAPI) { | 370 TEST_F(TabStripModelTest, TestBasicAPI) { |
365 TabStripDummyDelegate delegate(NULL); | 371 TabStripDummyDelegate delegate(NULL); |
366 TabStripModel tabstrip(&delegate, profile()); | 372 TabStripModel tabstrip(&delegate, profile()); |
367 MockTabStripModelObserver observer; | 373 MockTabStripModelObserver observer; |
368 tabstrip.AddObserver(&observer); | 374 tabstrip.AddObserver(&observer); |
369 | 375 |
370 EXPECT_TRUE(tabstrip.empty()); | 376 EXPECT_TRUE(tabstrip.empty()); |
371 | 377 |
372 typedef MockTabStripModelObserver::State State; | 378 typedef MockTabStripModelObserver::State State; |
373 | 379 |
374 TabContents* contents1 = CreateTabContents(); | 380 TabContentsWrapper* contents1 = CreateTabContents(); |
375 | 381 |
376 // Note! The ordering of these tests is important, each subsequent test | 382 // Note! The ordering of these tests is important, each subsequent test |
377 // builds on the state established in the previous. This is important if you | 383 // builds on the state established in the previous. This is important if you |
378 // ever insert tests rather than append. | 384 // ever insert tests rather than append. |
379 | 385 |
380 // Test AppendTabContents, ContainsIndex | 386 // Test AppendTabContents, ContainsIndex |
381 { | 387 { |
382 EXPECT_FALSE(tabstrip.ContainsIndex(0)); | 388 EXPECT_FALSE(tabstrip.ContainsIndex(0)); |
383 tabstrip.AppendTabContents(contents1, true); | 389 tabstrip.AppendTabContents(contents1, true); |
384 EXPECT_TRUE(tabstrip.ContainsIndex(0)); | 390 EXPECT_TRUE(tabstrip.ContainsIndex(0)); |
385 EXPECT_EQ(1, tabstrip.count()); | 391 EXPECT_EQ(1, tabstrip.count()); |
386 EXPECT_EQ(2, observer.GetStateCount()); | 392 EXPECT_EQ(2, observer.GetStateCount()); |
387 State s1(contents1, 0, MockTabStripModelObserver::INSERT); | 393 State s1(contents1, 0, MockTabStripModelObserver::INSERT); |
388 s1.foreground = true; | 394 s1.foreground = true; |
389 EXPECT_TRUE(observer.StateEquals(0, s1)); | 395 EXPECT_TRUE(observer.StateEquals(0, s1)); |
390 State s2(contents1, 0, MockTabStripModelObserver::SELECT); | 396 State s2(contents1, 0, MockTabStripModelObserver::SELECT); |
391 s2.src_contents = NULL; | 397 s2.src_contents = NULL; |
392 EXPECT_TRUE(observer.StateEquals(1, s2)); | 398 EXPECT_TRUE(observer.StateEquals(1, s2)); |
393 observer.ClearStates(); | 399 observer.ClearStates(); |
394 } | 400 } |
395 | 401 |
396 // Test InsertTabContentsAt, foreground tab. | 402 // Test InsertTabContentsAt, foreground tab. |
397 TabContents* contents2 = CreateTabContents(); | 403 TabContentsWrapper* contents2 = CreateTabContents(); |
398 { | 404 { |
399 tabstrip.InsertTabContentsAt(1, contents2, TabStripModel::ADD_SELECTED); | 405 tabstrip.InsertTabContentsAt(1, contents2, TabStripModel::ADD_SELECTED); |
400 | 406 |
401 EXPECT_EQ(2, tabstrip.count()); | 407 EXPECT_EQ(2, tabstrip.count()); |
402 EXPECT_EQ(2, observer.GetStateCount()); | 408 EXPECT_EQ(2, observer.GetStateCount()); |
403 State s1(contents2, 1, MockTabStripModelObserver::INSERT); | 409 State s1(contents2, 1, MockTabStripModelObserver::INSERT); |
404 s1.foreground = true; | 410 s1.foreground = true; |
405 EXPECT_TRUE(observer.StateEquals(0, s1)); | 411 EXPECT_TRUE(observer.StateEquals(0, s1)); |
406 State s2(contents2, 1, MockTabStripModelObserver::SELECT); | 412 State s2(contents2, 1, MockTabStripModelObserver::SELECT); |
407 s2.src_contents = contents1; | 413 s2.src_contents = contents1; |
408 EXPECT_TRUE(observer.StateEquals(1, s2)); | 414 EXPECT_TRUE(observer.StateEquals(1, s2)); |
409 observer.ClearStates(); | 415 observer.ClearStates(); |
410 } | 416 } |
411 | 417 |
412 // Test InsertTabContentsAt, background tab. | 418 // Test InsertTabContentsAt, background tab. |
413 TabContents* contents3 = CreateTabContents(); | 419 TabContentsWrapper* contents3 = CreateTabContents(); |
414 { | 420 { |
415 tabstrip.InsertTabContentsAt(2, contents3, TabStripModel::ADD_NONE); | 421 tabstrip.InsertTabContentsAt(2, contents3, TabStripModel::ADD_NONE); |
416 | 422 |
417 EXPECT_EQ(3, tabstrip.count()); | 423 EXPECT_EQ(3, tabstrip.count()); |
418 EXPECT_EQ(1, observer.GetStateCount()); | 424 EXPECT_EQ(1, observer.GetStateCount()); |
419 State s1(contents3, 2, MockTabStripModelObserver::INSERT); | 425 State s1(contents3, 2, MockTabStripModelObserver::INSERT); |
420 s1.foreground = false; | 426 s1.foreground = false; |
421 EXPECT_TRUE(observer.StateEquals(0, s1)); | 427 EXPECT_TRUE(observer.StateEquals(0, s1)); |
422 observer.ClearStates(); | 428 observer.ClearStates(); |
423 } | 429 } |
424 | 430 |
425 // Test SelectTabContentsAt | 431 // Test SelectTabContentsAt |
426 { | 432 { |
427 tabstrip.SelectTabContentsAt(2, true); | 433 tabstrip.SelectTabContentsAt(2, true); |
428 EXPECT_EQ(1, observer.GetStateCount()); | 434 EXPECT_EQ(1, observer.GetStateCount()); |
429 State s1(contents3, 2, MockTabStripModelObserver::SELECT); | 435 State s1(contents3, 2, MockTabStripModelObserver::SELECT); |
430 s1.src_contents = contents2; | 436 s1.src_contents = contents2; |
431 s1.user_gesture = true; | 437 s1.user_gesture = true; |
432 EXPECT_TRUE(observer.StateEquals(0, s1)); | 438 EXPECT_TRUE(observer.StateEquals(0, s1)); |
433 observer.ClearStates(); | 439 observer.ClearStates(); |
434 } | 440 } |
435 | 441 |
436 // Test DetachTabContentsAt | 442 // Test DetachTabContentsAt |
437 { | 443 { |
438 // Detach | 444 // Detach |
439 TabContents* detached = tabstrip.DetachTabContentsAt(2); | 445 TabContentsWrapper* detached = tabstrip.DetachTabContentsAt(2); |
440 // ... and append again because we want this for later. | 446 // ... and append again because we want this for later. |
441 tabstrip.AppendTabContents(detached, true); | 447 tabstrip.AppendTabContents(detached, true); |
442 EXPECT_EQ(4, observer.GetStateCount()); | 448 EXPECT_EQ(4, observer.GetStateCount()); |
443 State s1(detached, 2, MockTabStripModelObserver::DETACH); | 449 State s1(detached, 2, MockTabStripModelObserver::DETACH); |
444 EXPECT_TRUE(observer.StateEquals(0, s1)); | 450 EXPECT_TRUE(observer.StateEquals(0, s1)); |
445 State s2(contents2, 1, MockTabStripModelObserver::SELECT); | 451 State s2(contents2, 1, MockTabStripModelObserver::SELECT); |
446 s2.src_contents = contents3; | 452 s2.src_contents = contents3; |
447 s2.user_gesture = false; | 453 s2.user_gesture = false; |
448 EXPECT_TRUE(observer.StateEquals(1, s2)); | 454 EXPECT_TRUE(observer.StateEquals(1, s2)); |
449 State s3(detached, 2, MockTabStripModelObserver::INSERT); | 455 State s3(detached, 2, MockTabStripModelObserver::INSERT); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 | 565 |
560 TEST_F(TabStripModelTest, TestBasicOpenerAPI) { | 566 TEST_F(TabStripModelTest, TestBasicOpenerAPI) { |
561 TabStripDummyDelegate delegate(NULL); | 567 TabStripDummyDelegate delegate(NULL); |
562 TabStripModel tabstrip(&delegate, profile()); | 568 TabStripModel tabstrip(&delegate, profile()); |
563 EXPECT_TRUE(tabstrip.empty()); | 569 EXPECT_TRUE(tabstrip.empty()); |
564 | 570 |
565 // This is a basic test of opener functionality. opener_contents is created | 571 // This is a basic test of opener functionality. opener_contents is created |
566 // as the first tab in the strip and then we create 5 other tabs in the | 572 // as the first tab in the strip and then we create 5 other tabs in the |
567 // background with opener_contents set as their opener. | 573 // background with opener_contents set as their opener. |
568 | 574 |
569 TabContents* opener_contents = CreateTabContents(); | 575 TabContentsWrapper* opener_contents = CreateTabContents(); |
570 NavigationController* opener = &opener_contents->controller(); | 576 NavigationController* opener = &opener_contents->controller(); |
571 tabstrip.AppendTabContents(opener_contents, true); | 577 tabstrip.AppendTabContents(opener_contents, true); |
572 TabContents* contents1 = CreateTabContents(); | 578 TabContentsWrapper* contents1 = CreateTabContents(); |
573 TabContents* contents2 = CreateTabContents(); | 579 TabContentsWrapper* contents2 = CreateTabContents(); |
574 TabContents* contents3 = CreateTabContents(); | 580 TabContentsWrapper* contents3 = CreateTabContents(); |
575 TabContents* contents4 = CreateTabContents(); | 581 TabContentsWrapper* contents4 = CreateTabContents(); |
576 TabContents* contents5 = CreateTabContents(); | 582 TabContentsWrapper* contents5 = CreateTabContents(); |
577 | 583 |
578 // We use |InsertTabContentsAt| here instead of AppendTabContents so that | 584 // We use |InsertTabContentsAt| here instead of AppendTabContents so that |
579 // openership relationships are preserved. | 585 // openership relationships are preserved. |
580 tabstrip.InsertTabContentsAt(tabstrip.count(), contents1, | 586 tabstrip.InsertTabContentsAt(tabstrip.count(), contents1, |
581 TabStripModel::ADD_INHERIT_GROUP); | 587 TabStripModel::ADD_INHERIT_GROUP); |
582 tabstrip.InsertTabContentsAt(tabstrip.count(), contents2, | 588 tabstrip.InsertTabContentsAt(tabstrip.count(), contents2, |
583 TabStripModel::ADD_INHERIT_GROUP); | 589 TabStripModel::ADD_INHERIT_GROUP); |
584 tabstrip.InsertTabContentsAt(tabstrip.count(), contents3, | 590 tabstrip.InsertTabContentsAt(tabstrip.count(), contents3, |
585 TabStripModel::ADD_INHERIT_GROUP); | 591 TabStripModel::ADD_INHERIT_GROUP); |
586 tabstrip.InsertTabContentsAt(tabstrip.count(), contents4, | 592 tabstrip.InsertTabContentsAt(tabstrip.count(), contents4, |
(...skipping 25 matching lines...) Expand all Loading... |
612 // ForgetAllOpeners should destroy all opener relationships. | 618 // ForgetAllOpeners should destroy all opener relationships. |
613 tabstrip.ForgetAllOpeners(); | 619 tabstrip.ForgetAllOpeners(); |
614 EXPECT_EQ(-1, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 1, false)); | 620 EXPECT_EQ(-1, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 1, false)); |
615 EXPECT_EQ(-1, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 5, false)); | 621 EXPECT_EQ(-1, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 5, false)); |
616 EXPECT_EQ(-1, tabstrip.GetIndexOfLastTabContentsOpenedBy(opener, 1)); | 622 EXPECT_EQ(-1, tabstrip.GetIndexOfLastTabContentsOpenedBy(opener, 1)); |
617 | 623 |
618 tabstrip.CloseAllTabs(); | 624 tabstrip.CloseAllTabs(); |
619 EXPECT_TRUE(tabstrip.empty()); | 625 EXPECT_TRUE(tabstrip.empty()); |
620 } | 626 } |
621 | 627 |
622 static int GetInsertionIndex(TabStripModel* tabstrip, TabContents* contents) { | 628 static int GetInsertionIndex(TabStripModel* tabstrip, |
| 629 TabContentsWrapper* contents) { |
623 return tabstrip->order_controller()->DetermineInsertionIndex( | 630 return tabstrip->order_controller()->DetermineInsertionIndex( |
624 contents, PageTransition::LINK, false); | 631 contents, PageTransition::LINK, false); |
625 } | 632 } |
626 | 633 |
627 static void InsertTabContentses(TabStripModel* tabstrip, | 634 static void InsertTabContentses(TabStripModel* tabstrip, |
628 TabContents* contents1, | 635 TabContentsWrapper* contents1, |
629 TabContents* contents2, | 636 TabContentsWrapper* contents2, |
630 TabContents* contents3) { | 637 TabContentsWrapper* contents3) { |
631 tabstrip->InsertTabContentsAt(GetInsertionIndex(tabstrip, contents1), | 638 tabstrip->InsertTabContentsAt(GetInsertionIndex(tabstrip, contents1), |
632 contents1, TabStripModel::ADD_INHERIT_GROUP); | 639 contents1, TabStripModel::ADD_INHERIT_GROUP); |
633 tabstrip->InsertTabContentsAt(GetInsertionIndex(tabstrip, contents2), | 640 tabstrip->InsertTabContentsAt(GetInsertionIndex(tabstrip, contents2), |
634 contents2, TabStripModel::ADD_INHERIT_GROUP); | 641 contents2, TabStripModel::ADD_INHERIT_GROUP); |
635 tabstrip->InsertTabContentsAt(GetInsertionIndex(tabstrip, contents3), | 642 tabstrip->InsertTabContentsAt(GetInsertionIndex(tabstrip, contents3), |
636 contents3, TabStripModel::ADD_INHERIT_GROUP); | 643 contents3, TabStripModel::ADD_INHERIT_GROUP); |
637 } | 644 } |
638 | 645 |
639 // Tests opening background tabs. | 646 // Tests opening background tabs. |
640 TEST_F(TabStripModelTest, TestLTRInsertionOptions) { | 647 TEST_F(TabStripModelTest, TestLTRInsertionOptions) { |
641 TabStripDummyDelegate delegate(NULL); | 648 TabStripDummyDelegate delegate(NULL); |
642 TabStripModel tabstrip(&delegate, profile()); | 649 TabStripModel tabstrip(&delegate, profile()); |
643 EXPECT_TRUE(tabstrip.empty()); | 650 EXPECT_TRUE(tabstrip.empty()); |
644 | 651 |
645 TabContents* opener_contents = CreateTabContents(); | 652 TabContentsWrapper* opener_contents = CreateTabContents(); |
646 tabstrip.AppendTabContents(opener_contents, true); | 653 tabstrip.AppendTabContents(opener_contents, true); |
647 | 654 |
648 TabContents* contents1 = CreateTabContents(); | 655 TabContentsWrapper* contents1 = CreateTabContents(); |
649 TabContents* contents2 = CreateTabContents(); | 656 TabContentsWrapper* contents2 = CreateTabContents(); |
650 TabContents* contents3 = CreateTabContents(); | 657 TabContentsWrapper* contents3 = CreateTabContents(); |
651 | 658 |
652 // Test LTR | 659 // Test LTR |
653 InsertTabContentses(&tabstrip, contents1, contents2, contents3); | 660 InsertTabContentses(&tabstrip, contents1, contents2, contents3); |
654 EXPECT_EQ(contents1, tabstrip.GetTabContentsAt(1)); | 661 EXPECT_EQ(contents1, tabstrip.GetTabContentsAt(1)); |
655 EXPECT_EQ(contents2, tabstrip.GetTabContentsAt(2)); | 662 EXPECT_EQ(contents2, tabstrip.GetTabContentsAt(2)); |
656 EXPECT_EQ(contents3, tabstrip.GetTabContentsAt(3)); | 663 EXPECT_EQ(contents3, tabstrip.GetTabContentsAt(3)); |
657 | 664 |
658 tabstrip.CloseAllTabs(); | 665 tabstrip.CloseAllTabs(); |
659 EXPECT_TRUE(tabstrip.empty()); | 666 EXPECT_TRUE(tabstrip.empty()); |
660 } | 667 } |
661 | 668 |
662 // Tests inserting tabs with InsertAfter set to false. | 669 // Tests inserting tabs with InsertAfter set to false. |
663 TEST_F(TabStripModelTest, InsertBefore) { | 670 TEST_F(TabStripModelTest, InsertBefore) { |
664 TabStripDummyDelegate delegate(NULL); | 671 TabStripDummyDelegate delegate(NULL); |
665 TabStripModel tabstrip(&delegate, profile()); | 672 TabStripModel tabstrip(&delegate, profile()); |
666 tabstrip.SetInsertionPolicy(TabStripModel::INSERT_BEFORE); | 673 tabstrip.SetInsertionPolicy(TabStripModel::INSERT_BEFORE); |
667 EXPECT_TRUE(tabstrip.empty()); | 674 EXPECT_TRUE(tabstrip.empty()); |
668 | 675 |
669 TabContents* contents1 = CreateTabContents(); | 676 TabContentsWrapper* contents1 = CreateTabContents(); |
670 TabContents* contents2 = CreateTabContents(); | 677 TabContentsWrapper* contents2 = CreateTabContents(); |
671 TabContents* contents3 = CreateTabContents(); | 678 TabContentsWrapper* contents3 = CreateTabContents(); |
672 | 679 |
673 InsertTabContentses(&tabstrip, contents1, contents2, contents3); | 680 InsertTabContentses(&tabstrip, contents1, contents2, contents3); |
674 | 681 |
675 // The order should be reversed. | 682 // The order should be reversed. |
676 EXPECT_EQ(contents3, tabstrip.GetTabContentsAt(0)); | 683 EXPECT_EQ(contents3, tabstrip.GetTabContentsAt(0)); |
677 EXPECT_EQ(contents2, tabstrip.GetTabContentsAt(1)); | 684 EXPECT_EQ(contents2, tabstrip.GetTabContentsAt(1)); |
678 EXPECT_EQ(contents1, tabstrip.GetTabContentsAt(2)); | 685 EXPECT_EQ(contents1, tabstrip.GetTabContentsAt(2)); |
679 | 686 |
680 tabstrip.CloseAllTabs(); | 687 tabstrip.CloseAllTabs(); |
681 EXPECT_TRUE(tabstrip.empty()); | 688 EXPECT_TRUE(tabstrip.empty()); |
682 } | 689 } |
683 | 690 |
684 // Tests opening background tabs with InsertAfter set to false. | 691 // Tests opening background tabs with InsertAfter set to false. |
685 TEST_F(TabStripModelTest, InsertBeforeOpeners) { | 692 TEST_F(TabStripModelTest, InsertBeforeOpeners) { |
686 TabStripDummyDelegate delegate(NULL); | 693 TabStripDummyDelegate delegate(NULL); |
687 TabStripModel tabstrip(&delegate, profile()); | 694 TabStripModel tabstrip(&delegate, profile()); |
688 tabstrip.SetInsertionPolicy(TabStripModel::INSERT_BEFORE); | 695 tabstrip.SetInsertionPolicy(TabStripModel::INSERT_BEFORE); |
689 EXPECT_TRUE(tabstrip.empty()); | 696 EXPECT_TRUE(tabstrip.empty()); |
690 TabContents* opener_contents = CreateTabContents(); | 697 TabContentsWrapper* opener_contents = CreateTabContents(); |
691 tabstrip.AppendTabContents(opener_contents, true); | 698 tabstrip.AppendTabContents(opener_contents, true); |
692 | 699 |
693 TabContents* contents1 = CreateTabContents(); | 700 TabContentsWrapper* contents1 = CreateTabContents(); |
694 TabContents* contents2 = CreateTabContents(); | 701 TabContentsWrapper* contents2 = CreateTabContents(); |
695 TabContents* contents3 = CreateTabContents(); | 702 TabContentsWrapper* contents3 = CreateTabContents(); |
696 | 703 |
697 InsertTabContentses(&tabstrip, contents1, contents2, contents3); | 704 InsertTabContentses(&tabstrip, contents1, contents2, contents3); |
698 | 705 |
699 // The order should be reversed. | 706 // The order should be reversed. |
700 EXPECT_EQ(contents3, tabstrip.GetTabContentsAt(0)); | 707 EXPECT_EQ(contents3, tabstrip.GetTabContentsAt(0)); |
701 EXPECT_EQ(contents2, tabstrip.GetTabContentsAt(1)); | 708 EXPECT_EQ(contents2, tabstrip.GetTabContentsAt(1)); |
702 EXPECT_EQ(contents1, tabstrip.GetTabContentsAt(2)); | 709 EXPECT_EQ(contents1, tabstrip.GetTabContentsAt(2)); |
703 | 710 |
704 tabstrip.CloseAllTabs(); | 711 tabstrip.CloseAllTabs(); |
705 EXPECT_TRUE(tabstrip.empty()); | 712 EXPECT_TRUE(tabstrip.empty()); |
706 } | 713 } |
707 | 714 |
708 // This test constructs a tabstrip, and then simulates loading several tabs in | 715 // This test constructs a tabstrip, and then simulates loading several tabs in |
709 // the background from link clicks on the first tab. Then it simulates opening | 716 // the background from link clicks on the first tab. Then it simulates opening |
710 // a new tab from the first tab in the foreground via a link click, verifies | 717 // a new tab from the first tab in the foreground via a link click, verifies |
711 // that this tab is opened adjacent to the opener, then closes it. | 718 // that this tab is opened adjacent to the opener, then closes it. |
712 // Finally it tests that a tab opened for some non-link purpose openes at the | 719 // Finally it tests that a tab opened for some non-link purpose openes at the |
713 // end of the strip, not bundled to any existing context. | 720 // end of the strip, not bundled to any existing context. |
714 TEST_F(TabStripModelTest, TestInsertionIndexDetermination) { | 721 TEST_F(TabStripModelTest, TestInsertionIndexDetermination) { |
715 TabStripDummyDelegate delegate(NULL); | 722 TabStripDummyDelegate delegate(NULL); |
716 TabStripModel tabstrip(&delegate, profile()); | 723 TabStripModel tabstrip(&delegate, profile()); |
717 EXPECT_TRUE(tabstrip.empty()); | 724 EXPECT_TRUE(tabstrip.empty()); |
718 | 725 |
719 TabContents* opener_contents = CreateTabContents(); | 726 TabContentsWrapper* opener_contents = CreateTabContents(); |
720 NavigationController* opener = &opener_contents->controller(); | 727 NavigationController* opener = &opener_contents->controller(); |
721 tabstrip.AppendTabContents(opener_contents, true); | 728 tabstrip.AppendTabContents(opener_contents, true); |
722 | 729 |
723 // Open some other random unrelated tab in the background to monkey with our | 730 // Open some other random unrelated tab in the background to monkey with our |
724 // insertion index. | 731 // insertion index. |
725 TabContents* other_contents = CreateTabContents(); | 732 TabContentsWrapper* other_contents = CreateTabContents(); |
726 tabstrip.AppendTabContents(other_contents, false); | 733 tabstrip.AppendTabContents(other_contents, false); |
727 | 734 |
728 TabContents* contents1 = CreateTabContents(); | 735 TabContentsWrapper* contents1 = CreateTabContents(); |
729 TabContents* contents2 = CreateTabContents(); | 736 TabContentsWrapper* contents2 = CreateTabContents(); |
730 TabContents* contents3 = CreateTabContents(); | 737 TabContentsWrapper* contents3 = CreateTabContents(); |
731 | 738 |
732 // Start by testing LTR | 739 // Start by testing LTR |
733 InsertTabContentses(&tabstrip, contents1, contents2, contents3); | 740 InsertTabContentses(&tabstrip, contents1, contents2, contents3); |
734 EXPECT_EQ(opener_contents, tabstrip.GetTabContentsAt(0)); | 741 EXPECT_EQ(opener_contents, tabstrip.GetTabContentsAt(0)); |
735 EXPECT_EQ(contents1, tabstrip.GetTabContentsAt(1)); | 742 EXPECT_EQ(contents1, tabstrip.GetTabContentsAt(1)); |
736 EXPECT_EQ(contents2, tabstrip.GetTabContentsAt(2)); | 743 EXPECT_EQ(contents2, tabstrip.GetTabContentsAt(2)); |
737 EXPECT_EQ(contents3, tabstrip.GetTabContentsAt(3)); | 744 EXPECT_EQ(contents3, tabstrip.GetTabContentsAt(3)); |
738 EXPECT_EQ(other_contents, tabstrip.GetTabContentsAt(4)); | 745 EXPECT_EQ(other_contents, tabstrip.GetTabContentsAt(4)); |
739 | 746 |
740 // The opener API should work... | 747 // The opener API should work... |
741 EXPECT_EQ(3, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 2, false)); | 748 EXPECT_EQ(3, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 2, false)); |
742 EXPECT_EQ(2, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 3, false)); | 749 EXPECT_EQ(2, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 3, false)); |
743 EXPECT_EQ(3, tabstrip.GetIndexOfLastTabContentsOpenedBy(opener, 1)); | 750 EXPECT_EQ(3, tabstrip.GetIndexOfLastTabContentsOpenedBy(opener, 1)); |
744 | 751 |
745 // Now open a foreground tab from a link. It should be opened adjacent to the | 752 // Now open a foreground tab from a link. It should be opened adjacent to the |
746 // opener tab. | 753 // opener tab. |
747 TabContents* fg_link_contents = CreateTabContents(); | 754 TabContentsWrapper* fg_link_contents = CreateTabContents(); |
748 int insert_index = tabstrip.order_controller()->DetermineInsertionIndex( | 755 int insert_index = tabstrip.order_controller()->DetermineInsertionIndex( |
749 fg_link_contents, PageTransition::LINK, true); | 756 fg_link_contents, PageTransition::LINK, true); |
750 EXPECT_EQ(1, insert_index); | 757 EXPECT_EQ(1, insert_index); |
751 tabstrip.InsertTabContentsAt(insert_index, fg_link_contents, | 758 tabstrip.InsertTabContentsAt(insert_index, fg_link_contents, |
752 TabStripModel::ADD_SELECTED | | 759 TabStripModel::ADD_SELECTED | |
753 TabStripModel::ADD_INHERIT_GROUP); | 760 TabStripModel::ADD_INHERIT_GROUP); |
754 EXPECT_EQ(1, tabstrip.selected_index()); | 761 EXPECT_EQ(1, tabstrip.selected_index()); |
755 EXPECT_EQ(fg_link_contents, tabstrip.GetSelectedTabContents()); | 762 EXPECT_EQ(fg_link_contents, tabstrip.GetSelectedTabContents()); |
756 | 763 |
757 // Now close this contents. The selection should move to the opener contents. | 764 // Now close this contents. The selection should move to the opener contents. |
758 tabstrip.CloseSelectedTab(); | 765 tabstrip.CloseSelectedTab(); |
759 EXPECT_EQ(0, tabstrip.selected_index()); | 766 EXPECT_EQ(0, tabstrip.selected_index()); |
760 | 767 |
761 // Now open a new empty tab. It should open at the end of the strip. | 768 // Now open a new empty tab. It should open at the end of the strip. |
762 TabContents* fg_nonlink_contents = CreateTabContents(); | 769 TabContentsWrapper* fg_nonlink_contents = CreateTabContents(); |
763 insert_index = tabstrip.order_controller()->DetermineInsertionIndex( | 770 insert_index = tabstrip.order_controller()->DetermineInsertionIndex( |
764 fg_nonlink_contents, PageTransition::AUTO_BOOKMARK, true); | 771 fg_nonlink_contents, PageTransition::AUTO_BOOKMARK, true); |
765 EXPECT_EQ(tabstrip.count(), insert_index); | 772 EXPECT_EQ(tabstrip.count(), insert_index); |
766 // We break the opener relationship... | 773 // We break the opener relationship... |
767 tabstrip.InsertTabContentsAt(insert_index, fg_nonlink_contents, | 774 tabstrip.InsertTabContentsAt(insert_index, fg_nonlink_contents, |
768 TabStripModel::ADD_NONE); | 775 TabStripModel::ADD_NONE); |
769 // Now select it, so that user_gesture == true causes the opener relationship | 776 // Now select it, so that user_gesture == true causes the opener relationship |
770 // to be forgotten... | 777 // to be forgotten... |
771 tabstrip.SelectTabContentsAt(tabstrip.count() - 1, true); | 778 tabstrip.SelectTabContentsAt(tabstrip.count() - 1, true); |
772 EXPECT_EQ(tabstrip.count() - 1, tabstrip.selected_index()); | 779 EXPECT_EQ(tabstrip.count() - 1, tabstrip.selected_index()); |
(...skipping 18 matching lines...) Expand all Loading... |
791 // The next tab (scanning LTR) in the entire strip that has the same opener | 798 // The next tab (scanning LTR) in the entire strip that has the same opener |
792 // is selected | 799 // is selected |
793 // If there are no other tabs that have the same opener, | 800 // If there are no other tabs that have the same opener, |
794 // The opener is selected | 801 // The opener is selected |
795 // | 802 // |
796 TEST_F(TabStripModelTest, TestSelectOnClose) { | 803 TEST_F(TabStripModelTest, TestSelectOnClose) { |
797 TabStripDummyDelegate delegate(NULL); | 804 TabStripDummyDelegate delegate(NULL); |
798 TabStripModel tabstrip(&delegate, profile()); | 805 TabStripModel tabstrip(&delegate, profile()); |
799 EXPECT_TRUE(tabstrip.empty()); | 806 EXPECT_TRUE(tabstrip.empty()); |
800 | 807 |
801 TabContents* opener_contents = CreateTabContents(); | 808 TabContentsWrapper* opener_contents = CreateTabContents(); |
802 tabstrip.AppendTabContents(opener_contents, true); | 809 tabstrip.AppendTabContents(opener_contents, true); |
803 | 810 |
804 TabContents* contents1 = CreateTabContents(); | 811 TabContentsWrapper* contents1 = CreateTabContents(); |
805 TabContents* contents2 = CreateTabContents(); | 812 TabContentsWrapper* contents2 = CreateTabContents(); |
806 TabContents* contents3 = CreateTabContents(); | 813 TabContentsWrapper* contents3 = CreateTabContents(); |
807 | 814 |
808 // Note that we use Detach instead of Close throughout this test to avoid | 815 // Note that we use Detach instead of Close throughout this test to avoid |
809 // having to keep reconstructing these TabContentses. | 816 // having to keep reconstructing these TabContentses. |
810 | 817 |
811 // First test that closing tabs that are in the background doesn't adjust the | 818 // First test that closing tabs that are in the background doesn't adjust the |
812 // current selection. | 819 // current selection. |
813 InsertTabContentses(&tabstrip, contents1, contents2, contents3); | 820 InsertTabContentses(&tabstrip, contents1, contents2, contents3); |
814 EXPECT_EQ(0, tabstrip.selected_index()); | 821 EXPECT_EQ(0, tabstrip.selected_index()); |
815 | 822 |
816 tabstrip.DetachTabContentsAt(1); | 823 tabstrip.DetachTabContentsAt(1); |
(...skipping 27 matching lines...) Expand all Loading... |
844 tabstrip.SelectTabContentsAt(2, false); | 851 tabstrip.SelectTabContentsAt(2, false); |
845 EXPECT_EQ(2, tabstrip.selected_index()); | 852 EXPECT_EQ(2, tabstrip.selected_index()); |
846 tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE); | 853 tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE); |
847 EXPECT_EQ(2, tabstrip.selected_index()); | 854 EXPECT_EQ(2, tabstrip.selected_index()); |
848 tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE); | 855 tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE); |
849 EXPECT_EQ(1, tabstrip.selected_index()); | 856 EXPECT_EQ(1, tabstrip.selected_index()); |
850 tabstrip.CloseTabContentsAt(1, TabStripModel::CLOSE_NONE); | 857 tabstrip.CloseTabContentsAt(1, TabStripModel::CLOSE_NONE); |
851 EXPECT_EQ(0, tabstrip.selected_index()); | 858 EXPECT_EQ(0, tabstrip.selected_index()); |
852 // Finally test that when a tab has no "siblings" that the opener is | 859 // Finally test that when a tab has no "siblings" that the opener is |
853 // selected. | 860 // selected. |
854 TabContents* other_contents = CreateTabContents(); | 861 TabContentsWrapper* other_contents = CreateTabContents(); |
855 tabstrip.InsertTabContentsAt(1, other_contents, TabStripModel::ADD_NONE); | 862 tabstrip.InsertTabContentsAt(1, other_contents, TabStripModel::ADD_NONE); |
856 EXPECT_EQ(2, tabstrip.count()); | 863 EXPECT_EQ(2, tabstrip.count()); |
857 TabContents* opened_contents = CreateTabContents(); | 864 TabContentsWrapper* opened_contents = CreateTabContents(); |
858 tabstrip.InsertTabContentsAt(2, opened_contents, | 865 tabstrip.InsertTabContentsAt(2, opened_contents, |
859 TabStripModel::ADD_SELECTED | | 866 TabStripModel::ADD_SELECTED | |
860 TabStripModel::ADD_INHERIT_GROUP); | 867 TabStripModel::ADD_INHERIT_GROUP); |
861 EXPECT_EQ(2, tabstrip.selected_index()); | 868 EXPECT_EQ(2, tabstrip.selected_index()); |
862 tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE); | 869 tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE); |
863 EXPECT_EQ(0, tabstrip.selected_index()); | 870 EXPECT_EQ(0, tabstrip.selected_index()); |
864 | 871 |
865 tabstrip.CloseAllTabs(); | 872 tabstrip.CloseAllTabs(); |
866 EXPECT_TRUE(tabstrip.empty()); | 873 EXPECT_TRUE(tabstrip.empty()); |
867 } | 874 } |
868 | 875 |
869 // Tests the following context menu commands: | 876 // Tests the following context menu commands: |
870 // - Close Tab | 877 // - Close Tab |
871 // - Close Other Tabs | 878 // - Close Other Tabs |
872 // - Close Tabs To Right | 879 // - Close Tabs To Right |
873 TEST_F(TabStripModelTest, TestContextMenuCloseCommands) { | 880 TEST_F(TabStripModelTest, TestContextMenuCloseCommands) { |
874 TabStripDummyDelegate delegate(NULL); | 881 TabStripDummyDelegate delegate(NULL); |
875 TabStripModel tabstrip(&delegate, profile()); | 882 TabStripModel tabstrip(&delegate, profile()); |
876 EXPECT_TRUE(tabstrip.empty()); | 883 EXPECT_TRUE(tabstrip.empty()); |
877 | 884 |
878 TabContents* opener_contents = CreateTabContents(); | 885 TabContentsWrapper* opener_contents = CreateTabContents(); |
879 tabstrip.AppendTabContents(opener_contents, true); | 886 tabstrip.AppendTabContents(opener_contents, true); |
880 | 887 |
881 TabContents* contents1 = CreateTabContents(); | 888 TabContentsWrapper* contents1 = CreateTabContents(); |
882 TabContents* contents2 = CreateTabContents(); | 889 TabContentsWrapper* contents2 = CreateTabContents(); |
883 TabContents* contents3 = CreateTabContents(); | 890 TabContentsWrapper* contents3 = CreateTabContents(); |
884 | 891 |
885 InsertTabContentses(&tabstrip, contents1, contents2, contents3); | 892 InsertTabContentses(&tabstrip, contents1, contents2, contents3); |
886 EXPECT_EQ(0, tabstrip.selected_index()); | 893 EXPECT_EQ(0, tabstrip.selected_index()); |
887 | 894 |
888 tabstrip.ExecuteContextMenuCommand(2, TabStripModel::CommandCloseTab); | 895 tabstrip.ExecuteContextMenuCommand(2, TabStripModel::CommandCloseTab); |
889 EXPECT_EQ(3, tabstrip.count()); | 896 EXPECT_EQ(3, tabstrip.count()); |
890 | 897 |
891 tabstrip.ExecuteContextMenuCommand(0, TabStripModel::CommandCloseTabsToRight); | 898 tabstrip.ExecuteContextMenuCommand(0, TabStripModel::CommandCloseTabsToRight); |
892 EXPECT_EQ(1, tabstrip.count()); | 899 EXPECT_EQ(1, tabstrip.count()); |
893 EXPECT_EQ(opener_contents, tabstrip.GetSelectedTabContents()); | 900 EXPECT_EQ(opener_contents, tabstrip.GetSelectedTabContents()); |
894 | 901 |
895 TabContents* dummy_contents = CreateTabContents(); | 902 TabContentsWrapper* dummy_contents = CreateTabContents(); |
896 tabstrip.AppendTabContents(dummy_contents, false); | 903 tabstrip.AppendTabContents(dummy_contents, false); |
897 | 904 |
898 contents1 = CreateTabContents(); | 905 contents1 = CreateTabContents(); |
899 contents2 = CreateTabContents(); | 906 contents2 = CreateTabContents(); |
900 contents3 = CreateTabContents(); | 907 contents3 = CreateTabContents(); |
901 InsertTabContentses(&tabstrip, contents1, contents2, contents3); | 908 InsertTabContentses(&tabstrip, contents1, contents2, contents3); |
902 EXPECT_EQ(5, tabstrip.count()); | 909 EXPECT_EQ(5, tabstrip.count()); |
903 | 910 |
904 int dummy_index = tabstrip.count() - 1; | 911 int dummy_index = tabstrip.count() - 1; |
905 tabstrip.SelectTabContentsAt(dummy_index, true); | 912 tabstrip.SelectTabContentsAt(dummy_index, true); |
906 EXPECT_EQ(dummy_contents, tabstrip.GetSelectedTabContents()); | 913 EXPECT_EQ(dummy_contents, tabstrip.GetSelectedTabContents()); |
907 | 914 |
908 tabstrip.ExecuteContextMenuCommand(dummy_index, | 915 tabstrip.ExecuteContextMenuCommand(dummy_index, |
909 TabStripModel::CommandCloseOtherTabs); | 916 TabStripModel::CommandCloseOtherTabs); |
910 EXPECT_EQ(1, tabstrip.count()); | 917 EXPECT_EQ(1, tabstrip.count()); |
911 EXPECT_EQ(dummy_contents, tabstrip.GetSelectedTabContents()); | 918 EXPECT_EQ(dummy_contents, tabstrip.GetSelectedTabContents()); |
912 | 919 |
913 tabstrip.CloseAllTabs(); | 920 tabstrip.CloseAllTabs(); |
914 EXPECT_TRUE(tabstrip.empty()); | 921 EXPECT_TRUE(tabstrip.empty()); |
915 } | 922 } |
916 | 923 |
917 // Tests GetIndicesClosedByCommand. | 924 // Tests GetIndicesClosedByCommand. |
918 TEST_F(TabStripModelTest, GetIndicesClosedByCommand) { | 925 TEST_F(TabStripModelTest, GetIndicesClosedByCommand) { |
919 TabStripDummyDelegate delegate(NULL); | 926 TabStripDummyDelegate delegate(NULL); |
920 TabStripModel tabstrip(&delegate, profile()); | 927 TabStripModel tabstrip(&delegate, profile()); |
921 EXPECT_TRUE(tabstrip.empty()); | 928 EXPECT_TRUE(tabstrip.empty()); |
922 | 929 |
923 TabContents* contents1 = CreateTabContents(); | 930 TabContentsWrapper* contents1 = CreateTabContents(); |
924 TabContents* contents2 = CreateTabContents(); | 931 TabContentsWrapper* contents2 = CreateTabContents(); |
925 TabContents* contents3 = CreateTabContents(); | 932 TabContentsWrapper* contents3 = CreateTabContents(); |
926 TabContents* contents4 = CreateTabContents(); | 933 TabContentsWrapper* contents4 = CreateTabContents(); |
927 TabContents* contents5 = CreateTabContents(); | 934 TabContentsWrapper* contents5 = CreateTabContents(); |
928 | 935 |
929 tabstrip.AppendTabContents(contents1, true); | 936 tabstrip.AppendTabContents(contents1, true); |
930 tabstrip.AppendTabContents(contents2, true); | 937 tabstrip.AppendTabContents(contents2, true); |
931 tabstrip.AppendTabContents(contents3, true); | 938 tabstrip.AppendTabContents(contents3, true); |
932 tabstrip.AppendTabContents(contents4, true); | 939 tabstrip.AppendTabContents(contents4, true); |
933 tabstrip.AppendTabContents(contents5, true); | 940 tabstrip.AppendTabContents(contents5, true); |
934 | 941 |
935 EXPECT_EQ("4 3 2 1", GetIndicesClosedByCommandAsString( | 942 EXPECT_EQ("4 3 2 1", GetIndicesClosedByCommandAsString( |
936 tabstrip, 0, TabStripModel::CommandCloseTabsToRight)); | 943 tabstrip, 0, TabStripModel::CommandCloseTabsToRight)); |
937 EXPECT_EQ("4 3 2", GetIndicesClosedByCommandAsString( | 944 EXPECT_EQ("4 3 2", GetIndicesClosedByCommandAsString( |
(...skipping 25 matching lines...) Expand all Loading... |
963 | 970 |
964 // Tests whether or not TabContentses are inserted in the correct position | 971 // Tests whether or not TabContentses are inserted in the correct position |
965 // using this "smart" function with a simulated middle click action on a series | 972 // using this "smart" function with a simulated middle click action on a series |
966 // of links on the home page. | 973 // of links on the home page. |
967 TEST_F(TabStripModelTest, AddTabContents_MiddleClickLinksAndClose) { | 974 TEST_F(TabStripModelTest, AddTabContents_MiddleClickLinksAndClose) { |
968 TabStripDummyDelegate delegate(NULL); | 975 TabStripDummyDelegate delegate(NULL); |
969 TabStripModel tabstrip(&delegate, profile()); | 976 TabStripModel tabstrip(&delegate, profile()); |
970 EXPECT_TRUE(tabstrip.empty()); | 977 EXPECT_TRUE(tabstrip.empty()); |
971 | 978 |
972 // Open the Home Page | 979 // Open the Home Page |
973 TabContents* homepage_contents = CreateTabContents(); | 980 TabContentsWrapper* homepage_contents = CreateTabContents(); |
974 tabstrip.AddTabContents( | 981 tabstrip.AddTabContents( |
975 homepage_contents, -1, PageTransition::AUTO_BOOKMARK, | 982 homepage_contents, -1, PageTransition::AUTO_BOOKMARK, |
976 TabStripModel::ADD_SELECTED); | 983 TabStripModel::ADD_SELECTED); |
977 | 984 |
978 // Open some other tab, by user typing. | 985 // Open some other tab, by user typing. |
979 TabContents* typed_page_contents = CreateTabContents(); | 986 TabContentsWrapper* typed_page_contents = CreateTabContents(); |
980 tabstrip.AddTabContents( | 987 tabstrip.AddTabContents( |
981 typed_page_contents, -1, PageTransition::TYPED, | 988 typed_page_contents, -1, PageTransition::TYPED, |
982 TabStripModel::ADD_SELECTED); | 989 TabStripModel::ADD_SELECTED); |
983 | 990 |
984 EXPECT_EQ(2, tabstrip.count()); | 991 EXPECT_EQ(2, tabstrip.count()); |
985 | 992 |
986 // Re-select the home page. | 993 // Re-select the home page. |
987 tabstrip.SelectTabContentsAt(0, true); | 994 tabstrip.SelectTabContentsAt(0, true); |
988 | 995 |
989 // Open a bunch of tabs by simulating middle clicking on links on the home | 996 // Open a bunch of tabs by simulating middle clicking on links on the home |
990 // page. | 997 // page. |
991 TabContents* middle_click_contents1 = CreateTabContents(); | 998 TabContentsWrapper* middle_click_contents1 = CreateTabContents(); |
992 tabstrip.AddTabContents( | 999 tabstrip.AddTabContents( |
993 middle_click_contents1, -1, PageTransition::LINK, | 1000 middle_click_contents1, -1, PageTransition::LINK, |
994 TabStripModel::ADD_NONE); | 1001 TabStripModel::ADD_NONE); |
995 TabContents* middle_click_contents2 = CreateTabContents(); | 1002 TabContentsWrapper* middle_click_contents2 = CreateTabContents(); |
996 tabstrip.AddTabContents( | 1003 tabstrip.AddTabContents( |
997 middle_click_contents2, -1, PageTransition::LINK, | 1004 middle_click_contents2, -1, PageTransition::LINK, |
998 TabStripModel::ADD_NONE); | 1005 TabStripModel::ADD_NONE); |
999 TabContents* middle_click_contents3 = CreateTabContents(); | 1006 TabContentsWrapper* middle_click_contents3 = CreateTabContents(); |
1000 tabstrip.AddTabContents( | 1007 tabstrip.AddTabContents( |
1001 middle_click_contents3, -1, PageTransition::LINK, | 1008 middle_click_contents3, -1, PageTransition::LINK, |
1002 TabStripModel::ADD_NONE); | 1009 TabStripModel::ADD_NONE); |
1003 | 1010 |
1004 EXPECT_EQ(5, tabstrip.count()); | 1011 EXPECT_EQ(5, tabstrip.count()); |
1005 | 1012 |
1006 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); | 1013 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); |
1007 EXPECT_EQ(middle_click_contents1, tabstrip.GetTabContentsAt(1)); | 1014 EXPECT_EQ(middle_click_contents1, tabstrip.GetTabContentsAt(1)); |
1008 EXPECT_EQ(middle_click_contents2, tabstrip.GetTabContentsAt(2)); | 1015 EXPECT_EQ(middle_click_contents2, tabstrip.GetTabContentsAt(2)); |
1009 EXPECT_EQ(middle_click_contents3, tabstrip.GetTabContentsAt(3)); | 1016 EXPECT_EQ(middle_click_contents3, tabstrip.GetTabContentsAt(3)); |
(...skipping 22 matching lines...) Expand all Loading... |
1032 } | 1039 } |
1033 | 1040 |
1034 // Tests whether or not a TabContents created by a left click on a link that | 1041 // Tests whether or not a TabContents created by a left click on a link that |
1035 // opens a new tab is inserted correctly adjacent to the tab that spawned it. | 1042 // opens a new tab is inserted correctly adjacent to the tab that spawned it. |
1036 TEST_F(TabStripModelTest, AddTabContents_LeftClickPopup) { | 1043 TEST_F(TabStripModelTest, AddTabContents_LeftClickPopup) { |
1037 TabStripDummyDelegate delegate(NULL); | 1044 TabStripDummyDelegate delegate(NULL); |
1038 TabStripModel tabstrip(&delegate, profile()); | 1045 TabStripModel tabstrip(&delegate, profile()); |
1039 EXPECT_TRUE(tabstrip.empty()); | 1046 EXPECT_TRUE(tabstrip.empty()); |
1040 | 1047 |
1041 // Open the Home Page | 1048 // Open the Home Page |
1042 TabContents* homepage_contents = CreateTabContents(); | 1049 TabContentsWrapper* homepage_contents = CreateTabContents(); |
1043 tabstrip.AddTabContents( | 1050 tabstrip.AddTabContents( |
1044 homepage_contents, -1, PageTransition::AUTO_BOOKMARK, | 1051 homepage_contents, -1, PageTransition::AUTO_BOOKMARK, |
1045 TabStripModel::ADD_SELECTED); | 1052 TabStripModel::ADD_SELECTED); |
1046 | 1053 |
1047 // Open some other tab, by user typing. | 1054 // Open some other tab, by user typing. |
1048 TabContents* typed_page_contents = CreateTabContents(); | 1055 TabContentsWrapper* typed_page_contents = CreateTabContents(); |
1049 tabstrip.AddTabContents( | 1056 tabstrip.AddTabContents( |
1050 typed_page_contents, -1, PageTransition::TYPED, | 1057 typed_page_contents, -1, PageTransition::TYPED, |
1051 TabStripModel::ADD_SELECTED); | 1058 TabStripModel::ADD_SELECTED); |
1052 | 1059 |
1053 EXPECT_EQ(2, tabstrip.count()); | 1060 EXPECT_EQ(2, tabstrip.count()); |
1054 | 1061 |
1055 // Re-select the home page. | 1062 // Re-select the home page. |
1056 tabstrip.SelectTabContentsAt(0, true); | 1063 tabstrip.SelectTabContentsAt(0, true); |
1057 | 1064 |
1058 // Open a tab by simulating a left click on a link that opens in a new tab. | 1065 // Open a tab by simulating a left click on a link that opens in a new tab. |
1059 TabContents* left_click_contents = CreateTabContents(); | 1066 TabContentsWrapper* left_click_contents = CreateTabContents(); |
1060 tabstrip.AddTabContents(left_click_contents, -1, PageTransition::LINK, | 1067 tabstrip.AddTabContents(left_click_contents, -1, PageTransition::LINK, |
1061 TabStripModel::ADD_SELECTED); | 1068 TabStripModel::ADD_SELECTED); |
1062 | 1069 |
1063 // Verify the state meets our expectations. | 1070 // Verify the state meets our expectations. |
1064 EXPECT_EQ(3, tabstrip.count()); | 1071 EXPECT_EQ(3, tabstrip.count()); |
1065 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); | 1072 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); |
1066 EXPECT_EQ(left_click_contents, tabstrip.GetTabContentsAt(1)); | 1073 EXPECT_EQ(left_click_contents, tabstrip.GetTabContentsAt(1)); |
1067 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(2)); | 1074 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(2)); |
1068 | 1075 |
1069 // The newly created tab should be selected. | 1076 // The newly created tab should be selected. |
(...skipping 12 matching lines...) Expand all Loading... |
1082 | 1089 |
1083 // Tests whether or not new tabs that should split context (typed pages, | 1090 // Tests whether or not new tabs that should split context (typed pages, |
1084 // generated urls, also blank tabs) open at the end of the tabstrip instead of | 1091 // generated urls, also blank tabs) open at the end of the tabstrip instead of |
1085 // in the middle. | 1092 // in the middle. |
1086 TEST_F(TabStripModelTest, AddTabContents_CreateNewBlankTab) { | 1093 TEST_F(TabStripModelTest, AddTabContents_CreateNewBlankTab) { |
1087 TabStripDummyDelegate delegate(NULL); | 1094 TabStripDummyDelegate delegate(NULL); |
1088 TabStripModel tabstrip(&delegate, profile()); | 1095 TabStripModel tabstrip(&delegate, profile()); |
1089 EXPECT_TRUE(tabstrip.empty()); | 1096 EXPECT_TRUE(tabstrip.empty()); |
1090 | 1097 |
1091 // Open the Home Page | 1098 // Open the Home Page |
1092 TabContents* homepage_contents = CreateTabContents(); | 1099 TabContentsWrapper* homepage_contents = CreateTabContents(); |
1093 tabstrip.AddTabContents( | 1100 tabstrip.AddTabContents( |
1094 homepage_contents, -1, PageTransition::AUTO_BOOKMARK, | 1101 homepage_contents, -1, PageTransition::AUTO_BOOKMARK, |
1095 TabStripModel::ADD_SELECTED); | 1102 TabStripModel::ADD_SELECTED); |
1096 | 1103 |
1097 // Open some other tab, by user typing. | 1104 // Open some other tab, by user typing. |
1098 TabContents* typed_page_contents = CreateTabContents(); | 1105 TabContentsWrapper* typed_page_contents = CreateTabContents(); |
1099 tabstrip.AddTabContents( | 1106 tabstrip.AddTabContents( |
1100 typed_page_contents, -1, PageTransition::TYPED, | 1107 typed_page_contents, -1, PageTransition::TYPED, |
1101 TabStripModel::ADD_SELECTED); | 1108 TabStripModel::ADD_SELECTED); |
1102 | 1109 |
1103 EXPECT_EQ(2, tabstrip.count()); | 1110 EXPECT_EQ(2, tabstrip.count()); |
1104 | 1111 |
1105 // Re-select the home page. | 1112 // Re-select the home page. |
1106 tabstrip.SelectTabContentsAt(0, true); | 1113 tabstrip.SelectTabContentsAt(0, true); |
1107 | 1114 |
1108 // Open a new blank tab in the foreground. | 1115 // Open a new blank tab in the foreground. |
1109 TabContents* new_blank_contents = CreateTabContents(); | 1116 TabContentsWrapper* new_blank_contents = CreateTabContents(); |
1110 tabstrip.AddTabContents(new_blank_contents, -1, PageTransition::TYPED, | 1117 tabstrip.AddTabContents(new_blank_contents, -1, PageTransition::TYPED, |
1111 TabStripModel::ADD_SELECTED); | 1118 TabStripModel::ADD_SELECTED); |
1112 | 1119 |
1113 // Verify the state of the tabstrip. | 1120 // Verify the state of the tabstrip. |
1114 EXPECT_EQ(3, tabstrip.count()); | 1121 EXPECT_EQ(3, tabstrip.count()); |
1115 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); | 1122 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); |
1116 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(1)); | 1123 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(1)); |
1117 EXPECT_EQ(new_blank_contents, tabstrip.GetTabContentsAt(2)); | 1124 EXPECT_EQ(new_blank_contents, tabstrip.GetTabContentsAt(2)); |
1118 | 1125 |
1119 // Now open a couple more blank tabs in the background. | 1126 // Now open a couple more blank tabs in the background. |
1120 TabContents* background_blank_contents1 = CreateTabContents(); | 1127 TabContentsWrapper* background_blank_contents1 = CreateTabContents(); |
1121 tabstrip.AddTabContents( | 1128 tabstrip.AddTabContents( |
1122 background_blank_contents1, -1, PageTransition::TYPED, | 1129 background_blank_contents1, -1, PageTransition::TYPED, |
1123 TabStripModel::ADD_NONE); | 1130 TabStripModel::ADD_NONE); |
1124 TabContents* background_blank_contents2 = CreateTabContents(); | 1131 TabContentsWrapper* background_blank_contents2 = CreateTabContents(); |
1125 tabstrip.AddTabContents( | 1132 tabstrip.AddTabContents( |
1126 background_blank_contents2, -1, PageTransition::GENERATED, | 1133 background_blank_contents2, -1, PageTransition::GENERATED, |
1127 TabStripModel::ADD_NONE); | 1134 TabStripModel::ADD_NONE); |
1128 EXPECT_EQ(5, tabstrip.count()); | 1135 EXPECT_EQ(5, tabstrip.count()); |
1129 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); | 1136 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); |
1130 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(1)); | 1137 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(1)); |
1131 EXPECT_EQ(new_blank_contents, tabstrip.GetTabContentsAt(2)); | 1138 EXPECT_EQ(new_blank_contents, tabstrip.GetTabContentsAt(2)); |
1132 EXPECT_EQ(background_blank_contents1, tabstrip.GetTabContentsAt(3)); | 1139 EXPECT_EQ(background_blank_contents1, tabstrip.GetTabContentsAt(3)); |
1133 EXPECT_EQ(background_blank_contents2, tabstrip.GetTabContentsAt(4)); | 1140 EXPECT_EQ(background_blank_contents2, tabstrip.GetTabContentsAt(4)); |
1134 | 1141 |
1135 tabstrip.CloseAllTabs(); | 1142 tabstrip.CloseAllTabs(); |
1136 EXPECT_TRUE(tabstrip.empty()); | 1143 EXPECT_TRUE(tabstrip.empty()); |
1137 } | 1144 } |
1138 | 1145 |
1139 // Tests whether opener state is correctly forgotten when the user switches | 1146 // Tests whether opener state is correctly forgotten when the user switches |
1140 // context. | 1147 // context. |
1141 TEST_F(TabStripModelTest, AddTabContents_ForgetOpeners) { | 1148 TEST_F(TabStripModelTest, AddTabContents_ForgetOpeners) { |
1142 TabStripDummyDelegate delegate(NULL); | 1149 TabStripDummyDelegate delegate(NULL); |
1143 TabStripModel tabstrip(&delegate, profile()); | 1150 TabStripModel tabstrip(&delegate, profile()); |
1144 EXPECT_TRUE(tabstrip.empty()); | 1151 EXPECT_TRUE(tabstrip.empty()); |
1145 | 1152 |
1146 // Open the Home Page | 1153 // Open the Home Page |
1147 TabContents* homepage_contents = CreateTabContents(); | 1154 TabContentsWrapper* homepage_contents = CreateTabContents(); |
1148 tabstrip.AddTabContents( | 1155 tabstrip.AddTabContents( |
1149 homepage_contents, -1, PageTransition::AUTO_BOOKMARK, | 1156 homepage_contents, -1, PageTransition::AUTO_BOOKMARK, |
1150 TabStripModel::ADD_SELECTED); | 1157 TabStripModel::ADD_SELECTED); |
1151 | 1158 |
1152 // Open some other tab, by user typing. | 1159 // Open some other tab, by user typing. |
1153 TabContents* typed_page_contents = CreateTabContents(); | 1160 TabContentsWrapper* typed_page_contents = CreateTabContents(); |
1154 tabstrip.AddTabContents( | 1161 tabstrip.AddTabContents( |
1155 typed_page_contents, -1, PageTransition::TYPED, | 1162 typed_page_contents, -1, PageTransition::TYPED, |
1156 TabStripModel::ADD_SELECTED); | 1163 TabStripModel::ADD_SELECTED); |
1157 | 1164 |
1158 EXPECT_EQ(2, tabstrip.count()); | 1165 EXPECT_EQ(2, tabstrip.count()); |
1159 | 1166 |
1160 // Re-select the home page. | 1167 // Re-select the home page. |
1161 tabstrip.SelectTabContentsAt(0, true); | 1168 tabstrip.SelectTabContentsAt(0, true); |
1162 | 1169 |
1163 // Open a bunch of tabs by simulating middle clicking on links on the home | 1170 // Open a bunch of tabs by simulating middle clicking on links on the home |
1164 // page. | 1171 // page. |
1165 TabContents* middle_click_contents1 = CreateTabContents(); | 1172 TabContentsWrapper* middle_click_contents1 = CreateTabContents(); |
1166 tabstrip.AddTabContents( | 1173 tabstrip.AddTabContents( |
1167 middle_click_contents1, -1, PageTransition::LINK, | 1174 middle_click_contents1, -1, PageTransition::LINK, |
1168 TabStripModel::ADD_NONE); | 1175 TabStripModel::ADD_NONE); |
1169 TabContents* middle_click_contents2 = CreateTabContents(); | 1176 TabContentsWrapper* middle_click_contents2 = CreateTabContents(); |
1170 tabstrip.AddTabContents( | 1177 tabstrip.AddTabContents( |
1171 middle_click_contents2, -1, PageTransition::LINK, | 1178 middle_click_contents2, -1, PageTransition::LINK, |
1172 TabStripModel::ADD_NONE); | 1179 TabStripModel::ADD_NONE); |
1173 TabContents* middle_click_contents3 = CreateTabContents(); | 1180 TabContentsWrapper* middle_click_contents3 = CreateTabContents(); |
1174 tabstrip.AddTabContents( | 1181 tabstrip.AddTabContents( |
1175 middle_click_contents3, -1, PageTransition::LINK, | 1182 middle_click_contents3, -1, PageTransition::LINK, |
1176 TabStripModel::ADD_NONE); | 1183 TabStripModel::ADD_NONE); |
1177 | 1184 |
1178 // Break out of the context by selecting a tab in a different context. | 1185 // Break out of the context by selecting a tab in a different context. |
1179 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(4)); | 1186 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(4)); |
1180 tabstrip.SelectLastTab(); | 1187 tabstrip.SelectLastTab(); |
1181 EXPECT_EQ(typed_page_contents, tabstrip.GetSelectedTabContents()); | 1188 EXPECT_EQ(typed_page_contents, tabstrip.GetSelectedTabContents()); |
1182 | 1189 |
1183 // Step back into the context by selecting a tab inside it. | 1190 // Step back into the context by selecting a tab inside it. |
(...skipping 13 matching lines...) Expand all Loading... |
1197 EXPECT_EQ(homepage_contents, tabstrip.GetSelectedTabContents()); | 1204 EXPECT_EQ(homepage_contents, tabstrip.GetSelectedTabContents()); |
1198 | 1205 |
1199 EXPECT_EQ(1, tabstrip.count()); | 1206 EXPECT_EQ(1, tabstrip.count()); |
1200 | 1207 |
1201 tabstrip.CloseAllTabs(); | 1208 tabstrip.CloseAllTabs(); |
1202 EXPECT_TRUE(tabstrip.empty()); | 1209 EXPECT_TRUE(tabstrip.empty()); |
1203 } | 1210 } |
1204 | 1211 |
1205 // Added for http://b/issue?id=958960 | 1212 // Added for http://b/issue?id=958960 |
1206 TEST_F(TabStripModelTest, AppendContentsReselectionTest) { | 1213 TEST_F(TabStripModelTest, AppendContentsReselectionTest) { |
1207 TabContents fake_destinations_tab(profile(), NULL, 0, NULL, NULL); | 1214 TabContents* fake_destinations_tab = |
1208 TabStripDummyDelegate delegate(&fake_destinations_tab); | 1215 new TabContents(profile(), NULL, 0, NULL, NULL); |
| 1216 TabContentsWrapper wrapper(fake_destinations_tab); |
| 1217 TabStripDummyDelegate delegate(&wrapper); |
1209 TabStripModel tabstrip(&delegate, profile()); | 1218 TabStripModel tabstrip(&delegate, profile()); |
1210 EXPECT_TRUE(tabstrip.empty()); | 1219 EXPECT_TRUE(tabstrip.empty()); |
1211 | 1220 |
1212 // Open the Home Page | 1221 // Open the Home Page |
1213 TabContents* homepage_contents = CreateTabContents(); | 1222 TabContentsWrapper* homepage_contents = CreateTabContents(); |
1214 tabstrip.AddTabContents( | 1223 tabstrip.AddTabContents( |
1215 homepage_contents, -1, PageTransition::AUTO_BOOKMARK, | 1224 homepage_contents, -1, PageTransition::AUTO_BOOKMARK, |
1216 TabStripModel::ADD_SELECTED); | 1225 TabStripModel::ADD_SELECTED); |
1217 | 1226 |
1218 // Open some other tab, by user typing. | 1227 // Open some other tab, by user typing. |
1219 TabContents* typed_page_contents = CreateTabContents(); | 1228 TabContentsWrapper* typed_page_contents = CreateTabContents(); |
1220 tabstrip.AddTabContents( | 1229 tabstrip.AddTabContents( |
1221 typed_page_contents, -1, PageTransition::TYPED, | 1230 typed_page_contents, -1, PageTransition::TYPED, |
1222 TabStripModel::ADD_NONE); | 1231 TabStripModel::ADD_NONE); |
1223 | 1232 |
1224 // The selected tab should still be the first. | 1233 // The selected tab should still be the first. |
1225 EXPECT_EQ(0, tabstrip.selected_index()); | 1234 EXPECT_EQ(0, tabstrip.selected_index()); |
1226 | 1235 |
1227 // Now simulate a link click that opens a new tab (by virtue of target=_blank) | 1236 // Now simulate a link click that opens a new tab (by virtue of target=_blank) |
1228 // and make sure the right tab gets selected when the new tab is closed. | 1237 // and make sure the right tab gets selected when the new tab is closed. |
1229 TabContents* target_blank_contents = CreateTabContents(); | 1238 TabContentsWrapper* target_blank_contents = CreateTabContents(); |
1230 tabstrip.AppendTabContents(target_blank_contents, true); | 1239 tabstrip.AppendTabContents(target_blank_contents, true); |
1231 EXPECT_EQ(2, tabstrip.selected_index()); | 1240 EXPECT_EQ(2, tabstrip.selected_index()); |
1232 tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE); | 1241 tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE); |
1233 EXPECT_EQ(0, tabstrip.selected_index()); | 1242 EXPECT_EQ(0, tabstrip.selected_index()); |
1234 | 1243 |
1235 // clean up after ourselves | 1244 // clean up after ourselves |
1236 tabstrip.CloseAllTabs(); | 1245 tabstrip.CloseAllTabs(); |
1237 } | 1246 } |
1238 | 1247 |
1239 // Added for http://b/issue?id=1027661 | 1248 // Added for http://b/issue?id=1027661 |
1240 TEST_F(TabStripModelTest, ReselectionConsidersChildrenTest) { | 1249 TEST_F(TabStripModelTest, ReselectionConsidersChildrenTest) { |
1241 TabStripDummyDelegate delegate(NULL); | 1250 TabStripDummyDelegate delegate(NULL); |
1242 TabStripModel strip(&delegate, profile()); | 1251 TabStripModel strip(&delegate, profile()); |
1243 | 1252 |
1244 // Open page A | 1253 // Open page A |
1245 TabContents* page_a_contents = CreateTabContents(); | 1254 TabContentsWrapper* page_a_contents = CreateTabContents(); |
1246 strip.AddTabContents( | 1255 strip.AddTabContents( |
1247 page_a_contents, -1, PageTransition::AUTO_BOOKMARK, | 1256 page_a_contents, -1, PageTransition::AUTO_BOOKMARK, |
1248 TabStripModel::ADD_SELECTED); | 1257 TabStripModel::ADD_SELECTED); |
1249 | 1258 |
1250 // Simulate middle click to open page A.A and A.B | 1259 // Simulate middle click to open page A.A and A.B |
1251 TabContents* page_a_a_contents = CreateTabContents(); | 1260 TabContentsWrapper* page_a_a_contents = CreateTabContents(); |
1252 strip.AddTabContents(page_a_a_contents, -1, PageTransition::LINK, | 1261 strip.AddTabContents(page_a_a_contents, -1, PageTransition::LINK, |
1253 TabStripModel::ADD_NONE); | 1262 TabStripModel::ADD_NONE); |
1254 TabContents* page_a_b_contents = CreateTabContents(); | 1263 TabContentsWrapper* page_a_b_contents = CreateTabContents(); |
1255 strip.AddTabContents(page_a_b_contents, -1, PageTransition::LINK, | 1264 strip.AddTabContents(page_a_b_contents, -1, PageTransition::LINK, |
1256 TabStripModel::ADD_NONE); | 1265 TabStripModel::ADD_NONE); |
1257 | 1266 |
1258 // Select page A.A | 1267 // Select page A.A |
1259 strip.SelectTabContentsAt(1, true); | 1268 strip.SelectTabContentsAt(1, true); |
1260 EXPECT_EQ(page_a_a_contents, strip.GetSelectedTabContents()); | 1269 EXPECT_EQ(page_a_a_contents, strip.GetSelectedTabContents()); |
1261 | 1270 |
1262 // Simulate a middle click to open page A.A.A | 1271 // Simulate a middle click to open page A.A.A |
1263 TabContents* page_a_a_a_contents = CreateTabContents(); | 1272 TabContentsWrapper* page_a_a_a_contents = CreateTabContents(); |
1264 strip.AddTabContents(page_a_a_a_contents, -1, PageTransition::LINK, | 1273 strip.AddTabContents(page_a_a_a_contents, -1, PageTransition::LINK, |
1265 TabStripModel::ADD_NONE); | 1274 TabStripModel::ADD_NONE); |
1266 | 1275 |
1267 EXPECT_EQ(page_a_a_a_contents, strip.GetTabContentsAt(2)); | 1276 EXPECT_EQ(page_a_a_a_contents, strip.GetTabContentsAt(2)); |
1268 | 1277 |
1269 // Close page A.A | 1278 // Close page A.A |
1270 strip.CloseTabContentsAt(strip.selected_index(), TabStripModel::CLOSE_NONE); | 1279 strip.CloseTabContentsAt(strip.selected_index(), TabStripModel::CLOSE_NONE); |
1271 | 1280 |
1272 // Page A.A.A should be selected, NOT A.B | 1281 // Page A.A.A should be selected, NOT A.B |
1273 EXPECT_EQ(page_a_a_a_contents, strip.GetSelectedTabContents()); | 1282 EXPECT_EQ(page_a_a_a_contents, strip.GetSelectedTabContents()); |
(...skipping 12 matching lines...) Expand all Loading... |
1286 | 1295 |
1287 // Clean up. | 1296 // Clean up. |
1288 strip.CloseAllTabs(); | 1297 strip.CloseAllTabs(); |
1289 } | 1298 } |
1290 | 1299 |
1291 TEST_F(TabStripModelTest, AddTabContents_NewTabAtEndOfStripInheritsGroup) { | 1300 TEST_F(TabStripModelTest, AddTabContents_NewTabAtEndOfStripInheritsGroup) { |
1292 TabStripDummyDelegate delegate(NULL); | 1301 TabStripDummyDelegate delegate(NULL); |
1293 TabStripModel strip(&delegate, profile()); | 1302 TabStripModel strip(&delegate, profile()); |
1294 | 1303 |
1295 // Open page A | 1304 // Open page A |
1296 TabContents* page_a_contents = CreateTabContents(); | 1305 TabContentsWrapper* page_a_contents = CreateTabContents(); |
1297 strip.AddTabContents(page_a_contents, -1, PageTransition::START_PAGE, | 1306 strip.AddTabContents(page_a_contents, -1, PageTransition::START_PAGE, |
1298 TabStripModel::ADD_SELECTED); | 1307 TabStripModel::ADD_SELECTED); |
1299 | 1308 |
1300 // Open pages B, C and D in the background from links on page A... | 1309 // Open pages B, C and D in the background from links on page A... |
1301 TabContents* page_b_contents = CreateTabContents(); | 1310 TabContentsWrapper* page_b_contents = CreateTabContents(); |
1302 TabContents* page_c_contents = CreateTabContents(); | 1311 TabContentsWrapper* page_c_contents = CreateTabContents(); |
1303 TabContents* page_d_contents = CreateTabContents(); | 1312 TabContentsWrapper* page_d_contents = CreateTabContents(); |
1304 strip.AddTabContents(page_b_contents, -1, PageTransition::LINK, | 1313 strip.AddTabContents(page_b_contents, -1, PageTransition::LINK, |
1305 TabStripModel::ADD_NONE); | 1314 TabStripModel::ADD_NONE); |
1306 strip.AddTabContents(page_c_contents, -1, PageTransition::LINK, | 1315 strip.AddTabContents(page_c_contents, -1, PageTransition::LINK, |
1307 TabStripModel::ADD_NONE); | 1316 TabStripModel::ADD_NONE); |
1308 strip.AddTabContents(page_d_contents, -1, PageTransition::LINK, | 1317 strip.AddTabContents(page_d_contents, -1, PageTransition::LINK, |
1309 TabStripModel::ADD_NONE); | 1318 TabStripModel::ADD_NONE); |
1310 | 1319 |
1311 // Switch to page B's tab. | 1320 // Switch to page B's tab. |
1312 strip.SelectTabContentsAt(1, true); | 1321 strip.SelectTabContentsAt(1, true); |
1313 | 1322 |
1314 // Open a New Tab at the end of the strip (simulate Ctrl+T) | 1323 // Open a New Tab at the end of the strip (simulate Ctrl+T) |
1315 TabContents* new_tab_contents = CreateTabContents(); | 1324 TabContentsWrapper* new_tab_contents = CreateTabContents(); |
1316 strip.AddTabContents(new_tab_contents, -1, PageTransition::TYPED, | 1325 strip.AddTabContents(new_tab_contents, -1, PageTransition::TYPED, |
1317 TabStripModel::ADD_SELECTED); | 1326 TabStripModel::ADD_SELECTED); |
1318 | 1327 |
1319 EXPECT_EQ(4, strip.GetIndexOfTabContents(new_tab_contents)); | 1328 EXPECT_EQ(4, strip.GetIndexOfTabContents(new_tab_contents)); |
1320 EXPECT_EQ(4, strip.selected_index()); | 1329 EXPECT_EQ(4, strip.selected_index()); |
1321 | 1330 |
1322 // Close the New Tab that was just opened. We should be returned to page B's | 1331 // Close the New Tab that was just opened. We should be returned to page B's |
1323 // Tab... | 1332 // Tab... |
1324 strip.CloseTabContentsAt(4, TabStripModel::CLOSE_NONE); | 1333 strip.CloseTabContentsAt(4, TabStripModel::CLOSE_NONE); |
1325 | 1334 |
1326 EXPECT_EQ(1, strip.selected_index()); | 1335 EXPECT_EQ(1, strip.selected_index()); |
1327 | 1336 |
1328 // Open a non-New Tab tab at the end of the strip, with a TYPED transition. | 1337 // Open a non-New Tab tab at the end of the strip, with a TYPED transition. |
1329 // This is like typing a URL in the address bar and pressing Alt+Enter. The | 1338 // This is like typing a URL in the address bar and pressing Alt+Enter. The |
1330 // behavior should be the same as above. | 1339 // behavior should be the same as above. |
1331 TabContents* page_e_contents = CreateTabContents(); | 1340 TabContentsWrapper* page_e_contents = CreateTabContents(); |
1332 strip.AddTabContents(page_e_contents, -1, PageTransition::TYPED, | 1341 strip.AddTabContents(page_e_contents, -1, PageTransition::TYPED, |
1333 TabStripModel::ADD_SELECTED); | 1342 TabStripModel::ADD_SELECTED); |
1334 | 1343 |
1335 EXPECT_EQ(4, strip.GetIndexOfTabContents(page_e_contents)); | 1344 EXPECT_EQ(4, strip.GetIndexOfTabContents(page_e_contents)); |
1336 EXPECT_EQ(4, strip.selected_index()); | 1345 EXPECT_EQ(4, strip.selected_index()); |
1337 | 1346 |
1338 // Close the Tab. Selection should shift back to page B's Tab. | 1347 // Close the Tab. Selection should shift back to page B's Tab. |
1339 strip.CloseTabContentsAt(4, TabStripModel::CLOSE_NONE); | 1348 strip.CloseTabContentsAt(4, TabStripModel::CLOSE_NONE); |
1340 | 1349 |
1341 EXPECT_EQ(1, strip.selected_index()); | 1350 EXPECT_EQ(1, strip.selected_index()); |
1342 | 1351 |
1343 // Open a non-New Tab tab at the end of the strip, with some other | 1352 // Open a non-New Tab tab at the end of the strip, with some other |
1344 // transition. This is like right clicking on a bookmark and choosing "Open | 1353 // transition. This is like right clicking on a bookmark and choosing "Open |
1345 // in New Tab". No opener relationship should be preserved between this Tab | 1354 // in New Tab". No opener relationship should be preserved between this Tab |
1346 // and the one that was active when the gesture was performed. | 1355 // and the one that was active when the gesture was performed. |
1347 TabContents* page_f_contents = CreateTabContents(); | 1356 TabContentsWrapper* page_f_contents = CreateTabContents(); |
1348 strip.AddTabContents(page_f_contents, -1, PageTransition::AUTO_BOOKMARK, | 1357 strip.AddTabContents(page_f_contents, -1, PageTransition::AUTO_BOOKMARK, |
1349 TabStripModel::ADD_SELECTED); | 1358 TabStripModel::ADD_SELECTED); |
1350 | 1359 |
1351 EXPECT_EQ(4, strip.GetIndexOfTabContents(page_f_contents)); | 1360 EXPECT_EQ(4, strip.GetIndexOfTabContents(page_f_contents)); |
1352 EXPECT_EQ(4, strip.selected_index()); | 1361 EXPECT_EQ(4, strip.selected_index()); |
1353 | 1362 |
1354 // Close the Tab. The next-adjacent should be selected. | 1363 // Close the Tab. The next-adjacent should be selected. |
1355 strip.CloseTabContentsAt(4, TabStripModel::CLOSE_NONE); | 1364 strip.CloseTabContentsAt(4, TabStripModel::CLOSE_NONE); |
1356 | 1365 |
1357 EXPECT_EQ(3, strip.selected_index()); | 1366 EXPECT_EQ(3, strip.selected_index()); |
1358 | 1367 |
1359 // Clean up. | 1368 // Clean up. |
1360 strip.CloseAllTabs(); | 1369 strip.CloseAllTabs(); |
1361 } | 1370 } |
1362 | 1371 |
1363 // A test of navigations in a tab that is part of a group of opened from some | 1372 // A test of navigations in a tab that is part of a group of opened from some |
1364 // parent tab. If the navigations are link clicks, the group relationship of | 1373 // parent tab. If the navigations are link clicks, the group relationship of |
1365 // the tab to its parent are preserved. If they are of any other type, they are | 1374 // the tab to its parent are preserved. If they are of any other type, they are |
1366 // not preserved. | 1375 // not preserved. |
1367 TEST_F(TabStripModelTest, NavigationForgetsOpeners) { | 1376 TEST_F(TabStripModelTest, NavigationForgetsOpeners) { |
1368 TabStripDummyDelegate delegate(NULL); | 1377 TabStripDummyDelegate delegate(NULL); |
1369 TabStripModel strip(&delegate, profile()); | 1378 TabStripModel strip(&delegate, profile()); |
1370 | 1379 |
1371 // Open page A | 1380 // Open page A |
1372 TabContents* page_a_contents = CreateTabContents(); | 1381 TabContentsWrapper* page_a_contents = CreateTabContents(); |
1373 strip.AddTabContents(page_a_contents, -1, PageTransition::START_PAGE, | 1382 strip.AddTabContents(page_a_contents, -1, PageTransition::START_PAGE, |
1374 TabStripModel::ADD_SELECTED); | 1383 TabStripModel::ADD_SELECTED); |
1375 | 1384 |
1376 // Open pages B, C and D in the background from links on page A... | 1385 // Open pages B, C and D in the background from links on page A... |
1377 TabContents* page_b_contents = CreateTabContents(); | 1386 TabContentsWrapper* page_b_contents = CreateTabContents(); |
1378 TabContents* page_c_contents = CreateTabContents(); | 1387 TabContentsWrapper* page_c_contents = CreateTabContents(); |
1379 TabContents* page_d_contents = CreateTabContents(); | 1388 TabContentsWrapper* page_d_contents = CreateTabContents(); |
1380 strip.AddTabContents(page_b_contents, -1, PageTransition::LINK, | 1389 strip.AddTabContents(page_b_contents, -1, PageTransition::LINK, |
1381 TabStripModel::ADD_NONE); | 1390 TabStripModel::ADD_NONE); |
1382 strip.AddTabContents(page_c_contents, -1, PageTransition::LINK, | 1391 strip.AddTabContents(page_c_contents, -1, PageTransition::LINK, |
1383 TabStripModel::ADD_NONE); | 1392 TabStripModel::ADD_NONE); |
1384 strip.AddTabContents(page_d_contents, -1, PageTransition::LINK, | 1393 strip.AddTabContents(page_d_contents, -1, PageTransition::LINK, |
1385 TabStripModel::ADD_NONE); | 1394 TabStripModel::ADD_NONE); |
1386 | 1395 |
1387 // Open page E in a different opener group from page A. | 1396 // Open page E in a different opener group from page A. |
1388 TabContents* page_e_contents = CreateTabContents(); | 1397 TabContentsWrapper* page_e_contents = CreateTabContents(); |
1389 strip.AddTabContents(page_e_contents, -1, PageTransition::START_PAGE, | 1398 strip.AddTabContents(page_e_contents, -1, PageTransition::START_PAGE, |
1390 TabStripModel::ADD_NONE); | 1399 TabStripModel::ADD_NONE); |
1391 | 1400 |
1392 // Tell the TabStripModel that we are navigating page D via a link click. | 1401 // Tell the TabStripModel that we are navigating page D via a link click. |
1393 strip.SelectTabContentsAt(3, true); | 1402 strip.SelectTabContentsAt(3, true); |
1394 strip.TabNavigating(page_d_contents, PageTransition::LINK); | 1403 strip.TabNavigating(page_d_contents, PageTransition::LINK); |
1395 | 1404 |
1396 // Close page D, page C should be selected. (part of same group). | 1405 // Close page D, page C should be selected. (part of same group). |
1397 strip.CloseTabContentsAt(3, TabStripModel::CLOSE_NONE); | 1406 strip.CloseTabContentsAt(3, TabStripModel::CLOSE_NONE); |
1398 EXPECT_EQ(2, strip.selected_index()); | 1407 EXPECT_EQ(2, strip.selected_index()); |
(...skipping 12 matching lines...) Expand all Loading... |
1411 // A test that the forgetting behavior tested in NavigationForgetsOpeners above | 1420 // A test that the forgetting behavior tested in NavigationForgetsOpeners above |
1412 // doesn't cause the opener relationship for a New Tab opened at the end of the | 1421 // doesn't cause the opener relationship for a New Tab opened at the end of the |
1413 // TabStrip to be reset (Test 1 below), unless another any other tab is | 1422 // TabStrip to be reset (Test 1 below), unless another any other tab is |
1414 // seelcted (Test 2 below). | 1423 // seelcted (Test 2 below). |
1415 TEST_F(TabStripModelTest, NavigationForgettingDoesntAffectNewTab) { | 1424 TEST_F(TabStripModelTest, NavigationForgettingDoesntAffectNewTab) { |
1416 TabStripDummyDelegate delegate(NULL); | 1425 TabStripDummyDelegate delegate(NULL); |
1417 TabStripModel strip(&delegate, profile()); | 1426 TabStripModel strip(&delegate, profile()); |
1418 | 1427 |
1419 // Open a tab and several tabs from it, then select one of the tabs that was | 1428 // Open a tab and several tabs from it, then select one of the tabs that was |
1420 // opened. | 1429 // opened. |
1421 TabContents* page_a_contents = CreateTabContents(); | 1430 TabContentsWrapper* page_a_contents = CreateTabContents(); |
1422 strip.AddTabContents(page_a_contents, -1, PageTransition::START_PAGE, | 1431 strip.AddTabContents(page_a_contents, -1, PageTransition::START_PAGE, |
1423 TabStripModel::ADD_SELECTED); | 1432 TabStripModel::ADD_SELECTED); |
1424 | 1433 |
1425 TabContents* page_b_contents = CreateTabContents(); | 1434 TabContentsWrapper* page_b_contents = CreateTabContents(); |
1426 TabContents* page_c_contents = CreateTabContents(); | 1435 TabContentsWrapper* page_c_contents = CreateTabContents(); |
1427 TabContents* page_d_contents = CreateTabContents(); | 1436 TabContentsWrapper* page_d_contents = CreateTabContents(); |
1428 strip.AddTabContents(page_b_contents, -1, PageTransition::LINK, | 1437 strip.AddTabContents(page_b_contents, -1, PageTransition::LINK, |
1429 TabStripModel::ADD_NONE); | 1438 TabStripModel::ADD_NONE); |
1430 strip.AddTabContents(page_c_contents, -1, PageTransition::LINK, | 1439 strip.AddTabContents(page_c_contents, -1, PageTransition::LINK, |
1431 TabStripModel::ADD_NONE); | 1440 TabStripModel::ADD_NONE); |
1432 strip.AddTabContents(page_d_contents, -1, PageTransition::LINK, | 1441 strip.AddTabContents(page_d_contents, -1, PageTransition::LINK, |
1433 TabStripModel::ADD_NONE); | 1442 TabStripModel::ADD_NONE); |
1434 | 1443 |
1435 strip.SelectTabContentsAt(2, true); | 1444 strip.SelectTabContentsAt(2, true); |
1436 | 1445 |
1437 // TEST 1: If the user is in a group of tabs and opens a new tab at the end | 1446 // TEST 1: If the user is in a group of tabs and opens a new tab at the end |
1438 // of the strip, closing that new tab will select the tab that they were | 1447 // of the strip, closing that new tab will select the tab that they were |
1439 // last on. | 1448 // last on. |
1440 | 1449 |
1441 // Now simulate opening a new tab at the end of the TabStrip. | 1450 // Now simulate opening a new tab at the end of the TabStrip. |
1442 TabContents* new_tab_contents1 = CreateTabContents(); | 1451 TabContentsWrapper* new_tab_contents1 = CreateTabContents(); |
1443 strip.AddTabContents(new_tab_contents1, -1, PageTransition::TYPED, | 1452 strip.AddTabContents(new_tab_contents1, -1, PageTransition::TYPED, |
1444 TabStripModel::ADD_SELECTED); | 1453 TabStripModel::ADD_SELECTED); |
1445 | 1454 |
1446 // At this point, if we close this tab the last selected one should be | 1455 // At this point, if we close this tab the last selected one should be |
1447 // re-selected. | 1456 // re-selected. |
1448 strip.CloseTabContentsAt(strip.count() - 1, TabStripModel::CLOSE_NONE); | 1457 strip.CloseTabContentsAt(strip.count() - 1, TabStripModel::CLOSE_NONE); |
1449 EXPECT_EQ(page_c_contents, strip.GetTabContentsAt(strip.selected_index())); | 1458 EXPECT_EQ(page_c_contents, strip.GetTabContentsAt(strip.selected_index())); |
1450 | 1459 |
1451 // TEST 2: If the user is in a group of tabs and opens a new tab at the end | 1460 // TEST 2: If the user is in a group of tabs and opens a new tab at the end |
1452 // of the strip, selecting any other tab in the strip will cause that new | 1461 // of the strip, selecting any other tab in the strip will cause that new |
1453 // tab's opener relationship to be forgotten. | 1462 // tab's opener relationship to be forgotten. |
1454 | 1463 |
1455 // Open a new tab again. | 1464 // Open a new tab again. |
1456 TabContents* new_tab_contents2 = CreateTabContents(); | 1465 TabContentsWrapper* new_tab_contents2 = CreateTabContents(); |
1457 strip.AddTabContents(new_tab_contents2, -1, PageTransition::TYPED, | 1466 strip.AddTabContents(new_tab_contents2, -1, PageTransition::TYPED, |
1458 TabStripModel::ADD_SELECTED); | 1467 TabStripModel::ADD_SELECTED); |
1459 | 1468 |
1460 // Now select the first tab. | 1469 // Now select the first tab. |
1461 strip.SelectTabContentsAt(0, true); | 1470 strip.SelectTabContentsAt(0, true); |
1462 | 1471 |
1463 // Now select the last tab. | 1472 // Now select the last tab. |
1464 strip.SelectTabContentsAt(strip.count() - 1, true); | 1473 strip.SelectTabContentsAt(strip.count() - 1, true); |
1465 | 1474 |
1466 // Now close the last tab. The next adjacent should be selected. | 1475 // Now close the last tab. The next adjacent should be selected. |
1467 strip.CloseTabContentsAt(strip.count() - 1, TabStripModel::CLOSE_NONE); | 1476 strip.CloseTabContentsAt(strip.count() - 1, TabStripModel::CLOSE_NONE); |
1468 EXPECT_EQ(page_d_contents, strip.GetTabContentsAt(strip.selected_index())); | 1477 EXPECT_EQ(page_d_contents, strip.GetTabContentsAt(strip.selected_index())); |
1469 | 1478 |
1470 strip.CloseAllTabs(); | 1479 strip.CloseAllTabs(); |
1471 } | 1480 } |
1472 | 1481 |
1473 // Tests that fast shutdown is attempted appropriately. | 1482 // Tests that fast shutdown is attempted appropriately. |
1474 TEST_F(TabStripModelTest, FastShutdown) { | 1483 TEST_F(TabStripModelTest, FastShutdown) { |
1475 TabStripDummyDelegate delegate(NULL); | 1484 TabStripDummyDelegate delegate(NULL); |
1476 TabStripModel tabstrip(&delegate, profile()); | 1485 TabStripModel tabstrip(&delegate, profile()); |
1477 MockTabStripModelObserver observer; | 1486 MockTabStripModelObserver observer; |
1478 tabstrip.AddObserver(&observer); | 1487 tabstrip.AddObserver(&observer); |
1479 | 1488 |
1480 EXPECT_TRUE(tabstrip.empty()); | 1489 EXPECT_TRUE(tabstrip.empty()); |
1481 | 1490 |
1482 // Make sure fast shutdown is attempted when tabs that share a RPH are shut | 1491 // Make sure fast shutdown is attempted when tabs that share a RPH are shut |
1483 // down. | 1492 // down. |
1484 { | 1493 { |
1485 TabContents* contents1 = CreateTabContents(); | 1494 TabContentsWrapper* contents1 = CreateTabContents(); |
1486 TabContents* contents2 = CreateTabContentsWithSharedRPH(contents1); | 1495 TabContentsWrapper* contents2 = |
| 1496 CreateTabContentsWithSharedRPH(contents1->tab_contents()); |
1487 | 1497 |
1488 SetID(contents1, 1); | 1498 SetID(contents1->tab_contents(), 1); |
1489 SetID(contents2, 2); | 1499 SetID(contents2->tab_contents(), 2); |
1490 | 1500 |
1491 tabstrip.AppendTabContents(contents1, true); | 1501 tabstrip.AppendTabContents(contents1, true); |
1492 tabstrip.AppendTabContents(contents2, true); | 1502 tabstrip.AppendTabContents(contents2, true); |
1493 | 1503 |
1494 // Turn on the fake unload listener so the tabs don't actually get shut | 1504 // Turn on the fake unload listener so the tabs don't actually get shut |
1495 // down when we call CloseAllTabs()---we need to be able to check that | 1505 // down when we call CloseAllTabs()---we need to be able to check that |
1496 // fast shutdown was attempted. | 1506 // fast shutdown was attempted. |
1497 delegate.set_run_unload_listener(true); | 1507 delegate.set_run_unload_listener(true); |
1498 tabstrip.CloseAllTabs(); | 1508 tabstrip.CloseAllTabs(); |
1499 // On a mock RPH this checks whether we *attempted* fast shutdown. | 1509 // On a mock RPH this checks whether we *attempted* fast shutdown. |
1500 // A real RPH would reject our attempt since there is an unload handler. | 1510 // A real RPH would reject our attempt since there is an unload handler. |
1501 EXPECT_TRUE(contents1->GetRenderProcessHost()->fast_shutdown_started()); | 1511 EXPECT_TRUE(contents1->tab_contents()-> |
| 1512 GetRenderProcessHost()->fast_shutdown_started()); |
1502 EXPECT_EQ(2, tabstrip.count()); | 1513 EXPECT_EQ(2, tabstrip.count()); |
1503 | 1514 |
1504 delegate.set_run_unload_listener(false); | 1515 delegate.set_run_unload_listener(false); |
1505 tabstrip.CloseAllTabs(); | 1516 tabstrip.CloseAllTabs(); |
1506 EXPECT_TRUE(tabstrip.empty()); | 1517 EXPECT_TRUE(tabstrip.empty()); |
1507 } | 1518 } |
1508 | 1519 |
1509 // Make sure fast shutdown is not attempted when only some tabs that share a | 1520 // Make sure fast shutdown is not attempted when only some tabs that share a |
1510 // RPH are shut down. | 1521 // RPH are shut down. |
1511 { | 1522 { |
1512 TabContents* contents1 = CreateTabContents(); | 1523 TabContentsWrapper* contents1 = CreateTabContents(); |
1513 TabContents* contents2 = CreateTabContentsWithSharedRPH(contents1); | 1524 TabContentsWrapper* contents2 = |
| 1525 CreateTabContentsWithSharedRPH(contents1->tab_contents()); |
1514 | 1526 |
1515 SetID(contents1, 1); | 1527 SetID(contents1->tab_contents(), 1); |
1516 SetID(contents2, 2); | 1528 SetID(contents2->tab_contents(), 2); |
1517 | 1529 |
1518 tabstrip.AppendTabContents(contents1, true); | 1530 tabstrip.AppendTabContents(contents1, true); |
1519 tabstrip.AppendTabContents(contents2, true); | 1531 tabstrip.AppendTabContents(contents2, true); |
1520 | 1532 |
1521 tabstrip.CloseTabContentsAt(1, TabStripModel::CLOSE_NONE); | 1533 tabstrip.CloseTabContentsAt(1, TabStripModel::CLOSE_NONE); |
1522 EXPECT_FALSE(contents1->GetRenderProcessHost()->fast_shutdown_started()); | 1534 EXPECT_FALSE(contents1->tab_contents()-> |
| 1535 GetRenderProcessHost()->fast_shutdown_started()); |
1523 EXPECT_EQ(1, tabstrip.count()); | 1536 EXPECT_EQ(1, tabstrip.count()); |
1524 | 1537 |
1525 tabstrip.CloseAllTabs(); | 1538 tabstrip.CloseAllTabs(); |
1526 EXPECT_TRUE(tabstrip.empty()); | 1539 EXPECT_TRUE(tabstrip.empty()); |
1527 } | 1540 } |
1528 } | 1541 } |
1529 | 1542 |
1530 // Tests various permutations of apps. | 1543 // Tests various permutations of apps. |
1531 TEST_F(TabStripModelTest, Apps) { | 1544 TEST_F(TabStripModelTest, Apps) { |
1532 TabStripDummyDelegate delegate(NULL); | 1545 TabStripDummyDelegate delegate(NULL); |
1533 TabStripModel tabstrip(&delegate, profile()); | 1546 TabStripModel tabstrip(&delegate, profile()); |
1534 MockTabStripModelObserver observer; | 1547 MockTabStripModelObserver observer; |
1535 tabstrip.AddObserver(&observer); | 1548 tabstrip.AddObserver(&observer); |
1536 | 1549 |
1537 EXPECT_TRUE(tabstrip.empty()); | 1550 EXPECT_TRUE(tabstrip.empty()); |
1538 | 1551 |
1539 typedef MockTabStripModelObserver::State State; | 1552 typedef MockTabStripModelObserver::State State; |
1540 | 1553 |
1541 #if defined(OS_WIN) | 1554 #if defined(OS_WIN) |
1542 FilePath path(FILE_PATH_LITERAL("c:\\foo")); | 1555 FilePath path(FILE_PATH_LITERAL("c:\\foo")); |
1543 #elif defined(OS_POSIX) | 1556 #elif defined(OS_POSIX) |
1544 FilePath path(FILE_PATH_LITERAL("/foo")); | 1557 FilePath path(FILE_PATH_LITERAL("/foo")); |
1545 #endif | 1558 #endif |
1546 scoped_refptr<Extension> extension_app(new Extension(path, | 1559 scoped_refptr<Extension> extension_app(new Extension(path, |
1547 Extension::INVALID)); | 1560 Extension::INVALID)); |
1548 extension_app->launch_web_url_ = "http://www.google.com"; | 1561 extension_app->launch_web_url_ = "http://www.google.com"; |
1549 TabContents* contents1 = CreateTabContents(); | 1562 TabContentsWrapper* contents1 = CreateTabContents(); |
1550 contents1->SetExtensionApp(extension_app); | 1563 contents1->tab_contents()->SetExtensionApp(extension_app); |
1551 TabContents* contents2 = CreateTabContents(); | 1564 TabContentsWrapper* contents2 = CreateTabContents(); |
1552 contents2->SetExtensionApp(extension_app); | 1565 contents2->tab_contents()->SetExtensionApp(extension_app); |
1553 TabContents* contents3 = CreateTabContents(); | 1566 TabContentsWrapper* contents3 = CreateTabContents(); |
1554 | 1567 |
1555 SetID(contents1, 1); | 1568 SetID(contents1->tab_contents(), 1); |
1556 SetID(contents2, 2); | 1569 SetID(contents2->tab_contents(), 2); |
1557 SetID(contents3, 3); | 1570 SetID(contents3->tab_contents(), 3); |
1558 | 1571 |
1559 // Note! The ordering of these tests is important, each subsequent test | 1572 // Note! The ordering of these tests is important, each subsequent test |
1560 // builds on the state established in the previous. This is important if you | 1573 // builds on the state established in the previous. This is important if you |
1561 // ever insert tests rather than append. | 1574 // ever insert tests rather than append. |
1562 | 1575 |
1563 // Initial state, tab3 only and selected. | 1576 // Initial state, tab3 only and selected. |
1564 tabstrip.AppendTabContents(contents3, true); | 1577 tabstrip.AppendTabContents(contents3, true); |
1565 | 1578 |
1566 observer.ClearStates(); | 1579 observer.ClearStates(); |
1567 | 1580 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1657 TEST_F(TabStripModelTest, Pinning) { | 1670 TEST_F(TabStripModelTest, Pinning) { |
1658 TabStripDummyDelegate delegate(NULL); | 1671 TabStripDummyDelegate delegate(NULL); |
1659 TabStripModel tabstrip(&delegate, profile()); | 1672 TabStripModel tabstrip(&delegate, profile()); |
1660 MockTabStripModelObserver observer; | 1673 MockTabStripModelObserver observer; |
1661 tabstrip.AddObserver(&observer); | 1674 tabstrip.AddObserver(&observer); |
1662 | 1675 |
1663 EXPECT_TRUE(tabstrip.empty()); | 1676 EXPECT_TRUE(tabstrip.empty()); |
1664 | 1677 |
1665 typedef MockTabStripModelObserver::State State; | 1678 typedef MockTabStripModelObserver::State State; |
1666 | 1679 |
1667 TabContents* contents1 = CreateTabContents(); | 1680 TabContentsWrapper* contents1 = CreateTabContents(); |
1668 TabContents* contents2 = CreateTabContents(); | 1681 TabContentsWrapper* contents2 = CreateTabContents(); |
1669 TabContents* contents3 = CreateTabContents(); | 1682 TabContentsWrapper* contents3 = CreateTabContents(); |
1670 | 1683 |
1671 SetID(contents1, 1); | 1684 SetID(contents1->tab_contents(), 1); |
1672 SetID(contents2, 2); | 1685 SetID(contents2->tab_contents(), 2); |
1673 SetID(contents3, 3); | 1686 SetID(contents3->tab_contents(), 3); |
1674 | 1687 |
1675 // Note! The ordering of these tests is important, each subsequent test | 1688 // Note! The ordering of these tests is important, each subsequent test |
1676 // builds on the state established in the previous. This is important if you | 1689 // builds on the state established in the previous. This is important if you |
1677 // ever insert tests rather than append. | 1690 // ever insert tests rather than append. |
1678 | 1691 |
1679 // Initial state, three tabs, first selected. | 1692 // Initial state, three tabs, first selected. |
1680 tabstrip.AppendTabContents(contents1, true); | 1693 tabstrip.AppendTabContents(contents1, true); |
1681 tabstrip.AppendTabContents(contents2, false); | 1694 tabstrip.AppendTabContents(contents2, false); |
1682 tabstrip.AppendTabContents(contents3, false); | 1695 tabstrip.AppendTabContents(contents3, false); |
1683 | 1696 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1792 // Pin "3" and "1". | 1805 // Pin "3" and "1". |
1793 { | 1806 { |
1794 tabstrip.SetTabPinned(0, true); | 1807 tabstrip.SetTabPinned(0, true); |
1795 tabstrip.SetTabPinned(1, true); | 1808 tabstrip.SetTabPinned(1, true); |
1796 | 1809 |
1797 EXPECT_EQ("1p 3p 2", GetPinnedState(tabstrip)); | 1810 EXPECT_EQ("1p 3p 2", GetPinnedState(tabstrip)); |
1798 | 1811 |
1799 observer.ClearStates(); | 1812 observer.ClearStates(); |
1800 } | 1813 } |
1801 | 1814 |
1802 TabContents* contents4 = CreateTabContents(); | 1815 TabContentsWrapper* contents4 = CreateTabContents(); |
1803 SetID(contents4, 4); | 1816 SetID(contents4->tab_contents(), 4); |
1804 | 1817 |
1805 // Insert "4" between "1" and "3". As "1" and "4" are pinned, "4" should end | 1818 // Insert "4" between "1" and "3". As "1" and "4" are pinned, "4" should end |
1806 // up after them. | 1819 // up after them. |
1807 { | 1820 { |
1808 tabstrip.InsertTabContentsAt(1, contents4, TabStripModel::ADD_NONE); | 1821 tabstrip.InsertTabContentsAt(1, contents4, TabStripModel::ADD_NONE); |
1809 | 1822 |
1810 ASSERT_EQ(1, observer.GetStateCount()); | 1823 ASSERT_EQ(1, observer.GetStateCount()); |
1811 State state(contents4, 2, MockTabStripModelObserver::INSERT); | 1824 State state(contents4, 2, MockTabStripModelObserver::INSERT); |
1812 EXPECT_TRUE(observer.StateEquals(0, state)); | 1825 EXPECT_TRUE(observer.StateEquals(0, state)); |
1813 | 1826 |
1814 EXPECT_EQ("1p 3p 4 2", GetPinnedState(tabstrip)); | 1827 EXPECT_EQ("1p 3p 4 2", GetPinnedState(tabstrip)); |
1815 } | 1828 } |
1816 | 1829 |
1817 tabstrip.CloseAllTabs(); | 1830 tabstrip.CloseAllTabs(); |
1818 } | 1831 } |
1819 | 1832 |
1820 // Makes sure the TabStripModel calls the right observer methods during a | 1833 // Makes sure the TabStripModel calls the right observer methods during a |
1821 // replace. | 1834 // replace. |
1822 TEST_F(TabStripModelTest, ReplaceSendsSelected) { | 1835 TEST_F(TabStripModelTest, ReplaceSendsSelected) { |
1823 typedef MockTabStripModelObserver::State State; | 1836 typedef MockTabStripModelObserver::State State; |
1824 | 1837 |
1825 TabStripDummyDelegate delegate(NULL); | 1838 TabStripDummyDelegate delegate(NULL); |
1826 TabStripModel strip(&delegate, profile()); | 1839 TabStripModel strip(&delegate, profile()); |
1827 | 1840 |
1828 TabContents* first_contents = CreateTabContents(); | 1841 TabContentsWrapper* first_contents = CreateTabContents(); |
1829 strip.AddTabContents(first_contents, -1, PageTransition::TYPED, | 1842 strip.AddTabContents(first_contents, -1, PageTransition::TYPED, |
1830 TabStripModel::ADD_SELECTED); | 1843 TabStripModel::ADD_SELECTED); |
1831 | 1844 |
1832 MockTabStripModelObserver tabstrip_observer; | 1845 MockTabStripModelObserver tabstrip_observer; |
1833 strip.AddObserver(&tabstrip_observer); | 1846 strip.AddObserver(&tabstrip_observer); |
1834 | 1847 |
1835 TabContents* new_contents = CreateTabContents(); | 1848 TabContentsWrapper* new_contents = CreateTabContents(); |
1836 strip.ReplaceTabContentsAt(0, new_contents); | 1849 strip.ReplaceTabContentsAt(0, new_contents); |
1837 | 1850 |
1838 ASSERT_EQ(2, tabstrip_observer.GetStateCount()); | 1851 ASSERT_EQ(2, tabstrip_observer.GetStateCount()); |
1839 | 1852 |
1840 // First event should be for replaced. | 1853 // First event should be for replaced. |
1841 State state(new_contents, 0, MockTabStripModelObserver::REPLACED); | 1854 State state(new_contents, 0, MockTabStripModelObserver::REPLACED); |
1842 state.src_contents = first_contents; | 1855 state.src_contents = first_contents; |
1843 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state)); | 1856 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state)); |
1844 | 1857 |
1845 // And the second for selected. | 1858 // And the second for selected. |
1846 state = State(new_contents, 0, MockTabStripModelObserver::SELECT); | 1859 state = State(new_contents, 0, MockTabStripModelObserver::SELECT); |
1847 state.src_contents = first_contents; | 1860 state.src_contents = first_contents; |
1848 EXPECT_TRUE(tabstrip_observer.StateEquals(1, state)); | 1861 EXPECT_TRUE(tabstrip_observer.StateEquals(1, state)); |
1849 | 1862 |
1850 // Now add another tab and replace it, making sure we don't get a selected | 1863 // Now add another tab and replace it, making sure we don't get a selected |
1851 // event this time. | 1864 // event this time. |
1852 TabContents* third_contents = CreateTabContents(); | 1865 TabContentsWrapper* third_contents = CreateTabContents(); |
1853 strip.AddTabContents(third_contents, 1, PageTransition::TYPED, | 1866 strip.AddTabContents(third_contents, 1, PageTransition::TYPED, |
1854 TabStripModel::ADD_NONE); | 1867 TabStripModel::ADD_NONE); |
1855 | 1868 |
1856 tabstrip_observer.ClearStates(); | 1869 tabstrip_observer.ClearStates(); |
1857 | 1870 |
1858 // And replace it. | 1871 // And replace it. |
1859 new_contents = CreateTabContents(); | 1872 new_contents = CreateTabContents(); |
1860 strip.ReplaceTabContentsAt(1, new_contents); | 1873 strip.ReplaceTabContentsAt(1, new_contents); |
1861 | 1874 |
1862 ASSERT_EQ(1, tabstrip_observer.GetStateCount()); | 1875 ASSERT_EQ(1, tabstrip_observer.GetStateCount()); |
1863 | 1876 |
1864 state = State(new_contents, 1, MockTabStripModelObserver::REPLACED); | 1877 state = State(new_contents, 1, MockTabStripModelObserver::REPLACED); |
1865 state.src_contents = third_contents; | 1878 state.src_contents = third_contents; |
1866 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state)); | 1879 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state)); |
1867 | 1880 |
1868 strip.CloseAllTabs(); | 1881 strip.CloseAllTabs(); |
1869 } | 1882 } |
1870 | 1883 |
1871 // Makes sure TabStripModel handles the case of deleting a tab while removing | 1884 // Makes sure TabStripModel handles the case of deleting a tab while removing |
1872 // another tab. | 1885 // another tab. |
1873 TEST_F(TabStripModelTest, DeleteFromDestroy) { | 1886 TEST_F(TabStripModelTest, DeleteFromDestroy) { |
1874 TabStripDummyDelegate delegate(NULL); | 1887 TabStripDummyDelegate delegate(NULL); |
1875 TabStripModel strip(&delegate, profile()); | 1888 TabStripModel strip(&delegate, profile()); |
1876 TabContents* contents1 = CreateTabContents(); | 1889 TabContentsWrapper* contents1 = CreateTabContents(); |
1877 TabContents* contents2 = CreateTabContents(); | 1890 TabContentsWrapper* contents2 = CreateTabContents(); |
1878 strip.AppendTabContents(contents1, true); | 1891 strip.AppendTabContents(contents1, true); |
1879 strip.AppendTabContents(contents2, true); | 1892 strip.AppendTabContents(contents2, true); |
1880 // DeleteTabContentsOnDestroyedObserver deletes contents1 when contents2 sends | 1893 // DeleteTabContentsOnDestroyedObserver deletes contents1 when contents2 sends |
1881 // out notification that it is being destroyed. | 1894 // out notification that it is being destroyed. |
1882 DeleteTabContentsOnDestroyedObserver observer(contents2, contents1); | 1895 DeleteTabContentsOnDestroyedObserver observer(contents2, contents1); |
1883 strip.CloseAllTabs(); | 1896 strip.CloseAllTabs(); |
1884 } | 1897 } |
OLD | NEW |