Chromium Code Reviews| 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 "base/command_line.h" | |
| 6 #include "base/json/json_writer.h" | |
| 7 #include "base/values.h" | |
| 8 #include "chrome/browser/browser_process.h" | |
| 9 #include "chrome/browser/printing/background_printing_manager.h" | |
| 10 #include "chrome/browser/printing/print_preview_tab_controller.h" | |
| 11 #include "chrome/browser/ui/browser_list.h" | |
| 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | |
| 13 #include "chrome/browser/ui/webui/print_preview_handler.h" | |
| 14 #include "chrome/browser/ui/webui/print_preview_ui.h" | |
| 15 #include "chrome/common/chrome_switches.h" | |
| 16 #include "chrome/test/base/browser_with_test_window_test.h" | |
| 17 #include "printing/page_size_margins.h" | |
| 18 #include "printing/print_job_constants.h" | |
| 19 | |
| 20 typedef BrowserWithTestWindowTest PrintPreviewHandlerTest; | |
| 21 | |
| 22 // When users hit print in the print preview tab, the print preview tab hides | |
| 23 // and the focus should return to the initiator tab. | |
| 24 TEST_F(PrintPreviewHandlerTest, HandlePrintTest) { | |
|
kmadhusu
2011/11/11 23:39:40
Your test case is fine. But you can add more infor
dpapad
2011/11/14 16:31:55
Done.
| |
| 25 #if !defined(GOOGLE_CHROME_BUILD) || defined(OS_CHROMEOS) | |
| 26 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnablePrintPreview); | |
| 27 #endif | |
| 28 ASSERT_TRUE(browser()); | |
| 29 BrowserList::SetLastActive(browser()); | |
| 30 ASSERT_TRUE(BrowserList::GetLastActive()); | |
| 31 | |
| 32 browser()->NewTab(); | |
| 33 EXPECT_EQ(1, browser()->tab_count()); | |
| 34 TabContentsWrapper* initiator_tab = | |
| 35 browser()->GetSelectedTabContentsWrapper(); | |
| 36 ASSERT_TRUE(initiator_tab); | |
| 37 | |
| 38 scoped_refptr<printing::PrintPreviewTabController> | |
| 39 controller(new printing::PrintPreviewTabController()); | |
| 40 ASSERT_TRUE(controller.get()); | |
| 41 | |
| 42 TabContentsWrapper* preview_tab = | |
| 43 controller->GetOrCreatePreviewTab(initiator_tab); | |
| 44 ASSERT_TRUE(preview_tab); | |
| 45 EXPECT_EQ(2, browser()->tab_count()); | |
| 46 | |
| 47 PrintPreviewUI* preview_ui = | |
| 48 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); | |
| 49 ASSERT_TRUE(preview_ui); | |
| 50 | |
| 51 // Set the minimal dummy settings to make the HandlePrint() code happy. | |
| 52 DictionaryValue settings; | |
| 53 settings.SetBoolean(printing::kSettingPreviewModifiable, true); | |
| 54 settings.SetInteger(printing::kSettingColor, printing::COLOR); | |
| 55 settings.SetBoolean(printing::kSettingPrintToPDF, false); | |
| 56 settings.SetInteger(printing::kSettingMarginsType, printing::CUSTOM_MARGINS); | |
| 57 | |
| 58 // Creating custom margins dictionary and nesting it in |settings|. | |
| 59 std::string custom_margins_root(printing::kSettingMarginsCustom); | |
| 60 custom_margins_root.append("."); | |
| 61 std::stringstream ss; | |
|
kmadhusu
2011/11/11 23:39:40
Any special reason to use the stringstream?
You c
dpapad
2011/11/14 16:31:55
Done. I was following the instructions on the top
| |
| 62 ss << custom_margins_root << printing::kSettingMarginTop; | |
| 63 settings.SetDouble(ss.str(), 25.5); | |
|
Lei Zhang
2011/11/11 22:56:30
make the values constants?
dpapad
2011/11/14 16:31:55
Done.
| |
| 64 ss.str(std::string()); | |
| 65 ss << custom_margins_root << printing::kSettingMarginRight; | |
| 66 settings.SetDouble(ss.str(), 26.5); | |
| 67 ss.str(std::string()); | |
| 68 ss << custom_margins_root << printing::kSettingMarginBottom; | |
| 69 settings.SetDouble(ss.str(), 27.5); | |
| 70 ss.str(std::string()); | |
| 71 ss << custom_margins_root << printing::kSettingMarginLeft; | |
| 72 settings.SetDouble(ss.str(), 28.5); | |
| 73 | |
| 74 // Put |settings| in to |args| as a JSON string. | |
| 75 std::string json_string; | |
| 76 base::JSONWriter::Write(&settings, false, &json_string); | |
| 77 ListValue args; | |
| 78 args.Append(new base::StringValue(json_string)); // |args| takes ownership. | |
|
Lei Zhang
2011/11/11 22:56:30
nit: 2 spaces
dpapad
2011/11/14 16:31:55
Done.
| |
| 79 preview_ui->handler_->HandlePrint(&args); | |
| 80 EXPECT_EQ(1, browser()->tab_count()); | |
| 81 | |
| 82 // Checking that sticky settings were saved correctly. | |
| 83 EXPECT_EQ(PrintPreviewHandler::last_used_color_model_, printing::COLOR); | |
| 84 EXPECT_EQ(PrintPreviewHandler::last_used_margins_type_, | |
| 85 printing::CUSTOM_MARGINS); | |
| 86 EXPECT_EQ(PrintPreviewHandler::last_used_page_size_margins_->margin_top, | |
| 87 25.5); | |
| 88 EXPECT_EQ(PrintPreviewHandler::last_used_page_size_margins_->margin_right, | |
| 89 26.5); | |
| 90 EXPECT_EQ(PrintPreviewHandler::last_used_page_size_margins_->margin_bottom, | |
| 91 27.5); | |
| 92 EXPECT_EQ(PrintPreviewHandler::last_used_page_size_margins_->margin_left, | |
| 93 28.5); | |
| 94 | |
| 95 printing::BackgroundPrintingManager* bg_printing_manager = | |
|
Lei Zhang
2011/11/11 22:56:30
Might want a comment to explain why this is here a
dpapad
2011/11/14 16:31:55
Done.
| |
| 96 g_browser_process->background_printing_manager(); | |
| 97 ASSERT_TRUE(bg_printing_manager->HasPrintPreviewTab(preview_tab)); | |
| 98 | |
| 99 delete preview_tab; | |
| 100 } | |
| OLD | NEW |