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

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

Issue 2508923003: Make printing work better with OOPIF. (try 2) (Closed)
Patch Set: Fix android_webview Created 4 years, 1 month 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
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 #include <string> 8 #include <string>
9 9
10 #include "chrome/browser/printing/print_preview_test.h" 10 #include "chrome/browser/printing/print_preview_test.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 63 EXPECT_EQ(1, browser()->tab_strip_model()->count());
64 64
65 // Create a reference to initiator contents. 65 // Create a reference to initiator contents.
66 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents(); 66 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents();
67 67
68 PrintPreviewDialogController* dialog_controller = 68 PrintPreviewDialogController* dialog_controller =
69 PrintPreviewDialogController::GetInstance(); 69 PrintPreviewDialogController::GetInstance();
70 ASSERT_TRUE(dialog_controller); 70 ASSERT_TRUE(dialog_controller);
71 71
72 // Get the preview dialog for initiator. 72 // Get the preview dialog for initiator.
73 PrintViewManager::FromWebContents(initiator)->PrintPreviewNow(false); 73 PrintViewManager::FromWebContents(initiator)->PrintPreviewNow(
74 initiator->GetMainFrame(), false);
74 WebContents* preview_dialog = 75 WebContents* preview_dialog =
75 dialog_controller->GetOrCreatePreviewDialog(initiator); 76 dialog_controller->GetOrCreatePreviewDialog(initiator);
76 77
77 // New print preview dialog is a constrained window, so the number of tabs is 78 // New print preview dialog is a constrained window, so the number of tabs is
78 // still 1. 79 // still 1.
79 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 80 EXPECT_EQ(1, browser()->tab_strip_model()->count());
80 EXPECT_NE(initiator, preview_dialog); 81 EXPECT_NE(initiator, preview_dialog);
81 82
82 // Get the print preview dialog for the same initiator. 83 // Get the print preview dialog for the same initiator.
83 WebContents* new_preview_dialog = 84 WebContents* new_preview_dialog =
(...skipping 25 matching lines...) Expand all
109 chrome::NewTab(browser()); 110 chrome::NewTab(browser());
110 WebContents* web_contents_2 = tab_strip_model->GetActiveWebContents(); 111 WebContents* web_contents_2 = tab_strip_model->GetActiveWebContents();
111 ASSERT_TRUE(web_contents_2); 112 ASSERT_TRUE(web_contents_2);
112 EXPECT_EQ(2, tab_strip_model->count()); 113 EXPECT_EQ(2, tab_strip_model->count());
113 114
114 PrintPreviewDialogController* dialog_controller = 115 PrintPreviewDialogController* dialog_controller =
115 PrintPreviewDialogController::GetInstance(); 116 PrintPreviewDialogController::GetInstance();
116 ASSERT_TRUE(dialog_controller); 117 ASSERT_TRUE(dialog_controller);
117 118
118 // Create preview dialog for |web_contents_1| 119 // Create preview dialog for |web_contents_1|
119 PrintViewManager::FromWebContents(web_contents_1)->PrintPreviewNow(false); 120 PrintViewManager::FromWebContents(web_contents_1)
121 ->PrintPreviewNow(web_contents_1->GetMainFrame(), false);
120 WebContents* preview_dialog_1 = 122 WebContents* preview_dialog_1 =
121 dialog_controller->GetOrCreatePreviewDialog(web_contents_1); 123 dialog_controller->GetOrCreatePreviewDialog(web_contents_1);
122 124
123 EXPECT_NE(web_contents_1, preview_dialog_1); 125 EXPECT_NE(web_contents_1, preview_dialog_1);
124 EXPECT_EQ(2, tab_strip_model->count()); 126 EXPECT_EQ(2, tab_strip_model->count());
125 127
126 // Create preview dialog for |web_contents_2| 128 // Create preview dialog for |web_contents_2|
127 PrintViewManager::FromWebContents(web_contents_2)->PrintPreviewNow(false); 129 PrintViewManager::FromWebContents(web_contents_2)
130 ->PrintPreviewNow(web_contents_2->GetMainFrame(), false);
128 WebContents* preview_dialog_2 = 131 WebContents* preview_dialog_2 =
129 dialog_controller->GetOrCreatePreviewDialog(web_contents_2); 132 dialog_controller->GetOrCreatePreviewDialog(web_contents_2);
130 133
131 EXPECT_NE(web_contents_2, preview_dialog_2); 134 EXPECT_NE(web_contents_2, preview_dialog_2);
132 EXPECT_NE(preview_dialog_1, preview_dialog_2); 135 EXPECT_NE(preview_dialog_1, preview_dialog_2);
133 // 2 initiators and 2 preview dialogs exist in the same browser. The preview 136 // 2 initiators and 2 preview dialogs exist in the same browser. The preview
134 // dialogs are constrained in their respective initiators. 137 // dialogs are constrained in their respective initiators.
135 EXPECT_EQ(2, tab_strip_model->count()); 138 EXPECT_EQ(2, tab_strip_model->count());
136 139
137 int tab_1_index = tab_strip_model->GetIndexOfWebContents(web_contents_1); 140 int tab_1_index = tab_strip_model->GetIndexOfWebContents(web_contents_1);
(...skipping 27 matching lines...) Expand all
165 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 168 EXPECT_EQ(1, browser()->tab_strip_model()->count());
166 169
167 // Create a reference to initiator contents. 170 // Create a reference to initiator contents.
168 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents(); 171 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents();
169 172
170 PrintPreviewDialogController* dialog_controller = 173 PrintPreviewDialogController* dialog_controller =
171 PrintPreviewDialogController::GetInstance(); 174 PrintPreviewDialogController::GetInstance();
172 ASSERT_TRUE(dialog_controller); 175 ASSERT_TRUE(dialog_controller);
173 176
174 // Get the preview dialog for the initiator. 177 // Get the preview dialog for the initiator.
175 PrintViewManager::FromWebContents(initiator)->PrintPreviewNow(false); 178 PrintViewManager::FromWebContents(initiator)->PrintPreviewNow(
179 initiator->GetMainFrame(), false);
176 WebContents* preview_dialog = 180 WebContents* preview_dialog =
177 dialog_controller->GetOrCreatePreviewDialog(initiator); 181 dialog_controller->GetOrCreatePreviewDialog(initiator);
178 182
179 // New print preview dialog is a constrained window, so the number of tabs is 183 // New print preview dialog is a constrained window, so the number of tabs is
180 // still 1. 184 // still 1.
181 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 185 EXPECT_EQ(1, browser()->tab_strip_model()->count());
182 EXPECT_NE(initiator, preview_dialog); 186 EXPECT_NE(initiator, preview_dialog);
183 187
184 // Clear the initiator details associated with the preview dialog. 188 // Clear the initiator details associated with the preview dialog.
185 dialog_controller->EraseInitiatorInfo(preview_dialog); 189 dialog_controller->EraseInitiatorInfo(preview_dialog);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 CommitPendingLoad(&nav_controller); 225 CommitPendingLoad(&nav_controller);
222 EXPECT_EQ(tiger, web_contents->GetLastCommittedURL()); 226 EXPECT_EQ(tiger, web_contents->GetLastCommittedURL());
223 227
224 // Get the preview dialog 228 // Get the preview dialog
225 PrintPreviewDialogController* dialog_controller = 229 PrintPreviewDialogController* dialog_controller =
226 PrintPreviewDialogController::GetInstance(); 230 PrintPreviewDialogController::GetInstance();
227 ASSERT_TRUE(dialog_controller); 231 ASSERT_TRUE(dialog_controller);
228 WebContents* tiger_preview_dialog = 232 WebContents* tiger_preview_dialog =
229 dialog_controller->GetOrCreatePreviewDialog(web_contents); 233 dialog_controller->GetOrCreatePreviewDialog(web_contents);
230 PrintViewManager* manager = PrintViewManager::FromWebContents(web_contents); 234 PrintViewManager* manager = PrintViewManager::FromWebContents(web_contents);
231 manager->PrintPreviewNow(false); 235 manager->PrintPreviewNow(web_contents->GetMainFrame(), false);
232 236
233 // New print preview dialog is a constrained window, so the number of tabs is 237 // New print preview dialog is a constrained window, so the number of tabs is
234 // still 1. 238 // still 1.
235 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 239 EXPECT_EQ(1, browser()->tab_strip_model()->count());
236 EXPECT_NE(web_contents, tiger_preview_dialog); 240 EXPECT_NE(web_contents, tiger_preview_dialog);
237 PrintPreviewDialogDestroyedObserver tiger_destroyed(tiger_preview_dialog); 241 PrintPreviewDialogDestroyedObserver tiger_destroyed(tiger_preview_dialog);
238 242
239 // Navigate via link to a similar page. 243 // Navigate via link to a similar page.
240 nav_controller.LoadURL(tiger_barb, content::Referrer(), 244 nav_controller.LoadURL(tiger_barb, content::Referrer(),
241 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK), 245 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK),
242 std::string()); 246 std::string());
243 CommitPendingLoad(&nav_controller); 247 CommitPendingLoad(&nav_controller);
244 248
245 // Check navigation was successful 249 // Check navigation was successful
246 EXPECT_EQ(tiger_barb, web_contents->GetLastCommittedURL()); 250 EXPECT_EQ(tiger_barb, web_contents->GetLastCommittedURL());
247 251
248 // Print preview now should return true as the navigation should have closed 252 // Print preview now should return true as the navigation should have closed
249 // |tiger_preview_dialog| and the previous dialog should have closed. 253 // |tiger_preview_dialog| and the previous dialog should have closed.
250 EXPECT_TRUE(manager->PrintPreviewNow(false)); 254 EXPECT_TRUE(manager->PrintPreviewNow(web_contents->GetMainFrame(), false));
251 WebContents* tiger_barb_preview_dialog = 255 WebContents* tiger_barb_preview_dialog =
252 dialog_controller->GetOrCreatePreviewDialog(web_contents); 256 dialog_controller->GetOrCreatePreviewDialog(web_contents);
253 ASSERT_TRUE(tiger_barb_preview_dialog); 257 ASSERT_TRUE(tiger_barb_preview_dialog);
254 258
255 // Check a new dialog was created - either the pointers should be different or 259 // Check a new dialog was created - either the pointers should be different or
256 // the previous web contents must have been destroyed. 260 // the previous web contents must have been destroyed.
257 EXPECT_TRUE(tiger_destroyed.dialog_destroyed() || 261 EXPECT_TRUE(tiger_destroyed.dialog_destroyed() ||
258 tiger_barb_preview_dialog != tiger_preview_dialog); 262 tiger_barb_preview_dialog != tiger_preview_dialog);
259 EXPECT_NE(tiger_barb_preview_dialog, web_contents); 263 EXPECT_NE(tiger_barb_preview_dialog, web_contents);
260 PrintPreviewDialogDestroyedObserver tiger_barb_destroyed( 264 PrintPreviewDialogDestroyedObserver tiger_barb_destroyed(
261 tiger_barb_preview_dialog); 265 tiger_barb_preview_dialog);
262 266
263 // Now this returns false as |tiger_barb_preview_dialog| is open. 267 // Now this returns false as |tiger_barb_preview_dialog| is open.
264 EXPECT_FALSE(manager->PrintPreviewNow(false)); 268 EXPECT_FALSE(manager->PrintPreviewNow(web_contents->GetMainFrame(), false));
265 269
266 // Navigate with back button or ALT+LEFT ARROW to a similar page. 270 // Navigate with back button or ALT+LEFT ARROW to a similar page.
267 nav_controller.GoBack(); 271 nav_controller.GoBack();
268 CommitPendingLoad(&nav_controller); 272 CommitPendingLoad(&nav_controller);
269 EXPECT_EQ(tiger, web_contents->GetLastCommittedURL()); 273 EXPECT_EQ(tiger, web_contents->GetLastCommittedURL());
270 EXPECT_TRUE(manager->PrintPreviewNow(false)); 274 EXPECT_TRUE(manager->PrintPreviewNow(web_contents->GetMainFrame(), false));
271 275
272 // Get new dialog 276 // Get new dialog
273 WebContents* tiger_preview_dialog_2 = 277 WebContents* tiger_preview_dialog_2 =
274 dialog_controller->GetOrCreatePreviewDialog(web_contents); 278 dialog_controller->GetOrCreatePreviewDialog(web_contents);
275 ASSERT_TRUE(tiger_preview_dialog_2); 279 ASSERT_TRUE(tiger_preview_dialog_2);
276 280
277 // Verify this is a new dialog. 281 // Verify this is a new dialog.
278 EXPECT_TRUE(tiger_barb_destroyed.dialog_destroyed() || 282 EXPECT_TRUE(tiger_barb_destroyed.dialog_destroyed() ||
279 tiger_barb_preview_dialog != tiger_preview_dialog_2); 283 tiger_barb_preview_dialog != tiger_preview_dialog_2);
280 EXPECT_NE(tiger_preview_dialog_2, web_contents); 284 EXPECT_NE(tiger_preview_dialog_2, web_contents);
281 PrintPreviewDialogDestroyedObserver tiger_2_destroyed( 285 PrintPreviewDialogDestroyedObserver tiger_2_destroyed(
282 tiger_preview_dialog_2); 286 tiger_preview_dialog_2);
283 287
284 // Try to simulate Gmail navigation: Navigate to an existing page (via 288 // Try to simulate Gmail navigation: Navigate to an existing page (via
285 // Forward) but modify the navigation type while pending to look like an 289 // Forward) but modify the navigation type while pending to look like an
286 // address bar + typed transition (like Gmail auto navigation) 290 // address bar + typed transition (like Gmail auto navigation)
287 nav_controller.GoForward(); 291 nav_controller.GoForward();
288 nav_controller.GetPendingEntry()->SetTransitionType(ui::PageTransitionFromInt( 292 nav_controller.GetPendingEntry()->SetTransitionType(ui::PageTransitionFromInt(
289 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR)); 293 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR));
290 CommitPendingLoad(&nav_controller); 294 CommitPendingLoad(&nav_controller);
291 295
292 // Navigation successful 296 // Navigation successful
293 EXPECT_EQ(tiger_barb, web_contents->GetLastCommittedURL()); 297 EXPECT_EQ(tiger_barb, web_contents->GetLastCommittedURL());
294 298
295 // Print preview should not have changed due to this navigation type so print 299 // Print preview should not have changed due to this navigation type so print
296 // preview now should return false, dialog is still alive, and the dialog 300 // preview now should return false, dialog is still alive, and the dialog
297 // returned by GetOrCreatePreviewDialog should be the same as the earlier 301 // returned by GetOrCreatePreviewDialog should be the same as the earlier
298 // dialog. 302 // dialog.
299 EXPECT_FALSE(manager->PrintPreviewNow(false)); 303 EXPECT_FALSE(manager->PrintPreviewNow(web_contents->GetMainFrame(), false));
300 EXPECT_FALSE(tiger_2_destroyed.dialog_destroyed()); 304 EXPECT_FALSE(tiger_2_destroyed.dialog_destroyed());
301 WebContents* tiger_preview_dialog_2b = 305 WebContents* tiger_preview_dialog_2b =
302 dialog_controller->GetOrCreatePreviewDialog(web_contents); 306 dialog_controller->GetOrCreatePreviewDialog(web_contents);
303 ASSERT_TRUE(tiger_preview_dialog_2b); 307 ASSERT_TRUE(tiger_preview_dialog_2b);
304 EXPECT_EQ(tiger_preview_dialog_2b, tiger_preview_dialog_2); 308 EXPECT_EQ(tiger_preview_dialog_2b, tiger_preview_dialog_2);
305 EXPECT_NE(tiger_preview_dialog_2b, web_contents); 309 EXPECT_NE(tiger_preview_dialog_2b, web_contents);
306 } 310 }
307 311
308 // Tests preview dialog controller cleans up correctly and does not throw errors 312 // Tests preview dialog controller cleans up correctly and does not throw errors
309 // on a renderer process crash. Checks that the renderer process closed 313 // on a renderer process crash. Checks that the renderer process closed
310 // notification is still received even if one of two preview dialogs with the 314 // notification is still received even if one of two preview dialogs with the
311 // same renderer process host is closed before the process "crashes". 315 // same renderer process host is closed before the process "crashes".
312 TEST_F(PrintPreviewDialogControllerUnitTest, MultiplePreviewDialogsClose) { 316 TEST_F(PrintPreviewDialogControllerUnitTest, MultiplePreviewDialogsClose) {
313 // Set up the browser. 317 // Set up the browser.
314 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); 318 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
315 TabStripModel* tab_strip_model = browser()->tab_strip_model(); 319 TabStripModel* tab_strip_model = browser()->tab_strip_model();
316 ASSERT_TRUE(tab_strip_model); 320 ASSERT_TRUE(tab_strip_model);
317 EXPECT_EQ(0, tab_strip_model->count()); 321 EXPECT_EQ(0, tab_strip_model->count());
318 322
319 // Create a new tab with contents |web_contents_1| 323 // Create a new tab with contents |web_contents_1|
320 chrome::NewTab(browser()); 324 chrome::NewTab(browser());
321 WebContents* web_contents_1 = tab_strip_model->GetActiveWebContents(); 325 WebContents* web_contents_1 = tab_strip_model->GetActiveWebContents();
322 ASSERT_TRUE(web_contents_1); 326 ASSERT_TRUE(web_contents_1);
323 EXPECT_EQ(1, tab_strip_model->count()); 327 EXPECT_EQ(1, tab_strip_model->count());
324 PrintPreviewDialogController* dialog_controller = 328 PrintPreviewDialogController* dialog_controller =
325 PrintPreviewDialogController::GetInstance(); 329 PrintPreviewDialogController::GetInstance();
326 ASSERT_TRUE(dialog_controller); 330 ASSERT_TRUE(dialog_controller);
327 331
328 // Create preview dialog for |web_contents_1|. Should not create a new tab. 332 // Create preview dialog for |web_contents_1|. Should not create a new tab.
329 PrintViewManager::FromWebContents(web_contents_1)->PrintPreviewNow(false); 333 PrintViewManager::FromWebContents(web_contents_1)
334 ->PrintPreviewNow(web_contents_1->GetMainFrame(), false);
330 WebContents* preview_dialog_1 = 335 WebContents* preview_dialog_1 =
331 dialog_controller->GetOrCreatePreviewDialog(web_contents_1); 336 dialog_controller->GetOrCreatePreviewDialog(web_contents_1);
332 EXPECT_NE(web_contents_1, preview_dialog_1); 337 EXPECT_NE(web_contents_1, preview_dialog_1);
333 EXPECT_EQ(1, tab_strip_model->count()); 338 EXPECT_EQ(1, tab_strip_model->count());
334 339
335 // Create a new tab with contents |web_contents_2| 340 // Create a new tab with contents |web_contents_2|
336 chrome::NewTab(browser()); 341 chrome::NewTab(browser());
337 WebContents* web_contents_2 = tab_strip_model->GetActiveWebContents(); 342 WebContents* web_contents_2 = tab_strip_model->GetActiveWebContents();
338 ASSERT_TRUE(web_contents_2); 343 ASSERT_TRUE(web_contents_2);
339 EXPECT_EQ(2, tab_strip_model->count()); 344 EXPECT_EQ(2, tab_strip_model->count());
340 345
341 // Create preview dialog for |web_contents_2| 346 // Create preview dialog for |web_contents_2|
342 PrintViewManager::FromWebContents(web_contents_2)->PrintPreviewNow(false); 347 PrintViewManager::FromWebContents(web_contents_2)
348 ->PrintPreviewNow(web_contents_2->GetMainFrame(), false);
343 WebContents* preview_dialog_2 = 349 WebContents* preview_dialog_2 =
344 dialog_controller->GetOrCreatePreviewDialog(web_contents_2); 350 dialog_controller->GetOrCreatePreviewDialog(web_contents_2);
345 EXPECT_NE(web_contents_2, preview_dialog_2); 351 EXPECT_NE(web_contents_2, preview_dialog_2);
346 EXPECT_NE(preview_dialog_1, preview_dialog_2); 352 EXPECT_NE(preview_dialog_1, preview_dialog_2);
347 353
348 // 2 initiators and 2 preview dialogs exist in the same browser. The preview 354 // 2 initiators and 2 preview dialogs exist in the same browser. The preview
349 // dialogs are constrained in their respective initiators. 355 // dialogs are constrained in their respective initiators.
350 EXPECT_EQ(2, tab_strip_model->count()); 356 EXPECT_EQ(2, tab_strip_model->count());
351 357
352 // Close |web_contents_1|'s tab 358 // Close |web_contents_1|'s tab
353 int tab_1_index = tab_strip_model->GetIndexOfWebContents(web_contents_1); 359 int tab_1_index = tab_strip_model->GetIndexOfWebContents(web_contents_1);
354 tab_strip_model->CloseWebContentsAt(tab_1_index, 0); 360 tab_strip_model->CloseWebContentsAt(tab_1_index, 0);
355 EXPECT_EQ(1, tab_strip_model->count()); 361 EXPECT_EQ(1, tab_strip_model->count());
356 362
357 // Simulate a crash of the render process host for |web_contents_2|. Print 363 // Simulate a crash of the render process host for |web_contents_2|. Print
358 // preview controller should exit cleanly and not crash. 364 // preview controller should exit cleanly and not crash.
359 content::MockRenderProcessHost* rph = 365 content::MockRenderProcessHost* rph =
360 static_cast<content::MockRenderProcessHost*>( 366 static_cast<content::MockRenderProcessHost*>(
361 web_contents_2->GetRenderViewHost()->GetProcess()); 367 web_contents_2->GetRenderViewHost()->GetProcess());
362 rph->SimulateCrash(); 368 rph->SimulateCrash();
363 } 369 }
364 } // namespace printing 370 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698