Index: chrome/browser/printing/print_preview_dialog_controller_unittest.cc |
diff --git a/chrome/browser/printing/print_preview_dialog_controller_unittest.cc b/chrome/browser/printing/print_preview_dialog_controller_unittest.cc |
index cae8b66e7db7c701ed2a98ee7f91213431421074..732dee4f5e5980252b0ec0b1578cc1bd6593b0f2 100644 |
--- a/chrome/browser/printing/print_preview_dialog_controller_unittest.cc |
+++ b/chrome/browser/printing/print_preview_dialog_controller_unittest.cc |
@@ -12,7 +12,9 @@ |
#include "chrome/browser/ui/browser_finder.h" |
#include "chrome/browser/ui/tabs/tab_strip_model.h" |
#include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
+#include "content/public/browser/navigation_controller.h" |
#include "content/public/browser/navigation_details.h" |
+#include "content/public/browser/navigation_entry.h" |
#include "content/public/browser/web_contents_delegate.h" |
#include "content/public/common/url_constants.h" |
#include "content/public/test/web_contents_tester.h" |
@@ -169,4 +171,88 @@ TEST_F(PrintPreviewDialogControllerUnitTest, ClearInitiatorDetails) { |
EXPECT_NE(new_preview_dialog, preview_dialog); |
} |
+// Test that print preview dialogs close on navigation to new pages |
+// and when navigating to old pages via fwd/back, but that auto navigation |
+// (typed + address bar) to an existing page as occurs in gmail does not cause |
+// the dialogs to close. |
+TEST_F(PrintPreviewDialogControllerUnitTest, CloseDialogOnNavigation) { |
+ |
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.
|
+ // 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.
|
+ GURL tiger_barb("https://www.google.com/#q=tiger+barb"); |
+ GURL tiger("https://www.google.com/#q=tiger"); |
+ |
+ // Set up by opening a new tab and getting web contents |
+ EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
+ EXPECT_EQ(0, browser()->tab_strip_model()->count()); |
+ chrome::NewTab(browser()); |
+ EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
+ WebContents* web_contents = |
+ browser()->tab_strip_model()->GetActiveWebContents(); |
+ ASSERT_TRUE(web_contents); |
+ 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.
|
+ &web_contents->GetController(); |
+ ASSERT_TRUE(controller); |
Lei Zhang
2016/08/09 01:20:17
This cannot ever fail.
rbpotter
2016/08/09 02:14:14
Done.
|
+ |
+ // 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.
|
+ PrintPreviewDialogController* dialog_controller = |
+ PrintPreviewDialogController::GetInstance(); |
+ ASSERT_TRUE(dialog_controller); |
+ controller->LoadURL(tiger, content::Referrer(), ui::PageTransitionFromInt( |
+ ui::PAGE_TRANSITION_LINK), std::string()); |
+ CommitPendingLoad(controller); |
+ |
+ // Get the preview dialog |
+ PrintViewManager *manager = PrintViewManager::FromWebContents(web_contents); |
Lei Zhang
2016/08/09 01:20:16
PrintViewManager* manager...
rbpotter
2016/08/09 02:14:14
Done.
|
+ manager->PrintPreviewNow(false); |
+ 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.
|
+ dialog_controller->GetOrCreatePreviewDialog(web_contents); |
+ |
+ // New print preview dialog is a constrained window, so the number of tabs is |
+ // still 1. |
+ EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
+ EXPECT_NE(web_contents, preview_dialog); |
+ |
+ // Navigate via link to a similar page. |
+ controller->LoadURL(tiger_barb, content::Referrer(), |
+ ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK), |
+ std::string()); |
+ CommitPendingLoad(controller); |
+ |
+ // 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.
|
+ 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.
|
+ WebContents* preview_dialog_2 = |
+ dialog_controller->GetOrCreatePreviewDialog(web_contents); |
+ |
+ // Check that new dialog was created |
+ ASSERT_TRUE(preview_dialog_2); |
+ 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.
|
+ |
+ // 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.
|
+ controller->GoBack(); |
+ CommitPendingLoad(controller); |
+ ASSERT_TRUE(manager->PrintPreviewNow(false)); |
+ WebContents* preview_dialog_3 = |
+ dialog_controller->GetOrCreatePreviewDialog(web_contents); |
+ ASSERT_TRUE(preview_dialog_3); |
+ EXPECT_NE(preview_dialog_2, preview_dialog_3); |
+ |
+ // Try to simulate Gmail navigation: Navigate to an existing page (via |
+ // Forward) but modify the navigation type while pending to look like an |
+ // address bar + typed transition (like Gmail auto navigation) |
+ content::NavigationController::LoadURLParams params(tiger); |
+ controller->GoForward(); |
+ controller->GetPendingEntry()->SetTransitionType(ui::PageTransitionFromInt( |
+ ui::PAGE_TRANSITION_TYPED|ui::PAGE_TRANSITION_FROM_ADDRESS_BAR)); |
+ CommitPendingLoad(controller); |
+ |
+ // Print preview should not have changed due to this navigation type so print |
+ // preview now should return false and the dialogs should be the same. |
+ ASSERT_FALSE(manager->PrintPreviewNow(false)); |
+ WebContents* preview_dialog_4 = |
+ dialog_controller->GetOrCreatePreviewDialog(web_contents); |
+ ASSERT_TRUE(preview_dialog_4); |
+ EXPECT_EQ(preview_dialog_4, preview_dialog_3); |
+ |
+} |
+ |
} // namespace printing |