OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/printing/print_preview_tab_controller.h" |
| 6 #include "chrome/browser/ui/browser.h" |
| 7 #include "chrome/browser/ui/browser_list.h" |
| 8 #include "chrome/common/url_constants.h" |
| 9 #include "chrome/test/base/in_process_browser_test.h" |
| 10 #include "chrome/test/base/ui_test_utils.h" |
| 11 #include "content/browser/tab_contents/tab_contents.h" |
| 12 #include "googleurl/src/gurl.h" |
| 13 |
| 14 namespace { |
| 15 |
| 16 typedef InProcessBrowserTest PrintPreviewTabControllerBrowserTest; |
| 17 |
| 18 // Test to verify that when a preview tab navigates, we can create a new print |
| 19 // preview tab for both initiator tab and new preview tab contents. |
| 20 IN_PROC_BROWSER_TEST_F(PrintPreviewTabControllerBrowserTest, |
| 21 NavigateFromPrintPreviewTab) { |
| 22 ASSERT_TRUE(browser()); |
| 23 BrowserList::SetLastActive(browser()); |
| 24 ASSERT_TRUE(BrowserList::GetLastActive()); |
| 25 |
| 26 // Lets start with one window with one tab. |
| 27 EXPECT_EQ(1u, BrowserList::size()); |
| 28 EXPECT_EQ(1, browser()->tab_count()); |
| 29 |
| 30 // Create a reference to initiator tab contents. |
| 31 TabContents* initiator_tab = browser()->GetSelectedTabContents(); |
| 32 ASSERT_TRUE(initiator_tab); |
| 33 |
| 34 scoped_refptr<printing::PrintPreviewTabController> |
| 35 tab_controller(new printing::PrintPreviewTabController()); |
| 36 ASSERT_TRUE(tab_controller); |
| 37 |
| 38 // Get the preview tab for initiator tab. |
| 39 TabContents* preview_tab = |
| 40 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
| 41 |
| 42 // New print preview tab is created. Current focus is on preview tab. |
| 43 EXPECT_EQ(2, browser()->tab_count()); |
| 44 EXPECT_NE(initiator_tab, preview_tab); |
| 45 |
| 46 GURL url(chrome::kAboutBlankURL); |
| 47 ui_test_utils::NavigateToURL(browser(), url); |
| 48 EXPECT_EQ(url, preview_tab->GetURL()); |
| 49 |
| 50 // Get the print preview tab for initiator tab. |
| 51 TabContents* new_preview_tab = |
| 52 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
| 53 |
| 54 // New preview tab is created. |
| 55 EXPECT_EQ(3, browser()->tab_count()); |
| 56 EXPECT_NE(new_preview_tab, preview_tab); |
| 57 |
| 58 // Get the print preview tab for old preview tab. |
| 59 TabContents* newest_preview_tab = |
| 60 tab_controller->GetOrCreatePreviewTab(preview_tab); |
| 61 |
| 62 // Newest preview tab is created and the previously created preview tab is not |
| 63 // merely activated. |
| 64 EXPECT_EQ(4, browser()->tab_count()); |
| 65 EXPECT_NE(newest_preview_tab, new_preview_tab); |
| 66 } |
| 67 |
| 68 // Test to verify that when a initiator tab navigates, we can create a new |
| 69 // preview tab for the new tab contents. But we cannot create a preview tab for |
| 70 // the old preview tab. |
| 71 IN_PROC_BROWSER_TEST_F(PrintPreviewTabControllerBrowserTest, |
| 72 NavigateFromInitiatorTab) { |
| 73 ASSERT_TRUE(browser()); |
| 74 BrowserList::SetLastActive(browser()); |
| 75 ASSERT_TRUE(BrowserList::GetLastActive()); |
| 76 |
| 77 // Lets start with one window with one tab. |
| 78 EXPECT_EQ(1u, BrowserList::size()); |
| 79 EXPECT_EQ(1, browser()->tab_count()); |
| 80 |
| 81 // Create a reference to initiator tab contents. |
| 82 TabContents* initiator_tab = browser()->GetSelectedTabContents(); |
| 83 ASSERT_TRUE(initiator_tab); |
| 84 |
| 85 scoped_refptr<printing::PrintPreviewTabController> |
| 86 tab_controller(new printing::PrintPreviewTabController()); |
| 87 ASSERT_TRUE(tab_controller); |
| 88 |
| 89 // Get the preview tab for initiator tab. |
| 90 TabContents* preview_tab = |
| 91 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
| 92 |
| 93 // New print preview tab is created. Current focus is on preview tab. |
| 94 EXPECT_EQ(2, browser()->tab_count()); |
| 95 EXPECT_NE(initiator_tab, preview_tab); |
| 96 |
| 97 // Activate initiator tab. |
| 98 browser()->ActivateTabAt(0, true); |
| 99 GURL url(chrome::kChromeUINewTabURL); |
| 100 ui_test_utils::NavigateToURL(browser(), url); |
| 101 |
| 102 // Get the print preview tab for initiator tab. |
| 103 TabContents* new_preview_tab = |
| 104 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
| 105 |
| 106 // New preview tab is created. |
| 107 EXPECT_EQ(3, browser()->tab_count()); |
| 108 EXPECT_NE(new_preview_tab, preview_tab); |
| 109 |
| 110 // Get the print preview tab for old preview tab. |
| 111 TabContents* newest_preview_tab = |
| 112 tab_controller->GetOrCreatePreviewTab(preview_tab); |
| 113 |
| 114 // Make sure preview tab is not created for |preview_tab|. |
| 115 EXPECT_EQ(3, browser()->tab_count()); |
| 116 EXPECT_EQ(newest_preview_tab, preview_tab); |
| 117 } |
| 118 |
| 119 // Test to verify that even after reloading initiator tab and preview tab, |
| 120 // their association exists. |
| 121 IN_PROC_BROWSER_TEST_F(PrintPreviewTabControllerBrowserTest, |
| 122 ReloadInitiatorTabAndPreviewTab) { |
| 123 ASSERT_TRUE(browser()); |
| 124 BrowserList::SetLastActive(browser()); |
| 125 ASSERT_TRUE(BrowserList::GetLastActive()); |
| 126 |
| 127 // Lets start with one window with one tab. |
| 128 EXPECT_EQ(1u, BrowserList::size()); |
| 129 EXPECT_EQ(1, browser()->tab_count()); |
| 130 |
| 131 // Create a reference to initiator tab contents. |
| 132 TabContents* initiator_tab = browser()->GetSelectedTabContents(); |
| 133 ASSERT_TRUE(initiator_tab); |
| 134 |
| 135 scoped_refptr<printing::PrintPreviewTabController> |
| 136 tab_controller(new printing::PrintPreviewTabController()); |
| 137 ASSERT_TRUE(tab_controller); |
| 138 |
| 139 // Get the preview tab for initiator tab. |
| 140 TabContents* preview_tab = |
| 141 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
| 142 |
| 143 // New print preview tab is created. Current focus is on preview tab. |
| 144 EXPECT_EQ(2, browser()->tab_count()); |
| 145 EXPECT_NE(initiator_tab, preview_tab); |
| 146 |
| 147 // Activate initiator tab and reload. |
| 148 browser()->ActivateTabAt(0, true); |
| 149 browser()->Reload(CURRENT_TAB); |
| 150 |
| 151 // Get the print preview tab for initiator tab. |
| 152 TabContents* new_preview_tab = |
| 153 tab_controller->GetOrCreatePreviewTab(initiator_tab); |
| 154 |
| 155 // Old preview tab is activated. |
| 156 EXPECT_EQ(2, browser()->tab_count()); |
| 157 EXPECT_EQ(new_preview_tab, preview_tab); |
| 158 |
| 159 // Reload preview tab. |
| 160 browser()->Reload(CURRENT_TAB); |
| 161 // Get the print preview tab for old preview tab. |
| 162 TabContents* newest_preview_tab = |
| 163 tab_controller->GetOrCreatePreviewTab(preview_tab); |
| 164 |
| 165 // Make sure new preview tab is not created for |preview_tab|. |
| 166 EXPECT_EQ(2, browser()->tab_count()); |
| 167 EXPECT_EQ(newest_preview_tab, preview_tab); |
| 168 } |
| 169 |
| 170 } // namespace |
OLD | NEW |