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/printing/print_preview_dialog_controller.h" | 5 #include "chrome/browser/printing/print_preview_dialog_controller.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "chrome/browser/printing/print_preview_test.h" | 9 #include "chrome/browser/printing/print_preview_test.h" |
10 #include "chrome/browser/printing/print_view_manager.h" | 10 #include "chrome/browser/printing/print_view_manager.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // Since |preview_dialog_2_index| was the most recently created dialog, its | 122 // Since |preview_dialog_2_index| was the most recently created dialog, its |
123 // initiator should have focus. | 123 // initiator should have focus. |
124 EXPECT_EQ(tab_2_index, tab_strip_model->active_index()); | 124 EXPECT_EQ(tab_2_index, tab_strip_model->active_index()); |
125 | 125 |
126 // When we get the preview dialog for |web_contents_1|, | 126 // When we get the preview dialog for |web_contents_1|, |
127 // |preview_dialog_1| is activated and focused. | 127 // |preview_dialog_1| is activated and focused. |
128 dialog_controller->GetOrCreatePreviewDialog(web_contents_1); | 128 dialog_controller->GetOrCreatePreviewDialog(web_contents_1); |
129 EXPECT_EQ(tab_1_index, tab_strip_model->active_index()); | 129 EXPECT_EQ(tab_1_index, tab_strip_model->active_index()); |
130 } | 130 } |
131 | 131 |
132 // Get a preview dialog for a proxied initiator should work. | |
133 TEST_F(PrintPreviewDialogControllerUnitTest, ProxyGetOrCreatePreviewDialog) { | |
134 // Lets start with one window with one tab. | |
135 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | |
136 EXPECT_EQ(0, browser()->tab_strip_model()->count()); | |
137 chrome::NewTab(browser()); | |
138 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
139 | |
140 // Create a reference to initiator contents. | |
141 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents(); | |
142 | |
143 PrintPreviewDialogController* dialog_controller = | |
144 PrintPreviewDialogController::GetInstance(); | |
145 ASSERT_TRUE(dialog_controller); | |
146 | |
147 // Get the preview dialog for initiator. | |
148 PrintViewManager::FromWebContents(initiator)->PrintPreviewNow(false); | |
149 WebContents* preview_dialog = | |
150 dialog_controller->GetOrCreatePreviewDialog(initiator); | |
151 | |
152 // New print preview dialog is a constrained window, so the number of tabs is | |
153 // still 1. | |
154 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
155 EXPECT_NE(initiator, preview_dialog); | |
156 | |
157 // Create the proxy web contents. | |
158 std::unique_ptr<WebContents> proxy( | |
159 content::WebContentsTester::CreateTestWebContents(profile(), nullptr)); | |
160 TestWebContentsDelegate delegate; | |
161 proxy->SetDelegate(&delegate); | |
162 dialog_controller->AddProxyDialogForWebContents(proxy.get(), initiator); | |
163 | |
164 // Get the print preview dialog for the initiator and proxy. | |
165 WebContents* initiator_preview_dialog = | |
166 dialog_controller->GetOrCreatePreviewDialog(initiator); | |
167 WebContents* proxy_preview_dialog = | |
168 dialog_controller->GetOrCreatePreviewDialog(proxy.get()); | |
169 | |
170 // Preview dialog already exists. Tab count remains the same. | |
171 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
172 | |
173 // 1:1 relationship between initiator and preview dialog. | |
174 EXPECT_EQ(initiator_preview_dialog, preview_dialog); | |
175 EXPECT_EQ(proxy_preview_dialog, preview_dialog); | |
176 | |
177 dialog_controller->RemoveProxyDialogForWebContents(proxy.get()); | |
178 } | |
179 | |
180 // Create a preview dialog for a proxied initiator should fail. | |
181 TEST_F(PrintPreviewDialogControllerUnitTest, ProxyNoGetOrCreatePreviewDialog) { | |
182 // Lets start with one window with one tab. | |
183 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | |
184 EXPECT_EQ(0, browser()->tab_strip_model()->count()); | |
185 chrome::NewTab(browser()); | |
186 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
187 | |
188 // Create a reference to initiator contents. | |
189 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents(); | |
190 | |
191 PrintPreviewDialogController* dialog_controller = | |
192 PrintPreviewDialogController::GetInstance(); | |
193 ASSERT_TRUE(dialog_controller); | |
194 | |
195 // Create the proxy web contents. | |
196 std::unique_ptr<WebContents> proxy( | |
197 content::WebContentsTester::CreateTestWebContents(profile(), nullptr)); | |
198 TestWebContentsDelegate delegate; | |
199 proxy->SetDelegate(&delegate); | |
200 dialog_controller->AddProxyDialogForWebContents(proxy.get(), initiator); | |
201 | |
202 // Get the print preview dialog for the proxy. | |
203 WebContents* proxy_preview_dialog = | |
204 dialog_controller->GetOrCreatePreviewDialog(proxy.get()); | |
205 | |
206 // Preview dialog shouldn't be created. Tab count remains the same. | |
207 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
208 | |
209 // A proxy should not create a dialog, only re-use. | |
210 EXPECT_EQ(proxy_preview_dialog, nullptr); | |
211 | |
212 dialog_controller->RemoveProxyDialogForWebContents(proxy.get()); | |
213 } | |
214 | |
215 // Check clearing the initiator details associated with a print preview dialog | 132 // Check clearing the initiator details associated with a print preview dialog |
216 // allows the initiator to create another print preview dialog. | 133 // allows the initiator to create another print preview dialog. |
217 TEST_F(PrintPreviewDialogControllerUnitTest, ClearInitiatorDetails) { | 134 TEST_F(PrintPreviewDialogControllerUnitTest, ClearInitiatorDetails) { |
218 // Lets start with one window with one tab. | 135 // Lets start with one window with one tab. |
219 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | 136 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
220 EXPECT_EQ(0, browser()->tab_strip_model()->count()); | 137 EXPECT_EQ(0, browser()->tab_strip_model()->count()); |
221 chrome::NewTab(browser()); | 138 chrome::NewTab(browser()); |
222 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 139 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
223 | 140 |
224 // Create a reference to initiator contents. | 141 // Create a reference to initiator contents. |
(...skipping 21 matching lines...) Expand all Loading... |
246 dialog_controller->GetOrCreatePreviewDialog(initiator); | 163 dialog_controller->GetOrCreatePreviewDialog(initiator); |
247 | 164 |
248 // New print preview dialog is a constrained window, so the number of tabs is | 165 // New print preview dialog is a constrained window, so the number of tabs is |
249 // still 1. | 166 // still 1. |
250 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 167 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
251 // Verify a new print preview dialog has been created. | 168 // Verify a new print preview dialog has been created. |
252 EXPECT_NE(new_preview_dialog, preview_dialog); | 169 EXPECT_NE(new_preview_dialog, preview_dialog); |
253 } | 170 } |
254 | 171 |
255 } // namespace printing | 172 } // namespace printing |
OLD | NEW |