| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_tab_controller.h" | 5 #include "chrome/browser/printing/print_preview_tab_controller.h" |
| 6 #include "chrome/browser/printing/print_view_manager.h" |
| 6 #include "chrome/browser/tabs/tab_strip_model.h" | 7 #include "chrome/browser/tabs/tab_strip_model.h" |
| 7 #include "chrome/browser/ui/browser_list.h" | 8 #include "chrome/browser/ui/browser_list.h" |
| 8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 9 #include "chrome/browser/ui/webui/print_preview_ui.h" | 10 #include "chrome/browser/ui/webui/print_preview_ui.h" |
| 10 #include "chrome/test/base/browser_with_test_window_test.h" | 11 #include "chrome/test/base/browser_with_test_window_test.h" |
| 11 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 12 #include "content/browser/tab_contents/navigation_entry.h" | 13 #include "content/browser/tab_contents/navigation_entry.h" |
| 13 #include "content/browser/tab_contents/navigation_details.h" | 14 #include "content/browser/tab_contents/navigation_details.h" |
| 14 #include "content/browser/tab_contents/tab_contents.h" | 15 #include "content/browser/tab_contents/tab_contents.h" |
| 15 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 39 | 40 |
| 40 // Create a reference to initiator tab contents. | 41 // Create a reference to initiator tab contents. |
| 41 TabContentsWrapper* initiator_tab = | 42 TabContentsWrapper* initiator_tab = |
| 42 browser()->GetSelectedTabContentsWrapper(); | 43 browser()->GetSelectedTabContentsWrapper(); |
| 43 | 44 |
| 44 printing::PrintPreviewTabController* tab_controller = | 45 printing::PrintPreviewTabController* tab_controller = |
| 45 printing::PrintPreviewTabController::GetInstance(); | 46 printing::PrintPreviewTabController::GetInstance(); |
| 46 ASSERT_TRUE(tab_controller); | 47 ASSERT_TRUE(tab_controller); |
| 47 | 48 |
| 48 // Get the preview tab for initiator tab. | 49 // Get the preview tab for initiator tab. |
| 50 initiator_tab->print_view_manager()->PrintPreviewNow(); |
| 49 TabContentsWrapper* preview_tab = | 51 TabContentsWrapper* preview_tab = |
| 50 tab_controller->GetOrCreatePreviewTab(initiator_tab); | 52 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
| 51 | 53 |
| 52 // New print preview tab is created. | 54 // New print preview tab is created. |
| 53 EXPECT_EQ(1, browser()->tab_count()); | 55 EXPECT_EQ(1, browser()->tab_count()); |
| 54 EXPECT_NE(initiator_tab, preview_tab); | 56 EXPECT_NE(initiator_tab, preview_tab); |
| 55 | 57 |
| 56 // Get the print preview tab for initiator tab. | 58 // Get the print preview tab for initiator tab. |
| 57 TabContentsWrapper* new_preview_tab = | 59 TabContentsWrapper* new_preview_tab = |
| 58 tab_controller->GetOrCreatePreviewTab(initiator_tab); | 60 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 TabContentsWrapper* tab_contents_2 = | 93 TabContentsWrapper* tab_contents_2 = |
| 92 browser()->GetSelectedTabContentsWrapper(); | 94 browser()->GetSelectedTabContentsWrapper(); |
| 93 ASSERT_TRUE(tab_contents_2); | 95 ASSERT_TRUE(tab_contents_2); |
| 94 EXPECT_EQ(2, browser()->tab_count()); | 96 EXPECT_EQ(2, browser()->tab_count()); |
| 95 | 97 |
| 96 printing::PrintPreviewTabController* tab_controller = | 98 printing::PrintPreviewTabController* tab_controller = |
| 97 printing::PrintPreviewTabController::GetInstance(); | 99 printing::PrintPreviewTabController::GetInstance(); |
| 98 ASSERT_TRUE(tab_controller); | 100 ASSERT_TRUE(tab_controller); |
| 99 | 101 |
| 100 // Create preview tab for |tab_contents_1| | 102 // Create preview tab for |tab_contents_1| |
| 103 tab_contents_1->print_view_manager()->PrintPreviewNow(); |
| 101 TabContentsWrapper* preview_tab_1 = | 104 TabContentsWrapper* preview_tab_1 = |
| 102 tab_controller->GetOrCreatePreviewTab(tab_contents_1); | 105 tab_controller->GetOrCreatePreviewTab(tab_contents_1); |
| 103 | 106 |
| 104 EXPECT_NE(tab_contents_1, preview_tab_1); | 107 EXPECT_NE(tab_contents_1, preview_tab_1); |
| 105 EXPECT_EQ(2, browser()->tab_count()); | 108 EXPECT_EQ(2, browser()->tab_count()); |
| 106 | 109 |
| 107 // Create preview tab for |tab_contents_2| | 110 // Create preview tab for |tab_contents_2| |
| 111 tab_contents_2->print_view_manager()->PrintPreviewNow(); |
| 108 TabContentsWrapper* preview_tab_2 = | 112 TabContentsWrapper* preview_tab_2 = |
| 109 tab_controller->GetOrCreatePreviewTab(tab_contents_2); | 113 tab_controller->GetOrCreatePreviewTab(tab_contents_2); |
| 110 | 114 |
| 111 EXPECT_NE(tab_contents_2, preview_tab_2); | 115 EXPECT_NE(tab_contents_2, preview_tab_2); |
| 112 // 2 initiator tab and 2 preview tabs exist in the same browser. | 116 // 2 initiator tab and 2 preview tabs exist in the same browser. |
| 113 // The preview tabs are constrained in their respective initiator tabs. | 117 // The preview tabs are constrained in their respective initiator tabs. |
| 114 EXPECT_EQ(2, browser()->tab_count()); | 118 EXPECT_EQ(2, browser()->tab_count()); |
| 115 | 119 |
| 116 TabStripModel* model = browser()->tabstrip_model(); | 120 TabStripModel* model = browser()->tabstrip_model(); |
| 117 ASSERT_TRUE(model); | 121 ASSERT_TRUE(model); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 155 |
| 152 // Create a reference to initiator tab contents. | 156 // Create a reference to initiator tab contents. |
| 153 TabContentsWrapper* initiator_tab = | 157 TabContentsWrapper* initiator_tab = |
| 154 browser()->GetSelectedTabContentsWrapper(); | 158 browser()->GetSelectedTabContentsWrapper(); |
| 155 | 159 |
| 156 printing::PrintPreviewTabController* tab_controller = | 160 printing::PrintPreviewTabController* tab_controller = |
| 157 printing::PrintPreviewTabController::GetInstance(); | 161 printing::PrintPreviewTabController::GetInstance(); |
| 158 ASSERT_TRUE(tab_controller); | 162 ASSERT_TRUE(tab_controller); |
| 159 | 163 |
| 160 // Get the preview tab for initiator tab. | 164 // Get the preview tab for initiator tab. |
| 165 initiator_tab->print_view_manager()->PrintPreviewNow(); |
| 161 TabContentsWrapper* preview_tab = | 166 TabContentsWrapper* preview_tab = |
| 162 tab_controller->GetOrCreatePreviewTab(initiator_tab); | 167 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
| 163 | 168 |
| 164 // New print preview tab is created. Current focus is on preview tab. | 169 // New print preview tab is created. Current focus is on preview tab. |
| 165 EXPECT_EQ(1, browser()->tab_count()); | 170 EXPECT_EQ(1, browser()->tab_count()); |
| 166 EXPECT_NE(initiator_tab, preview_tab); | 171 EXPECT_NE(initiator_tab, preview_tab); |
| 167 | 172 |
| 168 // Clear the initiator tab details associated with the preview tab. | 173 // Clear the initiator tab details associated with the preview tab. |
| 169 tab_controller->EraseInitiatorTabInfo(preview_tab); | 174 tab_controller->EraseInitiatorTabInfo(preview_tab); |
| 170 | 175 |
| 171 // Get the print preview tab for initiator tab. | 176 // Get the print preview tab for initiator tab. |
| 172 TabContentsWrapper* new_preview_tab = | 177 TabContentsWrapper* new_preview_tab = |
| 173 tab_controller->GetOrCreatePreviewTab(initiator_tab); | 178 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
| 174 | 179 |
| 175 // New preview tab is created. | 180 // New preview tab is created. |
| 176 EXPECT_EQ(1, browser()->tab_count()); | 181 EXPECT_EQ(1, browser()->tab_count()); |
| 177 EXPECT_NE(new_preview_tab, preview_tab); | 182 EXPECT_NE(new_preview_tab, preview_tab); |
| 178 } | 183 } |
| OLD | NEW |