| 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 } | |
| 33 }; | 25 }; |
| 34 | 26 |
| 35 // TODO(thestig) Remove this test in the future if loading | 27 TEST_F(PrintPreviewUITest, PrintCommands) { |
| 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) { | |
| 50 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 28 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 51 ASSERT_TRUE(browser.get()); | 29 ASSERT_TRUE(browser.get()); |
| 52 | 30 |
| 53 // Go to the about:blank page. | 31 // Go to the about:blank page. |
| 54 NavigateToURL(GURL(chrome::kAboutBlankURL)); | 32 NavigateToURL(GURL(chrome::kAboutBlankURL)); |
| 55 | 33 |
| 56 // Make sure there is 1 tab and print is enabled. Create print preview tab. | 34 // Make sure there is 1 tab and print is enabled. |
| 57 int tab_count; | 35 int tab_count; |
| 58 ASSERT_TRUE(browser->GetTabCount(&tab_count)); | 36 ASSERT_TRUE(browser->GetTabCount(&tab_count)); |
| 59 ASSERT_EQ(1, tab_count); | 37 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 | 38 |
| 65 // Make sure there are 2 tabs and print is disabled. | 39 bool enabled = false; |
| 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; | |
| 87 ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_PRINT, &enabled)); | 40 ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_PRINT, &enabled)); |
| 88 ASSERT_TRUE(enabled); | 41 ASSERT_TRUE(enabled); |
| 89 | 42 |
| 90 // Make sure advanced print command (Ctrl+Shift+p) is enabled. | 43 // Make sure advanced print command (Ctrl+Shift+p) is enabled. |
| 91 enabled = false; | 44 enabled = false; |
| 92 ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_ADVANCED_PRINT, &enabled)); | 45 ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_ADVANCED_PRINT, &enabled)); |
| 93 ASSERT_TRUE(enabled); | 46 ASSERT_TRUE(enabled); |
| 94 | 47 |
| 48 // Create print preview tab. |
| 95 ASSERT_TRUE(browser->RunCommand(IDC_PRINT)); | 49 ASSERT_TRUE(browser->RunCommand(IDC_PRINT)); |
| 96 | 50 |
| 97 // Make sure there are 2 tabs and print is disabled. | 51 // Make sure 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); | |
| 103 ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_PRINT, &enabled)); | 52 ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_PRINT, &enabled)); |
| 104 ASSERT_FALSE(enabled); | 53 ASSERT_FALSE(enabled); |
| 105 | 54 |
| 106 // Make sure advanced print command (Ctrl+Shift+p) is enabled on preview tab. | 55 // Make sure advanced print command (Ctrl+Shift+p) is enabled. |
| 107 enabled = false; | 56 enabled = false; |
| 108 ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_ADVANCED_PRINT, &enabled)); | 57 ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_ADVANCED_PRINT, &enabled)); |
| 109 ASSERT_TRUE(enabled); | 58 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); |
| 110 } | 70 } |
| 111 | 71 |
| 112 } // namespace | 72 } // namespace |
| OLD | NEW |