Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: chrome/browser/printing/print_preview_tab_controller_unittest.cc

Issue 7550063: Print Preview: Handle a crashed initiator tab by showing a message in PP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/test/base/browser_with_test_window_test.h" 8 #include "chrome/test/base/browser_with_test_window_test.h"
9 #include "chrome/test/base/testing_profile.h" 9 #include "chrome/test/base/testing_profile.h"
10 #include "content/browser/tab_contents/tab_contents.h" 10 #include "content/browser/tab_contents/tab_contents.h"
11 #include "content/common/url_constants.h"
11 12
12 typedef BrowserWithTestWindowTest PrintPreviewTabControllerTest; 13 typedef BrowserWithTestWindowTest PrintPreviewTabControllerUnitTest;
13 14
14 // Create/Get a preview tab for initiator tab. 15 // Create/Get a preview tab for initiator tab.
15 TEST_F(PrintPreviewTabControllerTest, GetOrCreatePreviewTab) { 16 TEST_F(PrintPreviewTabControllerUnitTest, GetOrCreatePreviewTab) {
16 ASSERT_TRUE(browser()); 17 ASSERT_TRUE(browser());
17 BrowserList::SetLastActive(browser()); 18 BrowserList::SetLastActive(browser());
18 ASSERT_TRUE(BrowserList::GetLastActive()); 19 ASSERT_TRUE(BrowserList::GetLastActive());
19 20
20 // Lets start with one window with one tab. 21 // Lets start with one window with one tab.
21 EXPECT_EQ(1u, BrowserList::size()); 22 EXPECT_EQ(1u, BrowserList::size());
22 EXPECT_EQ(0, browser()->tab_count()); 23 EXPECT_EQ(0, browser()->tab_count());
23 browser()->NewTab(); 24 browser()->NewTab();
24 EXPECT_EQ(1, browser()->tab_count()); 25 EXPECT_EQ(1, browser()->tab_count());
25 26
26 // Create a reference to initiator tab contents. 27 // Create a reference to initiator tab contents.
27 TabContents* initiator_tab = browser()->GetSelectedTabContents(); 28 TabContents* initiator_tab = browser()->GetSelectedTabContents();
28 29
29 scoped_refptr<printing::PrintPreviewTabController> 30 scoped_refptr<printing::PrintPreviewTabController>
30 tab_controller(new printing::PrintPreviewTabController()); 31 tab_controller(new printing::PrintPreviewTabController());
31 ASSERT_TRUE(tab_controller); 32 ASSERT_TRUE(tab_controller);
32 33
33 // Get the preview tab for initiator tab. 34 // Get the preview tab for initiator tab.
34 TabContents* preview_tab = 35 TabContents* preview_tab =
35 tab_controller->GetOrCreatePreviewTab(initiator_tab); 36 tab_controller->GetOrCreatePreviewTab(initiator_tab);
36 37
37 // New print preview tab is created. Current focus is on preview tab. 38 // New print preview tab is created. Current focus is on preview tab.
38 EXPECT_EQ(2, browser()->tab_count()); 39 EXPECT_EQ(2, browser()->tab_count());
39 EXPECT_NE(initiator_tab, preview_tab); 40 EXPECT_NE(initiator_tab, preview_tab);
40 41
41 // Activate initiator_tab.
42 static_cast<RenderViewHostDelegate*>(initiator_tab)->Activate();
43
44 // Get the print preview tab for initiator tab. 42 // Get the print preview tab for initiator tab.
45 TabContents* new_preview_tab = 43 TabContents* new_preview_tab =
46 tab_controller->GetOrCreatePreviewTab(initiator_tab); 44 tab_controller->GetOrCreatePreviewTab(initiator_tab);
47 45
48 // Preview tab already exists. Tab count remains the same. 46 // Preview tab already exists. Tab count remains the same.
49 EXPECT_EQ(2, browser()->tab_count()); 47 EXPECT_EQ(2, browser()->tab_count());
50 48
51 // 1:1 relationship between initiator and preview tab. 49 // 1:1 relationship between initiator and preview tab.
52 EXPECT_EQ(new_preview_tab, preview_tab); 50 EXPECT_EQ(new_preview_tab, preview_tab);
53 } 51 }
54 52
55 // To show multiple print preview tabs exist in the same browser for 53 // To show multiple print preview tabs exist in the same browser for
56 // different initiator tabs. If preview tab already exists for an initiator, it 54 // different initiator tabs. If preview tab already exists for an initiator, it
57 // gets focused. 55 // gets focused.
58 TEST_F(PrintPreviewTabControllerTest, MultiplePreviewTabs) { 56 TEST_F(PrintPreviewTabControllerUnitTest, MultiplePreviewTabs) {
59 ASSERT_TRUE(browser()); 57 ASSERT_TRUE(browser());
60 BrowserList::SetLastActive(browser()); 58 BrowserList::SetLastActive(browser());
61 ASSERT_TRUE(BrowserList::GetLastActive()); 59 ASSERT_TRUE(BrowserList::GetLastActive());
62 60
63 // Lets start with one window and two tabs. 61 // Lets start with one window and two tabs.
64 EXPECT_EQ(1u, BrowserList::size()); 62 EXPECT_EQ(1u, BrowserList::size());
65 EXPECT_EQ(0, browser()->tab_count()); 63 EXPECT_EQ(0, browser()->tab_count());
66 64
67 browser()->NewTab(); 65 browser()->NewTab();
68 TabContents* tab_contents_1 = browser()->GetSelectedTabContents(); 66 TabContents* tab_contents_1 = browser()->GetSelectedTabContents();
(...skipping 27 matching lines...) Expand all
96 ASSERT_TRUE(model); 94 ASSERT_TRUE(model);
97 95
98 int preview_tab_1_index = model->GetWrapperIndex(preview_tab_1); 96 int preview_tab_1_index = model->GetWrapperIndex(preview_tab_1);
99 int preview_tab_2_index = model->GetWrapperIndex(preview_tab_2); 97 int preview_tab_2_index = model->GetWrapperIndex(preview_tab_2);
100 98
101 EXPECT_NE(-1, preview_tab_1_index); 99 EXPECT_NE(-1, preview_tab_1_index);
102 EXPECT_NE(-1, preview_tab_2_index); 100 EXPECT_NE(-1, preview_tab_2_index);
103 // Current tab is |preview_tab_2|. 101 // Current tab is |preview_tab_2|.
104 EXPECT_EQ(preview_tab_2_index, browser()->active_index()); 102 EXPECT_EQ(preview_tab_2_index, browser()->active_index());
105 103
106 // Activate |tab_contents_1| tab.
107 static_cast<RenderViewHostDelegate*>(tab_contents_1)->Activate();
108
109 // When we get the preview tab for |tab_contents_1|, 104 // When we get the preview tab for |tab_contents_1|,
110 // |preview_tab_1| is activated and focused. 105 // |preview_tab_1| is activated and focused.
111 tab_controller->GetOrCreatePreviewTab(tab_contents_1); 106 tab_controller->GetOrCreatePreviewTab(tab_contents_1);
112 EXPECT_EQ(preview_tab_1_index, browser()->active_index()); 107 EXPECT_EQ(preview_tab_1_index, browser()->active_index());
113 } 108 }
114 109
115 // Clear the initiator tab details associated with preview tab. 110 // Clear the initiator tab details associated with preview tab.
116 TEST_F(PrintPreviewTabControllerTest, ClearInitiatorTabDetails) { 111 TEST_F(PrintPreviewTabControllerUnitTest, ClearInitiatorTabDetails) {
117 ASSERT_TRUE(browser()); 112 ASSERT_TRUE(browser());
118 BrowserList::SetLastActive(browser()); 113 BrowserList::SetLastActive(browser());
119 ASSERT_TRUE(BrowserList::GetLastActive()); 114 ASSERT_TRUE(BrowserList::GetLastActive());
120 115
121 // Lets start with one window with one tab. 116 // Lets start with one window with one tab.
122 EXPECT_EQ(1u, BrowserList::size()); 117 EXPECT_EQ(1u, BrowserList::size());
123 EXPECT_EQ(0, browser()->tab_count()); 118 EXPECT_EQ(0, browser()->tab_count());
124 browser()->NewTab(); 119 browser()->NewTab();
125 EXPECT_EQ(1, browser()->tab_count()); 120 EXPECT_EQ(1, browser()->tab_count());
126 121
127 // Create a reference to initiator tab contents. 122 // Create a reference to initiator tab contents.
128 TabContents* initiator_tab = browser()->GetSelectedTabContents(); 123 TabContents* initiator_tab = browser()->GetSelectedTabContents();
129 124
130 scoped_refptr<printing::PrintPreviewTabController> 125 scoped_refptr<printing::PrintPreviewTabController>
131 tab_controller(new printing::PrintPreviewTabController()); 126 tab_controller(new printing::PrintPreviewTabController());
132 ASSERT_TRUE(tab_controller); 127 ASSERT_TRUE(tab_controller);
133 128
134 // Get the preview tab for initiator tab. 129 // Get the preview tab for initiator tab.
135 TabContents* preview_tab = 130 TabContents* preview_tab =
136 tab_controller->GetOrCreatePreviewTab(initiator_tab); 131 tab_controller->GetOrCreatePreviewTab(initiator_tab);
137 132
138 // New print preview tab is created. Current focus is on preview tab. 133 // New print preview tab is created. Current focus is on preview tab.
139 EXPECT_EQ(2, browser()->tab_count()); 134 EXPECT_EQ(2, browser()->tab_count());
140 EXPECT_NE(initiator_tab, preview_tab); 135 EXPECT_NE(initiator_tab, preview_tab);
141 136
142 // Clear the initiator tab details associated with the preview tab. 137 // Clear the initiator tab details associated with the preview tab.
143 tab_controller->EraseInitiatorTabInfo(preview_tab); 138 tab_controller->EraseInitiatorTabInfo(preview_tab);
144 139
145 // Activate initiator_tab.
146 static_cast<RenderViewHostDelegate*>(initiator_tab)->Activate();
147
148 // Get the print preview tab for initiator tab. 140 // Get the print preview tab for initiator tab.
149 TabContents* new_preview_tab = 141 TabContents* new_preview_tab =
150 tab_controller->GetOrCreatePreviewTab(initiator_tab); 142 tab_controller->GetOrCreatePreviewTab(initiator_tab);
151 143
152 // New preview tab is created. 144 // New preview tab is created.
153 EXPECT_EQ(3, browser()->tab_count()); 145 EXPECT_EQ(3, browser()->tab_count());
154 EXPECT_NE(new_preview_tab, preview_tab); 146 EXPECT_NE(new_preview_tab, preview_tab);
155 } 147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698