| Index: chrome/browser/ui/webui/print_preview_ui_unittest.cc
|
| ===================================================================
|
| --- chrome/browser/ui/webui/print_preview_ui_unittest.cc (revision 98330)
|
| +++ chrome/browser/ui/webui/print_preview_ui_unittest.cc (working copy)
|
| @@ -2,6 +2,8 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include <vector>
|
| +
|
| #include "base/command_line.h"
|
| #include "base/memory/ref_counted_memory.h"
|
| #include "chrome/browser/printing/print_preview_tab_controller.h"
|
| @@ -142,3 +144,63 @@
|
| preview_ui->GetPrintPreviewDataForIndex(printing::FIRST_PAGE_INDEX, &data);
|
| EXPECT_EQ(NULL, data.get());
|
| }
|
| +
|
| +// Test the browser-side print preview cancellation functionality.
|
| +TEST_F(PrintPreviewUITest, GetCurrentPrintPreviewStatus) {
|
| +#if !defined(GOOGLE_CHROME_BUILD) || defined(OS_CHROMEOS)
|
| + CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnablePrintPreview);
|
| +#endif
|
| + ASSERT_TRUE(browser());
|
| + BrowserList::SetLastActive(browser());
|
| + ASSERT_TRUE(BrowserList::GetLastActive());
|
| +
|
| + browser()->NewTab();
|
| + TabContents* initiator_tab = browser()->GetSelectedTabContents();
|
| + ASSERT_TRUE(initiator_tab);
|
| +
|
| + scoped_refptr<printing::PrintPreviewTabController>
|
| + controller(new printing::PrintPreviewTabController());
|
| + ASSERT_TRUE(controller);
|
| +
|
| + TabContents* preview_tab = controller->GetOrCreatePreviewTab(initiator_tab);
|
| +
|
| + EXPECT_NE(initiator_tab, preview_tab);
|
| + EXPECT_EQ(2, browser()->tab_count());
|
| +
|
| + PrintPreviewUI* preview_ui =
|
| + reinterpret_cast<PrintPreviewUI*>(preview_tab->web_ui());
|
| + ASSERT_TRUE(preview_ui != NULL);
|
| +
|
| + // Test with invalid |preview_ui_addr|.
|
| + bool cancel = false;
|
| + preview_ui->GetCurrentPrintPreviewStatus("invalid", 0, &cancel);
|
| + EXPECT_TRUE(cancel);
|
| +
|
| + const int kFirstRequestId = 1000;
|
| + const int kSecondRequestId = 1001;
|
| + const std::string preview_ui_addr = preview_ui->GetPrintPreviewUIAddress();
|
| +
|
| + // Test with kFirstRequestId.
|
| + preview_ui->OnPrintPreviewRequest(kFirstRequestId);
|
| + cancel = true;
|
| + preview_ui->GetCurrentPrintPreviewStatus(preview_ui_addr, kFirstRequestId,
|
| + &cancel);
|
| + EXPECT_FALSE(cancel);
|
| +
|
| + cancel = false;
|
| + preview_ui->GetCurrentPrintPreviewStatus(preview_ui_addr, kSecondRequestId,
|
| + &cancel);
|
| + EXPECT_TRUE(cancel);
|
| +
|
| + // Test with kSecondRequestId.
|
| + preview_ui->OnPrintPreviewRequest(kSecondRequestId);
|
| + cancel = false;
|
| + preview_ui->GetCurrentPrintPreviewStatus(preview_ui_addr, kFirstRequestId,
|
| + &cancel);
|
| + EXPECT_TRUE(cancel);
|
| +
|
| + cancel = true;
|
| + preview_ui->GetCurrentPrintPreviewStatus(preview_ui_addr, kSecondRequestId,
|
| + &cancel);
|
| + EXPECT_FALSE(cancel);
|
| +}
|
|
|