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