| 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_list.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/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
| 14 #include "content/public/browser/notification_types.h" | 14 #include "content/public/browser/notification_types.h" |
| 15 #include "content/public/common/url_constants.h" | 15 #include "content/public/common/url_constants.h" |
| 16 | 16 |
| 17 using content::WebContents; | 17 using content::WebContents; |
| 18 | 18 |
| 19 // Test crashes on Aura due to initiator tab's native view having no parent. | 19 // Test crashes on Aura due to initiator tab's native view having no parent. |
| 20 // http://crbug.com/104284 | 20 // http://crbug.com/104284 |
| 21 #if defined(USE_AURA) | 21 #if defined(USE_AURA) |
| 22 #define MAYBE_GetOrCreatePreviewTab DISABLED_GetOrCreatePreviewTab | 22 #define MAYBE_GetOrCreatePreviewTab DISABLED_GetOrCreatePreviewTab |
| 23 #define MAYBE_MultiplePreviewTabs DISABLED_MultiplePreviewTabs | 23 #define MAYBE_MultiplePreviewTabs DISABLED_MultiplePreviewTabs |
| 24 #define MAYBE_ClearInitiatorTabDetails DISABLED_ClearInitiatorTabDetails | 24 #define MAYBE_ClearInitiatorTabDetails DISABLED_ClearInitiatorTabDetails |
| 25 #else | 25 #else |
| 26 #define MAYBE_GetOrCreatePreviewTab GetOrCreatePreviewTab | 26 #define MAYBE_GetOrCreatePreviewTab GetOrCreatePreviewTab |
| 27 #define MAYBE_MultiplePreviewTabs MultiplePreviewTabs | 27 #define MAYBE_MultiplePreviewTabs MultiplePreviewTabs |
| 28 #define MAYBE_ClearInitiatorTabDetails ClearInitiatorTabDetails | 28 #define MAYBE_ClearInitiatorTabDetails ClearInitiatorTabDetails |
| 29 #endif | 29 #endif |
| 30 | 30 |
| 31 typedef PrintPreviewTest PrintPreviewDialogControllerUnitTest; | 31 typedef PrintPreviewTest PrintPreviewDialogControllerUnitTest; |
| 32 | 32 |
| 33 // Create/Get a preview tab for initiator tab. | 33 // Create/Get a preview tab for initiator tab. |
| 34 TEST_F(PrintPreviewDialogControllerUnitTest, MAYBE_GetOrCreatePreviewTab) { | 34 TEST_F(PrintPreviewDialogControllerUnitTest, MAYBE_GetOrCreatePreviewTab) { |
| 35 // Lets start with one window with one tab. | 35 // Lets start with one window with one tab. |
| 36 EXPECT_EQ(1u, BrowserList::size()); | 36 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 37 EXPECT_EQ(0, browser()->tab_strip_model()->count()); | 37 EXPECT_EQ(0, browser()->tab_strip_model()->count()); |
| 38 chrome::NewTab(browser()); | 38 chrome::NewTab(browser()); |
| 39 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 39 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 40 | 40 |
| 41 // Create a reference to initiator tab contents. | 41 // Create a reference to initiator tab contents. |
| 42 WebContents* initiator_tab = | 42 WebContents* initiator_tab = |
| 43 browser()->tab_strip_model()->GetActiveWebContents(); | 43 browser()->tab_strip_model()->GetActiveWebContents(); |
| 44 | 44 |
| 45 printing::PrintPreviewDialogController* tab_controller = | 45 printing::PrintPreviewDialogController* tab_controller = |
| 46 printing::PrintPreviewDialogController::GetInstance(); | 46 printing::PrintPreviewDialogController::GetInstance(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 64 | 64 |
| 65 // 1:1 relationship between initiator and preview tab. | 65 // 1:1 relationship between initiator and preview tab. |
| 66 EXPECT_EQ(new_preview_tab, preview_tab); | 66 EXPECT_EQ(new_preview_tab, preview_tab); |
| 67 } | 67 } |
| 68 | 68 |
| 69 // To show multiple print preview tabs exist in the same browser for | 69 // To show multiple print preview tabs exist in the same browser for |
| 70 // different initiator tabs. If preview tab already exists for an initiator, it | 70 // different initiator tabs. If preview tab already exists for an initiator, it |
| 71 // gets focused. | 71 // gets focused. |
| 72 TEST_F(PrintPreviewDialogControllerUnitTest, MAYBE_MultiplePreviewTabs) { | 72 TEST_F(PrintPreviewDialogControllerUnitTest, MAYBE_MultiplePreviewTabs) { |
| 73 // Lets start with one window and two tabs. | 73 // Lets start with one window and two tabs. |
| 74 EXPECT_EQ(1u, BrowserList::size()); | 74 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 75 TabStripModel* model = browser()->tab_strip_model(); | 75 TabStripModel* model = browser()->tab_strip_model(); |
| 76 ASSERT_TRUE(model); | 76 ASSERT_TRUE(model); |
| 77 | 77 |
| 78 EXPECT_EQ(0, model->count()); | 78 EXPECT_EQ(0, model->count()); |
| 79 | 79 |
| 80 chrome::NewTab(browser()); | 80 chrome::NewTab(browser()); |
| 81 WebContents* web_contents_1 = model->GetActiveWebContents(); | 81 WebContents* web_contents_1 = model->GetActiveWebContents(); |
| 82 ASSERT_TRUE(web_contents_1); | 82 ASSERT_TRUE(web_contents_1); |
| 83 | 83 |
| 84 chrome::NewTab(browser()); | 84 chrome::NewTab(browser()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 121 |
| 122 // When we get the preview tab for |tab_contents_1|, | 122 // When we get the preview tab for |tab_contents_1|, |
| 123 // |preview_tab_1| is activated and focused. | 123 // |preview_tab_1| is activated and focused. |
| 124 tab_controller->GetOrCreatePreviewTab(web_contents_1); | 124 tab_controller->GetOrCreatePreviewTab(web_contents_1); |
| 125 EXPECT_EQ(tab_1_index, model->active_index()); | 125 EXPECT_EQ(tab_1_index, model->active_index()); |
| 126 } | 126 } |
| 127 | 127 |
| 128 // Clear the initiator tab details associated with preview tab. | 128 // Clear the initiator tab details associated with preview tab. |
| 129 TEST_F(PrintPreviewDialogControllerUnitTest, MAYBE_ClearInitiatorTabDetails) { | 129 TEST_F(PrintPreviewDialogControllerUnitTest, MAYBE_ClearInitiatorTabDetails) { |
| 130 // Lets start with one window with one tab. | 130 // Lets start with one window with one tab. |
| 131 EXPECT_EQ(1u, BrowserList::size()); | 131 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 132 EXPECT_EQ(0, browser()->tab_strip_model()->count()); | 132 EXPECT_EQ(0, browser()->tab_strip_model()->count()); |
| 133 chrome::NewTab(browser()); | 133 chrome::NewTab(browser()); |
| 134 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 134 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 135 | 135 |
| 136 // Create a reference to initiator tab contents. | 136 // Create a reference to initiator tab contents. |
| 137 WebContents* initiator_tab = | 137 WebContents* initiator_tab = |
| 138 browser()->tab_strip_model()->GetActiveWebContents(); | 138 browser()->tab_strip_model()->GetActiveWebContents(); |
| 139 | 139 |
| 140 printing::PrintPreviewDialogController* tab_controller = | 140 printing::PrintPreviewDialogController* tab_controller = |
| 141 printing::PrintPreviewDialogController::GetInstance(); | 141 printing::PrintPreviewDialogController::GetInstance(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 154 tab_controller->EraseInitiatorTabInfo(preview_tab); | 154 tab_controller->EraseInitiatorTabInfo(preview_tab); |
| 155 | 155 |
| 156 // Get the print preview tab for initiator tab. | 156 // Get the print preview tab for initiator tab. |
| 157 WebContents* new_preview_tab = | 157 WebContents* new_preview_tab = |
| 158 tab_controller->GetOrCreatePreviewTab(initiator_tab); | 158 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
| 159 | 159 |
| 160 // New preview tab is created. | 160 // New preview tab is created. |
| 161 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 161 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 162 EXPECT_NE(new_preview_tab, preview_tab); | 162 EXPECT_NE(new_preview_tab, preview_tab); |
| 163 } | 163 } |
| OLD | NEW |