Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: chrome/browser/printing/print_preview_dialog_controller_unittest.cc

Issue 2215063002: Fix Print Preview Alt + Left Arrow breakage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comments and style issues Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/printing/print_preview_dialog_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // Two similar URLs (same webpage, different URL fragments)
180 GURL tiger_barb("https://www.google.com/#q=tiger+barb");
181 GURL tiger("https://www.google.com/#q=tiger");
182
183 // Set up by opening a new tab and getting web contents
184 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
185 EXPECT_EQ(0, browser()->tab_strip_model()->count());
186 chrome::NewTab(browser());
187 EXPECT_EQ(1, browser()->tab_strip_model()->count());
188 WebContents* web_contents =
189 browser()->tab_strip_model()->GetActiveWebContents();
190 ASSERT_TRUE(web_contents);
191 content::NavigationController& nav_controller =
192 web_contents->GetController();
Lei Zhang 2016/08/09 06:19:59 Fits on previous line. git cl format is your frien
193
194 // Navigate to first page
195 nav_controller.LoadURL(tiger, content::Referrer(),
196 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK),
Lei Zhang 2016/08/09 06:19:59 indentation is off. git cl format...
197 std::string());
198 CommitPendingLoad(&nav_controller);
199
200 // Get the preview dialog
201 PrintPreviewDialogController* dialog_controller =
202 PrintPreviewDialogController::GetInstance();
203 ASSERT_TRUE(dialog_controller);
204 PrintViewManager* manager = PrintViewManager::FromWebContents(web_contents);
205 manager->PrintPreviewNow(false);
206 WebContents* tiger_preview_dialog =
207 dialog_controller->GetOrCreatePreviewDialog(web_contents);
208
209 // New print preview dialog is a constrained window, so the number of tabs is
210 // still 1.
211 EXPECT_EQ(1, browser()->tab_strip_model()->count());
212 EXPECT_NE(web_contents, tiger_preview_dialog);
213
214 // Navigate via link to a similar page.
215 nav_controller.LoadURL(tiger_barb, content::Referrer(),
216 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK),
217 std::string());
218 CommitPendingLoad(&nav_controller);
219
220 // Print preview now should return true as the navigation should have closed
221 // |tiger_preview_dialog|
222 EXPECT_TRUE(manager->PrintPreviewNow(false));
223 WebContents* tiger_barb_preview_dialog =
224 dialog_controller->GetOrCreatePreviewDialog(web_contents);
225
226 // Check that new dialog was created
227 ASSERT_TRUE(tiger_barb_preview_dialog);
228 EXPECT_NE(tiger_preview_dialog, tiger_barb_preview_dialog);
229 EXPECT_NE(tiger_barb_preview_dialog, web_contents);
230
231 // Now this returns false as |tiger_barb_preview_dialog| is open.
232 EXPECT_FALSE(manager->PrintPreviewNow(false));
233
234 // Navigate with back button or ALT+LEFT ARROW to a similar page.
235 nav_controller.GoBack();
236 CommitPendingLoad(&nav_controller);
237 EXPECT_TRUE(manager->PrintPreviewNow(false));
238 WebContents* tiger_preview_dialog_2 =
239 dialog_controller->GetOrCreatePreviewDialog(web_contents);
240 ASSERT_TRUE(tiger_preview_dialog_2);
241 EXPECT_NE(tiger_barb_preview_dialog, tiger_preview_dialog_2);
242 EXPECT_NE(tiger_preview_dialog_2, web_contents);
243
244 // Try to simulate Gmail navigation: Navigate to an existing page (via
245 // Forward) but modify the navigation type while pending to look like an
246 // address bar + typed transition (like Gmail auto navigation)
247 nav_controller.GoForward();
248 nav_controller.GetPendingEntry()->SetTransitionType(
249 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED|
250 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR));
251 CommitPendingLoad(&nav_controller);
252
253 // Print preview should not have changed due to this navigation type so print
254 // preview now should return false and the dialogs should be the same.
255 EXPECT_FALSE(manager->PrintPreviewNow(false));
256 WebContents* tiger_preview_dialog_2b =
257 dialog_controller->GetOrCreatePreviewDialog(web_contents);
258 ASSERT_TRUE(tiger_preview_dialog_2b);
259 EXPECT_EQ(tiger_preview_dialog_2b, tiger_preview_dialog_2);
260 EXPECT_NE(tiger_preview_dialog_2b, web_contents);
261 }
262
172 } // namespace printing 263 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_preview_dialog_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698