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" | |
9 #include "chrome/common/chrome_switches.h" | 8 #include "chrome/common/chrome_switches.h" |
10 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
11 #include "chrome/test/automation/browser_proxy.h" | 10 #include "chrome/test/automation/browser_proxy.h" |
12 #include "chrome/test/automation/tab_proxy.h" | 11 #include "chrome/test/automation/tab_proxy.h" |
13 #include "chrome/test/ui/ui_test.h" | 12 #include "chrome/test/ui/ui_test.h" |
14 | 13 |
15 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
16 | 15 |
17 namespace { | 16 namespace { |
18 | 17 |
19 class PrintPreviewUITest : public UITest { | 18 class PrintPreviewUITest : public UITest { |
20 public: | 19 public: |
21 PrintPreviewUITest() { | 20 PrintPreviewUITest() { |
22 dom_automation_enabled_ = true; | 21 dom_automation_enabled_ = true; |
23 // TODO(thestig): Remove when print preview is enabled by default. | 22 // TODO(thestig): Remove when print preview is enabled by default. |
24 launch_arguments_.AppendSwitch(switches::kEnablePrintPreview); | 23 launch_arguments_.AppendSwitch(switches::kEnablePrintPreview); |
25 } | 24 } |
26 | 25 |
27 void AssertIsPrintPage(TabProxy* tab) { | 26 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 | |
36 std::wstring title; | 27 std::wstring title; |
37 ASSERT_TRUE(tab->GetTabTitle(&title)); | 28 ASSERT_TRUE(tab->GetTabTitle(&title)); |
38 string16 expected_title = | 29 string16 expected_title = |
39 l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_TITLE); | 30 l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_TITLE); |
40 ASSERT_EQ(expected_title, WideToUTF16Hack(title)); | 31 ASSERT_EQ(expected_title, WideToUTF16Hack(title)); |
41 } | 32 } |
42 }; | 33 }; |
43 | 34 |
44 // TODO(thestig) Remove this test in the future if loading | 35 // TODO(thestig) Remove this test in the future if loading |
45 // chrome::kChromeUIPrintURL directly does not make sense. | 36 // chrome::kChromeUIPrintURL directly does not make sense. |
46 TEST_F(PrintPreviewUITest, LoadPrintPreviewByURL) { | 37 TEST_F(PrintPreviewUITest, LoadPrintPreviewByURL) { |
47 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 38 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
48 ASSERT_TRUE(browser.get()); | 39 ASSERT_TRUE(browser.get()); |
49 | 40 |
50 scoped_refptr<TabProxy> tab = browser->GetActiveTab(); | 41 scoped_refptr<TabProxy> tab = browser->GetActiveTab(); |
51 ASSERT_TRUE(tab.get()); | 42 ASSERT_TRUE(tab.get()); |
52 | 43 |
53 // Go to the print preview tab via URL. | 44 // Go to the print preview tab via URL. |
54 NavigateToURL(GURL(chrome::kChromeUIPrintURL)); | 45 NavigateToURL(GURL(chrome::kChromeUIPrintURL)); |
55 AssertIsPrintPage(tab); | 46 AssertIsPrintPage(tab); |
56 } | 47 } |
57 | 48 |
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 | |
83 } // namespace | 49 } // namespace |
OLD | NEW |