| 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 "content/public/browser/navigation_controller.h" | 16 #include "content/public/browser/navigation_controller.h" |
| 17 #include "content/public/browser/navigation_details.h" | 17 #include "content/public/browser/navigation_details.h" |
| 18 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
| 19 #include "content/public/browser/web_contents_delegate.h" | 19 #include "content/public/browser/web_contents_delegate.h" |
| 20 #include "content/public/browser/web_contents_observer.h" | 20 #include "content/public/browser/web_contents_observer.h" |
| 21 #include "content/public/common/url_constants.h" | 21 #include "content/public/common/url_constants.h" |
| 22 #include "content/public/test/mock_render_process_host.h" | 22 #include "content/public/test/mock_render_process_host.h" |
| 23 #include "content/public/test/web_contents_tester.h" | 23 #include "content/public/test/web_contents_tester.h" |
| 24 #include "ui/views/widget/widget.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: |
| 34 explicit PrintPreviewDialogDestroyedObserver(WebContents* dialog) | 36 explicit PrintPreviewDialogDestroyedObserver(WebContents* dialog) |
| 35 : WebContentsObserver(dialog), | 37 : WebContentsObserver(dialog), |
| 36 dialog_destroyed_(false) { | 38 dialog_destroyed_(false) { |
| 37 } | 39 } |
| 38 ~PrintPreviewDialogDestroyedObserver() override {} | 40 ~PrintPreviewDialogDestroyedObserver() override {} |
| 39 | 41 |
| 40 bool dialog_destroyed() const { return dialog_destroyed_; } | 42 bool dialog_destroyed() const { return dialog_destroyed_; } |
| 41 | 43 |
| 42 private: | 44 private: |
| 43 // content::WebContentsObserver implementation. | 45 // content::WebContentsObserver implementation. |
| 44 void WebContentsDestroyed() override { dialog_destroyed_ = true; } | 46 void WebContentsDestroyed() override { dialog_destroyed_ = true; } |
| 45 | 47 |
| 46 bool dialog_destroyed_; | 48 bool dialog_destroyed_; |
| 47 | 49 |
| 48 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogDestroyedObserver); | 50 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogDestroyedObserver); |
| 49 }; | 51 }; |
| 50 | 52 |
| 53 #if defined(USE_AURA) |
| 54 class PrintPreviewDialogControllerTest: |
| 55 public printing::PrintPreviewDialogController { |
| 56 |
| 57 public: |
| 58 explicit PrintPreviewDialogControllerTest(gfx::NativeView context): |
| 59 context_(context) {} |
| 60 |
| 61 // Need to override the function to get the delegate so that it uses the |
| 62 // correct window. |
| 63 ConstrainedWebDialogDelegate* GetWebDialogDelegate( |
| 64 WebContents* initiator) override { |
| 65 ConstrainedWebDialogDelegate* dialog = |
| 66 ShowTopLevelConstrainedWebDialogInWindow( |
| 67 initiator->GetBrowserContext(), |
| 68 printing::GetPrintPreviewDialogDelegate(initiator), |
| 69 initiator, context_); |
| 70 return dialog; |
| 71 } |
| 72 |
| 73 protected: |
| 74 ~PrintPreviewDialogControllerTest() override {} |
| 75 |
| 76 private: |
| 77 gfx::NativeWindow context_; |
| 78 |
| 79 }; |
| 80 #endif |
| 51 } // namespace | 81 } // namespace |
| 52 | 82 |
| 53 namespace printing { | 83 namespace printing { |
| 54 | 84 |
| 55 using PrintPreviewDialogControllerUnitTest = PrintPreviewTest; | 85 using PrintPreviewDialogControllerUnitTest = PrintPreviewTest; |
| 56 | 86 |
| 57 // Create/Get a preview dialog for initiator. | 87 // Create/Get a preview dialog for initiator. |
| 58 TEST_F(PrintPreviewDialogControllerUnitTest, GetOrCreatePreviewDialog) { | 88 TEST_F(PrintPreviewDialogControllerUnitTest, GetOrCreatePreviewDialog) { |
| 59 // Lets start with one window with one tab. | 89 // Lets start with one window with one tab. |
| 60 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | 90 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 61 EXPECT_EQ(0, browser()->tab_strip_model()->count()); | 91 EXPECT_EQ(0, browser()->tab_strip_model()->count()); |
| 62 chrome::NewTab(browser()); | 92 chrome::NewTab(browser()); |
| 63 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 93 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 64 | 94 |
| 65 // Create a reference to initiator contents. | 95 // Create a reference to initiator contents. |
| 66 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents(); | 96 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents(); |
| 67 | 97 #if defined(USE_AURA) |
| 98 PrintPreviewDialogController* dialog_controller = |
| 99 new PrintPreviewDialogControllerTest(GetContext()); |
| 100 #else |
| 68 PrintPreviewDialogController* dialog_controller = | 101 PrintPreviewDialogController* dialog_controller = |
| 69 PrintPreviewDialogController::GetInstance(); | 102 PrintPreviewDialogController::GetInstance(); |
| 103 #endif |
| 70 ASSERT_TRUE(dialog_controller); | 104 ASSERT_TRUE(dialog_controller); |
| 71 | 105 |
| 72 // Get the preview dialog for initiator. | 106 // Get the preview dialog for initiator. |
| 73 PrintViewManager::FromWebContents(initiator)->PrintPreviewNow(false); | 107 PrintViewManager::FromWebContents(initiator)->PrintPreviewNow(false); |
| 74 WebContents* preview_dialog = | 108 WebContents* preview_dialog = |
| 75 dialog_controller->GetOrCreatePreviewDialog(initiator); | 109 dialog_controller->GetOrCreatePreviewDialog(initiator); |
| 76 | 110 |
| 77 // New print preview dialog is a constrained window, so the number of tabs is | 111 // New print preview dialog is a constrained window, so the number of tabs is |
| 78 // still 1. | 112 // still 1. |
| 79 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 113 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 80 EXPECT_NE(initiator, preview_dialog); | 114 EXPECT_NE(initiator, preview_dialog); |
| 81 | 115 |
| 82 // Get the print preview dialog for the same initiator. | 116 // Get the print preview dialog for the same initiator. |
| 83 WebContents* new_preview_dialog = | 117 WebContents* new_preview_dialog = |
| 84 dialog_controller->GetOrCreatePreviewDialog(initiator); | 118 dialog_controller->GetOrCreatePreviewDialog(initiator); |
| 85 | 119 |
| 86 // Preview dialog already exists. Tab count remains the same. | 120 // Preview dialog already exists. Tab count remains the same. |
| 87 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 121 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 88 | 122 |
| 89 // 1:1 relationship between initiator and preview dialog. | 123 // 1:1 relationship between initiator and preview dialog. |
| 90 EXPECT_EQ(new_preview_dialog, preview_dialog); | 124 EXPECT_EQ(new_preview_dialog, preview_dialog); |
| 125 preview_dialog->Close(); |
| 126 initiator->Close(); |
| 91 } | 127 } |
| 92 | 128 |
| 93 // Tests multiple print preview dialogs exist in the same browser for different | 129 // Tests multiple print preview dialogs exist in the same browser for different |
| 94 // initiators. If a preview dialog already exists for an initiator, that | 130 // initiators. If a preview dialog already exists for an initiator, that |
| 95 // initiator gets focused. | 131 // initiator gets focused. |
| 96 TEST_F(PrintPreviewDialogControllerUnitTest, MultiplePreviewDialogs) { | 132 TEST_F(PrintPreviewDialogControllerUnitTest, MultiplePreviewDialogs) { |
| 97 // Lets start with one window and two tabs. | 133 // Lets start with one window and two tabs. |
| 98 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | 134 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 99 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 135 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 100 ASSERT_TRUE(tab_strip_model); | 136 ASSERT_TRUE(tab_strip_model); |
| 101 | 137 |
| 102 EXPECT_EQ(0, tab_strip_model->count()); | 138 EXPECT_EQ(0, tab_strip_model->count()); |
| 103 | 139 |
| 104 // Create some new initiators. | 140 // Create some new initiators. |
| 105 chrome::NewTab(browser()); | 141 chrome::NewTab(browser()); |
| 106 WebContents* web_contents_1 = tab_strip_model->GetActiveWebContents(); | 142 WebContents* web_contents_1 = tab_strip_model->GetActiveWebContents(); |
| 107 ASSERT_TRUE(web_contents_1); | 143 ASSERT_TRUE(web_contents_1); |
| 108 | 144 |
| 109 chrome::NewTab(browser()); | 145 chrome::NewTab(browser()); |
| 110 WebContents* web_contents_2 = tab_strip_model->GetActiveWebContents(); | 146 WebContents* web_contents_2 = tab_strip_model->GetActiveWebContents(); |
| 111 ASSERT_TRUE(web_contents_2); | 147 ASSERT_TRUE(web_contents_2); |
| 112 EXPECT_EQ(2, tab_strip_model->count()); | 148 EXPECT_EQ(2, tab_strip_model->count()); |
| 113 | 149 |
| 150 #if defined(USE_AURA) |
| 151 PrintPreviewDialogController* dialog_controller = |
| 152 new PrintPreviewDialogControllerTest(GetContext()); |
| 153 #else |
| 114 PrintPreviewDialogController* dialog_controller = | 154 PrintPreviewDialogController* dialog_controller = |
| 115 PrintPreviewDialogController::GetInstance(); | 155 PrintPreviewDialogController::GetInstance(); |
| 156 #endif |
| 116 ASSERT_TRUE(dialog_controller); | 157 ASSERT_TRUE(dialog_controller); |
| 117 | 158 |
| 118 // Create preview dialog for |web_contents_1| | 159 // Create preview dialog for |web_contents_1| |
| 119 PrintViewManager::FromWebContents(web_contents_1)->PrintPreviewNow(false); | 160 PrintViewManager::FromWebContents(web_contents_1)->PrintPreviewNow(false); |
| 120 WebContents* preview_dialog_1 = | 161 WebContents* preview_dialog_1 = |
| 121 dialog_controller->GetOrCreatePreviewDialog(web_contents_1); | 162 dialog_controller->GetOrCreatePreviewDialog(web_contents_1); |
| 122 | 163 |
| 123 EXPECT_NE(web_contents_1, preview_dialog_1); | 164 EXPECT_NE(web_contents_1, preview_dialog_1); |
| 124 EXPECT_EQ(2, tab_strip_model->count()); | 165 EXPECT_EQ(2, tab_strip_model->count()); |
| 125 | 166 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 146 EXPECT_EQ(-1, preview_dialog_2_index); | 187 EXPECT_EQ(-1, preview_dialog_2_index); |
| 147 | 188 |
| 148 // Since |preview_dialog_2_index| was the most recently created dialog, its | 189 // Since |preview_dialog_2_index| was the most recently created dialog, its |
| 149 // initiator should have focus. | 190 // initiator should have focus. |
| 150 EXPECT_EQ(tab_2_index, tab_strip_model->active_index()); | 191 EXPECT_EQ(tab_2_index, tab_strip_model->active_index()); |
| 151 | 192 |
| 152 // When we get the preview dialog for |web_contents_1|, | 193 // When we get the preview dialog for |web_contents_1|, |
| 153 // |preview_dialog_1| is activated and focused. | 194 // |preview_dialog_1| is activated and focused. |
| 154 dialog_controller->GetOrCreatePreviewDialog(web_contents_1); | 195 dialog_controller->GetOrCreatePreviewDialog(web_contents_1); |
| 155 EXPECT_EQ(tab_1_index, tab_strip_model->active_index()); | 196 EXPECT_EQ(tab_1_index, tab_strip_model->active_index()); |
| 197 |
| 198 preview_dialog_1->Close(); |
| 199 web_contents_1->Close(); |
| 200 preview_dialog_2->Close(); |
| 201 web_contents_2->Close(); |
| 156 } | 202 } |
| 157 | 203 |
| 158 // Check clearing the initiator details associated with a print preview dialog | 204 // Check clearing the initiator details associated with a print preview dialog |
| 159 // allows the initiator to create another print preview dialog. | 205 // allows the initiator to create another print preview dialog. |
| 160 TEST_F(PrintPreviewDialogControllerUnitTest, ClearInitiatorDetails) { | 206 TEST_F(PrintPreviewDialogControllerUnitTest, ClearInitiatorDetails) { |
| 161 // Lets start with one window with one tab. | 207 // Lets start with one window with one tab. |
| 162 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | 208 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 163 EXPECT_EQ(0, browser()->tab_strip_model()->count()); | 209 EXPECT_EQ(0, browser()->tab_strip_model()->count()); |
| 164 chrome::NewTab(browser()); | 210 chrome::NewTab(browser()); |
| 165 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 211 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 166 | 212 |
| 167 // Create a reference to initiator contents. | 213 // Create a reference to initiator contents. |
| 168 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents(); | 214 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents(); |
| 169 | 215 |
| 216 #if defined(USE_AURA) |
| 217 PrintPreviewDialogController* dialog_controller = |
| 218 new PrintPreviewDialogControllerTest(GetContext()); |
| 219 #else |
| 170 PrintPreviewDialogController* dialog_controller = | 220 PrintPreviewDialogController* dialog_controller = |
| 171 PrintPreviewDialogController::GetInstance(); | 221 PrintPreviewDialogController::GetInstance(); |
| 222 #endif |
| 172 ASSERT_TRUE(dialog_controller); | 223 ASSERT_TRUE(dialog_controller); |
| 173 | 224 |
| 174 // Get the preview dialog for the initiator. | 225 // Get the preview dialog for the initiator. |
| 175 PrintViewManager::FromWebContents(initiator)->PrintPreviewNow(false); | 226 PrintViewManager::FromWebContents(initiator)->PrintPreviewNow(false); |
| 176 WebContents* preview_dialog = | 227 WebContents* preview_dialog = |
| 177 dialog_controller->GetOrCreatePreviewDialog(initiator); | 228 dialog_controller->GetOrCreatePreviewDialog(initiator); |
| 178 | 229 |
| 179 // New print preview dialog is a constrained window, so the number of tabs is | 230 // New print preview dialog is a constrained window, so the number of tabs is |
| 180 // still 1. | 231 // still 1. |
| 181 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 232 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 182 EXPECT_NE(initiator, preview_dialog); | 233 EXPECT_NE(initiator, preview_dialog); |
| 183 | 234 |
| 184 // Clear the initiator details associated with the preview dialog. | 235 // Clear the initiator details associated with the preview dialog. |
| 185 dialog_controller->EraseInitiatorInfo(preview_dialog); | 236 dialog_controller->EraseInitiatorInfo(preview_dialog); |
| 186 | 237 |
| 187 // Get a new print preview dialog for the initiator. | 238 // Get a new print preview dialog for the initiator. |
| 188 WebContents* new_preview_dialog = | 239 WebContents* new_preview_dialog = |
| 189 dialog_controller->GetOrCreatePreviewDialog(initiator); | 240 dialog_controller->GetOrCreatePreviewDialog(initiator); |
| 190 | 241 |
| 191 // New print preview dialog is a constrained window, so the number of tabs is | 242 // New print preview dialog is a constrained window, so the number of tabs is |
| 192 // still 1. | 243 // still 1. |
| 193 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 244 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 194 // Verify a new print preview dialog has been created. | 245 // Verify a new print preview dialog has been created. |
| 195 EXPECT_NE(new_preview_dialog, preview_dialog); | 246 EXPECT_NE(new_preview_dialog, preview_dialog); |
| 247 |
| 248 initiator->Close(); |
| 249 new_preview_dialog->Close(); |
| 196 } | 250 } |
| 197 | 251 |
| 198 // Test that print preview dialogs close on navigation to new pages | 252 // Test that print preview dialogs close on navigation to new pages |
| 199 // and when navigating to old pages via fwd/back, but that auto navigation | 253 // and when navigating to old pages via fwd/back, but that auto navigation |
| 200 // (typed + address bar) to an existing page as occurs in gmail does not cause | 254 // (typed + address bar) to an existing page as occurs in gmail does not cause |
| 201 // the dialogs to close. | 255 // the dialogs to close. |
| 202 TEST_F(PrintPreviewDialogControllerUnitTest, CloseDialogOnNavigation) { | 256 TEST_F(PrintPreviewDialogControllerUnitTest, CloseDialogOnNavigation) { |
| 203 // Two similar URLs (same webpage, different URL fragments) | 257 // Two similar URLs (same webpage, different URL fragments) |
| 204 GURL tiger_barb("https://www.google.com/#q=tiger+barb"); | 258 GURL tiger_barb("https://www.google.com/#q=tiger+barb"); |
| 205 GURL tiger("https://www.google.com/#q=tiger"); | 259 GURL tiger("https://www.google.com/#q=tiger"); |
| 206 | 260 |
| 207 // Set up by opening a new tab and getting web contents | 261 // Set up by opening a new tab and getting web contents |
| 208 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | 262 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 209 EXPECT_EQ(0, browser()->tab_strip_model()->count()); | 263 EXPECT_EQ(0, browser()->tab_strip_model()->count()); |
| 210 chrome::NewTab(browser()); | 264 chrome::NewTab(browser()); |
| 211 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 265 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 212 WebContents* web_contents = | 266 WebContents* web_contents = |
| 213 browser()->tab_strip_model()->GetActiveWebContents(); | 267 browser()->tab_strip_model()->GetActiveWebContents(); |
| 214 ASSERT_TRUE(web_contents); | 268 ASSERT_TRUE(web_contents); |
| 215 content::NavigationController& nav_controller = web_contents->GetController(); | 269 content::NavigationController& nav_controller = web_contents->GetController(); |
| 216 | 270 |
| 217 // Navigate to first page | 271 // Navigate to first page |
| 218 nav_controller.LoadURL(tiger, content::Referrer(), | 272 nav_controller.LoadURL(tiger, content::Referrer(), |
| 219 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK), | 273 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK), |
| 220 std::string()); | 274 std::string()); |
| 221 CommitPendingLoad(&nav_controller); | 275 CommitPendingLoad(&nav_controller); |
| 222 EXPECT_EQ(tiger, web_contents->GetLastCommittedURL()); | 276 EXPECT_EQ(tiger, web_contents->GetLastCommittedURL()); |
| 223 | 277 |
| 224 // Get the preview dialog | 278 // Get the preview dialog |
| 279 #if defined(USE_AURA) |
| 280 PrintPreviewDialogController* dialog_controller = |
| 281 new PrintPreviewDialogControllerTest(GetContext()); |
| 282 #else |
| 225 PrintPreviewDialogController* dialog_controller = | 283 PrintPreviewDialogController* dialog_controller = |
| 226 PrintPreviewDialogController::GetInstance(); | 284 PrintPreviewDialogController::GetInstance(); |
| 285 #endif |
| 227 ASSERT_TRUE(dialog_controller); | 286 ASSERT_TRUE(dialog_controller); |
| 228 WebContents* tiger_preview_dialog = | 287 WebContents* tiger_preview_dialog = |
| 229 dialog_controller->GetOrCreatePreviewDialog(web_contents); | 288 dialog_controller->GetOrCreatePreviewDialog(web_contents); |
| 230 PrintViewManager* manager = PrintViewManager::FromWebContents(web_contents); | 289 PrintViewManager* manager = PrintViewManager::FromWebContents(web_contents); |
| 231 manager->PrintPreviewNow(false); | 290 manager->PrintPreviewNow(false); |
| 232 | 291 |
| 233 // New print preview dialog is a constrained window, so the number of tabs is | 292 // New print preview dialog is a constrained window, so the number of tabs is |
| 234 // still 1. | 293 // still 1. |
| 235 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 294 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 236 EXPECT_NE(web_contents, tiger_preview_dialog); | 295 EXPECT_NE(web_contents, tiger_preview_dialog); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 // preview now should return false, dialog is still alive, and the dialog | 355 // preview now should return false, dialog is still alive, and the dialog |
| 297 // returned by GetOrCreatePreviewDialog should be the same as the earlier | 356 // returned by GetOrCreatePreviewDialog should be the same as the earlier |
| 298 // dialog. | 357 // dialog. |
| 299 EXPECT_FALSE(manager->PrintPreviewNow(false)); | 358 EXPECT_FALSE(manager->PrintPreviewNow(false)); |
| 300 EXPECT_FALSE(tiger_2_destroyed.dialog_destroyed()); | 359 EXPECT_FALSE(tiger_2_destroyed.dialog_destroyed()); |
| 301 WebContents* tiger_preview_dialog_2b = | 360 WebContents* tiger_preview_dialog_2b = |
| 302 dialog_controller->GetOrCreatePreviewDialog(web_contents); | 361 dialog_controller->GetOrCreatePreviewDialog(web_contents); |
| 303 ASSERT_TRUE(tiger_preview_dialog_2b); | 362 ASSERT_TRUE(tiger_preview_dialog_2b); |
| 304 EXPECT_EQ(tiger_preview_dialog_2b, tiger_preview_dialog_2); | 363 EXPECT_EQ(tiger_preview_dialog_2b, tiger_preview_dialog_2); |
| 305 EXPECT_NE(tiger_preview_dialog_2b, web_contents); | 364 EXPECT_NE(tiger_preview_dialog_2b, web_contents); |
| 365 tiger_preview_dialog_2->Close(); |
| 366 web_contents->Close(); |
| 306 } | 367 } |
| 307 | 368 |
| 308 // Tests preview dialog controller cleans up correctly and does not throw errors | 369 // Tests preview dialog controller cleans up correctly and does not throw errors |
| 309 // on a renderer process crash. Checks that the renderer process closed | 370 // 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 | 371 // notification is still received even if one of two preview dialogs with the |
| 311 // same renderer process host is closed before the process "crashes". | 372 // same renderer process host is closed before the process "crashes". |
| 312 TEST_F(PrintPreviewDialogControllerUnitTest, MultiplePreviewDialogsClose) { | 373 TEST_F(PrintPreviewDialogControllerUnitTest, MultiplePreviewDialogsClose) { |
| 313 // Set up the browser. | 374 // Set up the browser. |
| 314 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | 375 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 315 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 376 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 316 ASSERT_TRUE(tab_strip_model); | 377 ASSERT_TRUE(tab_strip_model); |
| 317 EXPECT_EQ(0, tab_strip_model->count()); | 378 EXPECT_EQ(0, tab_strip_model->count()); |
| 318 | 379 |
| 319 // Create a new tab with contents |web_contents_1| | 380 // Create a new tab with contents |web_contents_1| |
| 320 chrome::NewTab(browser()); | 381 chrome::NewTab(browser()); |
| 321 WebContents* web_contents_1 = tab_strip_model->GetActiveWebContents(); | 382 WebContents* web_contents_1 = tab_strip_model->GetActiveWebContents(); |
| 322 ASSERT_TRUE(web_contents_1); | 383 ASSERT_TRUE(web_contents_1); |
| 323 EXPECT_EQ(1, tab_strip_model->count()); | 384 EXPECT_EQ(1, tab_strip_model->count()); |
| 385 #if defined(USE_AURA) |
| 386 PrintPreviewDialogController* dialog_controller = |
| 387 new PrintPreviewDialogControllerTest(GetContext()); |
| 388 #else |
| 324 PrintPreviewDialogController* dialog_controller = | 389 PrintPreviewDialogController* dialog_controller = |
| 325 PrintPreviewDialogController::GetInstance(); | 390 PrintPreviewDialogController::GetInstance(); |
| 391 #endif |
| 326 ASSERT_TRUE(dialog_controller); | 392 ASSERT_TRUE(dialog_controller); |
| 327 | 393 |
| 328 // Create preview dialog for |web_contents_1|. Should not create a new tab. | 394 // Create preview dialog for |web_contents_1|. Should not create a new tab. |
| 329 PrintViewManager::FromWebContents(web_contents_1)->PrintPreviewNow(false); | 395 PrintViewManager::FromWebContents(web_contents_1)->PrintPreviewNow(false); |
| 330 WebContents* preview_dialog_1 = | 396 WebContents* preview_dialog_1 = |
| 331 dialog_controller->GetOrCreatePreviewDialog(web_contents_1); | 397 dialog_controller->GetOrCreatePreviewDialog(web_contents_1); |
| 332 EXPECT_NE(web_contents_1, preview_dialog_1); | 398 EXPECT_NE(web_contents_1, preview_dialog_1); |
| 333 EXPECT_EQ(1, tab_strip_model->count()); | 399 EXPECT_EQ(1, tab_strip_model->count()); |
| 334 | 400 |
| 335 // Create a new tab with contents |web_contents_2| | 401 // Create a new tab with contents |web_contents_2| |
| (...skipping 19 matching lines...) Expand all Loading... |
| 355 EXPECT_EQ(1, tab_strip_model->count()); | 421 EXPECT_EQ(1, tab_strip_model->count()); |
| 356 | 422 |
| 357 // Simulate a crash of the render process host for |web_contents_2|. Print | 423 // Simulate a crash of the render process host for |web_contents_2|. Print |
| 358 // preview controller should exit cleanly and not crash. | 424 // preview controller should exit cleanly and not crash. |
| 359 content::MockRenderProcessHost* rph = | 425 content::MockRenderProcessHost* rph = |
| 360 static_cast<content::MockRenderProcessHost*>( | 426 static_cast<content::MockRenderProcessHost*>( |
| 361 web_contents_2->GetRenderViewHost()->GetProcess()); | 427 web_contents_2->GetRenderViewHost()->GetProcess()); |
| 362 rph->SimulateCrash(); | 428 rph->SimulateCrash(); |
| 363 } | 429 } |
| 364 } // namespace printing | 430 } // namespace printing |
| OLD | NEW |