OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/gfx/gdi_util.h" | 7 #include "base/gfx/gdi_util.h" |
8 #include "skia/ext/platform_device.h" | 8 #include "skia/ext/platform_device.h" |
9 #include "base/gfx/png_decoder.h" | 9 #include "base/gfx/png_decoder.h" |
10 #include "base/gfx/png_encoder.h" | 10 #include "base/gfx/png_encoder.h" |
11 #include "base/simple_thread.h" | 11 #include "base/simple_thread.h" |
12 #include "base/win_util.h" | 12 #include "base/win_util.h" |
13 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
14 #include "chrome/common/gfx/emf.h" | |
15 #include "chrome/test/automation/browser_proxy.h" | 14 #include "chrome/test/automation/browser_proxy.h" |
16 #include "chrome/test/automation/tab_proxy.h" | 15 #include "chrome/test/automation/tab_proxy.h" |
17 #include "chrome/test/automation/window_proxy.h" | 16 #include "chrome/test/automation/window_proxy.h" |
18 #include "chrome/test/ui/ui_test.h" | 17 #include "chrome/test/ui/ui_test.h" |
19 #include "chrome/browser/printing/printing_test.h" | 18 #include "chrome/browser/printing/printing_test.h" |
20 #include "net/url_request/url_request_unittest.h" | 19 #include "net/url_request/url_request_unittest.h" |
| 20 #include "printing/native_metafile.h" |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 const wchar_t* const kGenerateSwitch = L"print-layout-generate"; | 24 const wchar_t* const kGenerateSwitch = L"print-layout-generate"; |
25 const wchar_t kDocRoot[] = L"chrome/test/data"; | 25 const wchar_t kDocRoot[] = L"chrome/test/data"; |
26 | 26 |
27 // Lightweight raw-bitmap management. The image, once initialized, is immuable. | 27 // Lightweight raw-bitmap management. The image, once initialized, is immuable. |
28 // It is mainly used for comparison. | 28 // It is mainly used for comparison. |
29 class Image { | 29 class Image { |
30 public: | 30 public: |
31 // Creates the image from the given filename on disk. | 31 // Creates the image from the given filename on disk. |
32 Image(const std::wstring& filename) : ignore_alpha_(true) { | 32 Image(const std::wstring& filename) : ignore_alpha_(true) { |
33 std::string data; | 33 std::string data; |
34 file_util::ReadFileToString(filename, &data); | 34 file_util::ReadFileToString(filename, &data); |
35 EXPECT_TRUE(data.size()); | 35 EXPECT_TRUE(data.size()); |
36 std::wstring ext = file_util::GetFileExtensionFromPath(filename); | 36 std::wstring ext = file_util::GetFileExtensionFromPath(filename); |
37 if (LowerCaseEqualsASCII(ext, "png")) { | 37 if (LowerCaseEqualsASCII(ext, "png")) { |
38 LoadPng(data); | 38 LoadPng(data); |
39 } else if (LowerCaseEqualsASCII(ext, "emf")) { | 39 } else if (LowerCaseEqualsASCII(ext, "emf")) { |
40 LoadEmf(data); | 40 LoadMetafile(data); |
41 } else { | 41 } else { |
42 EXPECT_TRUE(false); | 42 EXPECT_TRUE(false); |
43 } | 43 } |
44 } | 44 } |
45 | 45 |
46 const gfx::Size& size() const { | 46 const gfx::Size& size() const { |
47 return size_; | 47 return size_; |
48 } | 48 } |
49 | 49 |
50 // Used to create the initial test files. | 50 // Used to create the initial test files. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 void LoadPng(const std::string& compressed) { | 142 void LoadPng(const std::string& compressed) { |
143 int w; | 143 int w; |
144 int h; | 144 int h; |
145 EXPECT_TRUE(PNGDecoder::Decode( | 145 EXPECT_TRUE(PNGDecoder::Decode( |
146 reinterpret_cast<const unsigned char*>(compressed.c_str()), | 146 reinterpret_cast<const unsigned char*>(compressed.c_str()), |
147 compressed.size(), PNGDecoder::FORMAT_BGRA, &data_, &w, &h)); | 147 compressed.size(), PNGDecoder::FORMAT_BGRA, &data_, &w, &h)); |
148 size_.SetSize(w, h); | 148 size_.SetSize(w, h); |
149 row_length_ = size_.width() * sizeof(uint32); | 149 row_length_ = size_.width() * sizeof(uint32); |
150 } | 150 } |
151 | 151 |
152 void LoadEmf(const std::string& data) { | 152 void LoadMetafile(const std::string& data) { |
153 ASSERT_FALSE(data.empty()); | 153 ASSERT_FALSE(data.empty()); |
154 gfx::Emf emf; | 154 printing::NativeMetafile metafile; |
155 emf.CreateFromData(data.data(), data.size()); | 155 metafile.CreateFromData(data.data(), data.size()); |
156 gfx::Rect rect(emf.GetBounds()); | 156 gfx::Rect rect(metafile.GetBounds()); |
157 // Create a temporary HDC and bitmap to retrieve the renderered data. | 157 // Create a temporary HDC and bitmap to retrieve the renderered data. |
158 HDC hdc = CreateCompatibleDC(NULL); | 158 HDC hdc = CreateCompatibleDC(NULL); |
159 BITMAPV4HEADER hdr; | 159 BITMAPV4HEADER hdr; |
160 EXPECT_FALSE(rect.x()); | 160 EXPECT_FALSE(rect.x()); |
161 EXPECT_FALSE(rect.y()); | 161 EXPECT_FALSE(rect.y()); |
162 EXPECT_NE(rect.width(), 0); | 162 EXPECT_NE(rect.width(), 0); |
163 EXPECT_NE(rect.height(), 0); | 163 EXPECT_NE(rect.height(), 0); |
164 size_ = rect.size(); | 164 size_ = rect.size(); |
165 gfx::CreateBitmapV4Header(rect.width(), rect.height(), &hdr); | 165 gfx::CreateBitmapV4Header(rect.width(), rect.height(), &hdr); |
166 void* bits; | 166 void* bits; |
167 HBITMAP bitmap = CreateDIBSection(hdc, | 167 HBITMAP bitmap = CreateDIBSection(hdc, |
168 reinterpret_cast<BITMAPINFO*>(&hdr), 0, | 168 reinterpret_cast<BITMAPINFO*>(&hdr), 0, |
169 &bits, NULL, 0); | 169 &bits, NULL, 0); |
170 EXPECT_TRUE(bitmap); | 170 EXPECT_TRUE(bitmap); |
171 EXPECT_TRUE(SelectObject(hdc, bitmap)); | 171 EXPECT_TRUE(SelectObject(hdc, bitmap)); |
172 skia::PlatformDevice::InitializeDC(hdc); | 172 skia::PlatformDevice::InitializeDC(hdc); |
173 EXPECT_TRUE(emf.Playback(hdc, NULL)); | 173 EXPECT_TRUE(metafile.Playback(hdc, NULL)); |
174 row_length_ = size_.width() * sizeof(uint32); | 174 row_length_ = size_.width() * sizeof(uint32); |
175 size_t bytes = row_length_ * size_.height(); | 175 size_t bytes = row_length_ * size_.height(); |
176 ASSERT_TRUE(bytes); | 176 ASSERT_TRUE(bytes); |
177 data_.resize(bytes); | 177 data_.resize(bytes); |
178 memcpy(&*data_.begin(), bits, bytes); | 178 memcpy(&*data_.begin(), bits, bytes); |
179 DeleteDC(hdc); | 179 DeleteDC(hdc); |
180 DeleteObject(bitmap); | 180 DeleteObject(bitmap); |
181 } | 181 } |
182 | 182 |
183 // Pixel dimensions of the image. | 183 // Pixel dimensions of the image. |
184 gfx::Size size_; | 184 gfx::Size size_; |
185 | 185 |
186 // Length of a line in bytes. | 186 // Length of a line in bytes. |
187 int row_length_; | 187 int row_length_; |
188 | 188 |
189 // Actual bitmap data in arrays of RGBAs (so when loaded as uint32, it's | 189 // Actual bitmap data in arrays of RGBAs (so when loaded as uint32, it's |
190 // 0xABGR). | 190 // 0xABGR). |
191 std::vector<unsigned char> data_; | 191 std::vector<unsigned char> data_; |
192 | 192 |
193 // Flag to signal if the comparison functions should ignore the alpha channel. | 193 // Flag to signal if the comparison functions should ignore the alpha channel. |
194 const bool ignore_alpha_; | 194 const bool ignore_alpha_; |
195 | 195 |
196 DISALLOW_EVIL_CONSTRUCTORS(Image); | 196 DISALLOW_EVIL_CONSTRUCTORS(Image); |
197 }; | 197 }; |
198 | 198 |
199 class PrintingLayoutTest : public PrintingTest<UITest> { | 199 class PrintingLayoutTest : public PrintingTest<UITest> { |
200 public: | 200 public: |
201 PrintingLayoutTest() { | 201 PrintingLayoutTest() { |
202 emf_path_ = browser_directory_.ToWStringHack(); | 202 emf_path_ = browser_directory_.ToWStringHack(); |
203 file_util::AppendToPath(&emf_path_, L"emf_dumps"); | 203 file_util::AppendToPath(&emf_path_, L"metafile_dumps"); |
204 launch_arguments_.AppendSwitchWithValue(L"debug-print", | 204 launch_arguments_.AppendSwitchWithValue(L"debug-print", |
205 L'"' + emf_path_ + L'"'); | 205 L'"' + emf_path_ + L'"'); |
206 show_window_ = true; | 206 show_window_ = true; |
207 } | 207 } |
208 | 208 |
209 virtual void SetUp() { | 209 virtual void SetUp() { |
210 // Make sure there is no left overs. | 210 // Make sure there is no left overs. |
211 CleanupDumpDirectory(); | 211 CleanupDumpDirectory(); |
212 UITest::SetUp(); | 212 UITest::SetUp(); |
213 } | 213 } |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 | 615 |
616 // Force a navigation elsewhere to verify that it's fine with it. | 616 // Force a navigation elsewhere to verify that it's fine with it. |
617 url = server->TestServerPage("files/printing/test1.html"); | 617 url = server->TestServerPage("files/printing/test1.html"); |
618 EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | 618 EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
619 tab_proxy->NavigateToURL(url)); | 619 tab_proxy->NavigateToURL(url)); |
620 } | 620 } |
621 CloseBrowserAndServer(); | 621 CloseBrowserAndServer(); |
622 | 622 |
623 EXPECT_EQ(0., CompareWithResult(L"iframe")) << L"iframe"; | 623 EXPECT_EQ(0., CompareWithResult(L"iframe")) << L"iframe"; |
624 } | 624 } |
OLD | NEW |