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

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

Issue 10537062: TabContentsWrapper -> TabContents, part 13. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fiz Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/ui/tabs/tab_strip_model.h" 5 #include "chrome/browser/ui/tabs/tab_strip_model.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/property_bag.h" 14 #include "base/property_bag.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
17 #include "base/string_split.h" 17 #include "base/string_split.h"
18 #include "base/string_util.h" 18 #include "base/string_util.h"
19 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
20 #include "chrome/browser/defaults.h" 20 #include "chrome/browser/defaults.h"
21 #include "chrome/browser/extensions/extension_tab_helper.h" 21 #include "chrome/browser/extensions/extension_tab_helper.h"
22 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 24 #include "chrome/browser/ui/tab_contents/tab_contents.h"
25 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" 25 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
26 #include "chrome/browser/ui/tabs/tab_strip_model_order_controller.h" 26 #include "chrome/browser/ui/tabs/tab_strip_model_order_controller.h"
27 #include "chrome/browser/ui/tabs/test_tab_strip_model_delegate.h" 27 #include "chrome/browser/ui/tabs/test_tab_strip_model_delegate.h"
28 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 28 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
29 #include "chrome/common/chrome_notification_types.h" 29 #include "chrome/common/chrome_notification_types.h"
30 #include "chrome/common/extensions/extension.h" 30 #include "chrome/common/extensions/extension.h"
31 #include "chrome/common/url_constants.h" 31 #include "chrome/common/url_constants.h"
32 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 32 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
33 #include "chrome/test/base/testing_profile.h" 33 #include "chrome/test/base/testing_profile.h"
34 #include "content/public/browser/navigation_controller.h" 34 #include "content/public/browser/navigation_controller.h"
35 #include "content/public/browser/navigation_entry.h" 35 #include "content/public/browser/navigation_entry.h"
36 #include "content/public/browser/notification_details.h" 36 #include "content/public/browser/notification_details.h"
37 #include "content/public/browser/notification_registrar.h" 37 #include "content/public/browser/notification_registrar.h"
38 #include "content/public/browser/notification_source.h" 38 #include "content/public/browser/notification_source.h"
39 #include "content/public/browser/notification_types.h" 39 #include "content/public/browser/notification_types.h"
40 #include "content/public/browser/render_process_host.h" 40 #include "content/public/browser/render_process_host.h"
41 #include "content/public/browser/web_contents.h" 41 #include "content/public/browser/web_contents.h"
42 #include "content/public/test/test_browser_thread.h" 42 #include "content/public/test/test_browser_thread.h"
43 #include "testing/gtest/include/gtest/gtest.h" 43 #include "testing/gtest/include/gtest/gtest.h"
44 44
45 using content::BrowserThread; 45 using content::BrowserThread;
46 using content::NavigationController; 46 using content::NavigationController;
47 using content::SiteInstance; 47 using content::SiteInstance;
48 using content::WebContents; 48 using content::WebContents;
49 using extensions::Extension; 49 using extensions::Extension;
50 50
51 namespace { 51 namespace {
52 52
53 // Class used to delete a TabContentsWrapper when another TabContentsWrapper is 53 // Class used to delete a TabContents when another TabContents is destroyed.
54 // destroyed.
55 class DeleteTabContentsOnDestroyedObserver 54 class DeleteTabContentsOnDestroyedObserver
56 : public content::NotificationObserver { 55 : public content::NotificationObserver {
57 public: 56 public:
58 DeleteTabContentsOnDestroyedObserver(TabContentsWrapper* source, 57 DeleteTabContentsOnDestroyedObserver(TabContents* source,
59 TabContentsWrapper* tab_to_delete) 58 TabContents* tab_to_delete)
60 : source_(source), 59 : source_(source),
61 tab_to_delete_(tab_to_delete) { 60 tab_to_delete_(tab_to_delete) {
62 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, 61 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED,
63 content::Source<TabContentsWrapper>(source)); 62 content::Source<TabContents>(source));
64 } 63 }
65 64
66 virtual void Observe(int type, 65 virtual void Observe(int type,
67 const content::NotificationSource& source, 66 const content::NotificationSource& source,
68 const content::NotificationDetails& details) { 67 const content::NotificationDetails& details) {
69 TabContentsWrapper* tab_to_delete = tab_to_delete_; 68 TabContents* tab_to_delete = tab_to_delete_;
70 tab_to_delete_ = NULL; 69 tab_to_delete_ = NULL;
71 delete tab_to_delete; 70 delete tab_to_delete;
72 } 71 }
73 72
74 private: 73 private:
75 TabContentsWrapper* source_; 74 TabContents* source_;
76 TabContentsWrapper* tab_to_delete_; 75 TabContents* tab_to_delete_;
77 content::NotificationRegistrar registrar_; 76 content::NotificationRegistrar registrar_;
78 77
79 DISALLOW_COPY_AND_ASSIGN(DeleteTabContentsOnDestroyedObserver); 78 DISALLOW_COPY_AND_ASSIGN(DeleteTabContentsOnDestroyedObserver);
80 }; 79 };
81 80
82 } // namespace 81 } // namespace
83 82
84 class TabStripDummyDelegate : public TestTabStripModelDelegate { 83 class TabStripDummyDelegate : public TestTabStripModelDelegate {
85 public: 84 public:
86 explicit TabStripDummyDelegate(TabContentsWrapper* dummy) 85 explicit TabStripDummyDelegate(TabContents* dummy)
87 : dummy_contents_(dummy), 86 : dummy_contents_(dummy),
88 can_close_(true), 87 can_close_(true),
89 run_unload_(false) {} 88 run_unload_(false) {}
90 virtual ~TabStripDummyDelegate() {} 89 virtual ~TabStripDummyDelegate() {}
91 90
92 void set_can_close(bool value) { can_close_ = value; } 91 void set_can_close(bool value) { can_close_ = value; }
93 void set_run_unload_listener(bool value) { run_unload_ = value; } 92 void set_run_unload_listener(bool value) { run_unload_ = value; }
94 93
95 // Overridden from TabStripModelDelegate: 94 // Overridden from TabStripModelDelegate:
96 virtual TabContentsWrapper* CreateTabContentsForURL( 95 virtual TabContents* CreateTabContentsForURL(
97 const GURL& url, 96 const GURL& url,
98 const content::Referrer& referrer, 97 const content::Referrer& referrer,
99 Profile* profile, 98 Profile* profile,
100 content::PageTransition transition, 99 content::PageTransition transition,
101 bool defer_load, 100 bool defer_load,
102 SiteInstance* instance) const OVERRIDE { 101 SiteInstance* instance) const OVERRIDE {
103 if (url == GURL(chrome::kChromeUINewTabURL)) 102 if (url == GURL(chrome::kChromeUINewTabURL))
104 return dummy_contents_; 103 return dummy_contents_;
105 return NULL; 104 return NULL;
106 } 105 }
107 virtual bool RunUnloadListenerBeforeClosing( 106 virtual bool RunUnloadListenerBeforeClosing(TabContents* contents) OVERRIDE {
108 TabContentsWrapper* contents) OVERRIDE {
109 return run_unload_; 107 return run_unload_;
110 } 108 }
111 virtual bool CanCloseContents(std::vector<int>* indices) OVERRIDE { 109 virtual bool CanCloseContents(std::vector<int>* indices) OVERRIDE {
112 if (!can_close_) 110 if (!can_close_)
113 indices->clear(); 111 indices->clear();
114 return can_close_; 112 return can_close_;
115 } 113 }
116 114
117 private: 115 private:
118 // A dummy TabContentsWrapper we give to callers that expect us to actually 116 // A dummy TabContents we give to callers that expect us to actually
119 // build a Destinations tab for them. 117 // build a Destinations tab for them.
120 TabContentsWrapper* dummy_contents_; 118 TabContents* dummy_contents_;
121 119
122 // Whether tabs can be closed. 120 // Whether tabs can be closed.
123 bool can_close_; 121 bool can_close_;
124 122
125 // Whether to report that we need to run an unload listener before closing. 123 // Whether to report that we need to run an unload listener before closing.
126 bool run_unload_; 124 bool run_unload_;
127 125
128 DISALLOW_COPY_AND_ASSIGN(TabStripDummyDelegate); 126 DISALLOW_COPY_AND_ASSIGN(TabStripDummyDelegate);
129 }; 127 };
130 128
131 class TabStripModelTest : public ChromeRenderViewHostTestHarness { 129 class TabStripModelTest : public ChromeRenderViewHostTestHarness {
132 public: 130 public:
133 TabStripModelTest() : browser_thread_(BrowserThread::UI, &message_loop_) { 131 TabStripModelTest() : browser_thread_(BrowserThread::UI, &message_loop_) {
134 } 132 }
135 133
136 TabContentsWrapper* CreateTabContents() { 134 TabContents* CreateTabContents() {
137 return Browser::TabContentsFactory( 135 return Browser::TabContentsFactory(
138 profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); 136 profile(), NULL, MSG_ROUTING_NONE, NULL, NULL);
139 } 137 }
140 138
141 TabContentsWrapper* CreateTabContentsWithSharedRPH( 139 TabContents* CreateTabContentsWithSharedRPH(
142 WebContents* web_contents) { 140 WebContents* web_contents) {
143 TabContentsWrapper* retval = Browser::TabContentsFactory(profile(), 141 TabContents* retval = Browser::TabContentsFactory(profile(),
144 web_contents->GetRenderViewHost()->GetSiteInstance(), MSG_ROUTING_NONE, 142 web_contents->GetRenderViewHost()->GetSiteInstance(), MSG_ROUTING_NONE,
145 NULL, NULL); 143 NULL, NULL);
146 EXPECT_EQ(retval->web_contents()->GetRenderProcessHost(), 144 EXPECT_EQ(retval->web_contents()->GetRenderProcessHost(),
147 web_contents->GetRenderProcessHost()); 145 web_contents->GetRenderProcessHost());
148 return retval; 146 return retval;
149 } 147 }
150 148
151 // Forwards a URL "load" request through to our dummy TabContentsWrapper 149 // Forwards a URL "load" request through to our dummy TabContents
152 // implementation. 150 // implementation.
153 void LoadURL(WebContents* con, const std::wstring& url) { 151 void LoadURL(WebContents* con, const std::wstring& url) {
154 controller().LoadURL(GURL(WideToUTF16(url)), content::Referrer(), 152 controller().LoadURL(GURL(WideToUTF16(url)), content::Referrer(),
155 content::PAGE_TRANSITION_LINK, std::string()); 153 content::PAGE_TRANSITION_LINK, std::string());
156 } 154 }
157 155
158 void GoBack(WebContents* contents) { 156 void GoBack(WebContents* contents) {
159 controller().GoBack(); 157 controller().GoBack();
160 } 158 }
161 159
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 result += base::IntToString(indices[i]); 209 result += base::IntToString(indices[i]);
212 } 210 }
213 return result; 211 return result;
214 } 212 }
215 213
216 void PrepareTabstripForSelectionTest(TabStripModel* model, 214 void PrepareTabstripForSelectionTest(TabStripModel* model,
217 int tab_count, 215 int tab_count,
218 int pinned_count, 216 int pinned_count,
219 const std::string& selected_tabs) { 217 const std::string& selected_tabs) {
220 for (int i = 0; i < tab_count; ++i) { 218 for (int i = 0; i < tab_count; ++i) {
221 TabContentsWrapper* contents = CreateTabContents(); 219 TabContents* contents = CreateTabContents();
222 SetID(contents->web_contents(), i); 220 SetID(contents->web_contents(), i);
223 model->AppendTabContents(contents, true); 221 model->AppendTabContents(contents, true);
224 } 222 }
225 for (int i = 0; i < pinned_count; ++i) 223 for (int i = 0; i < pinned_count; ++i)
226 model->SetTabPinned(i, true); 224 model->SetTabPinned(i, true);
227 225
228 TabStripSelectionModel selection_model; 226 TabStripSelectionModel selection_model;
229 std::vector<std::string> selection; 227 std::vector<std::string> selection;
230 base::SplitStringAlongWhitespace(selected_tabs, &selection); 228 base::SplitStringAlongWhitespace(selected_tabs, &selection);
231 for (size_t i = 0; i < selection.size(); ++i) { 229 for (size_t i = 0; i < selection.size(); ++i) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 ACTIVATE, 266 ACTIVATE,
269 DEACTIVATE, 267 DEACTIVATE,
270 SELECT, 268 SELECT,
271 MOVE, 269 MOVE,
272 CHANGE, 270 CHANGE,
273 PINNED, 271 PINNED,
274 REPLACED 272 REPLACED
275 }; 273 };
276 274
277 struct State { 275 struct State {
278 State(TabContentsWrapper* a_dst_contents, 276 State(TabContents* a_dst_contents,
279 int a_dst_index, 277 int a_dst_index,
280 TabStripModelObserverAction a_action) 278 TabStripModelObserverAction a_action)
281 : src_contents(NULL), 279 : src_contents(NULL),
282 dst_contents(a_dst_contents), 280 dst_contents(a_dst_contents),
283 src_index(-1), 281 src_index(-1),
284 dst_index(a_dst_index), 282 dst_index(a_dst_index),
285 user_gesture(false), 283 user_gesture(false),
286 foreground(false), 284 foreground(false),
287 action(a_action) { 285 action(a_action) {
288 } 286 }
289 287
290 TabContentsWrapper* src_contents; 288 TabContents* src_contents;
291 TabContentsWrapper* dst_contents; 289 TabContents* dst_contents;
292 int src_index; 290 int src_index;
293 int dst_index; 291 int dst_index;
294 bool user_gesture; 292 bool user_gesture;
295 bool foreground; 293 bool foreground;
296 TabStripModelObserverAction action; 294 TabStripModelObserverAction action;
297 }; 295 };
298 296
299 int GetStateCount() const { 297 int GetStateCount() const {
300 return static_cast<int>(states_.size()); 298 return static_cast<int>(states_.size());
301 } 299 }
(...skipping 15 matching lines...) Expand all
317 return (s->src_contents == state.src_contents && 315 return (s->src_contents == state.src_contents &&
318 s->dst_contents == state.dst_contents && 316 s->dst_contents == state.dst_contents &&
319 s->src_index == state.src_index && 317 s->src_index == state.src_index &&
320 s->dst_index == state.dst_index && 318 s->dst_index == state.dst_index &&
321 s->user_gesture == state.user_gesture && 319 s->user_gesture == state.user_gesture &&
322 s->foreground == state.foreground && 320 s->foreground == state.foreground &&
323 s->action == state.action); 321 s->action == state.action);
324 } 322 }
325 323
326 // TabStripModelObserver implementation: 324 // TabStripModelObserver implementation:
327 virtual void TabInsertedAt(TabContentsWrapper* contents, 325 virtual void TabInsertedAt(TabContents* contents,
328 int index, 326 int index,
329 bool foreground) { 327 bool foreground) {
330 empty_ = false; 328 empty_ = false;
331 State* s = new State(contents, index, INSERT); 329 State* s = new State(contents, index, INSERT);
332 s->foreground = foreground; 330 s->foreground = foreground;
333 states_.push_back(s); 331 states_.push_back(s);
334 } 332 }
335 virtual void ActiveTabChanged(TabContentsWrapper* old_contents, 333 virtual void ActiveTabChanged(TabContents* old_contents,
336 TabContentsWrapper* new_contents, 334 TabContents* new_contents,
337 int index, 335 int index,
338 bool user_gesture) { 336 bool user_gesture) {
339 State* s = new State(new_contents, index, ACTIVATE); 337 State* s = new State(new_contents, index, ACTIVATE);
340 s->src_contents = old_contents; 338 s->src_contents = old_contents;
341 s->user_gesture = user_gesture; 339 s->user_gesture = user_gesture;
342 states_.push_back(s); 340 states_.push_back(s);
343 } 341 }
344 virtual void TabSelectionChanged(TabStripModel* tab_strip_model, 342 virtual void TabSelectionChanged(TabStripModel* tab_strip_model,
345 const TabStripSelectionModel& old_model) { 343 const TabStripSelectionModel& old_model) {
346 State* s = new State(model()->GetActiveTabContents(), 344 State* s = new State(model()->GetActiveTabContents(),
347 model()->active_index(), 345 model()->active_index(),
348 SELECT); 346 SELECT);
349 s->src_contents = model()->GetTabContentsAt(old_model.active()); 347 s->src_contents = model()->GetTabContentsAt(old_model.active());
350 s->src_index = old_model.active(); 348 s->src_index = old_model.active();
351 states_.push_back(s); 349 states_.push_back(s);
352 } 350 }
353 virtual void TabMoved( 351 virtual void TabMoved(TabContents* contents, int from_index, int to_index) {
354 TabContentsWrapper* contents, int from_index, int to_index) {
355 State* s = new State(contents, to_index, MOVE); 352 State* s = new State(contents, to_index, MOVE);
356 s->src_index = from_index; 353 s->src_index = from_index;
357 states_.push_back(s); 354 states_.push_back(s);
358 } 355 }
359 356
360 virtual void TabClosingAt(TabStripModel* tab_strip_model, 357 virtual void TabClosingAt(TabStripModel* tab_strip_model,
361 TabContentsWrapper* contents, 358 TabContents* contents,
362 int index) { 359 int index) {
363 states_.push_back(new State(contents, index, CLOSE)); 360 states_.push_back(new State(contents, index, CLOSE));
364 } 361 }
365 virtual void TabDetachedAt(TabContentsWrapper* contents, int index) { 362 virtual void TabDetachedAt(TabContents* contents, int index) {
366 states_.push_back(new State(contents, index, DETACH)); 363 states_.push_back(new State(contents, index, DETACH));
367 } 364 }
368 virtual void TabDeactivated(TabContentsWrapper* contents) { 365 virtual void TabDeactivated(TabContents* contents) {
369 states_.push_back(new State(contents, model()->active_index(), DEACTIVATE)); 366 states_.push_back(new State(contents, model()->active_index(), DEACTIVATE));
370 } 367 }
371 virtual void TabChangedAt(TabContentsWrapper* contents, int index, 368 virtual void TabChangedAt(TabContents* contents, int index,
372 TabChangeType change_type) { 369 TabChangeType change_type) {
373 states_.push_back(new State(contents, index, CHANGE)); 370 states_.push_back(new State(contents, index, CHANGE));
374 } 371 }
375 virtual void TabReplacedAt(TabStripModel* tab_strip_model, 372 virtual void TabReplacedAt(TabStripModel* tab_strip_model,
376 TabContentsWrapper* old_contents, 373 TabContents* old_contents,
377 TabContentsWrapper* new_contents, 374 TabContents* new_contents,
378 int index) { 375 int index) {
379 State* s = new State(new_contents, index, REPLACED); 376 State* s = new State(new_contents, index, REPLACED);
380 s ->src_contents = old_contents; 377 s ->src_contents = old_contents;
381 states_.push_back(s); 378 states_.push_back(s);
382 } 379 }
383 virtual void TabPinnedStateChanged(TabContentsWrapper* contents, int index) { 380 virtual void TabPinnedStateChanged(TabContents* contents, int index) {
384 states_.push_back(new State(contents, index, PINNED)); 381 states_.push_back(new State(contents, index, PINNED));
385 } 382 }
386 virtual void TabStripEmpty() { 383 virtual void TabStripEmpty() {
387 empty_ = true; 384 empty_ = true;
388 } 385 }
389 386
390 void ClearStates() { 387 void ClearStates() {
391 STLDeleteContainerPointers(states_.begin(), states_.end()); 388 STLDeleteContainerPointers(states_.begin(), states_.end());
392 states_.clear(); 389 states_.clear();
393 } 390 }
(...skipping 13 matching lines...) Expand all
407 TEST_F(TabStripModelTest, TestBasicAPI) { 404 TEST_F(TabStripModelTest, TestBasicAPI) {
408 TabStripDummyDelegate delegate(NULL); 405 TabStripDummyDelegate delegate(NULL);
409 TabStripModel tabstrip(&delegate, profile()); 406 TabStripModel tabstrip(&delegate, profile());
410 MockTabStripModelObserver observer(&tabstrip); 407 MockTabStripModelObserver observer(&tabstrip);
411 tabstrip.AddObserver(&observer); 408 tabstrip.AddObserver(&observer);
412 409
413 EXPECT_TRUE(tabstrip.empty()); 410 EXPECT_TRUE(tabstrip.empty());
414 411
415 typedef MockTabStripModelObserver::State State; 412 typedef MockTabStripModelObserver::State State;
416 413
417 TabContentsWrapper* contents1 = CreateTabContents(); 414 TabContents* contents1 = CreateTabContents();
418 415
419 // Note! The ordering of these tests is important, each subsequent test 416 // Note! The ordering of these tests is important, each subsequent test
420 // builds on the state established in the previous. This is important if you 417 // builds on the state established in the previous. This is important if you
421 // ever insert tests rather than append. 418 // ever insert tests rather than append.
422 419
423 // Test AppendTabContents, ContainsIndex 420 // Test AppendTabContents, ContainsIndex
424 { 421 {
425 EXPECT_FALSE(tabstrip.ContainsIndex(0)); 422 EXPECT_FALSE(tabstrip.ContainsIndex(0));
426 tabstrip.AppendTabContents(contents1, true); 423 tabstrip.AppendTabContents(contents1, true);
427 EXPECT_TRUE(tabstrip.ContainsIndex(0)); 424 EXPECT_TRUE(tabstrip.ContainsIndex(0));
428 EXPECT_EQ(1, tabstrip.count()); 425 EXPECT_EQ(1, tabstrip.count());
429 EXPECT_EQ(3, observer.GetStateCount()); 426 EXPECT_EQ(3, observer.GetStateCount());
430 State s1(contents1, 0, MockTabStripModelObserver::INSERT); 427 State s1(contents1, 0, MockTabStripModelObserver::INSERT);
431 s1.foreground = true; 428 s1.foreground = true;
432 EXPECT_TRUE(observer.StateEquals(0, s1)); 429 EXPECT_TRUE(observer.StateEquals(0, s1));
433 State s2(contents1, 0, MockTabStripModelObserver::ACTIVATE); 430 State s2(contents1, 0, MockTabStripModelObserver::ACTIVATE);
434 EXPECT_TRUE(observer.StateEquals(1, s2)); 431 EXPECT_TRUE(observer.StateEquals(1, s2));
435 State s3(contents1, 0, MockTabStripModelObserver::SELECT); 432 State s3(contents1, 0, MockTabStripModelObserver::SELECT);
436 s3.src_contents = NULL; 433 s3.src_contents = NULL;
437 s3.src_index = TabStripSelectionModel::kUnselectedIndex; 434 s3.src_index = TabStripSelectionModel::kUnselectedIndex;
438 EXPECT_TRUE(observer.StateEquals(2, s3)); 435 EXPECT_TRUE(observer.StateEquals(2, s3));
439 observer.ClearStates(); 436 observer.ClearStates();
440 } 437 }
441 438
442 // Test InsertTabContentsAt, foreground tab. 439 // Test InsertTabContentsAt, foreground tab.
443 TabContentsWrapper* contents2 = CreateTabContents(); 440 TabContents* contents2 = CreateTabContents();
444 { 441 {
445 tabstrip.InsertTabContentsAt(1, contents2, TabStripModel::ADD_ACTIVE); 442 tabstrip.InsertTabContentsAt(1, contents2, TabStripModel::ADD_ACTIVE);
446 443
447 EXPECT_EQ(2, tabstrip.count()); 444 EXPECT_EQ(2, tabstrip.count());
448 EXPECT_EQ(4, observer.GetStateCount()); 445 EXPECT_EQ(4, observer.GetStateCount());
449 State s1(contents2, 1, MockTabStripModelObserver::INSERT); 446 State s1(contents2, 1, MockTabStripModelObserver::INSERT);
450 s1.foreground = true; 447 s1.foreground = true;
451 EXPECT_TRUE(observer.StateEquals(0, s1)); 448 EXPECT_TRUE(observer.StateEquals(0, s1));
452 State s2(contents1, 0, MockTabStripModelObserver::DEACTIVATE); 449 State s2(contents1, 0, MockTabStripModelObserver::DEACTIVATE);
453 EXPECT_TRUE(observer.StateEquals(1, s2)); 450 EXPECT_TRUE(observer.StateEquals(1, s2));
454 State s3(contents2, 1, MockTabStripModelObserver::ACTIVATE); 451 State s3(contents2, 1, MockTabStripModelObserver::ACTIVATE);
455 s3.src_contents = contents1; 452 s3.src_contents = contents1;
456 EXPECT_TRUE(observer.StateEquals(2, s3)); 453 EXPECT_TRUE(observer.StateEquals(2, s3));
457 State s4(contents2, 1, MockTabStripModelObserver::SELECT); 454 State s4(contents2, 1, MockTabStripModelObserver::SELECT);
458 s4.src_contents = contents1; 455 s4.src_contents = contents1;
459 s4.src_index = 0; 456 s4.src_index = 0;
460 EXPECT_TRUE(observer.StateEquals(3, s4)); 457 EXPECT_TRUE(observer.StateEquals(3, s4));
461 observer.ClearStates(); 458 observer.ClearStates();
462 } 459 }
463 460
464 // Test InsertTabContentsAt, background tab. 461 // Test InsertTabContentsAt, background tab.
465 TabContentsWrapper* contents3 = CreateTabContents(); 462 TabContents* contents3 = CreateTabContents();
466 { 463 {
467 tabstrip.InsertTabContentsAt(2, contents3, TabStripModel::ADD_NONE); 464 tabstrip.InsertTabContentsAt(2, contents3, TabStripModel::ADD_NONE);
468 465
469 EXPECT_EQ(3, tabstrip.count()); 466 EXPECT_EQ(3, tabstrip.count());
470 EXPECT_EQ(1, observer.GetStateCount()); 467 EXPECT_EQ(1, observer.GetStateCount());
471 State s1(contents3, 2, MockTabStripModelObserver::INSERT); 468 State s1(contents3, 2, MockTabStripModelObserver::INSERT);
472 s1.foreground = false; 469 s1.foreground = false;
473 EXPECT_TRUE(observer.StateEquals(0, s1)); 470 EXPECT_TRUE(observer.StateEquals(0, s1));
474 observer.ClearStates(); 471 observer.ClearStates();
475 } 472 }
(...skipping 11 matching lines...) Expand all
487 State s3(contents3, 2, MockTabStripModelObserver::SELECT); 484 State s3(contents3, 2, MockTabStripModelObserver::SELECT);
488 s3.src_contents = contents2; 485 s3.src_contents = contents2;
489 s3.src_index = 1; 486 s3.src_index = 1;
490 EXPECT_TRUE(observer.StateEquals(2, s3)); 487 EXPECT_TRUE(observer.StateEquals(2, s3));
491 observer.ClearStates(); 488 observer.ClearStates();
492 } 489 }
493 490
494 // Test DetachTabContentsAt 491 // Test DetachTabContentsAt
495 { 492 {
496 // Detach 493 // Detach
497 TabContentsWrapper* detached = tabstrip.DetachTabContentsAt(2); 494 TabContents* detached = tabstrip.DetachTabContentsAt(2);
498 // ... and append again because we want this for later. 495 // ... and append again because we want this for later.
499 tabstrip.AppendTabContents(detached, true); 496 tabstrip.AppendTabContents(detached, true);
500 EXPECT_EQ(8, observer.GetStateCount()); 497 EXPECT_EQ(8, observer.GetStateCount());
501 State s1(detached, 2, MockTabStripModelObserver::DETACH); 498 State s1(detached, 2, MockTabStripModelObserver::DETACH);
502 EXPECT_TRUE(observer.StateEquals(0, s1)); 499 EXPECT_TRUE(observer.StateEquals(0, s1));
503 State s2(detached, TabStripSelectionModel::kUnselectedIndex, 500 State s2(detached, TabStripSelectionModel::kUnselectedIndex,
504 MockTabStripModelObserver::DEACTIVATE); 501 MockTabStripModelObserver::DEACTIVATE);
505 EXPECT_TRUE(observer.StateEquals(1, s2)); 502 EXPECT_TRUE(observer.StateEquals(1, s2));
506 State s3(contents2, 1, MockTabStripModelObserver::ACTIVATE); 503 State s3(contents2, 1, MockTabStripModelObserver::ACTIVATE);
507 s3.src_contents = contents3; 504 s3.src_contents = contents3;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 636
640 TEST_F(TabStripModelTest, TestBasicOpenerAPI) { 637 TEST_F(TabStripModelTest, TestBasicOpenerAPI) {
641 TabStripDummyDelegate delegate(NULL); 638 TabStripDummyDelegate delegate(NULL);
642 TabStripModel tabstrip(&delegate, profile()); 639 TabStripModel tabstrip(&delegate, profile());
643 EXPECT_TRUE(tabstrip.empty()); 640 EXPECT_TRUE(tabstrip.empty());
644 641
645 // This is a basic test of opener functionality. opener_contents is created 642 // This is a basic test of opener functionality. opener_contents is created
646 // as the first tab in the strip and then we create 5 other tabs in the 643 // as the first tab in the strip and then we create 5 other tabs in the
647 // background with opener_contents set as their opener. 644 // background with opener_contents set as their opener.
648 645
649 TabContentsWrapper* opener_contents = CreateTabContents(); 646 TabContents* opener_contents = CreateTabContents();
650 NavigationController* opener = 647 NavigationController* opener =
651 &opener_contents->web_contents()->GetController(); 648 &opener_contents->web_contents()->GetController();
652 tabstrip.AppendTabContents(opener_contents, true); 649 tabstrip.AppendTabContents(opener_contents, true);
653 TabContentsWrapper* contents1 = CreateTabContents(); 650 TabContents* contents1 = CreateTabContents();
654 TabContentsWrapper* contents2 = CreateTabContents(); 651 TabContents* contents2 = CreateTabContents();
655 TabContentsWrapper* contents3 = CreateTabContents(); 652 TabContents* contents3 = CreateTabContents();
656 TabContentsWrapper* contents4 = CreateTabContents(); 653 TabContents* contents4 = CreateTabContents();
657 TabContentsWrapper* contents5 = CreateTabContents(); 654 TabContents* contents5 = CreateTabContents();
658 655
659 // We use |InsertTabContentsAt| here instead of AppendTabContents so that 656 // We use |InsertTabContentsAt| here instead of AppendTabContents so that
660 // openership relationships are preserved. 657 // openership relationships are preserved.
661 tabstrip.InsertTabContentsAt(tabstrip.count(), contents1, 658 tabstrip.InsertTabContentsAt(tabstrip.count(), contents1,
662 TabStripModel::ADD_INHERIT_GROUP); 659 TabStripModel::ADD_INHERIT_GROUP);
663 tabstrip.InsertTabContentsAt(tabstrip.count(), contents2, 660 tabstrip.InsertTabContentsAt(tabstrip.count(), contents2,
664 TabStripModel::ADD_INHERIT_GROUP); 661 TabStripModel::ADD_INHERIT_GROUP);
665 tabstrip.InsertTabContentsAt(tabstrip.count(), contents3, 662 tabstrip.InsertTabContentsAt(tabstrip.count(), contents3,
666 TabStripModel::ADD_INHERIT_GROUP); 663 TabStripModel::ADD_INHERIT_GROUP);
667 tabstrip.InsertTabContentsAt(tabstrip.count(), contents4, 664 tabstrip.InsertTabContentsAt(tabstrip.count(), contents4,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 706
710 // If the last tab in the group is closed, the preceding tab in the same 707 // If the last tab in the group is closed, the preceding tab in the same
711 // group should be selected. 708 // group should be selected.
712 EXPECT_EQ(3, tabstrip.GetIndexOfNextTabContentsOpenedBy(o5, 4, false)); 709 EXPECT_EQ(3, tabstrip.GetIndexOfNextTabContentsOpenedBy(o5, 4, false));
713 710
714 tabstrip.CloseAllTabs(); 711 tabstrip.CloseAllTabs();
715 EXPECT_TRUE(tabstrip.empty()); 712 EXPECT_TRUE(tabstrip.empty());
716 } 713 }
717 714
718 static int GetInsertionIndex(TabStripModel* tabstrip, 715 static int GetInsertionIndex(TabStripModel* tabstrip,
719 TabContentsWrapper* contents) { 716 TabContents* contents) {
720 return tabstrip->order_controller()->DetermineInsertionIndex( 717 return tabstrip->order_controller()->DetermineInsertionIndex(
721 contents, content::PAGE_TRANSITION_LINK, false); 718 contents, content::PAGE_TRANSITION_LINK, false);
722 } 719 }
723 720
724 static void InsertTabContentses(TabStripModel* tabstrip, 721 static void InsertTabContentses(TabStripModel* tabstrip,
725 TabContentsWrapper* contents1, 722 TabContents* contents1,
726 TabContentsWrapper* contents2, 723 TabContents* contents2,
727 TabContentsWrapper* contents3) { 724 TabContents* contents3) {
728 tabstrip->InsertTabContentsAt(GetInsertionIndex(tabstrip, contents1), 725 tabstrip->InsertTabContentsAt(GetInsertionIndex(tabstrip, contents1),
729 contents1, TabStripModel::ADD_INHERIT_GROUP); 726 contents1, TabStripModel::ADD_INHERIT_GROUP);
730 tabstrip->InsertTabContentsAt(GetInsertionIndex(tabstrip, contents2), 727 tabstrip->InsertTabContentsAt(GetInsertionIndex(tabstrip, contents2),
731 contents2, TabStripModel::ADD_INHERIT_GROUP); 728 contents2, TabStripModel::ADD_INHERIT_GROUP);
732 tabstrip->InsertTabContentsAt(GetInsertionIndex(tabstrip, contents3), 729 tabstrip->InsertTabContentsAt(GetInsertionIndex(tabstrip, contents3),
733 contents3, TabStripModel::ADD_INHERIT_GROUP); 730 contents3, TabStripModel::ADD_INHERIT_GROUP);
734 } 731 }
735 732
736 // Tests opening background tabs. 733 // Tests opening background tabs.
737 TEST_F(TabStripModelTest, TestLTRInsertionOptions) { 734 TEST_F(TabStripModelTest, TestLTRInsertionOptions) {
738 TabStripDummyDelegate delegate(NULL); 735 TabStripDummyDelegate delegate(NULL);
739 TabStripModel tabstrip(&delegate, profile()); 736 TabStripModel tabstrip(&delegate, profile());
740 EXPECT_TRUE(tabstrip.empty()); 737 EXPECT_TRUE(tabstrip.empty());
741 738
742 TabContentsWrapper* opener_contents = CreateTabContents(); 739 TabContents* opener_contents = CreateTabContents();
743 tabstrip.AppendTabContents(opener_contents, true); 740 tabstrip.AppendTabContents(opener_contents, true);
744 741
745 TabContentsWrapper* contents1 = CreateTabContents(); 742 TabContents* contents1 = CreateTabContents();
746 TabContentsWrapper* contents2 = CreateTabContents(); 743 TabContents* contents2 = CreateTabContents();
747 TabContentsWrapper* contents3 = CreateTabContents(); 744 TabContents* contents3 = CreateTabContents();
748 745
749 // Test LTR 746 // Test LTR
750 InsertTabContentses(&tabstrip, contents1, contents2, contents3); 747 InsertTabContentses(&tabstrip, contents1, contents2, contents3);
751 EXPECT_EQ(contents1, tabstrip.GetTabContentsAt(1)); 748 EXPECT_EQ(contents1, tabstrip.GetTabContentsAt(1));
752 EXPECT_EQ(contents2, tabstrip.GetTabContentsAt(2)); 749 EXPECT_EQ(contents2, tabstrip.GetTabContentsAt(2));
753 EXPECT_EQ(contents3, tabstrip.GetTabContentsAt(3)); 750 EXPECT_EQ(contents3, tabstrip.GetTabContentsAt(3));
754 751
755 tabstrip.CloseAllTabs(); 752 tabstrip.CloseAllTabs();
756 EXPECT_TRUE(tabstrip.empty()); 753 EXPECT_TRUE(tabstrip.empty());
757 } 754 }
758 755
759 // Tests inserting tabs with InsertAfter set to false. 756 // Tests inserting tabs with InsertAfter set to false.
760 TEST_F(TabStripModelTest, InsertBefore) { 757 TEST_F(TabStripModelTest, InsertBefore) {
761 TabStripDummyDelegate delegate(NULL); 758 TabStripDummyDelegate delegate(NULL);
762 TabStripModel tabstrip(&delegate, profile()); 759 TabStripModel tabstrip(&delegate, profile());
763 tabstrip.SetInsertionPolicy(TabStripModel::INSERT_BEFORE); 760 tabstrip.SetInsertionPolicy(TabStripModel::INSERT_BEFORE);
764 EXPECT_TRUE(tabstrip.empty()); 761 EXPECT_TRUE(tabstrip.empty());
765 762
766 TabContentsWrapper* contents1 = CreateTabContents(); 763 TabContents* contents1 = CreateTabContents();
767 TabContentsWrapper* contents2 = CreateTabContents(); 764 TabContents* contents2 = CreateTabContents();
768 TabContentsWrapper* contents3 = CreateTabContents(); 765 TabContents* contents3 = CreateTabContents();
769 766
770 InsertTabContentses(&tabstrip, contents1, contents2, contents3); 767 InsertTabContentses(&tabstrip, contents1, contents2, contents3);
771 768
772 // The order should be reversed. 769 // The order should be reversed.
773 EXPECT_EQ(contents3, tabstrip.GetTabContentsAt(0)); 770 EXPECT_EQ(contents3, tabstrip.GetTabContentsAt(0));
774 EXPECT_EQ(contents2, tabstrip.GetTabContentsAt(1)); 771 EXPECT_EQ(contents2, tabstrip.GetTabContentsAt(1));
775 EXPECT_EQ(contents1, tabstrip.GetTabContentsAt(2)); 772 EXPECT_EQ(contents1, tabstrip.GetTabContentsAt(2));
776 773
777 tabstrip.CloseAllTabs(); 774 tabstrip.CloseAllTabs();
778 EXPECT_TRUE(tabstrip.empty()); 775 EXPECT_TRUE(tabstrip.empty());
779 } 776 }
780 777
781 // Tests opening background tabs with InsertAfter set to false. 778 // Tests opening background tabs with InsertAfter set to false.
782 TEST_F(TabStripModelTest, InsertBeforeOpeners) { 779 TEST_F(TabStripModelTest, InsertBeforeOpeners) {
783 TabStripDummyDelegate delegate(NULL); 780 TabStripDummyDelegate delegate(NULL);
784 TabStripModel tabstrip(&delegate, profile()); 781 TabStripModel tabstrip(&delegate, profile());
785 tabstrip.SetInsertionPolicy(TabStripModel::INSERT_BEFORE); 782 tabstrip.SetInsertionPolicy(TabStripModel::INSERT_BEFORE);
786 EXPECT_TRUE(tabstrip.empty()); 783 EXPECT_TRUE(tabstrip.empty());
787 TabContentsWrapper* opener_contents = CreateTabContents(); 784 TabContents* opener_contents = CreateTabContents();
788 tabstrip.AppendTabContents(opener_contents, true); 785 tabstrip.AppendTabContents(opener_contents, true);
789 786
790 TabContentsWrapper* contents1 = CreateTabContents(); 787 TabContents* contents1 = CreateTabContents();
791 TabContentsWrapper* contents2 = CreateTabContents(); 788 TabContents* contents2 = CreateTabContents();
792 TabContentsWrapper* contents3 = CreateTabContents(); 789 TabContents* contents3 = CreateTabContents();
793 790
794 InsertTabContentses(&tabstrip, contents1, contents2, contents3); 791 InsertTabContentses(&tabstrip, contents1, contents2, contents3);
795 792
796 // The order should be reversed. 793 // The order should be reversed.
797 EXPECT_EQ(contents3, tabstrip.GetTabContentsAt(0)); 794 EXPECT_EQ(contents3, tabstrip.GetTabContentsAt(0));
798 EXPECT_EQ(contents2, tabstrip.GetTabContentsAt(1)); 795 EXPECT_EQ(contents2, tabstrip.GetTabContentsAt(1));
799 EXPECT_EQ(contents1, tabstrip.GetTabContentsAt(2)); 796 EXPECT_EQ(contents1, tabstrip.GetTabContentsAt(2));
800 797
801 tabstrip.CloseAllTabs(); 798 tabstrip.CloseAllTabs();
802 EXPECT_TRUE(tabstrip.empty()); 799 EXPECT_TRUE(tabstrip.empty());
803 } 800 }
804 801
805 // This test constructs a tabstrip, and then simulates loading several tabs in 802 // This test constructs a tabstrip, and then simulates loading several tabs in
806 // the background from link clicks on the first tab. Then it simulates opening 803 // the background from link clicks on the first tab. Then it simulates opening
807 // a new tab from the first tab in the foreground via a link click, verifies 804 // a new tab from the first tab in the foreground via a link click, verifies
808 // that this tab is opened adjacent to the opener, then closes it. 805 // that this tab is opened adjacent to the opener, then closes it.
809 // Finally it tests that a tab opened for some non-link purpose openes at the 806 // Finally it tests that a tab opened for some non-link purpose openes at the
810 // end of the strip, not bundled to any existing context. 807 // end of the strip, not bundled to any existing context.
811 TEST_F(TabStripModelTest, TestInsertionIndexDetermination) { 808 TEST_F(TabStripModelTest, TestInsertionIndexDetermination) {
812 TabStripDummyDelegate delegate(NULL); 809 TabStripDummyDelegate delegate(NULL);
813 TabStripModel tabstrip(&delegate, profile()); 810 TabStripModel tabstrip(&delegate, profile());
814 EXPECT_TRUE(tabstrip.empty()); 811 EXPECT_TRUE(tabstrip.empty());
815 812
816 TabContentsWrapper* opener_contents = CreateTabContents(); 813 TabContents* opener_contents = CreateTabContents();
817 NavigationController* opener = 814 NavigationController* opener =
818 &opener_contents->web_contents()->GetController(); 815 &opener_contents->web_contents()->GetController();
819 tabstrip.AppendTabContents(opener_contents, true); 816 tabstrip.AppendTabContents(opener_contents, true);
820 817
821 // Open some other random unrelated tab in the background to monkey with our 818 // Open some other random unrelated tab in the background to monkey with our
822 // insertion index. 819 // insertion index.
823 TabContentsWrapper* other_contents = CreateTabContents(); 820 TabContents* other_contents = CreateTabContents();
824 tabstrip.AppendTabContents(other_contents, false); 821 tabstrip.AppendTabContents(other_contents, false);
825 822
826 TabContentsWrapper* contents1 = CreateTabContents(); 823 TabContents* contents1 = CreateTabContents();
827 TabContentsWrapper* contents2 = CreateTabContents(); 824 TabContents* contents2 = CreateTabContents();
828 TabContentsWrapper* contents3 = CreateTabContents(); 825 TabContents* contents3 = CreateTabContents();
829 826
830 // Start by testing LTR 827 // Start by testing LTR
831 InsertTabContentses(&tabstrip, contents1, contents2, contents3); 828 InsertTabContentses(&tabstrip, contents1, contents2, contents3);
832 EXPECT_EQ(opener_contents, tabstrip.GetTabContentsAt(0)); 829 EXPECT_EQ(opener_contents, tabstrip.GetTabContentsAt(0));
833 EXPECT_EQ(contents1, tabstrip.GetTabContentsAt(1)); 830 EXPECT_EQ(contents1, tabstrip.GetTabContentsAt(1));
834 EXPECT_EQ(contents2, tabstrip.GetTabContentsAt(2)); 831 EXPECT_EQ(contents2, tabstrip.GetTabContentsAt(2));
835 EXPECT_EQ(contents3, tabstrip.GetTabContentsAt(3)); 832 EXPECT_EQ(contents3, tabstrip.GetTabContentsAt(3));
836 EXPECT_EQ(other_contents, tabstrip.GetTabContentsAt(4)); 833 EXPECT_EQ(other_contents, tabstrip.GetTabContentsAt(4));
837 834
838 // The opener API should work... 835 // The opener API should work...
839 EXPECT_EQ(3, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 2, false)); 836 EXPECT_EQ(3, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 2, false));
840 EXPECT_EQ(2, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 3, false)); 837 EXPECT_EQ(2, tabstrip.GetIndexOfNextTabContentsOpenedBy(opener, 3, false));
841 EXPECT_EQ(3, tabstrip.GetIndexOfLastTabContentsOpenedBy(opener, 1)); 838 EXPECT_EQ(3, tabstrip.GetIndexOfLastTabContentsOpenedBy(opener, 1));
842 839
843 // Now open a foreground tab from a link. It should be opened adjacent to the 840 // Now open a foreground tab from a link. It should be opened adjacent to the
844 // opener tab. 841 // opener tab.
845 TabContentsWrapper* fg_link_contents = CreateTabContents(); 842 TabContents* fg_link_contents = CreateTabContents();
846 int insert_index = tabstrip.order_controller()->DetermineInsertionIndex( 843 int insert_index = tabstrip.order_controller()->DetermineInsertionIndex(
847 fg_link_contents, content::PAGE_TRANSITION_LINK, true); 844 fg_link_contents, content::PAGE_TRANSITION_LINK, true);
848 EXPECT_EQ(1, insert_index); 845 EXPECT_EQ(1, insert_index);
849 tabstrip.InsertTabContentsAt(insert_index, fg_link_contents, 846 tabstrip.InsertTabContentsAt(insert_index, fg_link_contents,
850 TabStripModel::ADD_ACTIVE | 847 TabStripModel::ADD_ACTIVE |
851 TabStripModel::ADD_INHERIT_GROUP); 848 TabStripModel::ADD_INHERIT_GROUP);
852 EXPECT_EQ(1, tabstrip.active_index()); 849 EXPECT_EQ(1, tabstrip.active_index());
853 EXPECT_EQ(fg_link_contents, tabstrip.GetActiveTabContents()); 850 EXPECT_EQ(fg_link_contents, tabstrip.GetActiveTabContents());
854 851
855 // Now close this contents. The selection should move to the opener contents. 852 // Now close this contents. The selection should move to the opener contents.
856 tabstrip.CloseSelectedTabs(); 853 tabstrip.CloseSelectedTabs();
857 EXPECT_EQ(0, tabstrip.active_index()); 854 EXPECT_EQ(0, tabstrip.active_index());
858 855
859 // Now open a new empty tab. It should open at the end of the strip. 856 // Now open a new empty tab. It should open at the end of the strip.
860 TabContentsWrapper* fg_nonlink_contents = CreateTabContents(); 857 TabContents* fg_nonlink_contents = CreateTabContents();
861 insert_index = tabstrip.order_controller()->DetermineInsertionIndex( 858 insert_index = tabstrip.order_controller()->DetermineInsertionIndex(
862 fg_nonlink_contents, content::PAGE_TRANSITION_AUTO_BOOKMARK, true); 859 fg_nonlink_contents, content::PAGE_TRANSITION_AUTO_BOOKMARK, true);
863 EXPECT_EQ(tabstrip.count(), insert_index); 860 EXPECT_EQ(tabstrip.count(), insert_index);
864 // We break the opener relationship... 861 // We break the opener relationship...
865 tabstrip.InsertTabContentsAt(insert_index, fg_nonlink_contents, 862 tabstrip.InsertTabContentsAt(insert_index, fg_nonlink_contents,
866 TabStripModel::ADD_NONE); 863 TabStripModel::ADD_NONE);
867 // Now select it, so that user_gesture == true causes the opener relationship 864 // Now select it, so that user_gesture == true causes the opener relationship
868 // to be forgotten... 865 // to be forgotten...
869 tabstrip.ActivateTabAt(tabstrip.count() - 1, true); 866 tabstrip.ActivateTabAt(tabstrip.count() - 1, true);
870 EXPECT_EQ(tabstrip.count() - 1, tabstrip.active_index()); 867 EXPECT_EQ(tabstrip.count() - 1, tabstrip.active_index());
(...skipping 18 matching lines...) Expand all
889 // The next tab (scanning LTR) in the entire strip that has the same opener 886 // The next tab (scanning LTR) in the entire strip that has the same opener
890 // is selected 887 // is selected
891 // If there are no other tabs that have the same opener, 888 // If there are no other tabs that have the same opener,
892 // The opener is selected 889 // The opener is selected
893 // 890 //
894 TEST_F(TabStripModelTest, TestSelectOnClose) { 891 TEST_F(TabStripModelTest, TestSelectOnClose) {
895 TabStripDummyDelegate delegate(NULL); 892 TabStripDummyDelegate delegate(NULL);
896 TabStripModel tabstrip(&delegate, profile()); 893 TabStripModel tabstrip(&delegate, profile());
897 EXPECT_TRUE(tabstrip.empty()); 894 EXPECT_TRUE(tabstrip.empty());
898 895
899 TabContentsWrapper* opener_contents = CreateTabContents(); 896 TabContents* opener_contents = CreateTabContents();
900 tabstrip.AppendTabContents(opener_contents, true); 897 tabstrip.AppendTabContents(opener_contents, true);
901 898
902 TabContentsWrapper* contents1 = CreateTabContents(); 899 TabContents* contents1 = CreateTabContents();
903 TabContentsWrapper* contents2 = CreateTabContents(); 900 TabContents* contents2 = CreateTabContents();
904 TabContentsWrapper* contents3 = CreateTabContents(); 901 TabContents* contents3 = CreateTabContents();
905 902
906 // Note that we use Detach instead of Close throughout this test to avoid 903 // Note that we use Detach instead of Close throughout this test to avoid
907 // having to keep reconstructing these TabContentses. 904 // having to keep reconstructing these TabContentses.
908 905
909 // First test that closing tabs that are in the background doesn't adjust the 906 // First test that closing tabs that are in the background doesn't adjust the
910 // current selection. 907 // current selection.
911 InsertTabContentses(&tabstrip, contents1, contents2, contents3); 908 InsertTabContentses(&tabstrip, contents1, contents2, contents3);
912 EXPECT_EQ(0, tabstrip.active_index()); 909 EXPECT_EQ(0, tabstrip.active_index());
913 910
914 tabstrip.DetachTabContentsAt(1); 911 tabstrip.DetachTabContentsAt(1);
(...skipping 27 matching lines...) Expand all
942 tabstrip.ActivateTabAt(2, false); 939 tabstrip.ActivateTabAt(2, false);
943 EXPECT_EQ(2, tabstrip.active_index()); 940 EXPECT_EQ(2, tabstrip.active_index());
944 tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE); 941 tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE);
945 EXPECT_EQ(2, tabstrip.active_index()); 942 EXPECT_EQ(2, tabstrip.active_index());
946 tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE); 943 tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE);
947 EXPECT_EQ(1, tabstrip.active_index()); 944 EXPECT_EQ(1, tabstrip.active_index());
948 tabstrip.CloseTabContentsAt(1, TabStripModel::CLOSE_NONE); 945 tabstrip.CloseTabContentsAt(1, TabStripModel::CLOSE_NONE);
949 EXPECT_EQ(0, tabstrip.active_index()); 946 EXPECT_EQ(0, tabstrip.active_index());
950 // Finally test that when a tab has no "siblings" that the opener is 947 // Finally test that when a tab has no "siblings" that the opener is
951 // selected. 948 // selected.
952 TabContentsWrapper* other_contents = CreateTabContents(); 949 TabContents* other_contents = CreateTabContents();
953 tabstrip.InsertTabContentsAt(1, other_contents, TabStripModel::ADD_NONE); 950 tabstrip.InsertTabContentsAt(1, other_contents, TabStripModel::ADD_NONE);
954 EXPECT_EQ(2, tabstrip.count()); 951 EXPECT_EQ(2, tabstrip.count());
955 TabContentsWrapper* opened_contents = CreateTabContents(); 952 TabContents* opened_contents = CreateTabContents();
956 tabstrip.InsertTabContentsAt(2, opened_contents, 953 tabstrip.InsertTabContentsAt(2, opened_contents,
957 TabStripModel::ADD_ACTIVE | 954 TabStripModel::ADD_ACTIVE |
958 TabStripModel::ADD_INHERIT_GROUP); 955 TabStripModel::ADD_INHERIT_GROUP);
959 EXPECT_EQ(2, tabstrip.active_index()); 956 EXPECT_EQ(2, tabstrip.active_index());
960 tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE); 957 tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE);
961 EXPECT_EQ(0, tabstrip.active_index()); 958 EXPECT_EQ(0, tabstrip.active_index());
962 959
963 tabstrip.CloseAllTabs(); 960 tabstrip.CloseAllTabs();
964 EXPECT_TRUE(tabstrip.empty()); 961 EXPECT_TRUE(tabstrip.empty());
965 } 962 }
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 1134
1138 // Tests the following context menu commands: 1135 // Tests the following context menu commands:
1139 // - Close Tab 1136 // - Close Tab
1140 // - Close Other Tabs 1137 // - Close Other Tabs
1141 // - Close Tabs To Right 1138 // - Close Tabs To Right
1142 TEST_F(TabStripModelTest, TestContextMenuCloseCommands) { 1139 TEST_F(TabStripModelTest, TestContextMenuCloseCommands) {
1143 TabStripDummyDelegate delegate(NULL); 1140 TabStripDummyDelegate delegate(NULL);
1144 TabStripModel tabstrip(&delegate, profile()); 1141 TabStripModel tabstrip(&delegate, profile());
1145 EXPECT_TRUE(tabstrip.empty()); 1142 EXPECT_TRUE(tabstrip.empty());
1146 1143
1147 TabContentsWrapper* opener_contents = CreateTabContents(); 1144 TabContents* opener_contents = CreateTabContents();
1148 tabstrip.AppendTabContents(opener_contents, true); 1145 tabstrip.AppendTabContents(opener_contents, true);
1149 1146
1150 TabContentsWrapper* contents1 = CreateTabContents(); 1147 TabContents* contents1 = CreateTabContents();
1151 TabContentsWrapper* contents2 = CreateTabContents(); 1148 TabContents* contents2 = CreateTabContents();
1152 TabContentsWrapper* contents3 = CreateTabContents(); 1149 TabContents* contents3 = CreateTabContents();
1153 1150
1154 InsertTabContentses(&tabstrip, contents1, contents2, contents3); 1151 InsertTabContentses(&tabstrip, contents1, contents2, contents3);
1155 EXPECT_EQ(0, tabstrip.active_index()); 1152 EXPECT_EQ(0, tabstrip.active_index());
1156 1153
1157 tabstrip.ExecuteContextMenuCommand(2, TabStripModel::CommandCloseTab); 1154 tabstrip.ExecuteContextMenuCommand(2, TabStripModel::CommandCloseTab);
1158 EXPECT_EQ(3, tabstrip.count()); 1155 EXPECT_EQ(3, tabstrip.count());
1159 1156
1160 tabstrip.ExecuteContextMenuCommand(0, TabStripModel::CommandCloseTabsToRight); 1157 tabstrip.ExecuteContextMenuCommand(0, TabStripModel::CommandCloseTabsToRight);
1161 EXPECT_EQ(1, tabstrip.count()); 1158 EXPECT_EQ(1, tabstrip.count());
1162 EXPECT_EQ(opener_contents, tabstrip.GetActiveTabContents()); 1159 EXPECT_EQ(opener_contents, tabstrip.GetActiveTabContents());
1163 1160
1164 TabContentsWrapper* dummy_contents = CreateTabContents(); 1161 TabContents* dummy_contents = CreateTabContents();
1165 tabstrip.AppendTabContents(dummy_contents, false); 1162 tabstrip.AppendTabContents(dummy_contents, false);
1166 1163
1167 contents1 = CreateTabContents(); 1164 contents1 = CreateTabContents();
1168 contents2 = CreateTabContents(); 1165 contents2 = CreateTabContents();
1169 contents3 = CreateTabContents(); 1166 contents3 = CreateTabContents();
1170 InsertTabContentses(&tabstrip, contents1, contents2, contents3); 1167 InsertTabContentses(&tabstrip, contents1, contents2, contents3);
1171 EXPECT_EQ(5, tabstrip.count()); 1168 EXPECT_EQ(5, tabstrip.count());
1172 1169
1173 int dummy_index = tabstrip.count() - 1; 1170 int dummy_index = tabstrip.count() - 1;
1174 tabstrip.ActivateTabAt(dummy_index, true); 1171 tabstrip.ActivateTabAt(dummy_index, true);
1175 EXPECT_EQ(dummy_contents, tabstrip.GetActiveTabContents()); 1172 EXPECT_EQ(dummy_contents, tabstrip.GetActiveTabContents());
1176 1173
1177 tabstrip.ExecuteContextMenuCommand(dummy_index, 1174 tabstrip.ExecuteContextMenuCommand(dummy_index,
1178 TabStripModel::CommandCloseOtherTabs); 1175 TabStripModel::CommandCloseOtherTabs);
1179 EXPECT_EQ(1, tabstrip.count()); 1176 EXPECT_EQ(1, tabstrip.count());
1180 EXPECT_EQ(dummy_contents, tabstrip.GetActiveTabContents()); 1177 EXPECT_EQ(dummy_contents, tabstrip.GetActiveTabContents());
1181 1178
1182 tabstrip.CloseAllTabs(); 1179 tabstrip.CloseAllTabs();
1183 EXPECT_TRUE(tabstrip.empty()); 1180 EXPECT_TRUE(tabstrip.empty());
1184 } 1181 }
1185 1182
1186 // Tests GetIndicesClosedByCommand. 1183 // Tests GetIndicesClosedByCommand.
1187 TEST_F(TabStripModelTest, GetIndicesClosedByCommand) { 1184 TEST_F(TabStripModelTest, GetIndicesClosedByCommand) {
1188 TabStripDummyDelegate delegate(NULL); 1185 TabStripDummyDelegate delegate(NULL);
1189 TabStripModel tabstrip(&delegate, profile()); 1186 TabStripModel tabstrip(&delegate, profile());
1190 EXPECT_TRUE(tabstrip.empty()); 1187 EXPECT_TRUE(tabstrip.empty());
1191 1188
1192 TabContentsWrapper* contents1 = CreateTabContents(); 1189 TabContents* contents1 = CreateTabContents();
1193 TabContentsWrapper* contents2 = CreateTabContents(); 1190 TabContents* contents2 = CreateTabContents();
1194 TabContentsWrapper* contents3 = CreateTabContents(); 1191 TabContents* contents3 = CreateTabContents();
1195 TabContentsWrapper* contents4 = CreateTabContents(); 1192 TabContents* contents4 = CreateTabContents();
1196 TabContentsWrapper* contents5 = CreateTabContents(); 1193 TabContents* contents5 = CreateTabContents();
1197 1194
1198 tabstrip.AppendTabContents(contents1, true); 1195 tabstrip.AppendTabContents(contents1, true);
1199 tabstrip.AppendTabContents(contents2, true); 1196 tabstrip.AppendTabContents(contents2, true);
1200 tabstrip.AppendTabContents(contents3, true); 1197 tabstrip.AppendTabContents(contents3, true);
1201 tabstrip.AppendTabContents(contents4, true); 1198 tabstrip.AppendTabContents(contents4, true);
1202 tabstrip.AppendTabContents(contents5, true); 1199 tabstrip.AppendTabContents(contents5, true);
1203 1200
1204 EXPECT_EQ("4 3 2 1", GetIndicesClosedByCommandAsString( 1201 EXPECT_EQ("4 3 2 1", GetIndicesClosedByCommandAsString(
1205 tabstrip, 0, TabStripModel::CommandCloseTabsToRight)); 1202 tabstrip, 0, TabStripModel::CommandCloseTabsToRight));
1206 EXPECT_EQ("4 3 2", GetIndicesClosedByCommandAsString( 1203 EXPECT_EQ("4 3 2", GetIndicesClosedByCommandAsString(
(...skipping 25 matching lines...) Expand all
1232 1229
1233 // Tests whether or not TabContentses are inserted in the correct position 1230 // Tests whether or not TabContentses are inserted in the correct position
1234 // using this "smart" function with a simulated middle click action on a series 1231 // using this "smart" function with a simulated middle click action on a series
1235 // of links on the home page. 1232 // of links on the home page.
1236 TEST_F(TabStripModelTest, AddTabContents_MiddleClickLinksAndClose) { 1233 TEST_F(TabStripModelTest, AddTabContents_MiddleClickLinksAndClose) {
1237 TabStripDummyDelegate delegate(NULL); 1234 TabStripDummyDelegate delegate(NULL);
1238 TabStripModel tabstrip(&delegate, profile()); 1235 TabStripModel tabstrip(&delegate, profile());
1239 EXPECT_TRUE(tabstrip.empty()); 1236 EXPECT_TRUE(tabstrip.empty());
1240 1237
1241 // Open the Home Page 1238 // Open the Home Page
1242 TabContentsWrapper* homepage_contents = CreateTabContents(); 1239 TabContents* homepage_contents = CreateTabContents();
1243 tabstrip.AddTabContents( 1240 tabstrip.AddTabContents(
1244 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, 1241 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK,
1245 TabStripModel::ADD_ACTIVE); 1242 TabStripModel::ADD_ACTIVE);
1246 1243
1247 // Open some other tab, by user typing. 1244 // Open some other tab, by user typing.
1248 TabContentsWrapper* typed_page_contents = CreateTabContents(); 1245 TabContents* typed_page_contents = CreateTabContents();
1249 tabstrip.AddTabContents( 1246 tabstrip.AddTabContents(
1250 typed_page_contents, -1, content::PAGE_TRANSITION_TYPED, 1247 typed_page_contents, -1, content::PAGE_TRANSITION_TYPED,
1251 TabStripModel::ADD_ACTIVE); 1248 TabStripModel::ADD_ACTIVE);
1252 1249
1253 EXPECT_EQ(2, tabstrip.count()); 1250 EXPECT_EQ(2, tabstrip.count());
1254 1251
1255 // Re-select the home page. 1252 // Re-select the home page.
1256 tabstrip.ActivateTabAt(0, true); 1253 tabstrip.ActivateTabAt(0, true);
1257 1254
1258 // Open a bunch of tabs by simulating middle clicking on links on the home 1255 // Open a bunch of tabs by simulating middle clicking on links on the home
1259 // page. 1256 // page.
1260 TabContentsWrapper* middle_click_contents1 = CreateTabContents(); 1257 TabContents* middle_click_contents1 = CreateTabContents();
1261 tabstrip.AddTabContents( 1258 tabstrip.AddTabContents(
1262 middle_click_contents1, -1, content::PAGE_TRANSITION_LINK, 1259 middle_click_contents1, -1, content::PAGE_TRANSITION_LINK,
1263 TabStripModel::ADD_NONE); 1260 TabStripModel::ADD_NONE);
1264 TabContentsWrapper* middle_click_contents2 = CreateTabContents(); 1261 TabContents* middle_click_contents2 = CreateTabContents();
1265 tabstrip.AddTabContents( 1262 tabstrip.AddTabContents(
1266 middle_click_contents2, -1, content::PAGE_TRANSITION_LINK, 1263 middle_click_contents2, -1, content::PAGE_TRANSITION_LINK,
1267 TabStripModel::ADD_NONE); 1264 TabStripModel::ADD_NONE);
1268 TabContentsWrapper* middle_click_contents3 = CreateTabContents(); 1265 TabContents* middle_click_contents3 = CreateTabContents();
1269 tabstrip.AddTabContents( 1266 tabstrip.AddTabContents(
1270 middle_click_contents3, -1, content::PAGE_TRANSITION_LINK, 1267 middle_click_contents3, -1, content::PAGE_TRANSITION_LINK,
1271 TabStripModel::ADD_NONE); 1268 TabStripModel::ADD_NONE);
1272 1269
1273 EXPECT_EQ(5, tabstrip.count()); 1270 EXPECT_EQ(5, tabstrip.count());
1274 1271
1275 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); 1272 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0));
1276 EXPECT_EQ(middle_click_contents1, tabstrip.GetTabContentsAt(1)); 1273 EXPECT_EQ(middle_click_contents1, tabstrip.GetTabContentsAt(1));
1277 EXPECT_EQ(middle_click_contents2, tabstrip.GetTabContentsAt(2)); 1274 EXPECT_EQ(middle_click_contents2, tabstrip.GetTabContentsAt(2));
1278 EXPECT_EQ(middle_click_contents3, tabstrip.GetTabContentsAt(3)); 1275 EXPECT_EQ(middle_click_contents3, tabstrip.GetTabContentsAt(3));
1279 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(4)); 1276 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(4));
1280 1277
1281 // Now simulate seleting a tab in the middle of the group of tabs opened from 1278 // Now simulate seleting a tab in the middle of the group of tabs opened from
1282 // the home page and start closing them. Each TabContentsWrapper in the group 1279 // the home page and start closing them. Each TabContents in the group
1283 // should be closed, right to left. This test is constructed to start at the 1280 // should be closed, right to left. This test is constructed to start at the
1284 // middle TabContentsWrapper in the group to make sure the cursor wraps around 1281 // middle TabContents in the group to make sure the cursor wraps around
1285 // to the first TabContentsWrapper in the group before closing the opener or 1282 // to the first TabContents in the group before closing the opener or
1286 // any other TabContentsWrapper. 1283 // any other TabContents.
1287 tabstrip.ActivateTabAt(2, true); 1284 tabstrip.ActivateTabAt(2, true);
1288 tabstrip.CloseSelectedTabs(); 1285 tabstrip.CloseSelectedTabs();
1289 EXPECT_EQ(middle_click_contents3, tabstrip.GetActiveTabContents()); 1286 EXPECT_EQ(middle_click_contents3, tabstrip.GetActiveTabContents());
1290 tabstrip.CloseSelectedTabs(); 1287 tabstrip.CloseSelectedTabs();
1291 EXPECT_EQ(middle_click_contents1, tabstrip.GetActiveTabContents()); 1288 EXPECT_EQ(middle_click_contents1, tabstrip.GetActiveTabContents());
1292 tabstrip.CloseSelectedTabs(); 1289 tabstrip.CloseSelectedTabs();
1293 EXPECT_EQ(homepage_contents, tabstrip.GetActiveTabContents()); 1290 EXPECT_EQ(homepage_contents, tabstrip.GetActiveTabContents());
1294 tabstrip.CloseSelectedTabs(); 1291 tabstrip.CloseSelectedTabs();
1295 EXPECT_EQ(typed_page_contents, tabstrip.GetActiveTabContents()); 1292 EXPECT_EQ(typed_page_contents, tabstrip.GetActiveTabContents());
1296 1293
1297 EXPECT_EQ(1, tabstrip.count()); 1294 EXPECT_EQ(1, tabstrip.count());
1298 1295
1299 tabstrip.CloseAllTabs(); 1296 tabstrip.CloseAllTabs();
1300 EXPECT_TRUE(tabstrip.empty()); 1297 EXPECT_TRUE(tabstrip.empty());
1301 } 1298 }
1302 1299
1303 // Tests whether or not a TabContentsWrapper created by a left click on a link 1300 // Tests whether or not a TabContents created by a left click on a link
1304 // that opens a new tab is inserted correctly adjacent to the tab that spawned 1301 // that opens a new tab is inserted correctly adjacent to the tab that spawned
1305 // it. 1302 // it.
1306 TEST_F(TabStripModelTest, AddTabContents_LeftClickPopup) { 1303 TEST_F(TabStripModelTest, AddTabContents_LeftClickPopup) {
1307 TabStripDummyDelegate delegate(NULL); 1304 TabStripDummyDelegate delegate(NULL);
1308 TabStripModel tabstrip(&delegate, profile()); 1305 TabStripModel tabstrip(&delegate, profile());
1309 EXPECT_TRUE(tabstrip.empty()); 1306 EXPECT_TRUE(tabstrip.empty());
1310 1307
1311 // Open the Home Page 1308 // Open the Home Page
1312 TabContentsWrapper* homepage_contents = CreateTabContents(); 1309 TabContents* homepage_contents = CreateTabContents();
1313 tabstrip.AddTabContents( 1310 tabstrip.AddTabContents(
1314 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, 1311 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK,
1315 TabStripModel::ADD_ACTIVE); 1312 TabStripModel::ADD_ACTIVE);
1316 1313
1317 // Open some other tab, by user typing. 1314 // Open some other tab, by user typing.
1318 TabContentsWrapper* typed_page_contents = CreateTabContents(); 1315 TabContents* typed_page_contents = CreateTabContents();
1319 tabstrip.AddTabContents( 1316 tabstrip.AddTabContents(
1320 typed_page_contents, -1, content::PAGE_TRANSITION_TYPED, 1317 typed_page_contents, -1, content::PAGE_TRANSITION_TYPED,
1321 TabStripModel::ADD_ACTIVE); 1318 TabStripModel::ADD_ACTIVE);
1322 1319
1323 EXPECT_EQ(2, tabstrip.count()); 1320 EXPECT_EQ(2, tabstrip.count());
1324 1321
1325 // Re-select the home page. 1322 // Re-select the home page.
1326 tabstrip.ActivateTabAt(0, true); 1323 tabstrip.ActivateTabAt(0, true);
1327 1324
1328 // Open a tab by simulating a left click on a link that opens in a new tab. 1325 // Open a tab by simulating a left click on a link that opens in a new tab.
1329 TabContentsWrapper* left_click_contents = CreateTabContents(); 1326 TabContents* left_click_contents = CreateTabContents();
1330 tabstrip.AddTabContents(left_click_contents, -1, 1327 tabstrip.AddTabContents(left_click_contents, -1,
1331 content::PAGE_TRANSITION_LINK, 1328 content::PAGE_TRANSITION_LINK,
1332 TabStripModel::ADD_ACTIVE); 1329 TabStripModel::ADD_ACTIVE);
1333 1330
1334 // Verify the state meets our expectations. 1331 // Verify the state meets our expectations.
1335 EXPECT_EQ(3, tabstrip.count()); 1332 EXPECT_EQ(3, tabstrip.count());
1336 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); 1333 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0));
1337 EXPECT_EQ(left_click_contents, tabstrip.GetTabContentsAt(1)); 1334 EXPECT_EQ(left_click_contents, tabstrip.GetTabContentsAt(1));
1338 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(2)); 1335 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(2));
1339 1336
(...skipping 13 matching lines...) Expand all
1353 1350
1354 // Tests whether or not new tabs that should split context (typed pages, 1351 // Tests whether or not new tabs that should split context (typed pages,
1355 // generated urls, also blank tabs) open at the end of the tabstrip instead of 1352 // generated urls, also blank tabs) open at the end of the tabstrip instead of
1356 // in the middle. 1353 // in the middle.
1357 TEST_F(TabStripModelTest, AddTabContents_CreateNewBlankTab) { 1354 TEST_F(TabStripModelTest, AddTabContents_CreateNewBlankTab) {
1358 TabStripDummyDelegate delegate(NULL); 1355 TabStripDummyDelegate delegate(NULL);
1359 TabStripModel tabstrip(&delegate, profile()); 1356 TabStripModel tabstrip(&delegate, profile());
1360 EXPECT_TRUE(tabstrip.empty()); 1357 EXPECT_TRUE(tabstrip.empty());
1361 1358
1362 // Open the Home Page 1359 // Open the Home Page
1363 TabContentsWrapper* homepage_contents = CreateTabContents(); 1360 TabContents* homepage_contents = CreateTabContents();
1364 tabstrip.AddTabContents( 1361 tabstrip.AddTabContents(
1365 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, 1362 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK,
1366 TabStripModel::ADD_ACTIVE); 1363 TabStripModel::ADD_ACTIVE);
1367 1364
1368 // Open some other tab, by user typing. 1365 // Open some other tab, by user typing.
1369 TabContentsWrapper* typed_page_contents = CreateTabContents(); 1366 TabContents* typed_page_contents = CreateTabContents();
1370 tabstrip.AddTabContents( 1367 tabstrip.AddTabContents(
1371 typed_page_contents, -1, content::PAGE_TRANSITION_TYPED, 1368 typed_page_contents, -1, content::PAGE_TRANSITION_TYPED,
1372 TabStripModel::ADD_ACTIVE); 1369 TabStripModel::ADD_ACTIVE);
1373 1370
1374 EXPECT_EQ(2, tabstrip.count()); 1371 EXPECT_EQ(2, tabstrip.count());
1375 1372
1376 // Re-select the home page. 1373 // Re-select the home page.
1377 tabstrip.ActivateTabAt(0, true); 1374 tabstrip.ActivateTabAt(0, true);
1378 1375
1379 // Open a new blank tab in the foreground. 1376 // Open a new blank tab in the foreground.
1380 TabContentsWrapper* new_blank_contents = CreateTabContents(); 1377 TabContents* new_blank_contents = CreateTabContents();
1381 tabstrip.AddTabContents(new_blank_contents, -1, 1378 tabstrip.AddTabContents(new_blank_contents, -1,
1382 content::PAGE_TRANSITION_TYPED, 1379 content::PAGE_TRANSITION_TYPED,
1383 TabStripModel::ADD_ACTIVE); 1380 TabStripModel::ADD_ACTIVE);
1384 1381
1385 // Verify the state of the tabstrip. 1382 // Verify the state of the tabstrip.
1386 EXPECT_EQ(3, tabstrip.count()); 1383 EXPECT_EQ(3, tabstrip.count());
1387 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); 1384 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0));
1388 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(1)); 1385 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(1));
1389 EXPECT_EQ(new_blank_contents, tabstrip.GetTabContentsAt(2)); 1386 EXPECT_EQ(new_blank_contents, tabstrip.GetTabContentsAt(2));
1390 1387
1391 // Now open a couple more blank tabs in the background. 1388 // Now open a couple more blank tabs in the background.
1392 TabContentsWrapper* background_blank_contents1 = CreateTabContents(); 1389 TabContents* background_blank_contents1 = CreateTabContents();
1393 tabstrip.AddTabContents( 1390 tabstrip.AddTabContents(
1394 background_blank_contents1, -1, content::PAGE_TRANSITION_TYPED, 1391 background_blank_contents1, -1, content::PAGE_TRANSITION_TYPED,
1395 TabStripModel::ADD_NONE); 1392 TabStripModel::ADD_NONE);
1396 TabContentsWrapper* background_blank_contents2 = CreateTabContents(); 1393 TabContents* background_blank_contents2 = CreateTabContents();
1397 tabstrip.AddTabContents( 1394 tabstrip.AddTabContents(
1398 background_blank_contents2, -1, content::PAGE_TRANSITION_GENERATED, 1395 background_blank_contents2, -1, content::PAGE_TRANSITION_GENERATED,
1399 TabStripModel::ADD_NONE); 1396 TabStripModel::ADD_NONE);
1400 EXPECT_EQ(5, tabstrip.count()); 1397 EXPECT_EQ(5, tabstrip.count());
1401 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); 1398 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0));
1402 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(1)); 1399 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(1));
1403 EXPECT_EQ(new_blank_contents, tabstrip.GetTabContentsAt(2)); 1400 EXPECT_EQ(new_blank_contents, tabstrip.GetTabContentsAt(2));
1404 EXPECT_EQ(background_blank_contents1, tabstrip.GetTabContentsAt(3)); 1401 EXPECT_EQ(background_blank_contents1, tabstrip.GetTabContentsAt(3));
1405 EXPECT_EQ(background_blank_contents2, tabstrip.GetTabContentsAt(4)); 1402 EXPECT_EQ(background_blank_contents2, tabstrip.GetTabContentsAt(4));
1406 1403
1407 tabstrip.CloseAllTabs(); 1404 tabstrip.CloseAllTabs();
1408 EXPECT_TRUE(tabstrip.empty()); 1405 EXPECT_TRUE(tabstrip.empty());
1409 } 1406 }
1410 1407
1411 // Tests whether opener state is correctly forgotten when the user switches 1408 // Tests whether opener state is correctly forgotten when the user switches
1412 // context. 1409 // context.
1413 TEST_F(TabStripModelTest, AddTabContents_ForgetOpeners) { 1410 TEST_F(TabStripModelTest, AddTabContents_ForgetOpeners) {
1414 TabStripDummyDelegate delegate(NULL); 1411 TabStripDummyDelegate delegate(NULL);
1415 TabStripModel tabstrip(&delegate, profile()); 1412 TabStripModel tabstrip(&delegate, profile());
1416 EXPECT_TRUE(tabstrip.empty()); 1413 EXPECT_TRUE(tabstrip.empty());
1417 1414
1418 // Open the Home Page 1415 // Open the Home Page
1419 TabContentsWrapper* homepage_contents = CreateTabContents(); 1416 TabContents* homepage_contents = CreateTabContents();
1420 tabstrip.AddTabContents( 1417 tabstrip.AddTabContents(
1421 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, 1418 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK,
1422 TabStripModel::ADD_ACTIVE); 1419 TabStripModel::ADD_ACTIVE);
1423 1420
1424 // Open some other tab, by user typing. 1421 // Open some other tab, by user typing.
1425 TabContentsWrapper* typed_page_contents = CreateTabContents(); 1422 TabContents* typed_page_contents = CreateTabContents();
1426 tabstrip.AddTabContents( 1423 tabstrip.AddTabContents(
1427 typed_page_contents, -1, content::PAGE_TRANSITION_TYPED, 1424 typed_page_contents, -1, content::PAGE_TRANSITION_TYPED,
1428 TabStripModel::ADD_ACTIVE); 1425 TabStripModel::ADD_ACTIVE);
1429 1426
1430 EXPECT_EQ(2, tabstrip.count()); 1427 EXPECT_EQ(2, tabstrip.count());
1431 1428
1432 // Re-select the home page. 1429 // Re-select the home page.
1433 tabstrip.ActivateTabAt(0, true); 1430 tabstrip.ActivateTabAt(0, true);
1434 1431
1435 // Open a bunch of tabs by simulating middle clicking on links on the home 1432 // Open a bunch of tabs by simulating middle clicking on links on the home
1436 // page. 1433 // page.
1437 TabContentsWrapper* middle_click_contents1 = CreateTabContents(); 1434 TabContents* middle_click_contents1 = CreateTabContents();
1438 tabstrip.AddTabContents( 1435 tabstrip.AddTabContents(
1439 middle_click_contents1, -1, content::PAGE_TRANSITION_LINK, 1436 middle_click_contents1, -1, content::PAGE_TRANSITION_LINK,
1440 TabStripModel::ADD_NONE); 1437 TabStripModel::ADD_NONE);
1441 TabContentsWrapper* middle_click_contents2 = CreateTabContents(); 1438 TabContents* middle_click_contents2 = CreateTabContents();
1442 tabstrip.AddTabContents( 1439 tabstrip.AddTabContents(
1443 middle_click_contents2, -1, content::PAGE_TRANSITION_LINK, 1440 middle_click_contents2, -1, content::PAGE_TRANSITION_LINK,
1444 TabStripModel::ADD_NONE); 1441 TabStripModel::ADD_NONE);
1445 TabContentsWrapper* middle_click_contents3 = CreateTabContents(); 1442 TabContents* middle_click_contents3 = CreateTabContents();
1446 tabstrip.AddTabContents( 1443 tabstrip.AddTabContents(
1447 middle_click_contents3, -1, content::PAGE_TRANSITION_LINK, 1444 middle_click_contents3, -1, content::PAGE_TRANSITION_LINK,
1448 TabStripModel::ADD_NONE); 1445 TabStripModel::ADD_NONE);
1449 1446
1450 // Break out of the context by selecting a tab in a different context. 1447 // Break out of the context by selecting a tab in a different context.
1451 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(4)); 1448 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(4));
1452 tabstrip.SelectLastTab(); 1449 tabstrip.SelectLastTab();
1453 EXPECT_EQ(typed_page_contents, tabstrip.GetActiveTabContents()); 1450 EXPECT_EQ(typed_page_contents, tabstrip.GetActiveTabContents());
1454 1451
1455 // Step back into the context by selecting a tab inside it. 1452 // Step back into the context by selecting a tab inside it.
(...skipping 15 matching lines...) Expand all
1471 EXPECT_EQ(1, tabstrip.count()); 1468 EXPECT_EQ(1, tabstrip.count());
1472 1469
1473 tabstrip.CloseAllTabs(); 1470 tabstrip.CloseAllTabs();
1474 EXPECT_TRUE(tabstrip.empty()); 1471 EXPECT_TRUE(tabstrip.empty());
1475 } 1472 }
1476 1473
1477 // Added for http://b/issue?id=958960 1474 // Added for http://b/issue?id=958960
1478 TEST_F(TabStripModelTest, AppendContentsReselectionTest) { 1475 TEST_F(TabStripModelTest, AppendContentsReselectionTest) {
1479 WebContents* fake_destinations_tab = 1476 WebContents* fake_destinations_tab =
1480 WebContents::Create(profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); 1477 WebContents::Create(profile(), NULL, MSG_ROUTING_NONE, NULL, NULL);
1481 TabContentsWrapper wrapper(fake_destinations_tab); 1478 TabContents tab_contents(fake_destinations_tab);
1482 TabStripDummyDelegate delegate(&wrapper); 1479 TabStripDummyDelegate delegate(&tab_contents);
1483 TabStripModel tabstrip(&delegate, profile()); 1480 TabStripModel tabstrip(&delegate, profile());
1484 EXPECT_TRUE(tabstrip.empty()); 1481 EXPECT_TRUE(tabstrip.empty());
1485 1482
1486 // Open the Home Page 1483 // Open the Home Page
1487 TabContentsWrapper* homepage_contents = CreateTabContents(); 1484 TabContents* homepage_contents = CreateTabContents();
1488 tabstrip.AddTabContents( 1485 tabstrip.AddTabContents(
1489 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, 1486 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK,
1490 TabStripModel::ADD_ACTIVE); 1487 TabStripModel::ADD_ACTIVE);
1491 1488
1492 // Open some other tab, by user typing. 1489 // Open some other tab, by user typing.
1493 TabContentsWrapper* typed_page_contents = CreateTabContents(); 1490 TabContents* typed_page_contents = CreateTabContents();
1494 tabstrip.AddTabContents( 1491 tabstrip.AddTabContents(
1495 typed_page_contents, -1, content::PAGE_TRANSITION_TYPED, 1492 typed_page_contents, -1, content::PAGE_TRANSITION_TYPED,
1496 TabStripModel::ADD_NONE); 1493 TabStripModel::ADD_NONE);
1497 1494
1498 // The selected tab should still be the first. 1495 // The selected tab should still be the first.
1499 EXPECT_EQ(0, tabstrip.active_index()); 1496 EXPECT_EQ(0, tabstrip.active_index());
1500 1497
1501 // Now simulate a link click that opens a new tab (by virtue of target=_blank) 1498 // Now simulate a link click that opens a new tab (by virtue of target=_blank)
1502 // and make sure the right tab gets selected when the new tab is closed. 1499 // and make sure the right tab gets selected when the new tab is closed.
1503 TabContentsWrapper* target_blank_contents = CreateTabContents(); 1500 TabContents* target_blank_contents = CreateTabContents();
1504 tabstrip.AppendTabContents(target_blank_contents, true); 1501 tabstrip.AppendTabContents(target_blank_contents, true);
1505 EXPECT_EQ(2, tabstrip.active_index()); 1502 EXPECT_EQ(2, tabstrip.active_index());
1506 tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE); 1503 tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE);
1507 EXPECT_EQ(0, tabstrip.active_index()); 1504 EXPECT_EQ(0, tabstrip.active_index());
1508 1505
1509 // clean up after ourselves 1506 // clean up after ourselves
1510 tabstrip.CloseAllTabs(); 1507 tabstrip.CloseAllTabs();
1511 } 1508 }
1512 1509
1513 // Added for http://b/issue?id=1027661 1510 // Added for http://b/issue?id=1027661
1514 TEST_F(TabStripModelTest, ReselectionConsidersChildrenTest) { 1511 TEST_F(TabStripModelTest, ReselectionConsidersChildrenTest) {
1515 TabStripDummyDelegate delegate(NULL); 1512 TabStripDummyDelegate delegate(NULL);
1516 TabStripModel strip(&delegate, profile()); 1513 TabStripModel strip(&delegate, profile());
1517 1514
1518 // Open page A 1515 // Open page A
1519 TabContentsWrapper* page_a_contents = CreateTabContents(); 1516 TabContents* page_a_contents = CreateTabContents();
1520 strip.AddTabContents( 1517 strip.AddTabContents(
1521 page_a_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, 1518 page_a_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK,
1522 TabStripModel::ADD_ACTIVE); 1519 TabStripModel::ADD_ACTIVE);
1523 1520
1524 // Simulate middle click to open page A.A and A.B 1521 // Simulate middle click to open page A.A and A.B
1525 TabContentsWrapper* page_a_a_contents = CreateTabContents(); 1522 TabContents* page_a_a_contents = CreateTabContents();
1526 strip.AddTabContents(page_a_a_contents, -1, content::PAGE_TRANSITION_LINK, 1523 strip.AddTabContents(page_a_a_contents, -1, content::PAGE_TRANSITION_LINK,
1527 TabStripModel::ADD_NONE); 1524 TabStripModel::ADD_NONE);
1528 TabContentsWrapper* page_a_b_contents = CreateTabContents(); 1525 TabContents* page_a_b_contents = CreateTabContents();
1529 strip.AddTabContents(page_a_b_contents, -1, content::PAGE_TRANSITION_LINK, 1526 strip.AddTabContents(page_a_b_contents, -1, content::PAGE_TRANSITION_LINK,
1530 TabStripModel::ADD_NONE); 1527 TabStripModel::ADD_NONE);
1531 1528
1532 // Select page A.A 1529 // Select page A.A
1533 strip.ActivateTabAt(1, true); 1530 strip.ActivateTabAt(1, true);
1534 EXPECT_EQ(page_a_a_contents, strip.GetActiveTabContents()); 1531 EXPECT_EQ(page_a_a_contents, strip.GetActiveTabContents());
1535 1532
1536 // Simulate a middle click to open page A.A.A 1533 // Simulate a middle click to open page A.A.A
1537 TabContentsWrapper* page_a_a_a_contents = CreateTabContents(); 1534 TabContents* page_a_a_a_contents = CreateTabContents();
1538 strip.AddTabContents(page_a_a_a_contents, -1, content::PAGE_TRANSITION_LINK, 1535 strip.AddTabContents(page_a_a_a_contents, -1, content::PAGE_TRANSITION_LINK,
1539 TabStripModel::ADD_NONE); 1536 TabStripModel::ADD_NONE);
1540 1537
1541 EXPECT_EQ(page_a_a_a_contents, strip.GetTabContentsAt(2)); 1538 EXPECT_EQ(page_a_a_a_contents, strip.GetTabContentsAt(2));
1542 1539
1543 // Close page A.A 1540 // Close page A.A
1544 strip.CloseTabContentsAt(strip.active_index(), TabStripModel::CLOSE_NONE); 1541 strip.CloseTabContentsAt(strip.active_index(), TabStripModel::CLOSE_NONE);
1545 1542
1546 // Page A.A.A should be selected, NOT A.B 1543 // Page A.A.A should be selected, NOT A.B
1547 EXPECT_EQ(page_a_a_a_contents, strip.GetActiveTabContents()); 1544 EXPECT_EQ(page_a_a_a_contents, strip.GetActiveTabContents());
(...skipping 12 matching lines...) Expand all
1560 1557
1561 // Clean up. 1558 // Clean up.
1562 strip.CloseAllTabs(); 1559 strip.CloseAllTabs();
1563 } 1560 }
1564 1561
1565 TEST_F(TabStripModelTest, AddTabContents_NewTabAtEndOfStripInheritsGroup) { 1562 TEST_F(TabStripModelTest, AddTabContents_NewTabAtEndOfStripInheritsGroup) {
1566 TabStripDummyDelegate delegate(NULL); 1563 TabStripDummyDelegate delegate(NULL);
1567 TabStripModel strip(&delegate, profile()); 1564 TabStripModel strip(&delegate, profile());
1568 1565
1569 // Open page A 1566 // Open page A
1570 TabContentsWrapper* page_a_contents = CreateTabContents(); 1567 TabContents* page_a_contents = CreateTabContents();
1571 strip.AddTabContents(page_a_contents, -1, content::PAGE_TRANSITION_START_PAGE, 1568 strip.AddTabContents(page_a_contents, -1, content::PAGE_TRANSITION_START_PAGE,
1572 TabStripModel::ADD_ACTIVE); 1569 TabStripModel::ADD_ACTIVE);
1573 1570
1574 // Open pages B, C and D in the background from links on page A... 1571 // Open pages B, C and D in the background from links on page A...
1575 TabContentsWrapper* page_b_contents = CreateTabContents(); 1572 TabContents* page_b_contents = CreateTabContents();
1576 TabContentsWrapper* page_c_contents = CreateTabContents(); 1573 TabContents* page_c_contents = CreateTabContents();
1577 TabContentsWrapper* page_d_contents = CreateTabContents(); 1574 TabContents* page_d_contents = CreateTabContents();
1578 strip.AddTabContents(page_b_contents, -1, content::PAGE_TRANSITION_LINK, 1575 strip.AddTabContents(page_b_contents, -1, content::PAGE_TRANSITION_LINK,
1579 TabStripModel::ADD_NONE); 1576 TabStripModel::ADD_NONE);
1580 strip.AddTabContents(page_c_contents, -1, content::PAGE_TRANSITION_LINK, 1577 strip.AddTabContents(page_c_contents, -1, content::PAGE_TRANSITION_LINK,
1581 TabStripModel::ADD_NONE); 1578 TabStripModel::ADD_NONE);
1582 strip.AddTabContents(page_d_contents, -1, content::PAGE_TRANSITION_LINK, 1579 strip.AddTabContents(page_d_contents, -1, content::PAGE_TRANSITION_LINK,
1583 TabStripModel::ADD_NONE); 1580 TabStripModel::ADD_NONE);
1584 1581
1585 // Switch to page B's tab. 1582 // Switch to page B's tab.
1586 strip.ActivateTabAt(1, true); 1583 strip.ActivateTabAt(1, true);
1587 1584
1588 // Open a New Tab at the end of the strip (simulate Ctrl+T) 1585 // Open a New Tab at the end of the strip (simulate Ctrl+T)
1589 TabContentsWrapper* new_tab_contents = CreateTabContents(); 1586 TabContents* new_tab_contents = CreateTabContents();
1590 strip.AddTabContents(new_tab_contents, -1, content::PAGE_TRANSITION_TYPED, 1587 strip.AddTabContents(new_tab_contents, -1, content::PAGE_TRANSITION_TYPED,
1591 TabStripModel::ADD_ACTIVE); 1588 TabStripModel::ADD_ACTIVE);
1592 1589
1593 EXPECT_EQ(4, strip.GetIndexOfTabContents(new_tab_contents)); 1590 EXPECT_EQ(4, strip.GetIndexOfTabContents(new_tab_contents));
1594 EXPECT_EQ(4, strip.active_index()); 1591 EXPECT_EQ(4, strip.active_index());
1595 1592
1596 // Close the New Tab that was just opened. We should be returned to page B's 1593 // Close the New Tab that was just opened. We should be returned to page B's
1597 // Tab... 1594 // Tab...
1598 strip.CloseTabContentsAt(4, TabStripModel::CLOSE_NONE); 1595 strip.CloseTabContentsAt(4, TabStripModel::CLOSE_NONE);
1599 1596
1600 EXPECT_EQ(1, strip.active_index()); 1597 EXPECT_EQ(1, strip.active_index());
1601 1598
1602 // Open a non-New Tab tab at the end of the strip, with a TYPED transition. 1599 // Open a non-New Tab tab at the end of the strip, with a TYPED transition.
1603 // This is like typing a URL in the address bar and pressing Alt+Enter. The 1600 // This is like typing a URL in the address bar and pressing Alt+Enter. The
1604 // behavior should be the same as above. 1601 // behavior should be the same as above.
1605 TabContentsWrapper* page_e_contents = CreateTabContents(); 1602 TabContents* page_e_contents = CreateTabContents();
1606 strip.AddTabContents(page_e_contents, -1, content::PAGE_TRANSITION_TYPED, 1603 strip.AddTabContents(page_e_contents, -1, content::PAGE_TRANSITION_TYPED,
1607 TabStripModel::ADD_ACTIVE); 1604 TabStripModel::ADD_ACTIVE);
1608 1605
1609 EXPECT_EQ(4, strip.GetIndexOfTabContents(page_e_contents)); 1606 EXPECT_EQ(4, strip.GetIndexOfTabContents(page_e_contents));
1610 EXPECT_EQ(4, strip.active_index()); 1607 EXPECT_EQ(4, strip.active_index());
1611 1608
1612 // Close the Tab. Selection should shift back to page B's Tab. 1609 // Close the Tab. Selection should shift back to page B's Tab.
1613 strip.CloseTabContentsAt(4, TabStripModel::CLOSE_NONE); 1610 strip.CloseTabContentsAt(4, TabStripModel::CLOSE_NONE);
1614 1611
1615 EXPECT_EQ(1, strip.active_index()); 1612 EXPECT_EQ(1, strip.active_index());
1616 1613
1617 // Open a non-New Tab tab at the end of the strip, with some other 1614 // Open a non-New Tab tab at the end of the strip, with some other
1618 // transition. This is like right clicking on a bookmark and choosing "Open 1615 // transition. This is like right clicking on a bookmark and choosing "Open
1619 // in New Tab". No opener relationship should be preserved between this Tab 1616 // in New Tab". No opener relationship should be preserved between this Tab
1620 // and the one that was active when the gesture was performed. 1617 // and the one that was active when the gesture was performed.
1621 TabContentsWrapper* page_f_contents = CreateTabContents(); 1618 TabContents* page_f_contents = CreateTabContents();
1622 strip.AddTabContents(page_f_contents, -1, 1619 strip.AddTabContents(page_f_contents, -1,
1623 content::PAGE_TRANSITION_AUTO_BOOKMARK, 1620 content::PAGE_TRANSITION_AUTO_BOOKMARK,
1624 TabStripModel::ADD_ACTIVE); 1621 TabStripModel::ADD_ACTIVE);
1625 1622
1626 EXPECT_EQ(4, strip.GetIndexOfTabContents(page_f_contents)); 1623 EXPECT_EQ(4, strip.GetIndexOfTabContents(page_f_contents));
1627 EXPECT_EQ(4, strip.active_index()); 1624 EXPECT_EQ(4, strip.active_index());
1628 1625
1629 // Close the Tab. The next-adjacent should be selected. 1626 // Close the Tab. The next-adjacent should be selected.
1630 strip.CloseTabContentsAt(4, TabStripModel::CLOSE_NONE); 1627 strip.CloseTabContentsAt(4, TabStripModel::CLOSE_NONE);
1631 1628
1632 EXPECT_EQ(3, strip.active_index()); 1629 EXPECT_EQ(3, strip.active_index());
1633 1630
1634 // Clean up. 1631 // Clean up.
1635 strip.CloseAllTabs(); 1632 strip.CloseAllTabs();
1636 } 1633 }
1637 1634
1638 // A test of navigations in a tab that is part of a group of opened from some 1635 // A test of navigations in a tab that is part of a group of opened from some
1639 // parent tab. If the navigations are link clicks, the group relationship of 1636 // parent tab. If the navigations are link clicks, the group relationship of
1640 // the tab to its parent are preserved. If they are of any other type, they are 1637 // the tab to its parent are preserved. If they are of any other type, they are
1641 // not preserved. 1638 // not preserved.
1642 TEST_F(TabStripModelTest, NavigationForgetsOpeners) { 1639 TEST_F(TabStripModelTest, NavigationForgetsOpeners) {
1643 TabStripDummyDelegate delegate(NULL); 1640 TabStripDummyDelegate delegate(NULL);
1644 TabStripModel strip(&delegate, profile()); 1641 TabStripModel strip(&delegate, profile());
1645 1642
1646 // Open page A 1643 // Open page A
1647 TabContentsWrapper* page_a_contents = CreateTabContents(); 1644 TabContents* page_a_contents = CreateTabContents();
1648 strip.AddTabContents(page_a_contents, -1, content::PAGE_TRANSITION_START_PAGE, 1645 strip.AddTabContents(page_a_contents, -1, content::PAGE_TRANSITION_START_PAGE,
1649 TabStripModel::ADD_ACTIVE); 1646 TabStripModel::ADD_ACTIVE);
1650 1647
1651 // Open pages B, C and D in the background from links on page A... 1648 // Open pages B, C and D in the background from links on page A...
1652 TabContentsWrapper* page_b_contents = CreateTabContents(); 1649 TabContents* page_b_contents = CreateTabContents();
1653 TabContentsWrapper* page_c_contents = CreateTabContents(); 1650 TabContents* page_c_contents = CreateTabContents();
1654 TabContentsWrapper* page_d_contents = CreateTabContents(); 1651 TabContents* page_d_contents = CreateTabContents();
1655 strip.AddTabContents(page_b_contents, -1, content::PAGE_TRANSITION_LINK, 1652 strip.AddTabContents(page_b_contents, -1, content::PAGE_TRANSITION_LINK,
1656 TabStripModel::ADD_NONE); 1653 TabStripModel::ADD_NONE);
1657 strip.AddTabContents(page_c_contents, -1, content::PAGE_TRANSITION_LINK, 1654 strip.AddTabContents(page_c_contents, -1, content::PAGE_TRANSITION_LINK,
1658 TabStripModel::ADD_NONE); 1655 TabStripModel::ADD_NONE);
1659 strip.AddTabContents(page_d_contents, -1, content::PAGE_TRANSITION_LINK, 1656 strip.AddTabContents(page_d_contents, -1, content::PAGE_TRANSITION_LINK,
1660 TabStripModel::ADD_NONE); 1657 TabStripModel::ADD_NONE);
1661 1658
1662 // Open page E in a different opener group from page A. 1659 // Open page E in a different opener group from page A.
1663 TabContentsWrapper* page_e_contents = CreateTabContents(); 1660 TabContents* page_e_contents = CreateTabContents();
1664 strip.AddTabContents(page_e_contents, -1, content::PAGE_TRANSITION_START_PAGE, 1661 strip.AddTabContents(page_e_contents, -1, content::PAGE_TRANSITION_START_PAGE,
1665 TabStripModel::ADD_NONE); 1662 TabStripModel::ADD_NONE);
1666 1663
1667 // Tell the TabStripModel that we are navigating page D via a link click. 1664 // Tell the TabStripModel that we are navigating page D via a link click.
1668 strip.ActivateTabAt(3, true); 1665 strip.ActivateTabAt(3, true);
1669 strip.TabNavigating(page_d_contents, content::PAGE_TRANSITION_LINK); 1666 strip.TabNavigating(page_d_contents, content::PAGE_TRANSITION_LINK);
1670 1667
1671 // Close page D, page C should be selected. (part of same group). 1668 // Close page D, page C should be selected. (part of same group).
1672 strip.CloseTabContentsAt(3, TabStripModel::CLOSE_NONE); 1669 strip.CloseTabContentsAt(3, TabStripModel::CLOSE_NONE);
1673 EXPECT_EQ(2, strip.active_index()); 1670 EXPECT_EQ(2, strip.active_index());
(...skipping 12 matching lines...) Expand all
1686 // A test that the forgetting behavior tested in NavigationForgetsOpeners above 1683 // A test that the forgetting behavior tested in NavigationForgetsOpeners above
1687 // doesn't cause the opener relationship for a New Tab opened at the end of the 1684 // doesn't cause the opener relationship for a New Tab opened at the end of the
1688 // TabStrip to be reset (Test 1 below), unless another any other tab is 1685 // TabStrip to be reset (Test 1 below), unless another any other tab is
1689 // seelcted (Test 2 below). 1686 // seelcted (Test 2 below).
1690 TEST_F(TabStripModelTest, NavigationForgettingDoesntAffectNewTab) { 1687 TEST_F(TabStripModelTest, NavigationForgettingDoesntAffectNewTab) {
1691 TabStripDummyDelegate delegate(NULL); 1688 TabStripDummyDelegate delegate(NULL);
1692 TabStripModel strip(&delegate, profile()); 1689 TabStripModel strip(&delegate, profile());
1693 1690
1694 // Open a tab and several tabs from it, then select one of the tabs that was 1691 // Open a tab and several tabs from it, then select one of the tabs that was
1695 // opened. 1692 // opened.
1696 TabContentsWrapper* page_a_contents = CreateTabContents(); 1693 TabContents* page_a_contents = CreateTabContents();
1697 strip.AddTabContents(page_a_contents, -1, content::PAGE_TRANSITION_START_PAGE, 1694 strip.AddTabContents(page_a_contents, -1, content::PAGE_TRANSITION_START_PAGE,
1698 TabStripModel::ADD_ACTIVE); 1695 TabStripModel::ADD_ACTIVE);
1699 1696
1700 TabContentsWrapper* page_b_contents = CreateTabContents(); 1697 TabContents* page_b_contents = CreateTabContents();
1701 TabContentsWrapper* page_c_contents = CreateTabContents(); 1698 TabContents* page_c_contents = CreateTabContents();
1702 TabContentsWrapper* page_d_contents = CreateTabContents(); 1699 TabContents* page_d_contents = CreateTabContents();
1703 strip.AddTabContents(page_b_contents, -1, content::PAGE_TRANSITION_LINK, 1700 strip.AddTabContents(page_b_contents, -1, content::PAGE_TRANSITION_LINK,
1704 TabStripModel::ADD_NONE); 1701 TabStripModel::ADD_NONE);
1705 strip.AddTabContents(page_c_contents, -1, content::PAGE_TRANSITION_LINK, 1702 strip.AddTabContents(page_c_contents, -1, content::PAGE_TRANSITION_LINK,
1706 TabStripModel::ADD_NONE); 1703 TabStripModel::ADD_NONE);
1707 strip.AddTabContents(page_d_contents, -1, content::PAGE_TRANSITION_LINK, 1704 strip.AddTabContents(page_d_contents, -1, content::PAGE_TRANSITION_LINK,
1708 TabStripModel::ADD_NONE); 1705 TabStripModel::ADD_NONE);
1709 1706
1710 strip.ActivateTabAt(2, true); 1707 strip.ActivateTabAt(2, true);
1711 1708
1712 // TEST 1: If the user is in a group of tabs and opens a new tab at the end 1709 // TEST 1: If the user is in a group of tabs and opens a new tab at the end
1713 // of the strip, closing that new tab will select the tab that they were 1710 // of the strip, closing that new tab will select the tab that they were
1714 // last on. 1711 // last on.
1715 1712
1716 // Now simulate opening a new tab at the end of the TabStrip. 1713 // Now simulate opening a new tab at the end of the TabStrip.
1717 TabContentsWrapper* new_tab_contents1 = CreateTabContents(); 1714 TabContents* new_tab_contents1 = CreateTabContents();
1718 strip.AddTabContents(new_tab_contents1, -1, content::PAGE_TRANSITION_TYPED, 1715 strip.AddTabContents(new_tab_contents1, -1, content::PAGE_TRANSITION_TYPED,
1719 TabStripModel::ADD_ACTIVE); 1716 TabStripModel::ADD_ACTIVE);
1720 1717
1721 // At this point, if we close this tab the last selected one should be 1718 // At this point, if we close this tab the last selected one should be
1722 // re-selected. 1719 // re-selected.
1723 strip.CloseTabContentsAt(strip.count() - 1, TabStripModel::CLOSE_NONE); 1720 strip.CloseTabContentsAt(strip.count() - 1, TabStripModel::CLOSE_NONE);
1724 EXPECT_EQ(page_c_contents, strip.GetTabContentsAt(strip.active_index())); 1721 EXPECT_EQ(page_c_contents, strip.GetTabContentsAt(strip.active_index()));
1725 1722
1726 // TEST 2: If the user is in a group of tabs and opens a new tab at the end 1723 // TEST 2: If the user is in a group of tabs and opens a new tab at the end
1727 // of the strip, selecting any other tab in the strip will cause that new 1724 // of the strip, selecting any other tab in the strip will cause that new
1728 // tab's opener relationship to be forgotten. 1725 // tab's opener relationship to be forgotten.
1729 1726
1730 // Open a new tab again. 1727 // Open a new tab again.
1731 TabContentsWrapper* new_tab_contents2 = CreateTabContents(); 1728 TabContents* new_tab_contents2 = CreateTabContents();
1732 strip.AddTabContents(new_tab_contents2, -1, content::PAGE_TRANSITION_TYPED, 1729 strip.AddTabContents(new_tab_contents2, -1, content::PAGE_TRANSITION_TYPED,
1733 TabStripModel::ADD_ACTIVE); 1730 TabStripModel::ADD_ACTIVE);
1734 1731
1735 // Now select the first tab. 1732 // Now select the first tab.
1736 strip.ActivateTabAt(0, true); 1733 strip.ActivateTabAt(0, true);
1737 1734
1738 // Now select the last tab. 1735 // Now select the last tab.
1739 strip.ActivateTabAt(strip.count() - 1, true); 1736 strip.ActivateTabAt(strip.count() - 1, true);
1740 1737
1741 // Now close the last tab. The next adjacent should be selected. 1738 // Now close the last tab. The next adjacent should be selected.
1742 strip.CloseTabContentsAt(strip.count() - 1, TabStripModel::CLOSE_NONE); 1739 strip.CloseTabContentsAt(strip.count() - 1, TabStripModel::CLOSE_NONE);
1743 EXPECT_EQ(page_d_contents, strip.GetTabContentsAt(strip.active_index())); 1740 EXPECT_EQ(page_d_contents, strip.GetTabContentsAt(strip.active_index()));
1744 1741
1745 strip.CloseAllTabs(); 1742 strip.CloseAllTabs();
1746 } 1743 }
1747 1744
1748 // Tests that fast shutdown is attempted appropriately. 1745 // Tests that fast shutdown is attempted appropriately.
1749 TEST_F(TabStripModelTest, FastShutdown) { 1746 TEST_F(TabStripModelTest, FastShutdown) {
1750 TabStripDummyDelegate delegate(NULL); 1747 TabStripDummyDelegate delegate(NULL);
1751 TabStripModel tabstrip(&delegate, profile()); 1748 TabStripModel tabstrip(&delegate, profile());
1752 MockTabStripModelObserver observer(&tabstrip); 1749 MockTabStripModelObserver observer(&tabstrip);
1753 tabstrip.AddObserver(&observer); 1750 tabstrip.AddObserver(&observer);
1754 1751
1755 EXPECT_TRUE(tabstrip.empty()); 1752 EXPECT_TRUE(tabstrip.empty());
1756 1753
1757 // Make sure fast shutdown is attempted when tabs that share a RPH are shut 1754 // Make sure fast shutdown is attempted when tabs that share a RPH are shut
1758 // down. 1755 // down.
1759 { 1756 {
1760 TabContentsWrapper* contents1 = CreateTabContents(); 1757 TabContents* contents1 = CreateTabContents();
1761 TabContentsWrapper* contents2 = 1758 TabContents* contents2 =
1762 CreateTabContentsWithSharedRPH(contents1->web_contents()); 1759 CreateTabContentsWithSharedRPH(contents1->web_contents());
1763 1760
1764 SetID(contents1->web_contents(), 1); 1761 SetID(contents1->web_contents(), 1);
1765 SetID(contents2->web_contents(), 2); 1762 SetID(contents2->web_contents(), 2);
1766 1763
1767 tabstrip.AppendTabContents(contents1, true); 1764 tabstrip.AppendTabContents(contents1, true);
1768 tabstrip.AppendTabContents(contents2, true); 1765 tabstrip.AppendTabContents(contents2, true);
1769 1766
1770 // Turn on the fake unload listener so the tabs don't actually get shut 1767 // Turn on the fake unload listener so the tabs don't actually get shut
1771 // down when we call CloseAllTabs()---we need to be able to check that 1768 // down when we call CloseAllTabs()---we need to be able to check that
1772 // fast shutdown was attempted. 1769 // fast shutdown was attempted.
1773 delegate.set_run_unload_listener(true); 1770 delegate.set_run_unload_listener(true);
1774 tabstrip.CloseAllTabs(); 1771 tabstrip.CloseAllTabs();
1775 // On a mock RPH this checks whether we *attempted* fast shutdown. 1772 // On a mock RPH this checks whether we *attempted* fast shutdown.
1776 // A real RPH would reject our attempt since there is an unload handler. 1773 // A real RPH would reject our attempt since there is an unload handler.
1777 EXPECT_TRUE(contents1->web_contents()-> 1774 EXPECT_TRUE(contents1->web_contents()->
1778 GetRenderProcessHost()->FastShutdownStarted()); 1775 GetRenderProcessHost()->FastShutdownStarted());
1779 EXPECT_EQ(2, tabstrip.count()); 1776 EXPECT_EQ(2, tabstrip.count());
1780 1777
1781 delegate.set_run_unload_listener(false); 1778 delegate.set_run_unload_listener(false);
1782 tabstrip.CloseAllTabs(); 1779 tabstrip.CloseAllTabs();
1783 EXPECT_TRUE(tabstrip.empty()); 1780 EXPECT_TRUE(tabstrip.empty());
1784 } 1781 }
1785 1782
1786 // Make sure fast shutdown is not attempted when only some tabs that share a 1783 // Make sure fast shutdown is not attempted when only some tabs that share a
1787 // RPH are shut down. 1784 // RPH are shut down.
1788 { 1785 {
1789 TabContentsWrapper* contents1 = CreateTabContents(); 1786 TabContents* contents1 = CreateTabContents();
1790 TabContentsWrapper* contents2 = 1787 TabContents* contents2 =
1791 CreateTabContentsWithSharedRPH(contents1->web_contents()); 1788 CreateTabContentsWithSharedRPH(contents1->web_contents());
1792 1789
1793 SetID(contents1->web_contents(), 1); 1790 SetID(contents1->web_contents(), 1);
1794 SetID(contents2->web_contents(), 2); 1791 SetID(contents2->web_contents(), 2);
1795 1792
1796 tabstrip.AppendTabContents(contents1, true); 1793 tabstrip.AppendTabContents(contents1, true);
1797 tabstrip.AppendTabContents(contents2, true); 1794 tabstrip.AppendTabContents(contents2, true);
1798 1795
1799 tabstrip.CloseTabContentsAt(1, TabStripModel::CLOSE_NONE); 1796 tabstrip.CloseTabContentsAt(1, TabStripModel::CLOSE_NONE);
1800 EXPECT_FALSE(contents1->web_contents()-> 1797 EXPECT_FALSE(contents1->web_contents()->
(...skipping 23 matching lines...) Expand all
1824 #endif 1821 #endif
1825 1822
1826 DictionaryValue manifest; 1823 DictionaryValue manifest;
1827 manifest.SetString("name", "hi!"); 1824 manifest.SetString("name", "hi!");
1828 manifest.SetString("version", "1"); 1825 manifest.SetString("version", "1");
1829 std::string error; 1826 std::string error;
1830 scoped_refptr<Extension> extension_app( 1827 scoped_refptr<Extension> extension_app(
1831 Extension::Create(path, Extension::INVALID, manifest, Extension::NO_FLAGS, 1828 Extension::Create(path, Extension::INVALID, manifest, Extension::NO_FLAGS,
1832 &error)); 1829 &error));
1833 extension_app->launch_web_url_ = "http://www.google.com"; 1830 extension_app->launch_web_url_ = "http://www.google.com";
1834 TabContentsWrapper* contents1 = CreateTabContents(); 1831 TabContents* contents1 = CreateTabContents();
1835 contents1->extension_tab_helper()->SetExtensionApp(extension_app); 1832 contents1->extension_tab_helper()->SetExtensionApp(extension_app);
1836 TabContentsWrapper* contents2 = CreateTabContents(); 1833 TabContents* contents2 = CreateTabContents();
1837 contents2->extension_tab_helper()->SetExtensionApp(extension_app); 1834 contents2->extension_tab_helper()->SetExtensionApp(extension_app);
1838 TabContentsWrapper* contents3 = CreateTabContents(); 1835 TabContents* contents3 = CreateTabContents();
1839 1836
1840 SetID(contents1->web_contents(), 1); 1837 SetID(contents1->web_contents(), 1);
1841 SetID(contents2->web_contents(), 2); 1838 SetID(contents2->web_contents(), 2);
1842 SetID(contents3->web_contents(), 3); 1839 SetID(contents3->web_contents(), 3);
1843 1840
1844 // Note! The ordering of these tests is important, each subsequent test 1841 // Note! The ordering of these tests is important, each subsequent test
1845 // builds on the state established in the previous. This is important if you 1842 // builds on the state established in the previous. This is important if you
1846 // ever insert tests rather than append. 1843 // ever insert tests rather than append.
1847 1844
1848 // Initial state, tab3 only and selected. 1845 // Initial state, tab3 only and selected.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1942 TEST_F(TabStripModelTest, Pinning) { 1939 TEST_F(TabStripModelTest, Pinning) {
1943 TabStripDummyDelegate delegate(NULL); 1940 TabStripDummyDelegate delegate(NULL);
1944 TabStripModel tabstrip(&delegate, profile()); 1941 TabStripModel tabstrip(&delegate, profile());
1945 MockTabStripModelObserver observer(&tabstrip); 1942 MockTabStripModelObserver observer(&tabstrip);
1946 tabstrip.AddObserver(&observer); 1943 tabstrip.AddObserver(&observer);
1947 1944
1948 EXPECT_TRUE(tabstrip.empty()); 1945 EXPECT_TRUE(tabstrip.empty());
1949 1946
1950 typedef MockTabStripModelObserver::State State; 1947 typedef MockTabStripModelObserver::State State;
1951 1948
1952 TabContentsWrapper* contents1 = CreateTabContents(); 1949 TabContents* contents1 = CreateTabContents();
1953 TabContentsWrapper* contents2 = CreateTabContents(); 1950 TabContents* contents2 = CreateTabContents();
1954 TabContentsWrapper* contents3 = CreateTabContents(); 1951 TabContents* contents3 = CreateTabContents();
1955 1952
1956 SetID(contents1->web_contents(), 1); 1953 SetID(contents1->web_contents(), 1);
1957 SetID(contents2->web_contents(), 2); 1954 SetID(contents2->web_contents(), 2);
1958 SetID(contents3->web_contents(), 3); 1955 SetID(contents3->web_contents(), 3);
1959 1956
1960 // Note! The ordering of these tests is important, each subsequent test 1957 // Note! The ordering of these tests is important, each subsequent test
1961 // builds on the state established in the previous. This is important if you 1958 // builds on the state established in the previous. This is important if you
1962 // ever insert tests rather than append. 1959 // ever insert tests rather than append.
1963 1960
1964 // Initial state, three tabs, first selected. 1961 // Initial state, three tabs, first selected.
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
2077 // Pin "3" and "1". 2074 // Pin "3" and "1".
2078 { 2075 {
2079 tabstrip.SetTabPinned(0, true); 2076 tabstrip.SetTabPinned(0, true);
2080 tabstrip.SetTabPinned(1, true); 2077 tabstrip.SetTabPinned(1, true);
2081 2078
2082 EXPECT_EQ("1p 3p 2", GetPinnedState(tabstrip)); 2079 EXPECT_EQ("1p 3p 2", GetPinnedState(tabstrip));
2083 2080
2084 observer.ClearStates(); 2081 observer.ClearStates();
2085 } 2082 }
2086 2083
2087 TabContentsWrapper* contents4 = CreateTabContents(); 2084 TabContents* contents4 = CreateTabContents();
2088 SetID(contents4->web_contents(), 4); 2085 SetID(contents4->web_contents(), 4);
2089 2086
2090 // Insert "4" between "1" and "3". As "1" and "4" are pinned, "4" should end 2087 // Insert "4" between "1" and "3". As "1" and "4" are pinned, "4" should end
2091 // up after them. 2088 // up after them.
2092 { 2089 {
2093 tabstrip.InsertTabContentsAt(1, contents4, TabStripModel::ADD_NONE); 2090 tabstrip.InsertTabContentsAt(1, contents4, TabStripModel::ADD_NONE);
2094 2091
2095 ASSERT_EQ(1, observer.GetStateCount()); 2092 ASSERT_EQ(1, observer.GetStateCount());
2096 State state(contents4, 2, MockTabStripModelObserver::INSERT); 2093 State state(contents4, 2, MockTabStripModelObserver::INSERT);
2097 EXPECT_TRUE(observer.StateEquals(0, state)); 2094 EXPECT_TRUE(observer.StateEquals(0, state));
2098 2095
2099 EXPECT_EQ("1p 3p 4 2", GetPinnedState(tabstrip)); 2096 EXPECT_EQ("1p 3p 4 2", GetPinnedState(tabstrip));
2100 } 2097 }
2101 2098
2102 tabstrip.CloseAllTabs(); 2099 tabstrip.CloseAllTabs();
2103 } 2100 }
2104 2101
2105 // Makes sure the TabStripModel calls the right observer methods during a 2102 // Makes sure the TabStripModel calls the right observer methods during a
2106 // replace. 2103 // replace.
2107 TEST_F(TabStripModelTest, ReplaceSendsSelected) { 2104 TEST_F(TabStripModelTest, ReplaceSendsSelected) {
2108 typedef MockTabStripModelObserver::State State; 2105 typedef MockTabStripModelObserver::State State;
2109 2106
2110 TabStripDummyDelegate delegate(NULL); 2107 TabStripDummyDelegate delegate(NULL);
2111 TabStripModel strip(&delegate, profile()); 2108 TabStripModel strip(&delegate, profile());
2112 2109
2113 TabContentsWrapper* first_contents = CreateTabContents(); 2110 TabContents* first_contents = CreateTabContents();
2114 strip.AddTabContents(first_contents, -1, content::PAGE_TRANSITION_TYPED, 2111 strip.AddTabContents(first_contents, -1, content::PAGE_TRANSITION_TYPED,
2115 TabStripModel::ADD_ACTIVE); 2112 TabStripModel::ADD_ACTIVE);
2116 2113
2117 MockTabStripModelObserver tabstrip_observer(&strip); 2114 MockTabStripModelObserver tabstrip_observer(&strip);
2118 strip.AddObserver(&tabstrip_observer); 2115 strip.AddObserver(&tabstrip_observer);
2119 2116
2120 TabContentsWrapper* new_contents = CreateTabContents(); 2117 TabContents* new_contents = CreateTabContents();
2121 delete strip.ReplaceTabContentsAt(0, new_contents); 2118 delete strip.ReplaceTabContentsAt(0, new_contents);
2122 2119
2123 ASSERT_EQ(2, tabstrip_observer.GetStateCount()); 2120 ASSERT_EQ(2, tabstrip_observer.GetStateCount());
2124 2121
2125 // First event should be for replaced. 2122 // First event should be for replaced.
2126 State state(new_contents, 0, MockTabStripModelObserver::REPLACED); 2123 State state(new_contents, 0, MockTabStripModelObserver::REPLACED);
2127 state.src_contents = first_contents; 2124 state.src_contents = first_contents;
2128 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state)); 2125 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state));
2129 2126
2130 // And the second for selected. 2127 // And the second for selected.
2131 state = State(new_contents, 0, MockTabStripModelObserver::ACTIVATE); 2128 state = State(new_contents, 0, MockTabStripModelObserver::ACTIVATE);
2132 state.src_contents = first_contents; 2129 state.src_contents = first_contents;
2133 EXPECT_TRUE(tabstrip_observer.StateEquals(1, state)); 2130 EXPECT_TRUE(tabstrip_observer.StateEquals(1, state));
2134 2131
2135 // Now add another tab and replace it, making sure we don't get a selected 2132 // Now add another tab and replace it, making sure we don't get a selected
2136 // event this time. 2133 // event this time.
2137 TabContentsWrapper* third_contents = CreateTabContents(); 2134 TabContents* third_contents = CreateTabContents();
2138 strip.AddTabContents(third_contents, 1, content::PAGE_TRANSITION_TYPED, 2135 strip.AddTabContents(third_contents, 1, content::PAGE_TRANSITION_TYPED,
2139 TabStripModel::ADD_NONE); 2136 TabStripModel::ADD_NONE);
2140 2137
2141 tabstrip_observer.ClearStates(); 2138 tabstrip_observer.ClearStates();
2142 2139
2143 // And replace it. 2140 // And replace it.
2144 new_contents = CreateTabContents(); 2141 new_contents = CreateTabContents();
2145 delete strip.ReplaceTabContentsAt(1, new_contents); 2142 delete strip.ReplaceTabContentsAt(1, new_contents);
2146 2143
2147 ASSERT_EQ(1, tabstrip_observer.GetStateCount()); 2144 ASSERT_EQ(1, tabstrip_observer.GetStateCount());
2148 2145
2149 state = State(new_contents, 1, MockTabStripModelObserver::REPLACED); 2146 state = State(new_contents, 1, MockTabStripModelObserver::REPLACED);
2150 state.src_contents = third_contents; 2147 state.src_contents = third_contents;
2151 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state)); 2148 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state));
2152 2149
2153 strip.CloseAllTabs(); 2150 strip.CloseAllTabs();
2154 } 2151 }
2155 2152
2156 // Ensures discarding tabs leaves TabStripModel in a good state. 2153 // Ensures discarding tabs leaves TabStripModel in a good state.
2157 TEST_F(TabStripModelTest, DiscardTabContentsAt) { 2154 TEST_F(TabStripModelTest, DiscardTabContentsAt) {
2158 typedef MockTabStripModelObserver::State State; 2155 typedef MockTabStripModelObserver::State State;
2159 2156
2160 TabStripDummyDelegate delegate(NULL); 2157 TabStripDummyDelegate delegate(NULL);
2161 TabStripModel tabstrip(&delegate, profile()); 2158 TabStripModel tabstrip(&delegate, profile());
2162 2159
2163 // Fill it with some tabs. 2160 // Fill it with some tabs.
2164 TabContentsWrapper* contents1 = CreateTabContents(); 2161 TabContents* contents1 = CreateTabContents();
2165 tabstrip.AppendTabContents(contents1, true); 2162 tabstrip.AppendTabContents(contents1, true);
2166 TabContentsWrapper* contents2 = CreateTabContents(); 2163 TabContents* contents2 = CreateTabContents();
2167 tabstrip.AppendTabContents(contents2, true); 2164 tabstrip.AppendTabContents(contents2, true);
2168 2165
2169 // Start watching for events after the appends to avoid observing state 2166 // Start watching for events after the appends to avoid observing state
2170 // transitions that aren't relevant to this test. 2167 // transitions that aren't relevant to this test.
2171 MockTabStripModelObserver tabstrip_observer(&tabstrip); 2168 MockTabStripModelObserver tabstrip_observer(&tabstrip);
2172 tabstrip.AddObserver(&tabstrip_observer); 2169 tabstrip.AddObserver(&tabstrip_observer);
2173 2170
2174 // Discard one of the tabs. 2171 // Discard one of the tabs.
2175 TabContentsWrapper* null_contents1 = tabstrip.DiscardTabContentsAt(0); 2172 TabContents* null_contents1 = tabstrip.DiscardTabContentsAt(0);
2176 ASSERT_EQ(2, tabstrip.count()); 2173 ASSERT_EQ(2, tabstrip.count());
2177 EXPECT_TRUE(tabstrip.IsTabDiscarded(0)); 2174 EXPECT_TRUE(tabstrip.IsTabDiscarded(0));
2178 EXPECT_FALSE(tabstrip.IsTabDiscarded(1)); 2175 EXPECT_FALSE(tabstrip.IsTabDiscarded(1));
2179 ASSERT_EQ(null_contents1, tabstrip.GetTabContentsAt(0)); 2176 ASSERT_EQ(null_contents1, tabstrip.GetTabContentsAt(0));
2180 ASSERT_EQ(contents2, tabstrip.GetTabContentsAt(1)); 2177 ASSERT_EQ(contents2, tabstrip.GetTabContentsAt(1));
2181 ASSERT_EQ(1, tabstrip_observer.GetStateCount()); 2178 ASSERT_EQ(1, tabstrip_observer.GetStateCount());
2182 State state1(null_contents1, 0, MockTabStripModelObserver::REPLACED); 2179 State state1(null_contents1, 0, MockTabStripModelObserver::REPLACED);
2183 state1.src_contents = contents1; 2180 state1.src_contents = contents1;
2184 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state1)); 2181 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state1));
2185 tabstrip_observer.ClearStates(); 2182 tabstrip_observer.ClearStates();
2186 2183
2187 // Discard the same tab again. 2184 // Discard the same tab again.
2188 TabContentsWrapper* null_contents2 = tabstrip.DiscardTabContentsAt(0); 2185 TabContents* null_contents2 = tabstrip.DiscardTabContentsAt(0);
2189 ASSERT_EQ(2, tabstrip.count()); 2186 ASSERT_EQ(2, tabstrip.count());
2190 EXPECT_TRUE(tabstrip.IsTabDiscarded(0)); 2187 EXPECT_TRUE(tabstrip.IsTabDiscarded(0));
2191 EXPECT_FALSE(tabstrip.IsTabDiscarded(1)); 2188 EXPECT_FALSE(tabstrip.IsTabDiscarded(1));
2192 ASSERT_EQ(null_contents2, tabstrip.GetTabContentsAt(0)); 2189 ASSERT_EQ(null_contents2, tabstrip.GetTabContentsAt(0));
2193 ASSERT_EQ(contents2, tabstrip.GetTabContentsAt(1)); 2190 ASSERT_EQ(contents2, tabstrip.GetTabContentsAt(1));
2194 ASSERT_EQ(1, tabstrip_observer.GetStateCount()); 2191 ASSERT_EQ(1, tabstrip_observer.GetStateCount());
2195 State state2(null_contents2, 0, MockTabStripModelObserver::REPLACED); 2192 State state2(null_contents2, 0, MockTabStripModelObserver::REPLACED);
2196 state2.src_contents = null_contents1; 2193 state2.src_contents = null_contents1;
2197 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state2)); 2194 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state2));
2198 tabstrip_observer.ClearStates(); 2195 tabstrip_observer.ClearStates();
2199 2196
2200 // Activating the tab should clear its discard state. 2197 // Activating the tab should clear its discard state.
2201 tabstrip.ActivateTabAt(0, true /* user_gesture */); 2198 tabstrip.ActivateTabAt(0, true /* user_gesture */);
2202 ASSERT_EQ(2, tabstrip.count()); 2199 ASSERT_EQ(2, tabstrip.count());
2203 EXPECT_FALSE(tabstrip.IsTabDiscarded(0)); 2200 EXPECT_FALSE(tabstrip.IsTabDiscarded(0));
2204 EXPECT_FALSE(tabstrip.IsTabDiscarded(1)); 2201 EXPECT_FALSE(tabstrip.IsTabDiscarded(1));
2205 2202
2206 // Discarding the active tab should not crash. 2203 // Discarding the active tab should not crash.
2207 TabContentsWrapper* null_contents3 = tabstrip.DiscardTabContentsAt(0); 2204 TabContents* null_contents3 = tabstrip.DiscardTabContentsAt(0);
2208 ASSERT_EQ(2, tabstrip.count()); 2205 ASSERT_EQ(2, tabstrip.count());
2209 EXPECT_TRUE(tabstrip.IsTabDiscarded(0)); 2206 EXPECT_TRUE(tabstrip.IsTabDiscarded(0));
2210 EXPECT_FALSE(tabstrip.IsTabDiscarded(1)); 2207 EXPECT_FALSE(tabstrip.IsTabDiscarded(1));
2211 ASSERT_EQ(null_contents3, tabstrip.GetTabContentsAt(0)); 2208 ASSERT_EQ(null_contents3, tabstrip.GetTabContentsAt(0));
2212 2209
2213 tabstrip.CloseAllTabs(); 2210 tabstrip.CloseAllTabs();
2214 } 2211 }
2215 2212
2216 // Makes sure TabStripModel handles the case of deleting a tab while removing 2213 // Makes sure TabStripModel handles the case of deleting a tab while removing
2217 // another tab. 2214 // another tab.
2218 TEST_F(TabStripModelTest, DeleteFromDestroy) { 2215 TEST_F(TabStripModelTest, DeleteFromDestroy) {
2219 TabStripDummyDelegate delegate(NULL); 2216 TabStripDummyDelegate delegate(NULL);
2220 TabStripModel strip(&delegate, profile()); 2217 TabStripModel strip(&delegate, profile());
2221 TabContentsWrapper* contents1 = CreateTabContents(); 2218 TabContents* contents1 = CreateTabContents();
2222 TabContentsWrapper* contents2 = CreateTabContents(); 2219 TabContents* contents2 = CreateTabContents();
2223 strip.AppendTabContents(contents1, true); 2220 strip.AppendTabContents(contents1, true);
2224 strip.AppendTabContents(contents2, true); 2221 strip.AppendTabContents(contents2, true);
2225 // DeleteTabContentsOnDestroyedObserver deletes contents1 when contents2 sends 2222 // DeleteTabContentsOnDestroyedObserver deletes contents1 when contents2 sends
2226 // out notification that it is being destroyed. 2223 // out notification that it is being destroyed.
2227 DeleteTabContentsOnDestroyedObserver observer(contents2, contents1); 2224 DeleteTabContentsOnDestroyedObserver observer(contents2, contents1);
2228 strip.CloseAllTabs(); 2225 strip.CloseAllTabs();
2229 } 2226 }
2230 2227
2231 TEST_F(TabStripModelTest, MoveSelectedTabsTo) { 2228 TEST_F(TabStripModelTest, MoveSelectedTabsTo) {
2232 struct TestData { 2229 struct TestData {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2287 test_data[i].selected_tabs)); 2284 test_data[i].selected_tabs));
2288 strip.MoveSelectedTabsTo(test_data[i].target_index); 2285 strip.MoveSelectedTabsTo(test_data[i].target_index);
2289 EXPECT_EQ(test_data[i].state_after_move, GetPinnedState(strip)) << i; 2286 EXPECT_EQ(test_data[i].state_after_move, GetPinnedState(strip)) << i;
2290 strip.CloseAllTabs(); 2287 strip.CloseAllTabs();
2291 } 2288 }
2292 } 2289 }
2293 2290
2294 TEST_F(TabStripModelTest, CloseSelectedTabs) { 2291 TEST_F(TabStripModelTest, CloseSelectedTabs) {
2295 TabStripDummyDelegate delegate(NULL); 2292 TabStripDummyDelegate delegate(NULL);
2296 TabStripModel strip(&delegate, profile()); 2293 TabStripModel strip(&delegate, profile());
2297 TabContentsWrapper* contents1 = CreateTabContents(); 2294 TabContents* contents1 = CreateTabContents();
2298 TabContentsWrapper* contents2 = CreateTabContents(); 2295 TabContents* contents2 = CreateTabContents();
2299 TabContentsWrapper* contents3 = CreateTabContents(); 2296 TabContents* contents3 = CreateTabContents();
2300 strip.AppendTabContents(contents1, true); 2297 strip.AppendTabContents(contents1, true);
2301 strip.AppendTabContents(contents2, true); 2298 strip.AppendTabContents(contents2, true);
2302 strip.AppendTabContents(contents3, true); 2299 strip.AppendTabContents(contents3, true);
2303 strip.ToggleSelectionAt(1); 2300 strip.ToggleSelectionAt(1);
2304 strip.CloseSelectedTabs(); 2301 strip.CloseSelectedTabs();
2305 EXPECT_EQ(1, strip.count()); 2302 EXPECT_EQ(1, strip.count());
2306 EXPECT_EQ(0, strip.active_index()); 2303 EXPECT_EQ(0, strip.active_index());
2307 strip.CloseAllTabs(); 2304 strip.CloseAllTabs();
2308 } 2305 }
2309 2306
2310 TEST_F(TabStripModelTest, MultipleSelection) { 2307 TEST_F(TabStripModelTest, MultipleSelection) {
2311 TabStripDummyDelegate delegate(NULL); 2308 TabStripDummyDelegate delegate(NULL);
2312 TabStripModel strip(&delegate, profile()); 2309 TabStripModel strip(&delegate, profile());
2313 MockTabStripModelObserver observer(&strip); 2310 MockTabStripModelObserver observer(&strip);
2314 TabContentsWrapper* contents0 = CreateTabContents(); 2311 TabContents* contents0 = CreateTabContents();
2315 TabContentsWrapper* contents1 = CreateTabContents(); 2312 TabContents* contents1 = CreateTabContents();
2316 TabContentsWrapper* contents2 = CreateTabContents(); 2313 TabContents* contents2 = CreateTabContents();
2317 TabContentsWrapper* contents3 = CreateTabContents(); 2314 TabContents* contents3 = CreateTabContents();
2318 strip.AppendTabContents(contents0, false); 2315 strip.AppendTabContents(contents0, false);
2319 strip.AppendTabContents(contents1, false); 2316 strip.AppendTabContents(contents1, false);
2320 strip.AppendTabContents(contents2, false); 2317 strip.AppendTabContents(contents2, false);
2321 strip.AppendTabContents(contents3, false); 2318 strip.AppendTabContents(contents3, false);
2322 strip.AddObserver(&observer); 2319 strip.AddObserver(&observer);
2323 2320
2324 // Selection and active tab change. 2321 // Selection and active tab change.
2325 strip.ActivateTabAt(3, true); 2322 strip.ActivateTabAt(3, true);
2326 ASSERT_EQ(2, observer.GetStateCount()); 2323 ASSERT_EQ(2, observer.GetStateCount());
2327 ASSERT_EQ(observer.GetStateAt(0)->action, 2324 ASSERT_EQ(observer.GetStateAt(0)->action,
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
2417 strip.RemoveObserver(&observer); 2414 strip.RemoveObserver(&observer);
2418 strip.CloseAllTabs(); 2415 strip.CloseAllTabs();
2419 } 2416 }
2420 2417
2421 // Verifies that if we change the selection from a multi selection to a single 2418 // Verifies that if we change the selection from a multi selection to a single
2422 // selection, but not in a way that changes the selected_index that 2419 // selection, but not in a way that changes the selected_index that
2423 // TabSelectionChanged is invoked. 2420 // TabSelectionChanged is invoked.
2424 TEST_F(TabStripModelTest, MultipleToSingle) { 2421 TEST_F(TabStripModelTest, MultipleToSingle) {
2425 TabStripDummyDelegate delegate(NULL); 2422 TabStripDummyDelegate delegate(NULL);
2426 TabStripModel strip(&delegate, profile()); 2423 TabStripModel strip(&delegate, profile());
2427 TabContentsWrapper* contents1 = CreateTabContents(); 2424 TabContents* contents1 = CreateTabContents();
2428 TabContentsWrapper* contents2 = CreateTabContents(); 2425 TabContents* contents2 = CreateTabContents();
2429 strip.AppendTabContents(contents1, false); 2426 strip.AppendTabContents(contents1, false);
2430 strip.AppendTabContents(contents2, false); 2427 strip.AppendTabContents(contents2, false);
2431 strip.ToggleSelectionAt(0); 2428 strip.ToggleSelectionAt(0);
2432 strip.ToggleSelectionAt(1); 2429 strip.ToggleSelectionAt(1);
2433 2430
2434 MockTabStripModelObserver observer(&strip); 2431 MockTabStripModelObserver observer(&strip);
2435 strip.AddObserver(&observer); 2432 strip.AddObserver(&observer);
2436 // This changes the selection (0 is no longer selected) but the selected_index 2433 // This changes the selection (0 is no longer selected) but the selected_index
2437 // still remains at 1. 2434 // still remains at 1.
2438 strip.ActivateTabAt(1, true); 2435 strip.ActivateTabAt(1, true);
2439 ASSERT_EQ(1, observer.GetStateCount()); 2436 ASSERT_EQ(1, observer.GetStateCount());
2440 MockTabStripModelObserver::State s( 2437 MockTabStripModelObserver::State s(
2441 contents2, 1, MockTabStripModelObserver::SELECT); 2438 contents2, 1, MockTabStripModelObserver::SELECT);
2442 s.src_contents = contents2; 2439 s.src_contents = contents2;
2443 s.src_index = 1; 2440 s.src_index = 1;
2444 s.user_gesture = false; 2441 s.user_gesture = false;
2445 EXPECT_TRUE(observer.StateEquals(0, s)); 2442 EXPECT_TRUE(observer.StateEquals(0, s));
2446 strip.RemoveObserver(&observer); 2443 strip.RemoveObserver(&observer);
2447 strip.CloseAllTabs(); 2444 strip.CloseAllTabs();
2448 } 2445 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/tabs/tab_strip_model_order_controller.cc ('k') | chrome/browser/ui/tabs/test_tab_strip_model_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698