Home | History | Annotate | Download | only in print_preview
      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.
      4 
      5 #include "base/command_line.h"
      6 #include "chrome/app/chrome_command_ids.h"
      7 #include "chrome/browser/ui/browser.h"
      8 #include "chrome/browser/ui/browser_commands.h"
      9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
     10 #include "chrome/common/chrome_switches.h"
     11 #include "chrome/common/url_constants.h"
     12 #include "chrome/test/base/in_process_browser_test.h"
     13 #include "content/public/browser/notification_service.h"
     14 #include "content/public/browser/notification_types.h"
     15 #include "content/public/test/test_navigation_observer.h"
     16 #include "content/public/test/test_utils.h"
     17 
     18 namespace {
     19 
     20 class PrintPreviewTest : public InProcessBrowserTest {
     21  public:
     22   PrintPreviewTest() {}
     23 
     24 #if !defined(GOOGLE_CHROME_BUILD)
     25   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
     26     command_line->AppendSwitch(switches::kEnablePrintPreview);
     27   }
     28 #endif
     29 
     30   void Print() {
     31     content::WindowedNotificationObserver observer(
     32         content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
     33         content::NotificationService::AllSources());
     34     chrome::ExecuteCommand(browser(), IDC_PRINT);
     35     observer.Wait();
     36   }
     37 };
     38 
     39 IN_PROC_BROWSER_TEST_F(PrintPreviewTest, PrintCommands) {
     40   // We start off at about:blank page.
     41   // Make sure there is 1 tab and print is enabled.
     42   ASSERT_EQ(1, browser()->tab_strip_model()->count());
     43 
     44   ASSERT_TRUE(chrome::IsCommandEnabled(browser(), IDC_PRINT));
     45 
     46   // Make sure advanced print command (Ctrl+Shift+p) is enabled.
     47   ASSERT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ADVANCED_PRINT));
     48 
     49   // Create the print preview dialog.
     50   Print();
     51 
     52   // Make sure print is disabled.
     53   ASSERT_FALSE(chrome::IsCommandEnabled(browser(), IDC_PRINT));
     54 
     55   // Make sure advanced print command (Ctrl+Shift+p) is enabled.
     56   ASSERT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ADVANCED_PRINT));
     57 
     58   content::TestNavigationObserver reload_observer(
     59       browser()->tab_strip_model()->GetActiveWebContents());
     60   chrome::Reload(browser(), CURRENT_TAB);
     61   reload_observer.Wait();
     62 
     63   ASSERT_TRUE(chrome::IsCommandEnabled(browser(), IDC_PRINT));
     64 
     65   // Make sure advanced print command (Ctrl+Shift+p) is enabled.
     66   ASSERT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ADVANCED_PRINT));
     67 }
     68 
     69 }  // namespace
     70