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 <vector> | |
6 | |
5 #include "base/command_line.h" | 7 #include "base/command_line.h" |
6 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
7 #include "chrome/browser/printing/print_preview_tab_controller.h" | 9 #include "chrome/browser/printing/print_preview_tab_controller.h" |
8 #include "chrome/browser/ui/browser_list.h" | 10 #include "chrome/browser/ui/browser_list.h" |
9 #include "chrome/browser/ui/webui/print_preview_ui.h" | 11 #include "chrome/browser/ui/webui/print_preview_ui.h" |
10 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
11 #include "chrome/test/base/browser_with_test_window_test.h" | 13 #include "chrome/test/base/browser_with_test_window_test.h" |
12 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
13 #include "content/browser/tab_contents/tab_contents.h" | 15 #include "content/browser/tab_contents/tab_contents.h" |
14 #include "printing/print_job_constants.h" | 16 #include "printing/print_job_constants.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 preview_ui->GetPrintPreviewDataForIndex(printing::FIRST_PAGE_INDEX + 1, | 137 preview_ui->GetPrintPreviewDataForIndex(printing::FIRST_PAGE_INDEX + 1, |
136 &data); | 138 &data); |
137 EXPECT_EQ(dummy_data->size(), data->size()); | 139 EXPECT_EQ(dummy_data->size(), data->size()); |
138 EXPECT_EQ(dummy_data.get(), data.get()); | 140 EXPECT_EQ(dummy_data.get(), data.get()); |
139 | 141 |
140 // Clear the preview data. | 142 // Clear the preview data. |
141 preview_ui->ClearAllPreviewData(); | 143 preview_ui->ClearAllPreviewData(); |
142 preview_ui->GetPrintPreviewDataForIndex(printing::FIRST_PAGE_INDEX, &data); | 144 preview_ui->GetPrintPreviewDataForIndex(printing::FIRST_PAGE_INDEX, &data); |
143 EXPECT_EQ(NULL, data.get()); | 145 EXPECT_EQ(NULL, data.get()); |
144 } | 146 } |
147 | |
148 // Set and get the individual draft pages. | |
kmadhusu
2011/08/22 21:23:57
nit: Update the comment.
Lei Zhang
2011/08/22 22:26:55
Done.
| |
149 TEST_F(PrintPreviewUITest, GetCurrentPrintPreviewStatus) { | |
150 #if !defined(GOOGLE_CHROME_BUILD) || defined(OS_CHROMEOS) | |
151 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnablePrintPreview); | |
152 #endif | |
153 ASSERT_TRUE(browser()); | |
154 BrowserList::SetLastActive(browser()); | |
155 ASSERT_TRUE(BrowserList::GetLastActive()); | |
156 | |
157 browser()->NewTab(); | |
158 TabContents* initiator_tab = browser()->GetSelectedTabContents(); | |
159 ASSERT_TRUE(initiator_tab); | |
160 | |
161 scoped_refptr<printing::PrintPreviewTabController> | |
162 controller(new printing::PrintPreviewTabController()); | |
163 ASSERT_TRUE(controller); | |
164 | |
165 TabContents* preview_tab = controller->GetOrCreatePreviewTab(initiator_tab); | |
166 | |
167 EXPECT_NE(initiator_tab, preview_tab); | |
168 EXPECT_EQ(2, browser()->tab_count()); | |
169 | |
170 PrintPreviewUI* preview_ui = | |
171 reinterpret_cast<PrintPreviewUI*>(preview_tab->web_ui()); | |
172 ASSERT_TRUE(preview_ui != NULL); | |
173 | |
174 // Test with invalid |preview_ui_addr|. | |
175 bool cancel = false; | |
176 preview_ui->GetCurrentPrintPreviewStatus("invalid", 0, &cancel); | |
177 EXPECT_TRUE(cancel); | |
178 | |
179 const int kFirstRequestId = 1000; | |
180 const int kSecondRequestId = 1001; | |
181 const std::string preview_ui_addr = preview_ui->GetPrintPreviewUIAddress(); | |
182 | |
183 // Test with kFirstRequestId. | |
184 preview_ui->OnPrintPreviewRequest(kFirstRequestId); | |
185 cancel = true; | |
186 preview_ui->GetCurrentPrintPreviewStatus(preview_ui_addr, kFirstRequestId, | |
187 &cancel); | |
188 EXPECT_FALSE(cancel); | |
189 | |
190 cancel = false; | |
191 preview_ui->GetCurrentPrintPreviewStatus(preview_ui_addr, kSecondRequestId, | |
192 &cancel); | |
193 EXPECT_TRUE(cancel); | |
194 | |
195 // Test with kSecondRequestId. | |
196 preview_ui->OnPrintPreviewRequest(kSecondRequestId); | |
197 cancel = false; | |
198 preview_ui->GetCurrentPrintPreviewStatus(preview_ui_addr, kFirstRequestId, | |
199 &cancel); | |
200 EXPECT_TRUE(cancel); | |
201 | |
202 cancel = true; | |
203 preview_ui->GetCurrentPrintPreviewStatus(preview_ui_addr, kSecondRequestId, | |
204 &cancel); | |
205 EXPECT_FALSE(cancel); | |
206 } | |
OLD | NEW |