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 <ocidl.h> | 5 #include <ocidl.h> |
6 #include <commdlg.h> | 6 #include <commdlg.h> |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "printing/backend/printing_info_win.h" | 14 #include "printing/backend/printing_info_win.h" |
15 #include "printing/backend/win_helper.h" | 15 #include "printing/backend/win_helper.h" |
16 #include "printing/printing_test.h" | 16 #include "printing/printing_test.h" |
17 #include "printing/printing_context.h" | 17 #include "printing/printing_context.h" |
18 #include "printing/printing_context_win.h" | 18 #include "printing/printing_context_win.h" |
19 #include "printing/print_settings.h" | 19 #include "printing/print_settings.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 | 21 |
22 namespace printing { | 22 namespace printing { |
23 | 23 |
24 // This test is automatically disabled if no printer is available. | 24 // This test is automatically disabled if no printer is available. |
25 class PrintingContextTest : public PrintingTest<testing::Test>, | 25 class PrintingContextTest : public PrintingTest<testing::Test> { |
26 public PrintingContext::Delegate { | |
27 public: | 26 public: |
28 void PrintSettingsCallback(PrintingContext::Result result) { | 27 void PrintSettingsCallback(PrintingContext::Result result) { |
29 result_ = result; | 28 result_ = result; |
30 } | 29 } |
31 | 30 |
32 // PrintingContext::Delegate methods. | |
33 virtual gfx::NativeView GetParentView() OVERRIDE { return NULL; } | |
34 virtual std::string GetAppLocale() OVERRIDE { return std::string(); } | |
35 | |
36 protected: | 31 protected: |
37 PrintingContext::Result result() const { return result_; } | 32 PrintingContext::Result result() const { return result_; } |
38 | 33 |
39 private: | 34 private: |
40 PrintingContext::Result result_; | 35 PrintingContext::Result result_; |
41 }; | 36 }; |
42 | 37 |
43 class MockPrintingContextWin : public PrintingContextWin { | 38 class MockPrintingContextWin : public PrintingContextWin { |
44 public: | 39 public: |
45 MockPrintingContextWin(Delegate* delegate) : PrintingContextWin(delegate) {} | 40 MockPrintingContextWin() : PrintingContextWin("") {} |
46 | 41 |
47 protected: | 42 protected: |
48 // This is a fake PrintDlgEx implementation that sets the right fields in | 43 // This is a fake PrintDlgEx implementation that sets the right fields in |
49 // |lppd| to trigger a bug in older revisions of PrintingContext. | 44 // |lppd| to trigger a bug in older revisions of PrintingContext. |
50 HRESULT ShowPrintDialog(PRINTDLGEX* lppd) OVERRIDE { | 45 HRESULT ShowPrintDialog(PRINTDLGEX* lppd) OVERRIDE { |
51 // The interesting bits: | 46 // The interesting bits: |
52 // Pretend the user hit print | 47 // Pretend the user hit print |
53 lppd->dwResultAction = PD_RESULT_PRINT; | 48 lppd->dwResultAction = PD_RESULT_PRINT; |
54 | 49 |
55 // Pretend the page range is 1-5, but since lppd->Flags does not have | 50 // Pretend the page range is 1-5, but since lppd->Flags does not have |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 } | 152 } |
158 }; | 153 }; |
159 | 154 |
160 TEST_F(PrintingContextTest, Base) { | 155 TEST_F(PrintingContextTest, Base) { |
161 if (IsTestCaseDisabled()) | 156 if (IsTestCaseDisabled()) |
162 return; | 157 return; |
163 | 158 |
164 PrintSettings settings; | 159 PrintSettings settings; |
165 settings.set_device_name(GetDefaultPrinter()); | 160 settings.set_device_name(GetDefaultPrinter()); |
166 // Initialize it. | 161 // Initialize it. |
167 scoped_ptr<PrintingContext> context(PrintingContext::Create(this)); | 162 scoped_ptr<PrintingContext> context(PrintingContext::Create(std::string())); |
168 EXPECT_EQ(PrintingContext::OK, context->InitWithSettings(settings)); | 163 EXPECT_EQ(PrintingContext::OK, context->InitWithSettings(settings)); |
169 | 164 |
170 // The print may lie to use and may not support world transformation. | 165 // The print may lie to use and may not support world transformation. |
171 // Verify right now. | 166 // Verify right now. |
172 XFORM random_matrix = { 1, 0.1f, 0, 1.5f, 0, 1 }; | 167 XFORM random_matrix = { 1, 0.1f, 0, 1.5f, 0, 1 }; |
173 EXPECT_TRUE(SetWorldTransform(context->context(), &random_matrix)); | 168 EXPECT_TRUE(SetWorldTransform(context->context(), &random_matrix)); |
174 EXPECT_TRUE(ModifyWorldTransform(context->context(), NULL, MWT_IDENTITY)); | 169 EXPECT_TRUE(ModifyWorldTransform(context->context(), NULL, MWT_IDENTITY)); |
175 } | 170 } |
176 | 171 |
177 TEST_F(PrintingContextTest, PrintAll) { | 172 TEST_F(PrintingContextTest, PrintAll) { |
178 base::MessageLoop message_loop; | 173 base::MessageLoop message_loop; |
179 if (IsTestCaseDisabled()) | 174 if (IsTestCaseDisabled()) |
180 return; | 175 return; |
181 | 176 |
182 MockPrintingContextWin context(this); | 177 MockPrintingContextWin context; |
183 context.AskUserForSettings( | 178 context.AskUserForSettings( |
184 123, | 179 NULL, 123, false, base::Bind(&PrintingContextTest::PrintSettingsCallback, |
185 false, | 180 base::Unretained(this))); |
186 base::Bind(&PrintingContextTest::PrintSettingsCallback, | |
187 base::Unretained(this))); | |
188 EXPECT_EQ(PrintingContext::OK, result()); | 181 EXPECT_EQ(PrintingContext::OK, result()); |
189 PrintSettings settings = context.settings(); | 182 PrintSettings settings = context.settings(); |
190 EXPECT_EQ(settings.ranges().size(), 0); | 183 EXPECT_EQ(settings.ranges().size(), 0); |
191 } | 184 } |
192 | 185 |
193 } // namespace printing | 186 } // namespace printing |
OLD | NEW |