| 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 #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" |
| 11 #include "chrome/browser/printing/print_view_manager.h" | 11 #include "chrome/browser/printing/print_view_manager.h" |
| 12 #include "chrome/browser/ui/browser_commands.h" | 12 #include "chrome/browser/ui/browser_commands.h" |
| 13 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" | 15 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
| 16 #include "chrome/test/base/testing_browser_process.h" |
| 16 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
| 17 #include "content/public/browser/navigation_details.h" | 18 #include "content/public/browser/navigation_details.h" |
| 18 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
| 19 #include "content/public/browser/web_contents_delegate.h" | 20 #include "content/public/browser/web_contents_delegate.h" |
| 20 #include "content/public/browser/web_contents_observer.h" | 21 #include "content/public/browser/web_contents_observer.h" |
| 21 #include "content/public/common/url_constants.h" | 22 #include "content/public/common/url_constants.h" |
| 22 #include "content/public/test/mock_render_process_host.h" | 23 #include "content/public/test/mock_render_process_host.h" |
| 23 #include "content/public/test/web_contents_tester.h" | 24 #include "content/public/test/web_contents_tester.h" |
| 25 #include "ui/views/window/dialog_delegate.h" |
| 24 | 26 |
| 25 using content::WebContents; | 27 using content::WebContents; |
| 26 using content::WebContentsObserver; | 28 using content::WebContentsObserver; |
| 27 | 29 |
| 28 namespace { | 30 namespace { |
| 29 // content::WebContentsDelegate destructor is protected: subclass for testing. | 31 // content::WebContentsDelegate destructor is protected: subclass for testing. |
| 30 class TestWebContentsDelegate : public content::WebContentsDelegate {}; | 32 class TestWebContentsDelegate : public content::WebContentsDelegate {}; |
| 31 | 33 |
| 32 class PrintPreviewDialogDestroyedObserver : public WebContentsObserver { | 34 class PrintPreviewDialogDestroyedObserver : public WebContentsObserver { |
| 33 public: | 35 public: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 57 // Create/Get a preview dialog for initiator. | 59 // Create/Get a preview dialog for initiator. |
| 58 TEST_F(PrintPreviewDialogControllerUnitTest, GetOrCreatePreviewDialog) { | 60 TEST_F(PrintPreviewDialogControllerUnitTest, GetOrCreatePreviewDialog) { |
| 59 // Lets start with one window with one tab. | 61 // Lets start with one window with one tab. |
| 60 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | 62 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 61 EXPECT_EQ(0, browser()->tab_strip_model()->count()); | 63 EXPECT_EQ(0, browser()->tab_strip_model()->count()); |
| 62 chrome::NewTab(browser()); | 64 chrome::NewTab(browser()); |
| 63 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 65 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 64 | 66 |
| 65 // Create a reference to initiator contents. | 67 // Create a reference to initiator contents. |
| 66 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents(); | 68 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents(); |
| 67 | 69 #if defined(USE_AURA) |
| 70 TestingBrowserProcess::GetGlobal()->SetPrintPreviewDialogController( |
| 71 new PrintPreviewDialogControllerTest(GetContext())); |
| 72 #endif |
| 68 PrintPreviewDialogController* dialog_controller = | 73 PrintPreviewDialogController* dialog_controller = |
| 69 PrintPreviewDialogController::GetInstance(); | 74 PrintPreviewDialogController::GetInstance(); |
| 70 ASSERT_TRUE(dialog_controller); | 75 ASSERT_TRUE(dialog_controller); |
| 71 | 76 |
| 72 // Get the preview dialog for initiator. | 77 // Get the preview dialog for initiator. |
| 73 PrintViewManager::FromWebContents(initiator)->PrintPreviewNow( | 78 PrintViewManager::FromWebContents(initiator)->PrintPreviewNow( |
| 74 initiator->GetMainFrame(), false); | 79 initiator->GetMainFrame(), false); |
| 75 WebContents* preview_dialog = | 80 WebContents* preview_dialog = |
| 76 dialog_controller->GetOrCreatePreviewDialog(initiator); | 81 dialog_controller->GetOrCreatePreviewDialog(initiator); |
| 77 | 82 |
| 78 // New print preview dialog is a constrained window, so the number of tabs is | 83 // New print preview dialog is a constrained window, so the number of tabs is |
| 79 // still 1. | 84 // still 1. |
| 80 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 85 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 81 EXPECT_NE(initiator, preview_dialog); | 86 EXPECT_NE(initiator, preview_dialog); |
| 82 | 87 |
| 83 // Get the print preview dialog for the same initiator. | 88 // Get the print preview dialog for the same initiator. |
| 84 WebContents* new_preview_dialog = | 89 WebContents* new_preview_dialog = |
| 85 dialog_controller->GetOrCreatePreviewDialog(initiator); | 90 dialog_controller->GetOrCreatePreviewDialog(initiator); |
| 86 | 91 |
| 87 // Preview dialog already exists. Tab count remains the same. | 92 // Preview dialog already exists. Tab count remains the same. |
| 88 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 93 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 89 | 94 |
| 90 // 1:1 relationship between initiator and preview dialog. | 95 // 1:1 relationship between initiator and preview dialog. |
| 91 EXPECT_EQ(new_preview_dialog, preview_dialog); | 96 EXPECT_EQ(new_preview_dialog, preview_dialog); |
| 97 preview_dialog->Close(); |
| 98 initiator->Close(); |
| 92 } | 99 } |
| 93 | 100 |
| 94 // Tests multiple print preview dialogs exist in the same browser for different | 101 // Tests multiple print preview dialogs exist in the same browser for different |
| 95 // initiators. If a preview dialog already exists for an initiator, that | 102 // initiators. If a preview dialog already exists for an initiator, that |
| 96 // initiator gets focused. | 103 // initiator gets focused. |
| 97 TEST_F(PrintPreviewDialogControllerUnitTest, MultiplePreviewDialogs) { | 104 TEST_F(PrintPreviewDialogControllerUnitTest, MultiplePreviewDialogs) { |
| 98 // Lets start with one window and two tabs. | 105 // Lets start with one window and two tabs. |
| 99 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | 106 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 100 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 107 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 101 ASSERT_TRUE(tab_strip_model); | 108 ASSERT_TRUE(tab_strip_model); |
| 102 | 109 |
| 103 EXPECT_EQ(0, tab_strip_model->count()); | 110 EXPECT_EQ(0, tab_strip_model->count()); |
| 104 | 111 |
| 105 // Create some new initiators. | 112 // Create some new initiators. |
| 106 chrome::NewTab(browser()); | 113 chrome::NewTab(browser()); |
| 107 WebContents* web_contents_1 = tab_strip_model->GetActiveWebContents(); | 114 WebContents* web_contents_1 = tab_strip_model->GetActiveWebContents(); |
| 108 ASSERT_TRUE(web_contents_1); | 115 ASSERT_TRUE(web_contents_1); |
| 109 | 116 |
| 110 chrome::NewTab(browser()); | 117 chrome::NewTab(browser()); |
| 111 WebContents* web_contents_2 = tab_strip_model->GetActiveWebContents(); | 118 WebContents* web_contents_2 = tab_strip_model->GetActiveWebContents(); |
| 112 ASSERT_TRUE(web_contents_2); | 119 ASSERT_TRUE(web_contents_2); |
| 113 EXPECT_EQ(2, tab_strip_model->count()); | 120 EXPECT_EQ(2, tab_strip_model->count()); |
| 114 | 121 |
| 122 #if defined(USE_AURA) |
| 123 TestingBrowserProcess::GetGlobal()->SetPrintPreviewDialogController( |
| 124 new PrintPreviewDialogControllerTest(GetContext())); |
| 125 #endif |
| 115 PrintPreviewDialogController* dialog_controller = | 126 PrintPreviewDialogController* dialog_controller = |
| 116 PrintPreviewDialogController::GetInstance(); | 127 PrintPreviewDialogController::GetInstance(); |
| 117 ASSERT_TRUE(dialog_controller); | 128 ASSERT_TRUE(dialog_controller); |
| 118 | 129 |
| 119 // Create preview dialog for |web_contents_1| | 130 // Create preview dialog for |web_contents_1| |
| 120 PrintViewManager::FromWebContents(web_contents_1) | 131 PrintViewManager::FromWebContents(web_contents_1) |
| 121 ->PrintPreviewNow(web_contents_1->GetMainFrame(), false); | 132 ->PrintPreviewNow(web_contents_1->GetMainFrame(), false); |
| 122 WebContents* preview_dialog_1 = | 133 WebContents* preview_dialog_1 = |
| 123 dialog_controller->GetOrCreatePreviewDialog(web_contents_1); | 134 dialog_controller->GetOrCreatePreviewDialog(web_contents_1); |
| 124 | 135 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 149 EXPECT_EQ(-1, preview_dialog_2_index); | 160 EXPECT_EQ(-1, preview_dialog_2_index); |
| 150 | 161 |
| 151 // Since |preview_dialog_2_index| was the most recently created dialog, its | 162 // Since |preview_dialog_2_index| was the most recently created dialog, its |
| 152 // initiator should have focus. | 163 // initiator should have focus. |
| 153 EXPECT_EQ(tab_2_index, tab_strip_model->active_index()); | 164 EXPECT_EQ(tab_2_index, tab_strip_model->active_index()); |
| 154 | 165 |
| 155 // When we get the preview dialog for |web_contents_1|, | 166 // When we get the preview dialog for |web_contents_1|, |
| 156 // |preview_dialog_1| is activated and focused. | 167 // |preview_dialog_1| is activated and focused. |
| 157 dialog_controller->GetOrCreatePreviewDialog(web_contents_1); | 168 dialog_controller->GetOrCreatePreviewDialog(web_contents_1); |
| 158 EXPECT_EQ(tab_1_index, tab_strip_model->active_index()); | 169 EXPECT_EQ(tab_1_index, tab_strip_model->active_index()); |
| 170 |
| 171 preview_dialog_1->Close(); |
| 172 web_contents_1->Close(); |
| 173 preview_dialog_2->Close(); |
| 174 web_contents_2->Close(); |
| 159 } | 175 } |
| 160 | 176 |
| 161 // Check clearing the initiator details associated with a print preview dialog | 177 // Check clearing the initiator details associated with a print preview dialog |
| 162 // allows the initiator to create another print preview dialog. | 178 // allows the initiator to create another print preview dialog. |
| 163 TEST_F(PrintPreviewDialogControllerUnitTest, ClearInitiatorDetails) { | 179 TEST_F(PrintPreviewDialogControllerUnitTest, ClearInitiatorDetails) { |
| 164 // Lets start with one window with one tab. | 180 // Lets start with one window with one tab. |
| 165 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | 181 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 166 EXPECT_EQ(0, browser()->tab_strip_model()->count()); | 182 EXPECT_EQ(0, browser()->tab_strip_model()->count()); |
| 167 chrome::NewTab(browser()); | 183 chrome::NewTab(browser()); |
| 168 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 184 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 169 | 185 |
| 170 // Create a reference to initiator contents. | 186 // Create a reference to initiator contents. |
| 171 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents(); | 187 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents(); |
| 172 | 188 |
| 189 #if defined(USE_AURA) |
| 190 TestingBrowserProcess::GetGlobal()->SetPrintPreviewDialogController( |
| 191 new PrintPreviewDialogControllerTest(GetContext())); |
| 192 #endif |
| 173 PrintPreviewDialogController* dialog_controller = | 193 PrintPreviewDialogController* dialog_controller = |
| 174 PrintPreviewDialogController::GetInstance(); | 194 PrintPreviewDialogController::GetInstance(); |
| 175 ASSERT_TRUE(dialog_controller); | 195 ASSERT_TRUE(dialog_controller); |
| 176 | 196 |
| 177 // Get the preview dialog for the initiator. | 197 // Get the preview dialog for the initiator. |
| 178 PrintViewManager::FromWebContents(initiator)->PrintPreviewNow( | 198 PrintViewManager::FromWebContents(initiator)->PrintPreviewNow( |
| 179 initiator->GetMainFrame(), false); | 199 initiator->GetMainFrame(), false); |
| 180 WebContents* preview_dialog = | 200 WebContents* preview_dialog = |
| 181 dialog_controller->GetOrCreatePreviewDialog(initiator); | 201 dialog_controller->GetOrCreatePreviewDialog(initiator); |
| 182 | 202 |
| 183 // New print preview dialog is a constrained window, so the number of tabs is | 203 // New print preview dialog is a constrained window, so the number of tabs is |
| 184 // still 1. | 204 // still 1. |
| 185 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 205 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 186 EXPECT_NE(initiator, preview_dialog); | 206 EXPECT_NE(initiator, preview_dialog); |
| 187 | 207 |
| 188 // Clear the initiator details associated with the preview dialog. | 208 // Clear the initiator details associated with the preview dialog. |
| 189 dialog_controller->EraseInitiatorInfo(preview_dialog); | 209 dialog_controller->EraseInitiatorInfo(preview_dialog); |
| 190 | 210 |
| 191 // Get a new print preview dialog for the initiator. | 211 // Get a new print preview dialog for the initiator. |
| 192 WebContents* new_preview_dialog = | 212 WebContents* new_preview_dialog = |
| 193 dialog_controller->GetOrCreatePreviewDialog(initiator); | 213 dialog_controller->GetOrCreatePreviewDialog(initiator); |
| 194 | 214 |
| 195 // New print preview dialog is a constrained window, so the number of tabs is | 215 // New print preview dialog is a constrained window, so the number of tabs is |
| 196 // still 1. | 216 // still 1. |
| 197 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 217 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 198 // Verify a new print preview dialog has been created. | 218 // Verify a new print preview dialog has been created. |
| 199 EXPECT_NE(new_preview_dialog, preview_dialog); | 219 EXPECT_NE(new_preview_dialog, preview_dialog); |
| 220 |
| 221 new_preview_dialog->Close(); |
| 222 initiator->Close(); |
| 200 } | 223 } |
| 201 | 224 |
| 202 // Test that print preview dialogs close on navigation to new pages | 225 // Test that print preview dialogs close on navigation to new pages |
| 203 // and when navigating to old pages via fwd/back, but that auto navigation | 226 // and when navigating to old pages via fwd/back, but that auto navigation |
| 204 // (typed + address bar) to an existing page as occurs in gmail does not cause | 227 // (typed + address bar) to an existing page as occurs in gmail does not cause |
| 205 // the dialogs to close. | 228 // the dialogs to close. |
| 206 TEST_F(PrintPreviewDialogControllerUnitTest, CloseDialogOnNavigation) { | 229 TEST_F(PrintPreviewDialogControllerUnitTest, CloseDialogOnNavigation) { |
| 207 // Two similar URLs (same webpage, different URL fragments) | 230 // Two similar URLs (same webpage, different URL fragments) |
| 208 GURL tiger_barb("https://www.google.com/#q=tiger+barb"); | 231 GURL tiger_barb("https://www.google.com/#q=tiger+barb"); |
| 209 GURL tiger("https://www.google.com/#q=tiger"); | 232 GURL tiger("https://www.google.com/#q=tiger"); |
| 210 | 233 |
| 211 // Set up by opening a new tab and getting web contents | 234 // Set up by opening a new tab and getting web contents |
| 212 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | 235 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 213 EXPECT_EQ(0, browser()->tab_strip_model()->count()); | 236 EXPECT_EQ(0, browser()->tab_strip_model()->count()); |
| 214 chrome::NewTab(browser()); | 237 chrome::NewTab(browser()); |
| 215 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 238 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 216 WebContents* web_contents = | 239 WebContents* web_contents = |
| 217 browser()->tab_strip_model()->GetActiveWebContents(); | 240 browser()->tab_strip_model()->GetActiveWebContents(); |
| 218 ASSERT_TRUE(web_contents); | 241 ASSERT_TRUE(web_contents); |
| 219 content::NavigationController& nav_controller = web_contents->GetController(); | 242 content::NavigationController& nav_controller = web_contents->GetController(); |
| 220 | 243 |
| 221 // Navigate to first page | 244 // Navigate to first page |
| 222 nav_controller.LoadURL(tiger, content::Referrer(), | 245 nav_controller.LoadURL(tiger, content::Referrer(), |
| 223 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK), | 246 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK), |
| 224 std::string()); | 247 std::string()); |
| 225 CommitPendingLoad(&nav_controller); | 248 CommitPendingLoad(&nav_controller); |
| 226 EXPECT_EQ(tiger, web_contents->GetLastCommittedURL()); | 249 EXPECT_EQ(tiger, web_contents->GetLastCommittedURL()); |
| 227 | 250 |
| 228 // Get the preview dialog | 251 // Get the preview dialog |
| 252 #if defined(USE_AURA) |
| 253 TestingBrowserProcess::GetGlobal()->SetPrintPreviewDialogController( |
| 254 new PrintPreviewDialogControllerTest(GetContext())); |
| 255 #endif |
| 229 PrintPreviewDialogController* dialog_controller = | 256 PrintPreviewDialogController* dialog_controller = |
| 230 PrintPreviewDialogController::GetInstance(); | 257 PrintPreviewDialogController::GetInstance(); |
| 231 ASSERT_TRUE(dialog_controller); | 258 ASSERT_TRUE(dialog_controller); |
| 259 |
| 232 WebContents* tiger_preview_dialog = | 260 WebContents* tiger_preview_dialog = |
| 233 dialog_controller->GetOrCreatePreviewDialog(web_contents); | 261 dialog_controller->GetOrCreatePreviewDialog(web_contents); |
| 234 PrintViewManager* manager = PrintViewManager::FromWebContents(web_contents); | 262 PrintViewManager* manager = PrintViewManager::FromWebContents(web_contents); |
| 235 manager->PrintPreviewNow(web_contents->GetMainFrame(), false); | 263 manager->PrintPreviewNow(web_contents->GetMainFrame(), false); |
| 236 | 264 |
| 237 // New print preview dialog is a constrained window, so the number of tabs is | 265 // New print preview dialog is a constrained window, so the number of tabs is |
| 238 // still 1. | 266 // still 1. |
| 239 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 267 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 240 EXPECT_NE(web_contents, tiger_preview_dialog); | 268 EXPECT_NE(web_contents, tiger_preview_dialog); |
| 241 PrintPreviewDialogDestroyedObserver tiger_destroyed(tiger_preview_dialog); | 269 PrintPreviewDialogDestroyedObserver tiger_destroyed(tiger_preview_dialog); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 // preview now should return false, dialog is still alive, and the dialog | 328 // preview now should return false, dialog is still alive, and the dialog |
| 301 // returned by GetOrCreatePreviewDialog should be the same as the earlier | 329 // returned by GetOrCreatePreviewDialog should be the same as the earlier |
| 302 // dialog. | 330 // dialog. |
| 303 EXPECT_FALSE(manager->PrintPreviewNow(web_contents->GetMainFrame(), false)); | 331 EXPECT_FALSE(manager->PrintPreviewNow(web_contents->GetMainFrame(), false)); |
| 304 EXPECT_FALSE(tiger_2_destroyed.dialog_destroyed()); | 332 EXPECT_FALSE(tiger_2_destroyed.dialog_destroyed()); |
| 305 WebContents* tiger_preview_dialog_2b = | 333 WebContents* tiger_preview_dialog_2b = |
| 306 dialog_controller->GetOrCreatePreviewDialog(web_contents); | 334 dialog_controller->GetOrCreatePreviewDialog(web_contents); |
| 307 ASSERT_TRUE(tiger_preview_dialog_2b); | 335 ASSERT_TRUE(tiger_preview_dialog_2b); |
| 308 EXPECT_EQ(tiger_preview_dialog_2b, tiger_preview_dialog_2); | 336 EXPECT_EQ(tiger_preview_dialog_2b, tiger_preview_dialog_2); |
| 309 EXPECT_NE(tiger_preview_dialog_2b, web_contents); | 337 EXPECT_NE(tiger_preview_dialog_2b, web_contents); |
| 338 tiger_preview_dialog_2->Close(); |
| 339 web_contents->Close(); |
| 310 } | 340 } |
| 311 | 341 |
| 312 // Tests preview dialog controller cleans up correctly and does not throw errors | 342 // Tests preview dialog controller cleans up correctly and does not throw errors |
| 313 // on a renderer process crash. Checks that the renderer process closed | 343 // on a renderer process crash. Checks that the renderer process closed |
| 314 // notification is still received even if one of two preview dialogs with the | 344 // notification is still received even if one of two preview dialogs with the |
| 315 // same renderer process host is closed before the process "crashes". | 345 // same renderer process host is closed before the process "crashes". |
| 316 TEST_F(PrintPreviewDialogControllerUnitTest, MultiplePreviewDialogsClose) { | 346 TEST_F(PrintPreviewDialogControllerUnitTest, MultiplePreviewDialogsClose) { |
| 317 // Set up the browser. | 347 // Set up the browser. |
| 318 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | 348 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 319 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 349 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 320 ASSERT_TRUE(tab_strip_model); | 350 ASSERT_TRUE(tab_strip_model); |
| 321 EXPECT_EQ(0, tab_strip_model->count()); | 351 EXPECT_EQ(0, tab_strip_model->count()); |
| 322 | 352 |
| 323 // Create a new tab with contents |web_contents_1| | 353 // Create a new tab with contents |web_contents_1| |
| 324 chrome::NewTab(browser()); | 354 chrome::NewTab(browser()); |
| 325 WebContents* web_contents_1 = tab_strip_model->GetActiveWebContents(); | 355 WebContents* web_contents_1 = tab_strip_model->GetActiveWebContents(); |
| 326 ASSERT_TRUE(web_contents_1); | 356 ASSERT_TRUE(web_contents_1); |
| 327 EXPECT_EQ(1, tab_strip_model->count()); | 357 EXPECT_EQ(1, tab_strip_model->count()); |
| 358 #if defined(USE_AURA) |
| 359 TestingBrowserProcess::GetGlobal()->SetPrintPreviewDialogController( |
| 360 new PrintPreviewDialogControllerTest(GetContext())); |
| 361 #endif |
| 328 PrintPreviewDialogController* dialog_controller = | 362 PrintPreviewDialogController* dialog_controller = |
| 329 PrintPreviewDialogController::GetInstance(); | 363 PrintPreviewDialogController::GetInstance(); |
| 330 ASSERT_TRUE(dialog_controller); | 364 ASSERT_TRUE(dialog_controller); |
| 331 | 365 |
| 332 // Create preview dialog for |web_contents_1|. Should not create a new tab. | 366 // Create preview dialog for |web_contents_1|. Should not create a new tab. |
| 333 PrintViewManager::FromWebContents(web_contents_1) | 367 PrintViewManager::FromWebContents(web_contents_1) |
| 334 ->PrintPreviewNow(web_contents_1->GetMainFrame(), false); | 368 ->PrintPreviewNow(web_contents_1->GetMainFrame(), false); |
| 335 WebContents* preview_dialog_1 = | 369 WebContents* preview_dialog_1 = |
| 336 dialog_controller->GetOrCreatePreviewDialog(web_contents_1); | 370 dialog_controller->GetOrCreatePreviewDialog(web_contents_1); |
| 337 EXPECT_NE(web_contents_1, preview_dialog_1); | 371 EXPECT_NE(web_contents_1, preview_dialog_1); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 361 EXPECT_EQ(1, tab_strip_model->count()); | 395 EXPECT_EQ(1, tab_strip_model->count()); |
| 362 | 396 |
| 363 // Simulate a crash of the render process host for |web_contents_2|. Print | 397 // Simulate a crash of the render process host for |web_contents_2|. Print |
| 364 // preview controller should exit cleanly and not crash. | 398 // preview controller should exit cleanly and not crash. |
| 365 content::MockRenderProcessHost* rph = | 399 content::MockRenderProcessHost* rph = |
| 366 static_cast<content::MockRenderProcessHost*>( | 400 static_cast<content::MockRenderProcessHost*>( |
| 367 web_contents_2->GetMainFrame()->GetProcess()); | 401 web_contents_2->GetMainFrame()->GetProcess()); |
| 368 rph->SimulateCrash(); | 402 rph->SimulateCrash(); |
| 369 } | 403 } |
| 370 } // namespace printing | 404 } // namespace printing |
| OLD | NEW |