blob: 051d87d4297da9eae11c0d98087b8f750b0d9c24 [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/command_line.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
namespace {
class PrintPreviewTest : public InProcessBrowserTest {
public:
PrintPreviewTest() {}
#if !defined(GOOGLE_CHROME_BUILD)
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitch(switches::kEnablePrintPreview);
}
#endif
void Print() {
content::TestNavigationObserver nav_observer(NULL);
nav_observer.StartWatchingNewWebContents();
chrome::ExecuteCommand(browser(), IDC_PRINT);
nav_observer.Wait();
nav_observer.StopWatchingNewWebContents();
}
};
IN_PROC_BROWSER_TEST_F(PrintPreviewTest, PrintCommands) {
// We start off at about:blank page.
// Make sure there is 1 tab and print is enabled.
ASSERT_EQ(1, browser()->tab_strip_model()->count());
ASSERT_TRUE(chrome::IsCommandEnabled(browser(), IDC_PRINT));
// Make sure advanced print command (Ctrl+Shift+p) is enabled.
ASSERT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ADVANCED_PRINT));
// Create the print preview dialog.
Print();
// Make sure print is disabled.
ASSERT_FALSE(chrome::IsCommandEnabled(browser(), IDC_PRINT));
// Make sure advanced print command (Ctrl+Shift+p) is enabled.
ASSERT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ADVANCED_PRINT));
content::TestNavigationObserver reload_observer(
browser()->tab_strip_model()->GetActiveWebContents());
chrome::Reload(browser(), CURRENT_TAB);
reload_observer.Wait();
ASSERT_TRUE(chrome::IsCommandEnabled(browser(), IDC_PRINT));
// Make sure advanced print command (Ctrl+Shift+p) is enabled.
ASSERT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ADVANCED_PRINT));
}
} // namespace