Chromium Code Reviews| 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/tabs/tab_strip_model.h" | 6 #include "chrome/browser/tabs/tab_strip_model.h" |
| 7 #include "chrome/browser/ui/browser_list.h" | 7 #include "chrome/browser/ui/browser_list.h" |
| 8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 9 #include "chrome/browser/ui/webui/print_preview_ui.h" | 9 #include "chrome/browser/ui/webui/print_preview_ui.h" |
| 10 #include "chrome/test/base/browser_with_test_window_test.h" | 10 #include "chrome/test/base/browser_with_test_window_test.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 browser()->GetSelectedTabContentsWrapper(); | 35 browser()->GetSelectedTabContentsWrapper(); |
| 36 | 36 |
| 37 scoped_refptr<printing::PrintPreviewTabController> | 37 scoped_refptr<printing::PrintPreviewTabController> |
| 38 tab_controller(new printing::PrintPreviewTabController()); | 38 tab_controller(new printing::PrintPreviewTabController()); |
| 39 ASSERT_TRUE(tab_controller); | 39 ASSERT_TRUE(tab_controller); |
| 40 | 40 |
| 41 // Get the preview tab for initiator tab. | 41 // Get the preview tab for initiator tab. |
| 42 TabContentsWrapper* preview_tab = | 42 TabContentsWrapper* preview_tab = |
| 43 tab_controller->GetOrCreatePreviewTab(initiator_tab); | 43 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
| 44 | 44 |
| 45 // New print preview tab is created. Current focus is on preview tab. | 45 // New print preview tab is created. |
| 46 EXPECT_EQ(2, browser()->tab_count()); | 46 EXPECT_EQ(1, browser()->tab_count()); |
|
vandebo (ex-Chrome)
2011/11/02 20:50:30
Hmm, will this CL fix 83456 as well?
Lei Zhang
2011/11/02 22:50:03
I suppose it does, since we don't create a new tab
vandebo (ex-Chrome)
2011/11/02 22:52:35
You may want to take ownership of the bug, or note
| |
| 47 EXPECT_NE(initiator_tab, preview_tab); | 47 EXPECT_NE(initiator_tab, preview_tab); |
| 48 | 48 |
| 49 // Get the print preview tab for initiator tab. | 49 // Get the print preview tab for initiator tab. |
| 50 TabContentsWrapper* new_preview_tab = | 50 TabContentsWrapper* new_preview_tab = |
| 51 tab_controller->GetOrCreatePreviewTab(initiator_tab); | 51 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
| 52 | 52 |
| 53 // Preview tab already exists. Tab count remains the same. | 53 // Preview tab already exists. Tab count remains the same. |
| 54 EXPECT_EQ(2, browser()->tab_count()); | 54 EXPECT_EQ(1, browser()->tab_count()); |
| 55 | 55 |
| 56 // 1:1 relationship between initiator and preview tab. | 56 // 1:1 relationship between initiator and preview tab. |
| 57 EXPECT_EQ(new_preview_tab, preview_tab); | 57 EXPECT_EQ(new_preview_tab, preview_tab); |
| 58 } | 58 } |
| 59 | 59 |
| 60 // Test to verify the initiator tab title is stored in |PrintPreviewUI| after | |
| 61 // preview tab reload. | |
| 62 TEST_F(PrintPreviewTabControllerUnitTest, TitleAfterReload) { | |
| 63 ASSERT_TRUE(browser()); | |
| 64 BrowserList::SetLastActive(browser()); | |
| 65 ASSERT_TRUE(BrowserList::GetLastActive()); | |
| 66 | |
| 67 // Lets start with one window with one tab. | |
| 68 EXPECT_EQ(1u, BrowserList::size()); | |
| 69 EXPECT_EQ(0, browser()->tab_count()); | |
| 70 browser()->NewTab(); | |
| 71 EXPECT_EQ(1, browser()->tab_count()); | |
| 72 | |
| 73 // Create a reference to initiator tab contents. | |
| 74 TabContentsWrapper* initiator_tab = | |
| 75 browser()->GetSelectedTabContentsWrapper(); | |
| 76 | |
| 77 scoped_refptr<printing::PrintPreviewTabController> | |
| 78 tab_controller(new printing::PrintPreviewTabController()); | |
| 79 ASSERT_TRUE(tab_controller); | |
| 80 | |
| 81 // Get the preview tab for initiator tab. | |
| 82 TabContentsWrapper* preview_tab = | |
| 83 tab_controller->GetOrCreatePreviewTab(initiator_tab); | |
| 84 | |
| 85 // New print preview tab is created. Current focus is on preview tab. | |
| 86 EXPECT_EQ(2, browser()->tab_count()); | |
| 87 EXPECT_NE(initiator_tab, preview_tab); | |
| 88 | |
| 89 // Set up a PrintPreviewUI for |preview_tab|. | |
| 90 PrintPreviewUI* preview_ui = new PrintPreviewUI(preview_tab->tab_contents()); | |
| 91 // RenderViewHostManager takes ownership of |preview_ui|. | |
| 92 preview_tab->tab_contents()->render_manager_for_testing()-> | |
| 93 SetWebUIPostCommit(preview_ui); | |
| 94 | |
| 95 // Simulate a reload event on |preview_tab|. | |
| 96 scoped_ptr<NavigationEntry> entry; | |
| 97 entry.reset(new NavigationEntry()); | |
| 98 entry->set_transition_type(content::PAGE_TRANSITION_RELOAD); | |
| 99 content::LoadCommittedDetails details; | |
| 100 details.type = content::NAVIGATION_TYPE_SAME_PAGE; | |
| 101 details.entry = entry.get(); | |
| 102 content::NotificationService::current()->Notify( | |
| 103 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 104 content::Source<NavigationController>(&preview_tab->controller()), | |
| 105 content::Details<content::LoadCommittedDetails>(&details)); | |
| 106 EXPECT_EQ(initiator_tab->tab_contents()->GetTitle(), | |
| 107 preview_ui->initiator_tab_title_); | |
| 108 } | |
| 109 | |
| 110 // To show multiple print preview tabs exist in the same browser for | 60 // To show multiple print preview tabs exist in the same browser for |
| 111 // different initiator tabs. If preview tab already exists for an initiator, it | 61 // different initiator tabs. If preview tab already exists for an initiator, it |
| 112 // gets focused. | 62 // gets focused. |
| 113 TEST_F(PrintPreviewTabControllerUnitTest, MultiplePreviewTabs) { | 63 TEST_F(PrintPreviewTabControllerUnitTest, MultiplePreviewTabs) { |
| 114 ASSERT_TRUE(browser()); | 64 ASSERT_TRUE(browser()); |
| 115 BrowserList::SetLastActive(browser()); | 65 BrowserList::SetLastActive(browser()); |
| 116 ASSERT_TRUE(BrowserList::GetLastActive()); | 66 ASSERT_TRUE(BrowserList::GetLastActive()); |
| 117 | 67 |
| 118 // Lets start with one window and two tabs. | 68 // Lets start with one window and two tabs. |
| 119 EXPECT_EQ(1u, BrowserList::size()); | 69 EXPECT_EQ(1u, BrowserList::size()); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 132 | 82 |
| 133 scoped_refptr<printing::PrintPreviewTabController> | 83 scoped_refptr<printing::PrintPreviewTabController> |
| 134 tab_controller(new printing::PrintPreviewTabController()); | 84 tab_controller(new printing::PrintPreviewTabController()); |
| 135 ASSERT_TRUE(tab_controller); | 85 ASSERT_TRUE(tab_controller); |
| 136 | 86 |
| 137 // Create preview tab for |tab_contents_1| | 87 // Create preview tab for |tab_contents_1| |
| 138 TabContentsWrapper* preview_tab_1 = | 88 TabContentsWrapper* preview_tab_1 = |
| 139 tab_controller->GetOrCreatePreviewTab(tab_contents_1); | 89 tab_controller->GetOrCreatePreviewTab(tab_contents_1); |
| 140 | 90 |
| 141 EXPECT_NE(tab_contents_1, preview_tab_1); | 91 EXPECT_NE(tab_contents_1, preview_tab_1); |
| 142 EXPECT_EQ(3, browser()->tab_count()); | 92 EXPECT_EQ(2, browser()->tab_count()); |
| 143 | 93 |
| 144 // Create preview tab for |tab_contents_2| | 94 // Create preview tab for |tab_contents_2| |
| 145 TabContentsWrapper* preview_tab_2 = | 95 TabContentsWrapper* preview_tab_2 = |
| 146 tab_controller->GetOrCreatePreviewTab(tab_contents_2); | 96 tab_controller->GetOrCreatePreviewTab(tab_contents_2); |
| 147 | 97 |
| 148 EXPECT_NE(tab_contents_2, preview_tab_2); | 98 EXPECT_NE(tab_contents_2, preview_tab_2); |
| 149 // 2 initiator tab and 2 preview tabs exist in the same browser. | 99 // 2 initiator tab and 2 preview tabs exist in the same browser. |
| 150 EXPECT_EQ(4, browser()->tab_count()); | 100 // The preview tabs are constrained in their respective initiator tabs. |
| 101 EXPECT_EQ(2, browser()->tab_count()); | |
| 151 | 102 |
| 152 TabStripModel* model = browser()->tabstrip_model(); | 103 TabStripModel* model = browser()->tabstrip_model(); |
| 153 ASSERT_TRUE(model); | 104 ASSERT_TRUE(model); |
| 154 | 105 |
| 106 int tab_1_index = model->GetIndexOfTabContents(tab_contents_1); | |
| 107 int tab_2_index = model->GetIndexOfTabContents(tab_contents_2); | |
| 155 int preview_tab_1_index = model->GetIndexOfTabContents(preview_tab_1); | 108 int preview_tab_1_index = model->GetIndexOfTabContents(preview_tab_1); |
| 156 int preview_tab_2_index = model->GetIndexOfTabContents(preview_tab_2); | 109 int preview_tab_2_index = model->GetIndexOfTabContents(preview_tab_2); |
| 157 | 110 |
| 158 EXPECT_NE(-1, preview_tab_1_index); | 111 EXPECT_EQ(-1, preview_tab_1_index); |
| 159 EXPECT_NE(-1, preview_tab_2_index); | 112 EXPECT_EQ(-1, preview_tab_2_index); |
| 160 // Current tab is |preview_tab_2|. | 113 EXPECT_EQ(tab_2_index, browser()->active_index()); |
| 161 EXPECT_EQ(preview_tab_2_index, browser()->active_index()); | |
| 162 | 114 |
| 163 // When we get the preview tab for |tab_contents_1|, | 115 // When we get the preview tab for |tab_contents_1|, |
| 164 // |preview_tab_1| is activated and focused. | 116 // |preview_tab_1| is activated and focused. |
| 165 tab_controller->GetOrCreatePreviewTab(tab_contents_1); | 117 tab_controller->GetOrCreatePreviewTab(tab_contents_1); |
| 166 EXPECT_EQ(preview_tab_1_index, browser()->active_index()); | 118 EXPECT_EQ(tab_1_index, browser()->active_index()); |
| 167 } | 119 } |
| 168 | 120 |
| 169 // Clear the initiator tab details associated with preview tab. | 121 // Clear the initiator tab details associated with preview tab. |
| 170 TEST_F(PrintPreviewTabControllerUnitTest, ClearInitiatorTabDetails) { | 122 TEST_F(PrintPreviewTabControllerUnitTest, ClearInitiatorTabDetails) { |
| 171 ASSERT_TRUE(browser()); | 123 ASSERT_TRUE(browser()); |
| 172 BrowserList::SetLastActive(browser()); | 124 BrowserList::SetLastActive(browser()); |
| 173 ASSERT_TRUE(BrowserList::GetLastActive()); | 125 ASSERT_TRUE(BrowserList::GetLastActive()); |
| 174 | 126 |
| 175 // Lets start with one window with one tab. | 127 // Lets start with one window with one tab. |
| 176 EXPECT_EQ(1u, BrowserList::size()); | 128 EXPECT_EQ(1u, BrowserList::size()); |
| 177 EXPECT_EQ(0, browser()->tab_count()); | 129 EXPECT_EQ(0, browser()->tab_count()); |
| 178 browser()->NewTab(); | 130 browser()->NewTab(); |
| 179 EXPECT_EQ(1, browser()->tab_count()); | 131 EXPECT_EQ(1, browser()->tab_count()); |
| 180 | 132 |
| 181 // Create a reference to initiator tab contents. | 133 // Create a reference to initiator tab contents. |
| 182 TabContentsWrapper* initiator_tab = | 134 TabContentsWrapper* initiator_tab = |
| 183 browser()->GetSelectedTabContentsWrapper(); | 135 browser()->GetSelectedTabContentsWrapper(); |
| 184 | 136 |
| 185 scoped_refptr<printing::PrintPreviewTabController> | 137 scoped_refptr<printing::PrintPreviewTabController> |
| 186 tab_controller(new printing::PrintPreviewTabController()); | 138 tab_controller(new printing::PrintPreviewTabController()); |
| 187 ASSERT_TRUE(tab_controller); | 139 ASSERT_TRUE(tab_controller); |
| 188 | 140 |
| 189 // Get the preview tab for initiator tab. | 141 // Get the preview tab for initiator tab. |
| 190 TabContentsWrapper* preview_tab = | 142 TabContentsWrapper* preview_tab = |
| 191 tab_controller->GetOrCreatePreviewTab(initiator_tab); | 143 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
| 192 | 144 |
| 193 // New print preview tab is created. Current focus is on preview tab. | 145 // New print preview tab is created. Current focus is on preview tab. |
| 194 EXPECT_EQ(2, browser()->tab_count()); | 146 EXPECT_EQ(1, browser()->tab_count()); |
| 195 EXPECT_NE(initiator_tab, preview_tab); | 147 EXPECT_NE(initiator_tab, preview_tab); |
| 196 | 148 |
| 197 // Clear the initiator tab details associated with the preview tab. | 149 // Clear the initiator tab details associated with the preview tab. |
| 198 tab_controller->EraseInitiatorTabInfo(preview_tab); | 150 tab_controller->EraseInitiatorTabInfo(preview_tab); |
| 199 | 151 |
| 200 // Get the print preview tab for initiator tab. | 152 // Get the print preview tab for initiator tab. |
| 201 TabContentsWrapper* new_preview_tab = | 153 TabContentsWrapper* new_preview_tab = |
| 202 tab_controller->GetOrCreatePreviewTab(initiator_tab); | 154 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
| 203 | 155 |
| 204 // New preview tab is created. | 156 // New preview tab is created. |
| 205 EXPECT_EQ(3, browser()->tab_count()); | 157 EXPECT_EQ(1, browser()->tab_count()); |
| 206 EXPECT_NE(new_preview_tab, preview_tab); | 158 EXPECT_NE(new_preview_tab, preview_tab); |
| 207 } | 159 } |
| OLD | NEW |