| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/string16.h" | 5 #include "base/string16.h" |
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
| 8 #include "chrome/common/chrome_switches.h" | 8 #include "chrome/common/chrome_switches.h" |
| 9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
| 10 #include "chrome/test/automation/automation_proxy.h" | 10 #include "chrome/test/automation/automation_proxy.h" |
| 11 #include "chrome/test/automation/browser_proxy.h" | 11 #include "chrome/test/automation/browser_proxy.h" |
| 12 #include "chrome/test/automation/tab_proxy.h" | 12 #include "chrome/test/automation/tab_proxy.h" |
| 13 #include "chrome/test/ui/ui_test.h" | 13 #include "chrome/test/ui/ui_test.h" |
| 14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 class PrintPreviewUITest : public UITest { | 19 class PrintPreviewUITest : public UITest { |
| 20 public: | 20 public: |
| 21 PrintPreviewUITest() { | 21 PrintPreviewUITest() { |
| 22 dom_automation_enabled_ = true; | 22 dom_automation_enabled_ = true; |
| 23 launch_arguments_.AppendSwitch(switches::kEnablePrintPreview); | 23 launch_arguments_.AppendSwitch(switches::kEnablePrintPreview); |
| 24 } | 24 } |
| 25 |
| 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 } |
| 25 }; | 33 }; |
| 26 | 34 |
| 27 TEST_F(PrintPreviewUITest, PrintCommands) { | 35 // TODO(thestig) Remove this test in the future if loading |
| 36 // chrome::kChromeUIPrintURL directly does not make sense. |
| 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 |
| 49 TEST_F(PrintPreviewUITest, PrintCommandDisabled) { |
| 28 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 50 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 29 ASSERT_TRUE(browser.get()); | 51 ASSERT_TRUE(browser.get()); |
| 30 | 52 |
| 31 // Go to the about:blank page. | 53 // Go to the about:blank page. |
| 32 NavigateToURL(GURL(chrome::kAboutBlankURL)); | 54 NavigateToURL(GURL(chrome::kAboutBlankURL)); |
| 33 | 55 |
| 34 // Make sure there is 1 tab and print is enabled. | 56 // Make sure there is 1 tab and print is enabled. Create print preview tab. |
| 35 int tab_count; | 57 int tab_count; |
| 36 ASSERT_TRUE(browser->GetTabCount(&tab_count)); | 58 ASSERT_TRUE(browser->GetTabCount(&tab_count)); |
| 37 ASSERT_EQ(1, 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)); |
| 38 | 64 |
| 39 bool enabled = false; | 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 TEST_F(PrintPreviewUITest, AdvancedPrintCommandEnabled) { |
| 76 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 77 ASSERT_TRUE(browser.get()); |
| 78 |
| 79 // Go to the about:blank page. |
| 80 NavigateToURL(GURL(chrome::kAboutBlankURL)); |
| 81 |
| 82 // Make sure there is 1 tab and print is enabled. Create print preview tab. |
| 83 int tab_count; |
| 84 ASSERT_TRUE(browser->GetTabCount(&tab_count)); |
| 85 ASSERT_EQ(1, tab_count); |
| 86 bool enabled; |
| 40 ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_PRINT, &enabled)); | 87 ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_PRINT, &enabled)); |
| 41 ASSERT_TRUE(enabled); | 88 ASSERT_TRUE(enabled); |
| 42 | 89 |
| 43 // Make sure advanced print command (Ctrl+Shift+p) is enabled. | 90 // Make sure advanced print command (Ctrl+Shift+p) is enabled. |
| 44 enabled = false; | 91 enabled = false; |
| 45 ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_ADVANCED_PRINT, &enabled)); | 92 ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_ADVANCED_PRINT, &enabled)); |
| 46 ASSERT_TRUE(enabled); | 93 ASSERT_TRUE(enabled); |
| 47 | 94 |
| 48 // Create print preview tab. | |
| 49 ASSERT_TRUE(browser->RunCommand(IDC_PRINT)); | 95 ASSERT_TRUE(browser->RunCommand(IDC_PRINT)); |
| 50 | 96 |
| 51 // Make sure print is disabled. | 97 // Make sure there are 2 tabs and print is disabled. |
| 98 ASSERT_TRUE(browser->GetTabCount(&tab_count)); |
| 99 ASSERT_EQ(2, tab_count); |
| 100 scoped_refptr<TabProxy> tab = browser->GetActiveTab(); |
| 101 ASSERT_TRUE(tab.get()); |
| 102 AssertIsPrintPage(tab); |
| 52 ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_PRINT, &enabled)); | 103 ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_PRINT, &enabled)); |
| 53 ASSERT_FALSE(enabled); | 104 ASSERT_FALSE(enabled); |
| 54 | 105 |
| 55 // Make sure advanced print command (Ctrl+Shift+p) is enabled. | 106 // Make sure advanced print command (Ctrl+Shift+p) is enabled on preview tab. |
| 56 enabled = false; | 107 enabled = false; |
| 57 ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_ADVANCED_PRINT, &enabled)); | 108 ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_ADVANCED_PRINT, &enabled)); |
| 58 ASSERT_TRUE(enabled); | 109 ASSERT_TRUE(enabled); |
| 59 | |
| 60 ASSERT_TRUE(browser->RunCommand(IDC_RELOAD)); | |
| 61 | |
| 62 enabled = false; | |
| 63 ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_PRINT, &enabled)); | |
| 64 ASSERT_TRUE(enabled); | |
| 65 | |
| 66 // Make sure advanced print command (Ctrl+Shift+p) is enabled. | |
| 67 enabled = false; | |
| 68 ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_ADVANCED_PRINT, &enabled)); | |
| 69 ASSERT_TRUE(enabled); | |
| 70 } | 110 } |
| 71 | 111 |
| 72 } // namespace | 112 } // namespace |
| OLD | NEW |