Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: printing/printing_context_win_unittest.cc

Issue 478183005: Added PrintingContext::Delegate to get parent view handle and application locale. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mon Aug 25 23:50:54 PDT 2014 Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « printing/printing_context_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 {
26 public: 27 public:
27 void PrintSettingsCallback(PrintingContext::Result result) { 28 void PrintSettingsCallback(PrintingContext::Result result) {
28 result_ = result; 29 result_ = result;
29 } 30 }
30 31
32 // PrintingContext::Delegate methods.
33 virtual gfx::NativeView GetParentView() OVERRIDE { return NULL; }
34 virtual std::string GetAppLocale() OVERRIDE { return std::string(); }
35
31 protected: 36 protected:
32 PrintingContext::Result result() const { return result_; } 37 PrintingContext::Result result() const { return result_; }
33 38
34 private: 39 private:
35 PrintingContext::Result result_; 40 PrintingContext::Result result_;
36 }; 41 };
37 42
38 class MockPrintingContextWin : public PrintingContextWin { 43 class MockPrintingContextWin : public PrintingContextWin {
39 public: 44 public:
40 MockPrintingContextWin() : PrintingContextWin("") {} 45 MockPrintingContextWin(Delegate* delegate) : PrintingContextWin(delegate) {}
41 46
42 protected: 47 protected:
43 // This is a fake PrintDlgEx implementation that sets the right fields in 48 // This is a fake PrintDlgEx implementation that sets the right fields in
44 // |lppd| to trigger a bug in older revisions of PrintingContext. 49 // |lppd| to trigger a bug in older revisions of PrintingContext.
45 HRESULT ShowPrintDialog(PRINTDLGEX* lppd) OVERRIDE { 50 HRESULT ShowPrintDialog(PRINTDLGEX* lppd) OVERRIDE {
46 // The interesting bits: 51 // The interesting bits:
47 // Pretend the user hit print 52 // Pretend the user hit print
48 lppd->dwResultAction = PD_RESULT_PRINT; 53 lppd->dwResultAction = PD_RESULT_PRINT;
49 54
50 // Pretend the page range is 1-5, but since lppd->Flags does not have 55 // 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
152 } 157 }
153 }; 158 };
154 159
155 TEST_F(PrintingContextTest, Base) { 160 TEST_F(PrintingContextTest, Base) {
156 if (IsTestCaseDisabled()) 161 if (IsTestCaseDisabled())
157 return; 162 return;
158 163
159 PrintSettings settings; 164 PrintSettings settings;
160 settings.set_device_name(GetDefaultPrinter()); 165 settings.set_device_name(GetDefaultPrinter());
161 // Initialize it. 166 // Initialize it.
162 scoped_ptr<PrintingContext> context(PrintingContext::Create(std::string())); 167 scoped_ptr<PrintingContext> context(PrintingContext::Create(this));
163 EXPECT_EQ(PrintingContext::OK, context->InitWithSettings(settings)); 168 EXPECT_EQ(PrintingContext::OK, context->InitWithSettings(settings));
164 169
165 // The print may lie to use and may not support world transformation. 170 // The print may lie to use and may not support world transformation.
166 // Verify right now. 171 // Verify right now.
167 XFORM random_matrix = { 1, 0.1f, 0, 1.5f, 0, 1 }; 172 XFORM random_matrix = { 1, 0.1f, 0, 1.5f, 0, 1 };
168 EXPECT_TRUE(SetWorldTransform(context->context(), &random_matrix)); 173 EXPECT_TRUE(SetWorldTransform(context->context(), &random_matrix));
169 EXPECT_TRUE(ModifyWorldTransform(context->context(), NULL, MWT_IDENTITY)); 174 EXPECT_TRUE(ModifyWorldTransform(context->context(), NULL, MWT_IDENTITY));
170 } 175 }
171 176
172 TEST_F(PrintingContextTest, PrintAll) { 177 TEST_F(PrintingContextTest, PrintAll) {
173 base::MessageLoop message_loop; 178 base::MessageLoop message_loop;
174 if (IsTestCaseDisabled()) 179 if (IsTestCaseDisabled())
175 return; 180 return;
176 181
177 MockPrintingContextWin context; 182 MockPrintingContextWin context(this);
178 context.AskUserForSettings( 183 context.AskUserForSettings(
179 NULL, 123, false, base::Bind(&PrintingContextTest::PrintSettingsCallback, 184 123,
180 base::Unretained(this))); 185 false,
186 base::Bind(&PrintingContextTest::PrintSettingsCallback,
187 base::Unretained(this)));
181 EXPECT_EQ(PrintingContext::OK, result()); 188 EXPECT_EQ(PrintingContext::OK, result());
182 PrintSettings settings = context.settings(); 189 PrintSettings settings = context.settings();
183 EXPECT_EQ(settings.ranges().size(), 0); 190 EXPECT_EQ(settings.ranges().size(), 0);
184 } 191 }
185 192
186 } // namespace printing 193 } // namespace printing
OLDNEW
« no previous file with comments | « printing/printing_context_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698