| 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" | 
| 11 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" | 
| 12 #include "content/browser/tab_contents/navigation_entry.h" | 12 #include "content/browser/tab_contents/navigation_entry.h" | 
| 13 #include "content/browser/tab_contents/navigation_details.h" | 13 #include "content/browser/tab_contents/navigation_details.h" | 
| 14 #include "content/browser/tab_contents/tab_contents.h" | 14 #include "content/browser/tab_contents/tab_contents.h" | 
| 15 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" | 
| 16 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" | 
| 17 #include "content/public/common/url_constants.h" | 17 #include "content/public/common/url_constants.h" | 
| 18 | 18 | 
|  | 19 // Test crashes on Aura due to initiator tab's native view having no parent. | 
|  | 20 // http://crbug.com/104284 | 
|  | 21 #if defined(USE_AURA) | 
|  | 22 #define MAYBE_GetOrCreatePreviewTab DISABLED_GetOrCreatePreviewTab | 
|  | 23 #define MAYBE_MultiplePreviewTabs DISABLED_MultiplePreviewTabs | 
|  | 24 #define MAYBE_ClearInitiatorTabDetails DISABLED_ClearInitiatorTabDetails | 
|  | 25 #else | 
|  | 26 #define MAYBE_GetOrCreatePreviewTab GetOrCreatePreviewTab | 
|  | 27 #define MAYBE_MultiplePreviewTabs MultiplePreviewTabs | 
|  | 28 #define MAYBE_ClearInitiatorTabDetails ClearInitiatorTabDetails | 
|  | 29 #endif | 
|  | 30 | 
| 19 typedef BrowserWithTestWindowTest PrintPreviewTabControllerUnitTest; | 31 typedef BrowserWithTestWindowTest PrintPreviewTabControllerUnitTest; | 
| 20 | 32 | 
| 21 // Test crashs on TouchUI due to initiator tab's native view having no parent. |  | 
| 22 // http://crbug.com/104284 |  | 
| 23 #if defined(TOUCH_UI) |  | 
| 24 #define MAYBE_GetOrCreatePreviewTab DISABLED_GetOrCreatePreviewTab |  | 
| 25 #else |  | 
| 26 #define MAYBE_GetOrCreatePreviewTab GetOrCreatePreviewTab |  | 
| 27 #endif |  | 
| 28 // Create/Get a preview tab for initiator tab. | 33 // Create/Get a preview tab for initiator tab. | 
| 29 TEST_F(PrintPreviewTabControllerUnitTest, MAYBE_GetOrCreatePreviewTab) { | 34 TEST_F(PrintPreviewTabControllerUnitTest, MAYBE_GetOrCreatePreviewTab) { | 
| 30   ASSERT_TRUE(browser()); | 35   ASSERT_TRUE(browser()); | 
| 31   BrowserList::SetLastActive(browser()); | 36   BrowserList::SetLastActive(browser()); | 
| 32   ASSERT_TRUE(BrowserList::GetLastActive()); | 37   ASSERT_TRUE(BrowserList::GetLastActive()); | 
| 33 | 38 | 
| 34   // Lets start with one window with one tab. | 39   // Lets start with one window with one tab. | 
| 35   EXPECT_EQ(1u, BrowserList::size()); | 40   EXPECT_EQ(1u, BrowserList::size()); | 
| 36   EXPECT_EQ(0, browser()->tab_count()); | 41   EXPECT_EQ(0, browser()->tab_count()); | 
| 37   browser()->NewTab(); | 42   browser()->NewTab(); | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 57   TabContentsWrapper* new_preview_tab = | 62   TabContentsWrapper* new_preview_tab = | 
| 58       tab_controller->GetOrCreatePreviewTab(initiator_tab); | 63       tab_controller->GetOrCreatePreviewTab(initiator_tab); | 
| 59 | 64 | 
| 60   // Preview tab already exists. Tab count remains the same. | 65   // Preview tab already exists. Tab count remains the same. | 
| 61   EXPECT_EQ(1, browser()->tab_count()); | 66   EXPECT_EQ(1, browser()->tab_count()); | 
| 62 | 67 | 
| 63   // 1:1 relationship between initiator and preview tab. | 68   // 1:1 relationship between initiator and preview tab. | 
| 64   EXPECT_EQ(new_preview_tab, preview_tab); | 69   EXPECT_EQ(new_preview_tab, preview_tab); | 
| 65 } | 70 } | 
| 66 | 71 | 
| 67 // http://crbug.com/104284 |  | 
| 68 #if defined(TOUCH_UI) |  | 
| 69 #define MAYBE_MultiplePreviewTabs DISABLED_MultiplePreviewTabs |  | 
| 70 #else |  | 
| 71 #define MAYBE_MultiplePreviewTabs MultiplePreviewTabs |  | 
| 72 #endif |  | 
| 73 // To show multiple print preview tabs exist in the same browser for | 72 // To show multiple print preview tabs exist in the same browser for | 
| 74 // different initiator tabs. If preview tab already exists for an initiator, it | 73 // different initiator tabs. If preview tab already exists for an initiator, it | 
| 75 // gets focused. | 74 // gets focused. | 
| 76 TEST_F(PrintPreviewTabControllerUnitTest, MAYBE_MultiplePreviewTabs) { | 75 TEST_F(PrintPreviewTabControllerUnitTest, MAYBE_MultiplePreviewTabs) { | 
| 77   ASSERT_TRUE(browser()); | 76   ASSERT_TRUE(browser()); | 
| 78   BrowserList::SetLastActive(browser()); | 77   BrowserList::SetLastActive(browser()); | 
| 79   ASSERT_TRUE(BrowserList::GetLastActive()); | 78   ASSERT_TRUE(BrowserList::GetLastActive()); | 
| 80 | 79 | 
| 81   // Lets start with one window and two tabs. | 80   // Lets start with one window and two tabs. | 
| 82   EXPECT_EQ(1u, BrowserList::size()); | 81   EXPECT_EQ(1u, BrowserList::size()); | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 124   EXPECT_EQ(-1, preview_tab_1_index); | 123   EXPECT_EQ(-1, preview_tab_1_index); | 
| 125   EXPECT_EQ(-1, preview_tab_2_index); | 124   EXPECT_EQ(-1, preview_tab_2_index); | 
| 126   EXPECT_EQ(tab_2_index, browser()->active_index()); | 125   EXPECT_EQ(tab_2_index, browser()->active_index()); | 
| 127 | 126 | 
| 128   // When we get the preview tab for |tab_contents_1|, | 127   // When we get the preview tab for |tab_contents_1|, | 
| 129   // |preview_tab_1| is activated and focused. | 128   // |preview_tab_1| is activated and focused. | 
| 130   tab_controller->GetOrCreatePreviewTab(tab_contents_1); | 129   tab_controller->GetOrCreatePreviewTab(tab_contents_1); | 
| 131   EXPECT_EQ(tab_1_index, browser()->active_index()); | 130   EXPECT_EQ(tab_1_index, browser()->active_index()); | 
| 132 } | 131 } | 
| 133 | 132 | 
| 134 // http://crbug.com/104284 |  | 
| 135 #if defined(TOUCH_UI) |  | 
| 136 #define MAYBE_ClearInitiatorTabDetails DISABLED_ClearInitiatorTabDetails |  | 
| 137 #else |  | 
| 138 #define MAYBE_ClearInitiatorTabDetails ClearInitiatorTabDetails |  | 
| 139 #endif |  | 
| 140 // Clear the initiator tab details associated with preview tab. | 133 // Clear the initiator tab details associated with preview tab. | 
| 141 TEST_F(PrintPreviewTabControllerUnitTest, MAYBE_ClearInitiatorTabDetails) { | 134 TEST_F(PrintPreviewTabControllerUnitTest, MAYBE_ClearInitiatorTabDetails) { | 
| 142   ASSERT_TRUE(browser()); | 135   ASSERT_TRUE(browser()); | 
| 143   BrowserList::SetLastActive(browser()); | 136   BrowserList::SetLastActive(browser()); | 
| 144   ASSERT_TRUE(BrowserList::GetLastActive()); | 137   ASSERT_TRUE(BrowserList::GetLastActive()); | 
| 145 | 138 | 
| 146   // Lets start with one window with one tab. | 139   // Lets start with one window with one tab. | 
| 147   EXPECT_EQ(1u, BrowserList::size()); | 140   EXPECT_EQ(1u, BrowserList::size()); | 
| 148   EXPECT_EQ(0, browser()->tab_count()); | 141   EXPECT_EQ(0, browser()->tab_count()); | 
| 149   browser()->NewTab(); | 142   browser()->NewTab(); | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 169   tab_controller->EraseInitiatorTabInfo(preview_tab); | 162   tab_controller->EraseInitiatorTabInfo(preview_tab); | 
| 170 | 163 | 
| 171   // Get the print preview tab for initiator tab. | 164   // Get the print preview tab for initiator tab. | 
| 172   TabContentsWrapper* new_preview_tab = | 165   TabContentsWrapper* new_preview_tab = | 
| 173       tab_controller->GetOrCreatePreviewTab(initiator_tab); | 166       tab_controller->GetOrCreatePreviewTab(initiator_tab); | 
| 174 | 167 | 
| 175   // New preview tab is created. | 168   // New preview tab is created. | 
| 176   EXPECT_EQ(1, browser()->tab_count()); | 169   EXPECT_EQ(1, browser()->tab_count()); | 
| 177   EXPECT_NE(new_preview_tab, preview_tab); | 170   EXPECT_NE(new_preview_tab, preview_tab); | 
| 178 } | 171 } | 
| OLD | NEW | 
|---|