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