| 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/tabs/tab_strip_model.h" | 5 #include "chrome/browser/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" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 testing::_; | 49 using testing::_; |
| 50 | 50 |
| 51 namespace { | 51 namespace { |
| 52 | 52 |
| 53 // Class used to delete a TabContents when another TabContents is destroyed. | 53 // Class used to delete a TabContentsWrapper when another TabContentsWrapper is |
| 54 // destroyed. |
| 54 class DeleteTabContentsOnDestroyedObserver | 55 class DeleteTabContentsOnDestroyedObserver |
| 55 : public content::NotificationObserver { | 56 : public content::NotificationObserver { |
| 56 public: | 57 public: |
| 57 DeleteTabContentsOnDestroyedObserver(TabContentsWrapper* source, | 58 DeleteTabContentsOnDestroyedObserver(TabContentsWrapper* source, |
| 58 TabContentsWrapper* tab_to_delete) | 59 TabContentsWrapper* tab_to_delete) |
| 59 : source_(source), | 60 : source_(source), |
| 60 tab_to_delete_(tab_to_delete) { | 61 tab_to_delete_(tab_to_delete) { |
| 61 registrar_.Add(this, | 62 registrar_.Add(this, |
| 62 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 63 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 63 content::Source<WebContents>(source->web_contents())); | 64 content::Source<WebContents>(source->web_contents())); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 TabContentsWrapper* contents) OVERRIDE { | 109 TabContentsWrapper* contents) OVERRIDE { |
| 109 return run_unload_; | 110 return run_unload_; |
| 110 } | 111 } |
| 111 virtual bool CanCloseContents(std::vector<int>* indices) OVERRIDE { | 112 virtual bool CanCloseContents(std::vector<int>* indices) OVERRIDE { |
| 112 if (!can_close_) | 113 if (!can_close_) |
| 113 indices->clear(); | 114 indices->clear(); |
| 114 return can_close_; | 115 return can_close_; |
| 115 } | 116 } |
| 116 | 117 |
| 117 private: | 118 private: |
| 118 // A dummy TabContents we give to callers that expect us to actually build a | 119 // A dummy TabContentsWrapper we give to callers that expect us to actually |
| 119 // Destinations tab for them. | 120 // build a Destinations tab for them. |
| 120 TabContentsWrapper* dummy_contents_; | 121 TabContentsWrapper* dummy_contents_; |
| 121 | 122 |
| 122 // Whether tabs can be closed. | 123 // Whether tabs can be closed. |
| 123 bool can_close_; | 124 bool can_close_; |
| 124 | 125 |
| 125 // Whether to report that we need to run an unload listener before closing. | 126 // Whether to report that we need to run an unload listener before closing. |
| 126 bool run_unload_; | 127 bool run_unload_; |
| 127 | 128 |
| 128 DISALLOW_COPY_AND_ASSIGN(TabStripDummyDelegate); | 129 DISALLOW_COPY_AND_ASSIGN(TabStripDummyDelegate); |
| 129 }; | 130 }; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 141 TabContentsWrapper* CreateTabContentsWithSharedRPH( | 142 TabContentsWrapper* CreateTabContentsWithSharedRPH( |
| 142 WebContents* web_contents) { | 143 WebContents* web_contents) { |
| 143 TabContentsWrapper* retval = Browser::TabContentsFactory(profile(), | 144 TabContentsWrapper* retval = Browser::TabContentsFactory(profile(), |
| 144 web_contents->GetRenderViewHost()->GetSiteInstance(), MSG_ROUTING_NONE, | 145 web_contents->GetRenderViewHost()->GetSiteInstance(), MSG_ROUTING_NONE, |
| 145 NULL, NULL); | 146 NULL, NULL); |
| 146 EXPECT_EQ(retval->web_contents()->GetRenderProcessHost(), | 147 EXPECT_EQ(retval->web_contents()->GetRenderProcessHost(), |
| 147 web_contents->GetRenderProcessHost()); | 148 web_contents->GetRenderProcessHost()); |
| 148 return retval; | 149 return retval; |
| 149 } | 150 } |
| 150 | 151 |
| 151 // Forwards a URL "load" request through to our dummy TabContents | 152 // Forwards a URL "load" request through to our dummy TabContentsWrapper |
| 152 // implementation. | 153 // implementation. |
| 153 void LoadURL(WebContents* con, const std::wstring& url) { | 154 void LoadURL(WebContents* con, const std::wstring& url) { |
| 154 controller().LoadURL(GURL(WideToUTF16(url)), content::Referrer(), | 155 controller().LoadURL(GURL(WideToUTF16(url)), content::Referrer(), |
| 155 content::PAGE_TRANSITION_LINK, std::string()); | 156 content::PAGE_TRANSITION_LINK, std::string()); |
| 156 } | 157 } |
| 157 | 158 |
| 158 void GoBack(WebContents* contents) { | 159 void GoBack(WebContents* contents) { |
| 159 controller().GoBack(); | 160 controller().GoBack(); |
| 160 } | 161 } |
| 161 | 162 |
| (...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1272 | 1273 |
| 1273 EXPECT_EQ(5, tabstrip.count()); | 1274 EXPECT_EQ(5, tabstrip.count()); |
| 1274 | 1275 |
| 1275 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); | 1276 EXPECT_EQ(homepage_contents, tabstrip.GetTabContentsAt(0)); |
| 1276 EXPECT_EQ(middle_click_contents1, tabstrip.GetTabContentsAt(1)); | 1277 EXPECT_EQ(middle_click_contents1, tabstrip.GetTabContentsAt(1)); |
| 1277 EXPECT_EQ(middle_click_contents2, tabstrip.GetTabContentsAt(2)); | 1278 EXPECT_EQ(middle_click_contents2, tabstrip.GetTabContentsAt(2)); |
| 1278 EXPECT_EQ(middle_click_contents3, tabstrip.GetTabContentsAt(3)); | 1279 EXPECT_EQ(middle_click_contents3, tabstrip.GetTabContentsAt(3)); |
| 1279 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(4)); | 1280 EXPECT_EQ(typed_page_contents, tabstrip.GetTabContentsAt(4)); |
| 1280 | 1281 |
| 1281 // Now simulate seleting a tab in the middle of the group of tabs opened from | 1282 // Now simulate seleting a tab in the middle of the group of tabs opened from |
| 1282 // the home page and start closing them. Each TabContents in the group should | 1283 // the home page and start closing them. Each TabContentsWrapper in the group |
| 1283 // be closed, right to left. This test is constructed to start at the middle | 1284 // should be closed, right to left. This test is constructed to start at the |
| 1284 // TabContents in the group to make sure the cursor wraps around to the first | 1285 // middle TabContentsWrapper in the group to make sure the cursor wraps around |
| 1285 // TabContents in the group before closing the opener or any other | 1286 // to the first TabContentsWrapper in the group before closing the opener or |
| 1286 // TabContents. | 1287 // any other TabContentsWrapper. |
| 1287 tabstrip.ActivateTabAt(2, true); | 1288 tabstrip.ActivateTabAt(2, true); |
| 1288 tabstrip.CloseSelectedTabs(); | 1289 tabstrip.CloseSelectedTabs(); |
| 1289 EXPECT_EQ(middle_click_contents3, tabstrip.GetActiveTabContents()); | 1290 EXPECT_EQ(middle_click_contents3, tabstrip.GetActiveTabContents()); |
| 1290 tabstrip.CloseSelectedTabs(); | 1291 tabstrip.CloseSelectedTabs(); |
| 1291 EXPECT_EQ(middle_click_contents1, tabstrip.GetActiveTabContents()); | 1292 EXPECT_EQ(middle_click_contents1, tabstrip.GetActiveTabContents()); |
| 1292 tabstrip.CloseSelectedTabs(); | 1293 tabstrip.CloseSelectedTabs(); |
| 1293 EXPECT_EQ(homepage_contents, tabstrip.GetActiveTabContents()); | 1294 EXPECT_EQ(homepage_contents, tabstrip.GetActiveTabContents()); |
| 1294 tabstrip.CloseSelectedTabs(); | 1295 tabstrip.CloseSelectedTabs(); |
| 1295 EXPECT_EQ(typed_page_contents, tabstrip.GetActiveTabContents()); | 1296 EXPECT_EQ(typed_page_contents, tabstrip.GetActiveTabContents()); |
| 1296 | 1297 |
| 1297 EXPECT_EQ(1, tabstrip.count()); | 1298 EXPECT_EQ(1, tabstrip.count()); |
| 1298 | 1299 |
| 1299 tabstrip.CloseAllTabs(); | 1300 tabstrip.CloseAllTabs(); |
| 1300 EXPECT_TRUE(tabstrip.empty()); | 1301 EXPECT_TRUE(tabstrip.empty()); |
| 1301 } | 1302 } |
| 1302 | 1303 |
| 1303 // Tests whether or not a TabContents created by a left click on a link that | 1304 // Tests whether or not a TabContentsWrapper created by a left click on a link |
| 1304 // opens a new tab is inserted correctly adjacent to the tab that spawned it. | 1305 // that opens a new tab is inserted correctly adjacent to the tab that spawned |
| 1306 // it. |
| 1305 TEST_F(TabStripModelTest, AddTabContents_LeftClickPopup) { | 1307 TEST_F(TabStripModelTest, AddTabContents_LeftClickPopup) { |
| 1306 TabStripDummyDelegate delegate(NULL); | 1308 TabStripDummyDelegate delegate(NULL); |
| 1307 TabStripModel tabstrip(&delegate, profile()); | 1309 TabStripModel tabstrip(&delegate, profile()); |
| 1308 EXPECT_TRUE(tabstrip.empty()); | 1310 EXPECT_TRUE(tabstrip.empty()); |
| 1309 | 1311 |
| 1310 // Open the Home Page | 1312 // Open the Home Page |
| 1311 TabContentsWrapper* homepage_contents = CreateTabContents(); | 1313 TabContentsWrapper* homepage_contents = CreateTabContents(); |
| 1312 tabstrip.AddTabContents( | 1314 tabstrip.AddTabContents( |
| 1313 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, | 1315 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, |
| 1314 TabStripModel::ADD_ACTIVE); | 1316 TabStripModel::ADD_ACTIVE); |
| (...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2438 ASSERT_EQ(1, observer.GetStateCount()); | 2440 ASSERT_EQ(1, observer.GetStateCount()); |
| 2439 MockTabStripModelObserver::State s( | 2441 MockTabStripModelObserver::State s( |
| 2440 contents2, 1, MockTabStripModelObserver::SELECT); | 2442 contents2, 1, MockTabStripModelObserver::SELECT); |
| 2441 s.src_contents = contents2; | 2443 s.src_contents = contents2; |
| 2442 s.src_index = 1; | 2444 s.src_index = 1; |
| 2443 s.user_gesture = false; | 2445 s.user_gesture = false; |
| 2444 EXPECT_TRUE(observer.StateEquals(0, s)); | 2446 EXPECT_TRUE(observer.StateEquals(0, s)); |
| 2445 strip.RemoveObserver(&observer); | 2447 strip.RemoveObserver(&observer); |
| 2446 strip.CloseAllTabs(); | 2448 strip.CloseAllTabs(); |
| 2447 } | 2449 } |
| OLD | NEW |