OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/printing/print_preview_tab_controller.h" | 5 #include "chrome/browser/printing/print_preview_tab_controller.h" |
6 #include "chrome/browser/tabs/tab_strip_model.h" | 6 #include "chrome/browser/tabs/tab_strip_model.h" |
7 #include "chrome/browser/ui/browser_list.h" | 7 #include "chrome/browser/ui/browser_list.h" |
8 #include "chrome/test/base/browser_with_test_window_test.h" | 8 #include "chrome/test/base/browser_with_test_window_test.h" |
9 #include "chrome/test/base/testing_profile.h" | 9 #include "chrome/test/base/testing_profile.h" |
10 #include "content/browser/tab_contents/tab_contents.h" | 10 #include "content/browser/tab_contents/tab_contents.h" |
| 11 #include "content/common/url_constants.h" |
11 | 12 |
12 typedef BrowserWithTestWindowTest PrintPreviewTabControllerTest; | 13 typedef BrowserWithTestWindowTest PrintPreviewTabControllerTest; |
13 | 14 |
14 // Create/Get a preview tab for initiator tab. | 15 // Create/Get a preview tab for initiator tab. |
15 TEST_F(PrintPreviewTabControllerTest, GetOrCreatePreviewTab) { | 16 TEST_F(PrintPreviewTabControllerTest, GetOrCreatePreviewTab) { |
16 ASSERT_TRUE(browser()); | 17 ASSERT_TRUE(browser()); |
17 BrowserList::SetLastActive(browser()); | 18 BrowserList::SetLastActive(browser()); |
18 ASSERT_TRUE(BrowserList::GetLastActive()); | 19 ASSERT_TRUE(BrowserList::GetLastActive()); |
19 | 20 |
20 // Lets start with one window with one tab. | 21 // Lets start with one window with one tab. |
(...skipping 10 matching lines...) Expand all Loading... |
31 ASSERT_TRUE(tab_controller); | 32 ASSERT_TRUE(tab_controller); |
32 | 33 |
33 // Get the preview tab for initiator tab. | 34 // Get the preview tab for initiator tab. |
34 TabContents* preview_tab = | 35 TabContents* preview_tab = |
35 tab_controller->GetOrCreatePreviewTab(initiator_tab); | 36 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
36 | 37 |
37 // New print preview tab is created. Current focus is on preview tab. | 38 // New print preview tab is created. Current focus is on preview tab. |
38 EXPECT_EQ(2, browser()->tab_count()); | 39 EXPECT_EQ(2, browser()->tab_count()); |
39 EXPECT_NE(initiator_tab, preview_tab); | 40 EXPECT_NE(initiator_tab, preview_tab); |
40 | 41 |
41 // Activate initiator_tab. | |
42 static_cast<RenderViewHostDelegate*>(initiator_tab)->Activate(); | |
43 | |
44 // Get the print preview tab for initiator tab. | 42 // Get the print preview tab for initiator tab. |
45 TabContents* new_preview_tab = | 43 TabContents* new_preview_tab = |
46 tab_controller->GetOrCreatePreviewTab(initiator_tab); | 44 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
47 | 45 |
48 // Preview tab already exists. Tab count remains the same. | 46 // Preview tab already exists. Tab count remains the same. |
49 EXPECT_EQ(2, browser()->tab_count()); | 47 EXPECT_EQ(2, browser()->tab_count()); |
50 | 48 |
51 // 1:1 relationship between initiator and preview tab. | 49 // 1:1 relationship between initiator and preview tab. |
52 EXPECT_EQ(new_preview_tab, preview_tab); | 50 EXPECT_EQ(new_preview_tab, preview_tab); |
53 } | 51 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 ASSERT_TRUE(model); | 94 ASSERT_TRUE(model); |
97 | 95 |
98 int preview_tab_1_index = model->GetWrapperIndex(preview_tab_1); | 96 int preview_tab_1_index = model->GetWrapperIndex(preview_tab_1); |
99 int preview_tab_2_index = model->GetWrapperIndex(preview_tab_2); | 97 int preview_tab_2_index = model->GetWrapperIndex(preview_tab_2); |
100 | 98 |
101 EXPECT_NE(-1, preview_tab_1_index); | 99 EXPECT_NE(-1, preview_tab_1_index); |
102 EXPECT_NE(-1, preview_tab_2_index); | 100 EXPECT_NE(-1, preview_tab_2_index); |
103 // Current tab is |preview_tab_2|. | 101 // Current tab is |preview_tab_2|. |
104 EXPECT_EQ(preview_tab_2_index, browser()->active_index()); | 102 EXPECT_EQ(preview_tab_2_index, browser()->active_index()); |
105 | 103 |
106 // Activate |tab_contents_1| tab. | |
107 static_cast<RenderViewHostDelegate*>(tab_contents_1)->Activate(); | |
108 | |
109 // When we get the preview tab for |tab_contents_1|, | 104 // When we get the preview tab for |tab_contents_1|, |
110 // |preview_tab_1| is activated and focused. | 105 // |preview_tab_1| is activated and focused. |
111 tab_controller->GetOrCreatePreviewTab(tab_contents_1); | 106 tab_controller->GetOrCreatePreviewTab(tab_contents_1); |
112 EXPECT_EQ(preview_tab_1_index, browser()->active_index()); | 107 EXPECT_EQ(preview_tab_1_index, browser()->active_index()); |
113 } | 108 } |
114 | 109 |
115 // Clear the initiator tab details associated with preview tab. | 110 // Clear the initiator tab details associated with preview tab. |
116 TEST_F(PrintPreviewTabControllerTest, ClearInitiatorTabDetails) { | 111 TEST_F(PrintPreviewTabControllerTest, ClearInitiatorTabDetails) { |
117 ASSERT_TRUE(browser()); | 112 ASSERT_TRUE(browser()); |
118 BrowserList::SetLastActive(browser()); | 113 BrowserList::SetLastActive(browser()); |
(...skipping 16 matching lines...) Expand all Loading... |
135 TabContents* preview_tab = | 130 TabContents* preview_tab = |
136 tab_controller->GetOrCreatePreviewTab(initiator_tab); | 131 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
137 | 132 |
138 // New print preview tab is created. Current focus is on preview tab. | 133 // New print preview tab is created. Current focus is on preview tab. |
139 EXPECT_EQ(2, browser()->tab_count()); | 134 EXPECT_EQ(2, browser()->tab_count()); |
140 EXPECT_NE(initiator_tab, preview_tab); | 135 EXPECT_NE(initiator_tab, preview_tab); |
141 | 136 |
142 // Clear the initiator tab details associated with the preview tab. | 137 // Clear the initiator tab details associated with the preview tab. |
143 tab_controller->EraseInitiatorTabInfo(preview_tab); | 138 tab_controller->EraseInitiatorTabInfo(preview_tab); |
144 | 139 |
145 // Activate initiator_tab. | 140 // Get the print preview tab for initiator tab. |
146 static_cast<RenderViewHostDelegate*>(initiator_tab)->Activate(); | 141 TabContents* new_preview_tab = |
| 142 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
| 143 |
| 144 // New preview tab is created. |
| 145 EXPECT_EQ(3, browser()->tab_count()); |
| 146 EXPECT_NE(new_preview_tab, preview_tab); |
| 147 } |
| 148 |
| 149 // Navigate away from the Print Preview tab. |
| 150 TEST_F(PrintPreviewTabControllerTest, NavigateFromPrintPreviewTab) { |
| 151 ASSERT_TRUE(browser()); |
| 152 BrowserList::SetLastActive(browser()); |
| 153 ASSERT_TRUE(BrowserList::GetLastActive()); |
| 154 |
| 155 // Lets start with one window with one tab. |
| 156 EXPECT_EQ(1u, BrowserList::size()); |
| 157 EXPECT_EQ(0, browser()->tab_count()); |
| 158 browser()->NewTab(); |
| 159 EXPECT_EQ(1, browser()->tab_count()); |
| 160 |
| 161 // Create a reference to initiator tab contents. |
| 162 TabContents* initiator_tab = browser()->GetSelectedTabContents(); |
| 163 |
| 164 scoped_refptr<printing::PrintPreviewTabController> |
| 165 tab_controller(new printing::PrintPreviewTabController()); |
| 166 ASSERT_TRUE(tab_controller); |
| 167 |
| 168 // Get the preview tab for initiator tab. |
| 169 TabContents* preview_tab = |
| 170 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
| 171 |
| 172 // New print preview tab is created. Current focus is on preview tab. |
| 173 EXPECT_EQ(2, browser()->tab_count()); |
| 174 EXPECT_NE(initiator_tab, preview_tab); |
| 175 |
| 176 NavigationController* controller = |
| 177 &browser()->GetTabContentsAt(1)->controller(); |
| 178 NavigateAndCommit(controller, GURL(chrome::kAboutBlankURL)); |
147 | 179 |
148 // Get the print preview tab for initiator tab. | 180 // Get the print preview tab for initiator tab. |
149 TabContents* new_preview_tab = | 181 TabContents* new_preview_tab = |
150 tab_controller->GetOrCreatePreviewTab(initiator_tab); | 182 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
151 | 183 |
152 // New preview tab is created. | 184 // New preview tab is created. |
153 EXPECT_EQ(3, browser()->tab_count()); | 185 EXPECT_EQ(3, browser()->tab_count()); |
154 EXPECT_NE(new_preview_tab, preview_tab); | 186 EXPECT_NE(new_preview_tab, preview_tab); |
| 187 |
| 188 // Get the print preview tab for old preview tab. |
| 189 TabContents* newest_preview_tab = |
| 190 tab_controller->GetOrCreatePreviewTab(preview_tab); |
| 191 |
| 192 // Newest preview tab is created and the previously created preview tab is not |
| 193 // merely activated. |
| 194 |
| 195 EXPECT_EQ(4, browser()->tab_count()); |
| 196 EXPECT_NE(newest_preview_tab, new_preview_tab); |
155 } | 197 } |
OLD | NEW |