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 chrome::ShowTaskManager(browser()); // Show task manager BEFORE print dialog.
95 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
96 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
97 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyPrint()));
99 // Create the print preview dialog.
102 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
103 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
104 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyPrint()));
105 ASSERT_NO_FATAL_FAILURE(
106 WaitForTaskManagerRows(1, MatchPrint(url::kAboutBlankURL
)));
109 // http://crbug/367665.
110 IN_PROC_BROWSER_TEST_F(PrintPreviewTest
,
111 DISABLED_TaskManagerExistingPrintPreview
) {
112 // Create the print preview dialog.
115 chrome::ShowTaskManager(browser()); // Show task manager AFTER print dialog.
117 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
118 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
119 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyPrint()));
120 ASSERT_NO_FATAL_FAILURE(
121 WaitForTaskManagerRows(1, MatchPrint(url::kAboutBlankURL
)));
125 // http://crbug.com/396360
126 IN_PROC_BROWSER_TEST_F(PrintPreviewTest
, DISABLED_NoCrashOnCloseWithOtherTabs
) {
127 // Now print preview.
130 ui_test_utils::NavigateToURLWithDisposition(
131 browser(), GURL("about:blank"), NEW_FOREGROUND_TAB
,
132 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
134 browser()->tab_strip_model()->ActivateTabAt(0, true);
136 // Navigate main tab to hide print preview.
137 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
139 browser()->tab_strip_model()->ActivateTabAt(1, true);
141 #endif // defined(OS_WIN)