• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/string16.h"
6 #include "base/utf_string_conversions.h"
7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/common/chrome_switches.h"
9 #include "chrome/common/url_constants.h"
10 #include "chrome/test/automation/browser_proxy.h"
11 #include "chrome/test/automation/tab_proxy.h"
12 #include "chrome/test/ui/ui_test.h"
13 #include "grit/generated_resources.h"
14 #include "ui/base/l10n/l10n_util.h"
15 
16 namespace {
17 
18 class PrintPreviewUITest : public UITest {
19  public:
PrintPreviewUITest()20   PrintPreviewUITest() {
21     dom_automation_enabled_ = true;
22     // TODO(thestig): Remove when print preview is enabled by default.
23     launch_arguments_.AppendSwitch(switches::kEnablePrintPreview);
24   }
25 
AssertIsPrintPage(TabProxy * tab)26   void AssertIsPrintPage(TabProxy* tab) {
27     std::wstring title;
28     ASSERT_TRUE(tab->GetTabTitle(&title));
29     string16 expected_title =
30         l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_TITLE);
31     ASSERT_EQ(expected_title, WideToUTF16Hack(title));
32   }
33 };
34 
35 // TODO(thestig) Remove this test in the future if loading
36 // chrome::kChromeUIPrintURL directly does not make sense.
TEST_F(PrintPreviewUITest,LoadPrintPreviewByURL)37 TEST_F(PrintPreviewUITest, LoadPrintPreviewByURL) {
38   scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
39   ASSERT_TRUE(browser.get());
40 
41   scoped_refptr<TabProxy> tab = browser->GetActiveTab();
42   ASSERT_TRUE(tab.get());
43 
44   // Go to the print preview tab via URL.
45   NavigateToURL(GURL(chrome::kChromeUIPrintURL));
46   AssertIsPrintPage(tab);
47 }
48 
TEST_F(PrintPreviewUITest,PrintCommandDisabled)49 TEST_F(PrintPreviewUITest, PrintCommandDisabled) {
50   scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
51   ASSERT_TRUE(browser.get());
52 
53   // Go to the about:blank page.
54   NavigateToURL(GURL(chrome::kAboutBlankURL));
55 
56   // Make sure there is 1 tab and print is enabled. Create print preview tab.
57   int tab_count;
58   ASSERT_TRUE(browser->GetTabCount(&tab_count));
59   ASSERT_EQ(1, tab_count);
60   bool enabled;
61   ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_PRINT, &enabled));
62   ASSERT_TRUE(enabled);
63   ASSERT_TRUE(browser->RunCommand(IDC_PRINT));
64 
65   // Make sure there are 2 tabs and print is disabled.
66   ASSERT_TRUE(browser->GetTabCount(&tab_count));
67   ASSERT_EQ(2, tab_count);
68   scoped_refptr<TabProxy> tab = browser->GetActiveTab();
69   ASSERT_TRUE(tab.get());
70   AssertIsPrintPage(tab);
71   ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_PRINT, &enabled));
72   ASSERT_FALSE(enabled);
73 }
74 
75 }  // namespace
76