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
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/tabpose_window.h"
7 #include "base/mac/mac_util.h"
8 #include "chrome/browser/ui/browser_window.h"
9 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/test/base/testing_profile.h"
12 #include "content/public/browser/site_instance.h"
13 #include "content/public/browser/web_contents.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 using content::SiteInstance;
18 class TabposeWindowTest : public CocoaProfileTest {
20 virtual void SetUp() {
21 CocoaProfileTest::SetUp();
22 ASSERT_TRUE(profile());
24 site_instance_ = SiteInstance::Create(profile());
27 void AppendTabToStrip() {
28 content::WebContents* web_contents = content::WebContents::Create(
29 content::WebContents::CreateParams(profile(), site_instance_.get()));
30 browser()->tab_strip_model()->AppendWebContents(
31 web_contents, /*foreground=*/true);
34 scoped_refptr<SiteInstance> site_instance_;
37 TEST_F(TabposeWindowTest, TestShow) {
38 // Skip this test on 10.7
39 // http://code.google.com/p/chromium/issues/detail?id=127845
40 if (base::mac::IsOSLionOrLater()) {
44 NSWindow* parent = browser()->window()->GetNativeWindow();
46 [parent orderFront:nil];
47 EXPECT_TRUE([parent isVisible]);
49 // Add a few tabs to the tab strip model.
50 for (int i = 0; i < 3; ++i)
53 base::mac::ScopedNSAutoreleasePool pool;
54 TabposeWindow* window =
55 [TabposeWindow openTabposeFor:parent
56 rect:NSMakeRect(10, 20, 250, 160)
58 tabStripModel:browser()->tab_strip_model()];
60 // Should release the window.
61 [window mouseDown:nil];
64 TEST_F(TabposeWindowTest, TestModelObserver) {
65 // Skip this test on 10.7
66 // http://code.google.com/p/chromium/issues/detail?id=127845
67 if (base::mac::IsOSLionOrLater()) {
71 NSWindow* parent = browser()->window()->GetNativeWindow();
72 [parent orderFront:nil];
74 // Add a few tabs to the tab strip model.
75 for (int i = 0; i < 3; ++i)
78 base::mac::ScopedNSAutoreleasePool pool;
79 TabposeWindow* window =
80 [TabposeWindow openTabposeFor:parent
81 rect:NSMakeRect(10, 20, 250, 160)
83 tabStripModel:browser()->tab_strip_model()];
85 // Exercise all the model change events.
86 TabStripModel* model = browser()->tab_strip_model();
87 DCHECK_EQ([window thumbnailLayerCount], 3u);
88 DCHECK_EQ([window selectedIndex], 2);
90 model->MoveWebContentsAt(0, 2, /*select_after_move=*/false);
91 DCHECK_EQ([window thumbnailLayerCount], 3u);
92 DCHECK_EQ([window selectedIndex], 1);
94 model->MoveWebContentsAt(2, 0, /*select_after_move=*/false);
95 DCHECK_EQ([window thumbnailLayerCount], 3u);
96 DCHECK_EQ([window selectedIndex], 2);
98 [window selectTileAtIndexWithoutAnimation:0];
99 DCHECK_EQ([window selectedIndex], 0);
101 model->MoveWebContentsAt(0, 2, /*select_after_move=*/false);
102 DCHECK_EQ([window selectedIndex], 2);
104 model->MoveWebContentsAt(2, 0, /*select_after_move=*/false);
105 DCHECK_EQ([window selectedIndex], 0);
107 delete model->DetachWebContentsAt(0);
108 DCHECK_EQ([window thumbnailLayerCount], 2u);
109 DCHECK_EQ([window selectedIndex], 0);
112 DCHECK_EQ([window thumbnailLayerCount], 3u);
113 DCHECK_EQ([window selectedIndex], 0);
115 model->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE);
116 DCHECK_EQ([window thumbnailLayerCount], 2u);
117 DCHECK_EQ([window selectedIndex], 0);
119 [window selectTileAtIndexWithoutAnimation:1];
120 model->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE);
121 DCHECK_EQ([window thumbnailLayerCount], 1u);
122 DCHECK_EQ([window selectedIndex], 0);
124 // Should release the window.
125 [window mouseDown:nil];