| 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 #include "chrome/browser/printing/print_preview_test.h" | 6 #include "chrome/browser/printing/print_preview_test.h" |
| 7 #include "chrome/browser/printing/print_view_manager.h" | 7 #include "chrome/browser/printing/print_view_manager.h" |
| 8 #include "chrome/browser/ui/browser_commands.h" | 8 #include "chrome/browser/ui/browser_commands.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" | 11 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
| 12 #include "content/public/browser/navigation_details.h" | 12 #include "content/public/browser/navigation_details.h" |
| 13 #include "content/public/common/url_constants.h" | 13 #include "content/public/common/url_constants.h" |
| 14 | 14 |
| 15 using content::WebContents; | 15 using content::WebContents; |
| 16 | 16 |
| 17 // Test crashes on Aura due to initiator's native view having no parent. | |
| 18 // http://crbug.com/104284 | |
| 19 #if defined(USE_AURA) | |
| 20 #define MAYBE_GetOrCreatePreviewDialog DISABLED_GetOrCreatePreviewDialog | |
| 21 #define MAYBE_MultiplePreviewDialogs DISABLED_MultiplePreviewDialogs | |
| 22 #define MAYBE_ClearInitiatorDetails DISABLED_ClearInitiatorDetails | |
| 23 #else | |
| 24 #define MAYBE_GetOrCreatePreviewDialog GetOrCreatePreviewDialog | |
| 25 #define MAYBE_MultiplePreviewDialogs MultiplePreviewDialogs | |
| 26 #define MAYBE_ClearInitiatorDetails ClearInitiatorDetails | |
| 27 #endif | |
| 28 | |
| 29 namespace printing { | 17 namespace printing { |
| 30 | 18 |
| 31 typedef PrintPreviewTest PrintPreviewDialogControllerUnitTest; | 19 typedef PrintPreviewTest PrintPreviewDialogControllerUnitTest; |
| 32 | 20 |
| 33 // Create/Get a preview dialog for initiator. | 21 // Create/Get a preview dialog for initiator. |
| 34 TEST_F(PrintPreviewDialogControllerUnitTest, MAYBE_GetOrCreatePreviewDialog) { | 22 TEST_F(PrintPreviewDialogControllerUnitTest, GetOrCreatePreviewDialog) { |
| 35 // Lets start with one window with one tab. | 23 // Lets start with one window with one tab. |
| 36 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | 24 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 37 EXPECT_EQ(0, browser()->tab_strip_model()->count()); | 25 EXPECT_EQ(0, browser()->tab_strip_model()->count()); |
| 38 chrome::NewTab(browser()); | 26 chrome::NewTab(browser()); |
| 39 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 27 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 40 | 28 |
| 41 // Create a reference to initiator contents. | 29 // Create a reference to initiator contents. |
| 42 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents(); | 30 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents(); |
| 43 | 31 |
| 44 PrintPreviewDialogController* dialog_controller = | 32 PrintPreviewDialogController* dialog_controller = |
| (...skipping 17 matching lines...) Expand all Loading... |
| 62 // Preview dialog already exists. Tab count remains the same. | 50 // Preview dialog already exists. Tab count remains the same. |
| 63 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 51 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 64 | 52 |
| 65 // 1:1 relationship between initiator and preview dialog. | 53 // 1:1 relationship between initiator and preview dialog. |
| 66 EXPECT_EQ(new_preview_dialog, preview_dialog); | 54 EXPECT_EQ(new_preview_dialog, preview_dialog); |
| 67 } | 55 } |
| 68 | 56 |
| 69 // Tests multiple print preview dialogs exist in the same browser for different | 57 // Tests multiple print preview dialogs exist in the same browser for different |
| 70 // initiators. If a preview dialog already exists for an initiator, that | 58 // initiators. If a preview dialog already exists for an initiator, that |
| 71 // initiator gets focused. | 59 // initiator gets focused. |
| 72 TEST_F(PrintPreviewDialogControllerUnitTest, MAYBE_MultiplePreviewDialogs) { | 60 TEST_F(PrintPreviewDialogControllerUnitTest, MultiplePreviewDialogs) { |
| 73 // Lets start with one window and two tabs. | 61 // Lets start with one window and two tabs. |
| 74 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | 62 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 75 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 63 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 76 ASSERT_TRUE(tab_strip_model); | 64 ASSERT_TRUE(tab_strip_model); |
| 77 | 65 |
| 78 EXPECT_EQ(0, tab_strip_model->count()); | 66 EXPECT_EQ(0, tab_strip_model->count()); |
| 79 | 67 |
| 80 // Create some new initiators. | 68 // Create some new initiators. |
| 81 chrome::NewTab(browser()); | 69 chrome::NewTab(browser()); |
| 82 WebContents* web_contents_1 = tab_strip_model->GetActiveWebContents(); | 70 WebContents* web_contents_1 = tab_strip_model->GetActiveWebContents(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 EXPECT_EQ(tab_2_index, tab_strip_model->active_index()); | 114 EXPECT_EQ(tab_2_index, tab_strip_model->active_index()); |
| 127 | 115 |
| 128 // When we get the preview dialog for |web_contents_1|, | 116 // When we get the preview dialog for |web_contents_1|, |
| 129 // |preview_dialog_1| is activated and focused. | 117 // |preview_dialog_1| is activated and focused. |
| 130 dialog_controller->GetOrCreatePreviewDialog(web_contents_1); | 118 dialog_controller->GetOrCreatePreviewDialog(web_contents_1); |
| 131 EXPECT_EQ(tab_1_index, tab_strip_model->active_index()); | 119 EXPECT_EQ(tab_1_index, tab_strip_model->active_index()); |
| 132 } | 120 } |
| 133 | 121 |
| 134 // Check clearing the initiator details associated with a print preview dialog | 122 // Check clearing the initiator details associated with a print preview dialog |
| 135 // allows the initiator to create another print preview dialog. | 123 // allows the initiator to create another print preview dialog. |
| 136 TEST_F(PrintPreviewDialogControllerUnitTest, MAYBE_ClearInitiatorDetails) { | 124 TEST_F(PrintPreviewDialogControllerUnitTest, ClearInitiatorDetails) { |
| 137 // Lets start with one window with one tab. | 125 // Lets start with one window with one tab. |
| 138 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | 126 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 139 EXPECT_EQ(0, browser()->tab_strip_model()->count()); | 127 EXPECT_EQ(0, browser()->tab_strip_model()->count()); |
| 140 chrome::NewTab(browser()); | 128 chrome::NewTab(browser()); |
| 141 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 129 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 142 | 130 |
| 143 // Create a reference to initiator contents. | 131 // Create a reference to initiator contents. |
| 144 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents(); | 132 WebContents* initiator = browser()->tab_strip_model()->GetActiveWebContents(); |
| 145 | 133 |
| 146 PrintPreviewDialogController* dialog_controller = | 134 PrintPreviewDialogController* dialog_controller = |
| (...skipping 18 matching lines...) Expand all Loading... |
| 165 dialog_controller->GetOrCreatePreviewDialog(initiator); | 153 dialog_controller->GetOrCreatePreviewDialog(initiator); |
| 166 | 154 |
| 167 // New print preview dialog is a constrained window, so the number of tabs is | 155 // New print preview dialog is a constrained window, so the number of tabs is |
| 168 // still 1. | 156 // still 1. |
| 169 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 157 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 170 // Verify a new print preview dialog has been created. | 158 // Verify a new print preview dialog has been created. |
| 171 EXPECT_NE(new_preview_dialog, preview_dialog); | 159 EXPECT_NE(new_preview_dialog, preview_dialog); |
| 172 } | 160 } |
| 173 | 161 |
| 174 } // namespace printing | 162 } // namespace printing |
| OLD | NEW |