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/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 30 matching lines...) Expand all Loading... |
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 // TODO(avi): Kill this when TabContents goes away. |
| 52 class TabStripModelContentsCreator { |
| 53 public: |
| 54 static TabContents* CreateTabContents(content::WebContents* contents) { |
| 55 return TabContents::Factory::CreateTabContents(contents); |
| 56 } |
| 57 }; |
| 58 |
51 namespace { | 59 namespace { |
52 | 60 |
53 // Class used to delete a TabContents when another TabContents is destroyed. | 61 // Class used to delete a TabContents when another TabContents is destroyed. |
54 class DeleteTabContentsOnDestroyedObserver | 62 class DeleteTabContentsOnDestroyedObserver |
55 : public content::NotificationObserver { | 63 : public content::NotificationObserver { |
56 public: | 64 public: |
57 DeleteTabContentsOnDestroyedObserver(TabContents* source, | 65 DeleteTabContentsOnDestroyedObserver(TabContents* source, |
58 TabContents* tab_to_delete) | 66 TabContents* tab_to_delete) |
59 : source_(source), | 67 : source_(source), |
60 tab_to_delete_(tab_to_delete) { | 68 tab_to_delete_(tab_to_delete) { |
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1459 EXPECT_EQ(1, tabstrip.count()); | 1467 EXPECT_EQ(1, tabstrip.count()); |
1460 | 1468 |
1461 tabstrip.CloseAllTabs(); | 1469 tabstrip.CloseAllTabs(); |
1462 EXPECT_TRUE(tabstrip.empty()); | 1470 EXPECT_TRUE(tabstrip.empty()); |
1463 } | 1471 } |
1464 | 1472 |
1465 // Added for http://b/issue?id=958960 | 1473 // Added for http://b/issue?id=958960 |
1466 TEST_F(TabStripModelTest, AppendContentsReselectionTest) { | 1474 TEST_F(TabStripModelTest, AppendContentsReselectionTest) { |
1467 WebContents* fake_destinations_tab = | 1475 WebContents* fake_destinations_tab = |
1468 WebContents::Create(profile(), NULL, MSG_ROUTING_NONE, NULL); | 1476 WebContents::Create(profile(), NULL, MSG_ROUTING_NONE, NULL); |
1469 TabContents tab_contents(fake_destinations_tab); | 1477 scoped_ptr<TabContents> tab_contents( |
1470 TabStripDummyDelegate delegate(&tab_contents); | 1478 TabStripModelContentsCreator::CreateTabContents(fake_destinations_tab)); |
| 1479 TabStripDummyDelegate delegate(tab_contents.get()); |
1471 TabStripModel tabstrip(&delegate, profile()); | 1480 TabStripModel tabstrip(&delegate, profile()); |
1472 EXPECT_TRUE(tabstrip.empty()); | 1481 EXPECT_TRUE(tabstrip.empty()); |
1473 | 1482 |
1474 // Open the Home Page | 1483 // Open the Home Page |
1475 TabContents* homepage_contents = CreateTabContents(); | 1484 TabContents* homepage_contents = CreateTabContents(); |
1476 tabstrip.AddTabContents( | 1485 tabstrip.AddTabContents( |
1477 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, | 1486 homepage_contents, -1, content::PAGE_TRANSITION_AUTO_BOOKMARK, |
1478 TabStripModel::ADD_ACTIVE); | 1487 TabStripModel::ADD_ACTIVE); |
1479 | 1488 |
1480 // Open some other tab, by user typing. | 1489 // Open some other tab, by user typing. |
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2427 ASSERT_EQ(1, observer.GetStateCount()); | 2436 ASSERT_EQ(1, observer.GetStateCount()); |
2428 MockTabStripModelObserver::State s( | 2437 MockTabStripModelObserver::State s( |
2429 contents2, 1, MockTabStripModelObserver::SELECT); | 2438 contents2, 1, MockTabStripModelObserver::SELECT); |
2430 s.src_contents = contents2; | 2439 s.src_contents = contents2; |
2431 s.src_index = 1; | 2440 s.src_index = 1; |
2432 s.user_gesture = false; | 2441 s.user_gesture = false; |
2433 EXPECT_TRUE(observer.StateEquals(0, s)); | 2442 EXPECT_TRUE(observer.StateEquals(0, s)); |
2434 strip.RemoveObserver(&observer); | 2443 strip.RemoveObserver(&observer); |
2435 strip.CloseAllTabs(); | 2444 strip.CloseAllTabs(); |
2436 } | 2445 } |
OLD | NEW |