1 // Copyright (c) 2012 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.
5 #include "base/prefs/pref_service.h"
6 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/task_manager/task_manager_browsertest_util.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_commands.h"
12 #include "chrome/browser/ui/browser_dialogs.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/common/url_constants.h"
15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "chrome/test/base/ui_test_utils.h"
17 #include "components/content_settings/core/browser/host_content_settings_map.h"
18 #include "content/public/browser/web_contents.h"
19 #include "content/public/browser/web_contents_observer.h"
20 #include "content/public/test/browser_test_utils.h"
21 #include "content/public/test/test_navigation_observer.h"
22 #include "content/public/test/test_utils.h"
23 #include "url/url_constants.h"
26 #include "ui/aura/window.h"
27 #include "ui/aura/window_tree_host.h"
30 using task_manager::browsertest_util::MatchAboutBlankTab
;
31 using task_manager::browsertest_util::MatchAnyPrint
;
32 using task_manager::browsertest_util::MatchAnyTab
;
33 using task_manager::browsertest_util::MatchPrint
;
34 using task_manager::browsertest_util::WaitForTaskManagerRows
;
38 class PrintPreviewTest
: public InProcessBrowserTest
{
43 content::TestNavigationObserver
nav_observer(NULL
);
44 nav_observer
.StartWatchingNewWebContents();
45 chrome::ExecuteCommand(browser(), IDC_PRINT
);
47 nav_observer
.StopWatchingNewWebContents();
51 IN_PROC_BROWSER_TEST_F(PrintPreviewTest
, PrintCommands
) {
52 // We start off at about:blank page.
53 // Make sure there is 1 tab and print is enabled.
54 ASSERT_EQ(1, browser()->tab_strip_model()->count());
56 ASSERT_TRUE(chrome::IsCommandEnabled(browser(), IDC_PRINT
));
58 #if defined(ENABLE_BASIC_PRINTING)
59 bool is_basic_print_expected
= true;
61 bool is_basic_print_expected
= false;
62 #endif // ENABLE_BASIC_PRINTING
64 ASSERT_EQ(is_basic_print_expected
,
65 chrome::IsCommandEnabled(browser(), IDC_BASIC_PRINT
));
67 // Create the print preview dialog.
70 ASSERT_FALSE(chrome::IsCommandEnabled(browser(), IDC_PRINT
));
72 ASSERT_EQ(is_basic_print_expected
,
73 chrome::IsCommandEnabled(browser(), IDC_BASIC_PRINT
));
75 content::TestNavigationObserver
reload_observer(
76 browser()->tab_strip_model()->GetActiveWebContents());
77 chrome::Reload(browser(), CURRENT_TAB
);
78 reload_observer
.Wait();
80 ASSERT_TRUE(chrome::IsCommandEnabled(browser(), IDC_PRINT
));
82 ASSERT_EQ(is_basic_print_expected
,
83 chrome::IsCommandEnabled(browser(), IDC_BASIC_PRINT
));
86 // Disable the test for mac, see http://crbug/367665.
87 #if (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_LINUX)
88 #define MAYBE_TaskManagerNewPrintPreview DISABLED_TaskManagerNewPrintPreview
90 #define MAYBE_TaskManagerNewPrintPreview TaskManagerNewPrintPreview
92 IN_PROC_BROWSER_TEST_F(PrintPreviewTest
, MAYBE_TaskManagerNewPrintPreview
) {
93 // This test is for the old implementation of the task manager. We must
94 // explicitly disable the new one.
95 task_manager::browsertest_util::EnableOldTaskManager();
97 chrome::ShowTaskManager(browser()); // Show task manager BEFORE print dialog.
99 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
100 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
101 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyPrint()));
103 // Create the print preview dialog.
106 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
107 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
108 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyPrint()));
109 ASSERT_NO_FATAL_FAILURE(
110 WaitForTaskManagerRows(1, MatchPrint(url::kAboutBlankURL
)));
113 // http://crbug/367665.
114 IN_PROC_BROWSER_TEST_F(PrintPreviewTest
,
115 DISABLED_TaskManagerExistingPrintPreview
) {
116 // This test is for the old implementation of the task manager. We must
117 // explicitly disable the new one.
118 task_manager::browsertest_util::EnableOldTaskManager();
120 // Create the print preview dialog.
123 chrome::ShowTaskManager(browser()); // Show task manager AFTER print dialog.
125 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
126 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
127 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyPrint()));
128 ASSERT_NO_FATAL_FAILURE(
129 WaitForTaskManagerRows(1, MatchPrint(url::kAboutBlankURL
)));
133 // http://crbug.com/396360
134 IN_PROC_BROWSER_TEST_F(PrintPreviewTest
, DISABLED_NoCrashOnCloseWithOtherTabs
) {
135 // Now print preview.
138 ui_test_utils::NavigateToURLWithDisposition(
139 browser(), GURL("about:blank"), NEW_FOREGROUND_TAB
,
140 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
142 browser()->tab_strip_model()->ActivateTabAt(0, true);
144 // Navigate main tab to hide print preview.
145 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
147 browser()->tab_strip_model()->ActivateTabAt(1, true);
149 #endif // defined(OS_WIN)