OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/cocoa/tabpose_window.h" | 5 #import "chrome/browser/cocoa/tabpose_window.h" |
6 | 6 |
7 #import "chrome/browser/browser_window.h" | 7 #import "chrome/browser/browser_window.h" |
8 #import "chrome/browser/cocoa/browser_test_helper.h" | 8 #import "chrome/browser/cocoa/browser_test_helper.h" |
9 #import "chrome/browser/cocoa/cocoa_test_helper.h" | 9 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
10 #include "chrome/browser/renderer_host/site_instance.h" | 10 #include "chrome/browser/renderer_host/site_instance.h" |
11 #include "chrome/browser/tab_contents/tab_contents.h" | 11 #include "chrome/browser/tab_contents/tab_contents.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 class TabposeWindowTest : public CocoaTest { | 14 class TabposeWindowTest : public CocoaTest { |
15 public: | 15 public: |
| 16 TabposeWindowTest() { |
| 17 site_instance_ = |
| 18 SiteInstance::CreateSiteInstance(browser_helper_.profile()); |
| 19 } |
| 20 |
| 21 void AppendTabToStrip() { |
| 22 TabContents* tab_contents = new TabContents( |
| 23 browser_helper_.profile(), site_instance_, MSG_ROUTING_NONE, NULL); |
| 24 browser_helper_.browser()->tabstrip_model()->AppendTabContents( |
| 25 tab_contents, /*foreground=*/true); |
| 26 } |
| 27 |
16 BrowserTestHelper browser_helper_; | 28 BrowserTestHelper browser_helper_; |
| 29 scoped_refptr<SiteInstance> site_instance_; |
17 }; | 30 }; |
18 | 31 |
19 // Check that this doesn't leak. | 32 // Check that this doesn't leak. |
20 TEST_F(TabposeWindowTest, TestShow) { | 33 TEST_F(TabposeWindowTest, TestShow) { |
21 Browser* browser = browser_helper_.browser(); | |
22 BrowserWindow* browser_window = browser_helper_.CreateBrowserWindow(); | 34 BrowserWindow* browser_window = browser_helper_.CreateBrowserWindow(); |
23 NSWindow* parent = browser_window->GetNativeHandle(); | 35 NSWindow* parent = browser_window->GetNativeHandle(); |
24 | 36 |
25 [parent orderFront:nil]; | 37 [parent orderFront:nil]; |
26 EXPECT_TRUE([parent isVisible]); | 38 EXPECT_TRUE([parent isVisible]); |
27 | 39 |
28 // Add a few tabs to the tab strip model. | 40 // Add a few tabs to the tab strip model. |
29 TabStripModel* model = browser->tabstrip_model(); | 41 for (int i = 0; i < 3; ++i) |
30 SiteInstance* instance = | 42 AppendTabToStrip(); |
31 SiteInstance::CreateSiteInstance(browser_helper_.profile()); | |
32 for (int i = 0; i < 3; ++i) { | |
33 TabContents* tab_contents = | |
34 new TabContents(browser_helper_.profile(), instance, MSG_ROUTING_NONE, | |
35 NULL); | |
36 model->AppendTabContents(tab_contents, /*foreground=*/true); | |
37 } | |
38 | 43 |
39 base::ScopedNSAutoreleasePool pool; | 44 base::ScopedNSAutoreleasePool pool; |
40 TabposeWindow* window = | 45 TabposeWindow* window = |
41 [TabposeWindow openTabposeFor:parent | 46 [TabposeWindow openTabposeFor:parent |
42 rect:NSMakeRect(10, 20, 250, 160) | 47 rect:NSMakeRect(10, 20, 250, 160) |
43 slomo:NO | 48 slomo:NO |
44 tabStripModel:model]; | 49 tabStripModel:browser_helper_.browser()->tabstrip_model()]; |
45 | 50 |
46 // Should release the window. | 51 // Should release the window. |
47 [window mouseDown:nil]; | 52 [window mouseDown:nil]; |
| 53 |
| 54 browser_helper_.CloseBrowserWindow(); |
| 55 } |
| 56 |
| 57 TEST_F(TabposeWindowTest, TestModelObserver) { |
| 58 BrowserWindow* browser_window = browser_helper_.CreateBrowserWindow(); |
| 59 NSWindow* parent = browser_window->GetNativeHandle(); |
| 60 [parent orderFront:nil]; |
| 61 |
| 62 // Add a few tabs to the tab strip model. |
| 63 for (int i = 0; i < 3; ++i) |
| 64 AppendTabToStrip(); |
| 65 |
| 66 base::ScopedNSAutoreleasePool pool; |
| 67 TabposeWindow* window = |
| 68 [TabposeWindow openTabposeFor:parent |
| 69 rect:NSMakeRect(10, 20, 250, 160) |
| 70 slomo:NO |
| 71 tabStripModel:browser_helper_.browser()->tabstrip_model()]; |
| 72 |
| 73 // Exercise all the model change events. |
| 74 TabStripModel* model = browser_helper_.browser()->tabstrip_model(); |
| 75 DCHECK_EQ([window thumbnailLayerCount], 3u); |
| 76 DCHECK_EQ([window selectedIndex], 2); |
| 77 |
| 78 model->MoveTabContentsAt(0, 2, /*select_after_move=*/false); |
| 79 DCHECK_EQ([window thumbnailLayerCount], 3u); |
| 80 DCHECK_EQ([window selectedIndex], 1); |
| 81 |
| 82 model->MoveTabContentsAt(2, 0, /*select_after_move=*/false); |
| 83 DCHECK_EQ([window thumbnailLayerCount], 3u); |
| 84 DCHECK_EQ([window selectedIndex], 2); |
| 85 |
| 86 [window selectTileAtIndexWithoutAnimation:0]; |
| 87 DCHECK_EQ([window selectedIndex], 0); |
| 88 |
| 89 model->MoveTabContentsAt(0, 2, /*select_after_move=*/false); |
| 90 DCHECK_EQ([window selectedIndex], 2); |
| 91 |
| 92 model->MoveTabContentsAt(2, 0, /*select_after_move=*/false); |
| 93 DCHECK_EQ([window selectedIndex], 0); |
| 94 |
| 95 delete model->DetachTabContentsAt(0); |
| 96 DCHECK_EQ([window thumbnailLayerCount], 2u); |
| 97 DCHECK_EQ([window selectedIndex], 0); |
| 98 |
| 99 AppendTabToStrip(); |
| 100 DCHECK_EQ([window thumbnailLayerCount], 3u); |
| 101 DCHECK_EQ([window selectedIndex], 0); |
| 102 |
| 103 model->CloseTabContentsAt(0, TabStripModel::CLOSE_NONE); |
| 104 DCHECK_EQ([window thumbnailLayerCount], 2u); |
| 105 DCHECK_EQ([window selectedIndex], 0); |
| 106 |
| 107 [window selectTileAtIndexWithoutAnimation:1]; |
| 108 model->CloseTabContentsAt(0, TabStripModel::CLOSE_NONE); |
| 109 DCHECK_EQ([window thumbnailLayerCount], 1u); |
| 110 DCHECK_EQ([window selectedIndex], 0); |
| 111 |
| 112 // Should release the window. |
| 113 [window mouseDown:nil]; |
48 | 114 |
49 browser_helper_.CloseBrowserWindow(); | 115 browser_helper_.CloseBrowserWindow(); |
50 } | 116 } |
OLD | NEW |