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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "chrome/browser/printing/print_preview_tab_controller.h" | 6 #include "chrome/browser/printing/print_preview_tab_controller.h" |
| 7 #include "chrome/browser/printing/print_view_manager.h" |
7 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
8 #include "chrome/browser/ui/browser_list.h" | 9 #include "chrome/browser/ui/browser_list.h" |
9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
10 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
11 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
12 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
13 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
14 #include "content/browser/tab_contents/tab_contents.h" | 15 #include "content/browser/tab_contents/tab_contents.h" |
15 #include "content/browser/tab_contents/tab_contents_observer.h" | 16 #include "content/browser/tab_contents/tab_contents_observer.h" |
16 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 // Create a reference to initiator tab contents. | 63 // Create a reference to initiator tab contents. |
63 TabContentsWrapper* initiator_tab = | 64 TabContentsWrapper* initiator_tab = |
64 browser()->GetSelectedTabContentsWrapper(); | 65 browser()->GetSelectedTabContentsWrapper(); |
65 ASSERT_TRUE(initiator_tab); | 66 ASSERT_TRUE(initiator_tab); |
66 | 67 |
67 printing::PrintPreviewTabController* tab_controller = | 68 printing::PrintPreviewTabController* tab_controller = |
68 printing::PrintPreviewTabController::GetInstance(); | 69 printing::PrintPreviewTabController::GetInstance(); |
69 ASSERT_TRUE(tab_controller); | 70 ASSERT_TRUE(tab_controller); |
70 | 71 |
71 // Get the preview tab for initiator tab. | 72 // Get the preview tab for initiator tab. |
| 73 initiator_tab->print_view_manager()->PrintPreviewNow(); |
72 TabContentsWrapper* preview_tab = | 74 TabContentsWrapper* preview_tab = |
73 tab_controller->GetOrCreatePreviewTab(initiator_tab); | 75 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
74 | 76 |
75 // New print preview tab is created. | 77 // New print preview tab is created. |
76 EXPECT_EQ(1, browser()->tab_count()); | 78 EXPECT_EQ(1, browser()->tab_count()); |
77 ASSERT_TRUE(preview_tab); | 79 ASSERT_TRUE(preview_tab); |
78 ASSERT_NE(initiator_tab, preview_tab); | 80 ASSERT_NE(initiator_tab, preview_tab); |
79 TabDestroyedObserver observer(preview_tab->tab_contents()); | 81 TabDestroyedObserver observer(preview_tab->tab_contents()); |
80 | 82 |
81 // Navigate in the initiator tab. | 83 // Navigate in the initiator tab. |
82 GURL url(chrome::kChromeUINewTabURL); | 84 GURL url(chrome::kChromeUINewTabURL); |
83 ui_test_utils::NavigateToURL(browser(), url); | 85 ui_test_utils::NavigateToURL(browser(), url); |
84 | 86 |
85 ASSERT_TRUE(observer.tab_destroyed()); | 87 ASSERT_TRUE(observer.tab_destroyed()); |
86 | 88 |
87 // Get the print preview tab for initiator tab. | 89 // Get the print preview tab for initiator tab. |
| 90 initiator_tab->print_view_manager()->PrintPreviewNow(); |
88 TabContentsWrapper* new_preview_tab = | 91 TabContentsWrapper* new_preview_tab = |
89 tab_controller->GetOrCreatePreviewTab(initiator_tab); | 92 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
90 | 93 |
91 // New preview tab is created. | 94 // New preview tab is created. |
92 EXPECT_EQ(1, browser()->tab_count()); | 95 EXPECT_EQ(1, browser()->tab_count()); |
93 EXPECT_TRUE(new_preview_tab); | 96 EXPECT_TRUE(new_preview_tab); |
94 } | 97 } |
95 | 98 |
96 // Test to verify that after reloading the initiator tab, it creates a new | 99 // Test to verify that after reloading the initiator tab, it creates a new |
97 // print preview tab. | 100 // print preview tab. |
(...skipping 10 matching lines...) Expand all Loading... |
108 // Create a reference to initiator tab contents. | 111 // Create a reference to initiator tab contents. |
109 TabContentsWrapper* initiator_tab = | 112 TabContentsWrapper* initiator_tab = |
110 browser()->GetSelectedTabContentsWrapper(); | 113 browser()->GetSelectedTabContentsWrapper(); |
111 ASSERT_TRUE(initiator_tab); | 114 ASSERT_TRUE(initiator_tab); |
112 | 115 |
113 printing::PrintPreviewTabController* tab_controller = | 116 printing::PrintPreviewTabController* tab_controller = |
114 printing::PrintPreviewTabController::GetInstance(); | 117 printing::PrintPreviewTabController::GetInstance(); |
115 ASSERT_TRUE(tab_controller); | 118 ASSERT_TRUE(tab_controller); |
116 | 119 |
117 // Get the preview tab for initiator tab. | 120 // Get the preview tab for initiator tab. |
| 121 initiator_tab->print_view_manager()->PrintPreviewNow(); |
118 TabContentsWrapper* preview_tab = | 122 TabContentsWrapper* preview_tab = |
119 tab_controller->GetOrCreatePreviewTab(initiator_tab); | 123 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
120 | 124 |
121 // New print preview tab is created. | 125 // New print preview tab is created. |
122 EXPECT_EQ(1, browser()->tab_count()); | 126 EXPECT_EQ(1, browser()->tab_count()); |
123 ASSERT_TRUE(preview_tab); | 127 ASSERT_TRUE(preview_tab); |
124 ASSERT_NE(initiator_tab, preview_tab); | 128 ASSERT_NE(initiator_tab, preview_tab); |
125 TabDestroyedObserver tab_destroyed_observer(preview_tab->tab_contents()); | 129 TabDestroyedObserver tab_destroyed_observer(preview_tab->tab_contents()); |
126 | 130 |
127 // Reload the initiator tab. | 131 // Reload the initiator tab. |
128 ui_test_utils::WindowedNotificationObserver notification_observer( | 132 ui_test_utils::WindowedNotificationObserver notification_observer( |
129 content::NOTIFICATION_LOAD_STOP, | 133 content::NOTIFICATION_LOAD_STOP, |
130 content::NotificationService::AllSources()); | 134 content::NotificationService::AllSources()); |
131 browser()->Reload(CURRENT_TAB); | 135 browser()->Reload(CURRENT_TAB); |
132 notification_observer.Wait(); | 136 notification_observer.Wait(); |
133 | 137 |
134 ASSERT_TRUE(tab_destroyed_observer.tab_destroyed()); | 138 ASSERT_TRUE(tab_destroyed_observer.tab_destroyed()); |
135 | 139 |
136 // Get the print preview tab for initiator tab. | 140 // Get the print preview tab for initiator tab. |
| 141 initiator_tab->print_view_manager()->PrintPreviewNow(); |
137 TabContentsWrapper* new_preview_tab = | 142 TabContentsWrapper* new_preview_tab = |
138 tab_controller->GetOrCreatePreviewTab(initiator_tab); | 143 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
139 | 144 |
140 EXPECT_EQ(1, browser()->tab_count()); | 145 EXPECT_EQ(1, browser()->tab_count()); |
141 EXPECT_TRUE(new_preview_tab); | 146 EXPECT_TRUE(new_preview_tab); |
142 } | 147 } |
143 | 148 |
144 } // namespace | 149 } // namespace |
OLD | NEW |