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

Side by Side Diff: chrome/browser/ui/webui/print_preview_handler_unittest.cc

Issue 7799019: Print Preview: Add a test for activating the initiator tab on print. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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/print_job_constants.h"
18
19 typedef BrowserWithTestWindowTest PrintPreviewHandlerTest;
20
21 // When users hit print in the print preview tab, the print preview tab hides
22 // and the focus should return to the initiator tab.
23 TEST_F(PrintPreviewHandlerTest, ActivateInitiatorTabOnPrint) {
24 #if !defined(GOOGLE_CHROME_BUILD) || defined(OS_CHROMEOS)
25 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnablePrintPreview);
26 #endif
27 ASSERT_TRUE(browser());
28 BrowserList::SetLastActive(browser());
29 ASSERT_TRUE(BrowserList::GetLastActive());
30
31 browser()->NewTab();
32 TabContentsWrapper* initiator_tab =
33 browser()->GetSelectedTabContentsWrapper();
34 ASSERT_TRUE(initiator_tab);
35
36 printing::PrintPreviewTabController* controller =
37 printing::PrintPreviewTabController::GetInstance();
38 ASSERT_TRUE(controller);
39
40 TabContentsWrapper* preview_tab =
41 controller->GetOrCreatePreviewTab(initiator_tab);
42 EXPECT_EQ(2, browser()->tab_count());
43
44 browser()->NewTab();
45 EXPECT_EQ(3, 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 value;
53 value.SetBoolean(printing::kSettingColor, false);
54 value.SetBoolean(printing::kSettingPrintToPDF, false);
55
56 // Put |value| in to |args| as a JSON string.
57 std::string json_string;
58 base::JSONWriter::Write(&value, false, &json_string);
59 ListValue args;
60 args.Append(new StringValue(json_string)); // |args| takes ownership.
61 preview_ui->handler_->HandlePrint(&args);
62
63 EXPECT_EQ(2, browser()->tab_count());
64 EXPECT_EQ(initiator_tab, browser()->GetSelectedTabContentsWrapper());
65
66 printing::BackgroundPrintingManager* bg_printing_manager =
67 g_browser_process->background_printing_manager();
68 EXPECT_TRUE(bg_printing_manager->HasPrintPreviewTab(preview_tab));
69 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/print_preview_handler.h ('k') | chrome/browser/ui/webui/print_preview_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698