OLD | NEW |
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/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 // When |source| is deleted both |tab_to_delete| and |tab_strip| are deleted. | 52 // When |source| is deleted both |tab_to_delete| and |tab_strip| are deleted. |
53 // |tab_to_delete| and |tab_strip| may be NULL. | 53 // |tab_to_delete| and |tab_strip| may be NULL. |
54 DeleteWebContentsOnDestroyedObserver(WebContents* source, | 54 DeleteWebContentsOnDestroyedObserver(WebContents* source, |
55 WebContents* tab_to_delete, | 55 WebContents* tab_to_delete, |
56 TabStripModel* tab_strip) | 56 TabStripModel* tab_strip) |
57 : WebContentsObserver(source), | 57 : WebContentsObserver(source), |
58 tab_to_delete_(tab_to_delete), | 58 tab_to_delete_(tab_to_delete), |
59 tab_strip_(tab_strip) { | 59 tab_strip_(tab_strip) { |
60 } | 60 } |
61 | 61 |
62 virtual void WebContentsDestroyed() OVERRIDE { | 62 virtual void WebContentsDestroyed() override { |
63 WebContents* tab_to_delete = tab_to_delete_; | 63 WebContents* tab_to_delete = tab_to_delete_; |
64 tab_to_delete_ = NULL; | 64 tab_to_delete_ = NULL; |
65 TabStripModel* tab_strip_to_delete = tab_strip_; | 65 TabStripModel* tab_strip_to_delete = tab_strip_; |
66 tab_strip_ = NULL; | 66 tab_strip_ = NULL; |
67 delete tab_to_delete; | 67 delete tab_to_delete; |
68 delete tab_strip_to_delete; | 68 delete tab_strip_to_delete; |
69 } | 69 } |
70 | 70 |
71 private: | 71 private: |
72 WebContents* tab_to_delete_; | 72 WebContents* tab_to_delete_; |
73 TabStripModel* tab_strip_; | 73 TabStripModel* tab_strip_; |
74 | 74 |
75 DISALLOW_COPY_AND_ASSIGN(DeleteWebContentsOnDestroyedObserver); | 75 DISALLOW_COPY_AND_ASSIGN(DeleteWebContentsOnDestroyedObserver); |
76 }; | 76 }; |
77 | 77 |
78 class TabStripDummyDelegate : public TestTabStripModelDelegate { | 78 class TabStripDummyDelegate : public TestTabStripModelDelegate { |
79 public: | 79 public: |
80 TabStripDummyDelegate() : run_unload_(false) {} | 80 TabStripDummyDelegate() : run_unload_(false) {} |
81 virtual ~TabStripDummyDelegate() {} | 81 virtual ~TabStripDummyDelegate() {} |
82 | 82 |
83 void set_run_unload_listener(bool value) { run_unload_ = value; } | 83 void set_run_unload_listener(bool value) { run_unload_ = value; } |
84 | 84 |
85 virtual bool RunUnloadListenerBeforeClosing(WebContents* contents) OVERRIDE { | 85 virtual bool RunUnloadListenerBeforeClosing(WebContents* contents) override { |
86 return run_unload_; | 86 return run_unload_; |
87 } | 87 } |
88 | 88 |
89 private: | 89 private: |
90 // Whether to report that we need to run an unload listener before closing. | 90 // Whether to report that we need to run an unload listener before closing. |
91 bool run_unload_; | 91 bool run_unload_; |
92 | 92 |
93 DISALLOW_COPY_AND_ASSIGN(TabStripDummyDelegate); | 93 DISALLOW_COPY_AND_ASSIGN(TabStripDummyDelegate); |
94 }; | 94 }; |
95 | 95 |
(...skipping 12 matching lines...) Expand all Loading... |
108 class DummySingleWebContentsDialogManager | 108 class DummySingleWebContentsDialogManager |
109 : public web_modal::SingleWebContentsDialogManager { | 109 : public web_modal::SingleWebContentsDialogManager { |
110 public: | 110 public: |
111 explicit DummySingleWebContentsDialogManager( | 111 explicit DummySingleWebContentsDialogManager( |
112 NativeWebContentsModalDialog dialog, | 112 NativeWebContentsModalDialog dialog, |
113 web_modal::SingleWebContentsDialogManagerDelegate* delegate) | 113 web_modal::SingleWebContentsDialogManagerDelegate* delegate) |
114 : delegate_(delegate), | 114 : delegate_(delegate), |
115 dialog_(dialog) {} | 115 dialog_(dialog) {} |
116 virtual ~DummySingleWebContentsDialogManager() {} | 116 virtual ~DummySingleWebContentsDialogManager() {} |
117 | 117 |
118 virtual void Show() OVERRIDE {} | 118 virtual void Show() override {} |
119 virtual void Hide() OVERRIDE {} | 119 virtual void Hide() override {} |
120 virtual void Close() OVERRIDE { | 120 virtual void Close() override { |
121 delegate_->WillClose(dialog_); | 121 delegate_->WillClose(dialog_); |
122 } | 122 } |
123 virtual void Focus() OVERRIDE {} | 123 virtual void Focus() override {} |
124 virtual void Pulse() OVERRIDE {} | 124 virtual void Pulse() override {} |
125 virtual void HostChanged( | 125 virtual void HostChanged( |
126 web_modal::WebContentsModalDialogHost* new_host) OVERRIDE {} | 126 web_modal::WebContentsModalDialogHost* new_host) override {} |
127 virtual NativeWebContentsModalDialog dialog() OVERRIDE { return dialog_; } | 127 virtual NativeWebContentsModalDialog dialog() override { return dialog_; } |
128 | 128 |
129 private: | 129 private: |
130 web_modal::SingleWebContentsDialogManagerDelegate* delegate_; | 130 web_modal::SingleWebContentsDialogManagerDelegate* delegate_; |
131 NativeWebContentsModalDialog dialog_; | 131 NativeWebContentsModalDialog dialog_; |
132 | 132 |
133 DISALLOW_COPY_AND_ASSIGN(DummySingleWebContentsDialogManager); | 133 DISALLOW_COPY_AND_ASSIGN(DummySingleWebContentsDialogManager); |
134 }; | 134 }; |
135 | 135 |
136 // Test Browser-like class for TabStripModelTest.TabBlockedState. | 136 // Test Browser-like class for TabStripModelTest.TabBlockedState. |
137 class TabBlockedStateTestBrowser | 137 class TabBlockedStateTestBrowser |
138 : public TabStripModelObserver, | 138 : public TabStripModelObserver, |
139 public web_modal::WebContentsModalDialogManagerDelegate { | 139 public web_modal::WebContentsModalDialogManagerDelegate { |
140 public: | 140 public: |
141 explicit TabBlockedStateTestBrowser(TabStripModel* tab_strip_model) | 141 explicit TabBlockedStateTestBrowser(TabStripModel* tab_strip_model) |
142 : tab_strip_model_(tab_strip_model) { | 142 : tab_strip_model_(tab_strip_model) { |
143 tab_strip_model_->AddObserver(this); | 143 tab_strip_model_->AddObserver(this); |
144 } | 144 } |
145 | 145 |
146 virtual ~TabBlockedStateTestBrowser() { | 146 virtual ~TabBlockedStateTestBrowser() { |
147 tab_strip_model_->RemoveObserver(this); | 147 tab_strip_model_->RemoveObserver(this); |
148 } | 148 } |
149 | 149 |
150 private: | 150 private: |
151 // TabStripModelObserver | 151 // TabStripModelObserver |
152 virtual void TabInsertedAt(WebContents* contents, | 152 virtual void TabInsertedAt(WebContents* contents, |
153 int index, | 153 int index, |
154 bool foreground) OVERRIDE { | 154 bool foreground) override { |
155 web_modal::WebContentsModalDialogManager* manager = | 155 web_modal::WebContentsModalDialogManager* manager = |
156 web_modal::WebContentsModalDialogManager::FromWebContents(contents); | 156 web_modal::WebContentsModalDialogManager::FromWebContents(contents); |
157 if (manager) | 157 if (manager) |
158 manager->SetDelegate(this); | 158 manager->SetDelegate(this); |
159 } | 159 } |
160 | 160 |
161 // WebContentsModalDialogManagerDelegate | 161 // WebContentsModalDialogManagerDelegate |
162 virtual void SetWebContentsBlocked(content::WebContents* contents, | 162 virtual void SetWebContentsBlocked(content::WebContents* contents, |
163 bool blocked) OVERRIDE { | 163 bool blocked) override { |
164 int index = tab_strip_model_->GetIndexOfWebContents(contents); | 164 int index = tab_strip_model_->GetIndexOfWebContents(contents); |
165 ASSERT_GE(index, 0); | 165 ASSERT_GE(index, 0); |
166 tab_strip_model_->SetTabBlocked(index, blocked); | 166 tab_strip_model_->SetTabBlocked(index, blocked); |
167 } | 167 } |
168 | 168 |
169 TabStripModel* tab_strip_model_; | 169 TabStripModel* tab_strip_model_; |
170 | 170 |
171 DISALLOW_COPY_AND_ASSIGN(TabBlockedStateTestBrowser); | 171 DISALLOW_COPY_AND_ASSIGN(TabBlockedStateTestBrowser); |
172 }; | 172 }; |
173 | 173 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 s.src_index == state.src_index && | 343 s.src_index == state.src_index && |
344 s.dst_index == state.dst_index && | 344 s.dst_index == state.dst_index && |
345 s.change_reason == state.change_reason && | 345 s.change_reason == state.change_reason && |
346 s.foreground == state.foreground && | 346 s.foreground == state.foreground && |
347 s.action == state.action); | 347 s.action == state.action); |
348 } | 348 } |
349 | 349 |
350 // TabStripModelObserver implementation: | 350 // TabStripModelObserver implementation: |
351 virtual void TabInsertedAt(WebContents* contents, | 351 virtual void TabInsertedAt(WebContents* contents, |
352 int index, | 352 int index, |
353 bool foreground) OVERRIDE { | 353 bool foreground) override { |
354 empty_ = false; | 354 empty_ = false; |
355 State s(contents, index, INSERT); | 355 State s(contents, index, INSERT); |
356 s.foreground = foreground; | 356 s.foreground = foreground; |
357 states_.push_back(s); | 357 states_.push_back(s); |
358 } | 358 } |
359 virtual void ActiveTabChanged(WebContents* old_contents, | 359 virtual void ActiveTabChanged(WebContents* old_contents, |
360 WebContents* new_contents, | 360 WebContents* new_contents, |
361 int index, | 361 int index, |
362 int reason) OVERRIDE { | 362 int reason) override { |
363 State s(new_contents, index, ACTIVATE); | 363 State s(new_contents, index, ACTIVATE); |
364 s.src_contents = old_contents; | 364 s.src_contents = old_contents; |
365 s.change_reason = reason; | 365 s.change_reason = reason; |
366 states_.push_back(s); | 366 states_.push_back(s); |
367 } | 367 } |
368 virtual void TabSelectionChanged( | 368 virtual void TabSelectionChanged( |
369 TabStripModel* tab_strip_model, | 369 TabStripModel* tab_strip_model, |
370 const ui::ListSelectionModel& old_model) OVERRIDE { | 370 const ui::ListSelectionModel& old_model) override { |
371 State s(model()->GetActiveWebContents(), model()->active_index(), SELECT); | 371 State s(model()->GetActiveWebContents(), model()->active_index(), SELECT); |
372 s.src_contents = model()->GetWebContentsAt(old_model.active()); | 372 s.src_contents = model()->GetWebContentsAt(old_model.active()); |
373 s.src_index = old_model.active(); | 373 s.src_index = old_model.active(); |
374 states_.push_back(s); | 374 states_.push_back(s); |
375 } | 375 } |
376 virtual void TabMoved(WebContents* contents, | 376 virtual void TabMoved(WebContents* contents, |
377 int from_index, | 377 int from_index, |
378 int to_index) OVERRIDE { | 378 int to_index) override { |
379 State s(contents, to_index, MOVE); | 379 State s(contents, to_index, MOVE); |
380 s.src_index = from_index; | 380 s.src_index = from_index; |
381 states_.push_back(s); | 381 states_.push_back(s); |
382 } | 382 } |
383 | 383 |
384 virtual void TabClosingAt(TabStripModel* tab_strip_model, | 384 virtual void TabClosingAt(TabStripModel* tab_strip_model, |
385 WebContents* contents, | 385 WebContents* contents, |
386 int index) OVERRIDE { | 386 int index) override { |
387 states_.push_back(State(contents, index, CLOSE)); | 387 states_.push_back(State(contents, index, CLOSE)); |
388 } | 388 } |
389 virtual void TabDetachedAt(WebContents* contents, int index) OVERRIDE { | 389 virtual void TabDetachedAt(WebContents* contents, int index) override { |
390 states_.push_back(State(contents, index, DETACH)); | 390 states_.push_back(State(contents, index, DETACH)); |
391 } | 391 } |
392 virtual void TabDeactivated(WebContents* contents) OVERRIDE { | 392 virtual void TabDeactivated(WebContents* contents) override { |
393 states_.push_back(State(contents, model()->active_index(), DEACTIVATE)); | 393 states_.push_back(State(contents, model()->active_index(), DEACTIVATE)); |
394 } | 394 } |
395 virtual void TabChangedAt(WebContents* contents, | 395 virtual void TabChangedAt(WebContents* contents, |
396 int index, | 396 int index, |
397 TabChangeType change_type) OVERRIDE { | 397 TabChangeType change_type) override { |
398 states_.push_back(State(contents, index, CHANGE)); | 398 states_.push_back(State(contents, index, CHANGE)); |
399 } | 399 } |
400 virtual void TabReplacedAt(TabStripModel* tab_strip_model, | 400 virtual void TabReplacedAt(TabStripModel* tab_strip_model, |
401 WebContents* old_contents, | 401 WebContents* old_contents, |
402 WebContents* new_contents, | 402 WebContents* new_contents, |
403 int index) OVERRIDE { | 403 int index) override { |
404 State s(new_contents, index, REPLACED); | 404 State s(new_contents, index, REPLACED); |
405 s.src_contents = old_contents; | 405 s.src_contents = old_contents; |
406 states_.push_back(s); | 406 states_.push_back(s); |
407 } | 407 } |
408 virtual void TabPinnedStateChanged(WebContents* contents, | 408 virtual void TabPinnedStateChanged(WebContents* contents, |
409 int index) OVERRIDE { | 409 int index) override { |
410 states_.push_back(State(contents, index, PINNED)); | 410 states_.push_back(State(contents, index, PINNED)); |
411 } | 411 } |
412 virtual void TabStripEmpty() OVERRIDE { | 412 virtual void TabStripEmpty() override { |
413 empty_ = true; | 413 empty_ = true; |
414 } | 414 } |
415 virtual void WillCloseAllTabs() OVERRIDE { | 415 virtual void WillCloseAllTabs() override { |
416 states_.push_back(State(NULL, -1, CLOSE_ALL)); | 416 states_.push_back(State(NULL, -1, CLOSE_ALL)); |
417 } | 417 } |
418 virtual void CloseAllTabsCanceled() OVERRIDE { | 418 virtual void CloseAllTabsCanceled() override { |
419 states_.push_back(State(NULL, -1, CLOSE_ALL_CANCELED)); | 419 states_.push_back(State(NULL, -1, CLOSE_ALL_CANCELED)); |
420 } | 420 } |
421 virtual void TabStripModelDeleted() OVERRIDE { | 421 virtual void TabStripModelDeleted() override { |
422 deleted_ = true; | 422 deleted_ = true; |
423 } | 423 } |
424 | 424 |
425 void ClearStates() { | 425 void ClearStates() { |
426 states_.clear(); | 426 states_.clear(); |
427 } | 427 } |
428 | 428 |
429 bool empty() const { return empty_; } | 429 bool empty() const { return empty_; } |
430 bool deleted() const { return deleted_; } | 430 bool deleted() const { return deleted_; } |
431 TabStripModel* model() { return model_; } | 431 TabStripModel* model() { return model_; } |
(...skipping 2152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2584 WebContents* moved_contents = strip_src.DetachWebContentsAt(1); | 2584 WebContents* moved_contents = strip_src.DetachWebContentsAt(1); |
2585 EXPECT_EQ(contents2, moved_contents); | 2585 EXPECT_EQ(contents2, moved_contents); |
2586 | 2586 |
2587 // Attach the tab to the destination tab strip. | 2587 // Attach the tab to the destination tab strip. |
2588 strip_dst.AppendWebContents(moved_contents, true); | 2588 strip_dst.AppendWebContents(moved_contents, true); |
2589 EXPECT_TRUE(strip_dst.IsTabBlocked(0)); | 2589 EXPECT_TRUE(strip_dst.IsTabBlocked(0)); |
2590 | 2590 |
2591 strip_dst.CloseAllTabs(); | 2591 strip_dst.CloseAllTabs(); |
2592 strip_src.CloseAllTabs(); | 2592 strip_src.CloseAllTabs(); |
2593 } | 2593 } |
OLD | NEW |