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" |
11 #include "chrome/browser/ui/browser_commands.h" | 11 #include "chrome/browser/ui/browser_commands.h" |
12 #include "chrome/browser/ui/browser_finder.h" | 12 #include "chrome/browser/ui/browser_finder.h" |
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
14 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" | 14 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
15 #include "content/public/browser/navigation_controller.h" | |
15 #include "content/public/browser/navigation_details.h" | 16 #include "content/public/browser/navigation_details.h" |
17 #include "content/public/browser/navigation_entry.h" | |
16 #include "content/public/browser/web_contents_delegate.h" | 18 #include "content/public/browser/web_contents_delegate.h" |
17 #include "content/public/common/url_constants.h" | 19 #include "content/public/common/url_constants.h" |
18 #include "content/public/test/web_contents_tester.h" | 20 #include "content/public/test/web_contents_tester.h" |
19 | 21 |
20 using content::WebContents; | 22 using content::WebContents; |
21 | 23 |
22 namespace { | 24 namespace { |
23 // content::WebContentsDelegate destructor is protected: subclass for testing. | 25 // content::WebContentsDelegate destructor is protected: subclass for testing. |
24 class TestWebContentsDelegate : public content::WebContentsDelegate {}; | 26 class TestWebContentsDelegate : public content::WebContentsDelegate {}; |
25 } // namespace | 27 } // namespace |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 WebContents* new_preview_dialog = | 164 WebContents* new_preview_dialog = |
163 dialog_controller->GetOrCreatePreviewDialog(initiator); | 165 dialog_controller->GetOrCreatePreviewDialog(initiator); |
164 | 166 |
165 // New print preview dialog is a constrained window, so the number of tabs is | 167 // New print preview dialog is a constrained window, so the number of tabs is |
166 // still 1. | 168 // still 1. |
167 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 169 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
168 // Verify a new print preview dialog has been created. | 170 // Verify a new print preview dialog has been created. |
169 EXPECT_NE(new_preview_dialog, preview_dialog); | 171 EXPECT_NE(new_preview_dialog, preview_dialog); |
170 } | 172 } |
171 | 173 |
174 // Test that print preview dialogs close on navigation to new pages | |
175 // and when navigating to old pages via fwd/back, but that auto navigation | |
176 // (typed + address bar) to an existing page as occurs in gmail does not cause | |
177 // the dialogs to close. | |
178 TEST_F(PrintPreviewDialogControllerUnitTest, CloseDialogOnNavigation) { | |
179 | |
Lei Zhang
2016/08/09 01:20:16
No blank lines at the beginning and end of functio
rbpotter
2016/08/09 02:14:14
Done.
| |
180 // Two similar URLs (same webpage, slight difference at end) | |
Lei Zhang
2016/08/09 01:20:17
s/slight difference.*/different URL fragments/
rbpotter
2016/08/09 02:14:14
Done.
| |
181 GURL tiger_barb("https://www.google.com/#q=tiger+barb"); | |
182 GURL tiger("https://www.google.com/#q=tiger"); | |
183 | |
184 // Set up by opening a new tab and getting web contents | |
185 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | |
186 EXPECT_EQ(0, browser()->tab_strip_model()->count()); | |
187 chrome::NewTab(browser()); | |
188 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
189 WebContents* web_contents = | |
190 browser()->tab_strip_model()->GetActiveWebContents(); | |
191 ASSERT_TRUE(web_contents); | |
192 content::NavigationController *controller = | |
Lei Zhang
2016/08/09 01:20:16
content::NavigationController* controller = <-- s
Lei Zhang
2016/08/09 01:20:17
Name this nav_controller since there's also a dial
rbpotter
2016/08/09 02:14:14
Done.
rbpotter
2016/08/09 02:14:14
Done.
| |
193 &web_contents->GetController(); | |
194 ASSERT_TRUE(controller); | |
Lei Zhang
2016/08/09 01:20:17
This cannot ever fail.
rbpotter
2016/08/09 02:14:14
Done.
| |
195 | |
196 // Get Print preview controller and navigate to first page | |
Lei Zhang
2016/08/09 01:20:16
Do you have to do it in this order? |dialog_contro
rbpotter
2016/08/09 02:14:14
Done.
| |
197 PrintPreviewDialogController* dialog_controller = | |
198 PrintPreviewDialogController::GetInstance(); | |
199 ASSERT_TRUE(dialog_controller); | |
200 controller->LoadURL(tiger, content::Referrer(), ui::PageTransitionFromInt( | |
201 ui::PAGE_TRANSITION_LINK), std::string()); | |
202 CommitPendingLoad(controller); | |
203 | |
204 // Get the preview dialog | |
205 PrintViewManager *manager = PrintViewManager::FromWebContents(web_contents); | |
Lei Zhang
2016/08/09 01:20:16
PrintViewManager* manager...
rbpotter
2016/08/09 02:14:14
Done.
| |
206 manager->PrintPreviewNow(false); | |
207 WebContents* preview_dialog = | |
Lei Zhang
2016/08/09 01:20:16
Maybe tiger_preview_dialog (and tiger_barb_preview
rbpotter
2016/08/09 02:14:14
Done.
| |
208 dialog_controller->GetOrCreatePreviewDialog(web_contents); | |
209 | |
210 // New print preview dialog is a constrained window, so the number of tabs is | |
211 // still 1. | |
212 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
213 EXPECT_NE(web_contents, preview_dialog); | |
214 | |
215 // Navigate via link to a similar page. | |
216 controller->LoadURL(tiger_barb, content::Referrer(), | |
217 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK), | |
218 std::string()); | |
219 CommitPendingLoad(controller); | |
220 | |
221 // Print preview now should return true as dialog should be closed. | |
Lei Zhang
2016/08/09 01:20:17
"Print preview should now return true because the
rbpotter
2016/08/09 02:14:14
Done.
| |
222 ASSERT_TRUE(manager->PrintPreviewNow(false)); | |
Lei Zhang
2016/08/09 01:20:16
Do the ASSERT.*()s here and below need to be ASSER
Lei Zhang
2016/08/09 01:20:17
Can you do another PrintPreviewNow() before the "t
rbpotter
2016/08/09 02:14:14
Done.
rbpotter
2016/08/09 02:14:14
Done.
| |
223 WebContents* preview_dialog_2 = | |
224 dialog_controller->GetOrCreatePreviewDialog(web_contents); | |
225 | |
226 // Check that new dialog was created | |
227 ASSERT_TRUE(preview_dialog_2); | |
228 EXPECT_NE(preview_dialog, preview_dialog_2); | |
Lei Zhang
2016/08/09 01:20:17
Also check |preview_dialog_2| is not |web_contents
rbpotter
2016/08/09 02:14:14
Done.
| |
229 | |
230 // Navigate with back button or CTRL+LEFT ARROW to a similar page. | |
Lei Zhang
2016/08/09 01:20:16
Did you mean ALT?
rbpotter
2016/08/09 02:14:14
Done.
| |
231 controller->GoBack(); | |
232 CommitPendingLoad(controller); | |
233 ASSERT_TRUE(manager->PrintPreviewNow(false)); | |
234 WebContents* preview_dialog_3 = | |
235 dialog_controller->GetOrCreatePreviewDialog(web_contents); | |
236 ASSERT_TRUE(preview_dialog_3); | |
237 EXPECT_NE(preview_dialog_2, preview_dialog_3); | |
238 | |
239 // Try to simulate Gmail navigation: Navigate to an existing page (via | |
240 // Forward) but modify the navigation type while pending to look like an | |
241 // address bar + typed transition (like Gmail auto navigation) | |
242 content::NavigationController::LoadURLParams params(tiger); | |
243 controller->GoForward(); | |
244 controller->GetPendingEntry()->SetTransitionType(ui::PageTransitionFromInt( | |
245 ui::PAGE_TRANSITION_TYPED|ui::PAGE_TRANSITION_FROM_ADDRESS_BAR)); | |
246 CommitPendingLoad(controller); | |
247 | |
248 // Print preview should not have changed due to this navigation type so print | |
249 // preview now should return false and the dialogs should be the same. | |
250 ASSERT_FALSE(manager->PrintPreviewNow(false)); | |
251 WebContents* preview_dialog_4 = | |
252 dialog_controller->GetOrCreatePreviewDialog(web_contents); | |
253 ASSERT_TRUE(preview_dialog_4); | |
254 EXPECT_EQ(preview_dialog_4, preview_dialog_3); | |
255 | |
256 } | |
257 | |
172 } // namespace printing | 258 } // namespace printing |
OLD | NEW |