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

Side by Side Diff: chrome/browser/printing/printing_layout_uitest.cc

Issue 1547003: [GTTF] Miscellanous UI tests cleanups: (Closed)
Patch Set: updated Created 10 years, 8 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
OLDNEW
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/simple_thread.h" 7 #include "base/simple_thread.h"
8 #include "base/test/test_file_util.h"
8 #include "base/win_util.h" 9 #include "base/win_util.h"
9 #include "chrome/common/chrome_paths.h" 10 #include "chrome/common/chrome_paths.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/automation/window_proxy.h" 13 #include "chrome/test/automation/window_proxy.h"
13 #include "chrome/test/ui/ui_test.h" 14 #include "chrome/test/ui/ui_test.h"
14 #include "gfx/gdi_util.h" 15 #include "gfx/gdi_util.h"
15 #include "net/url_request/url_request_unittest.h" 16 #include "net/url_request/url_request_unittest.h"
16 #include "printing/image.h" 17 #include "printing/image.h"
17 #include "printing/printing_test.h" 18 #include "printing/printing_test.h"
(...skipping 24 matching lines...) Expand all
42 43
43 virtual void TearDown() { 44 virtual void TearDown() {
44 UITest::TearDown(); 45 UITest::TearDown();
45 file_util::Delete(emf_path_, true); 46 file_util::Delete(emf_path_, true);
46 } 47 }
47 48
48 protected: 49 protected:
49 void PrintNowTab() { 50 void PrintNowTab() {
50 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); 51 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
51 ASSERT_TRUE(tab_proxy.get()); 52 ASSERT_TRUE(tab_proxy.get());
52 if (!tab_proxy.get())
53 return;
54
55 ASSERT_TRUE(tab_proxy->PrintNow()); 53 ASSERT_TRUE(tab_proxy->PrintNow());
56 } 54 }
57 55
58 // Finds the dump for the last print job and compares it to the data named 56 // Finds the dump for the last print job and compares it to the data named
59 // |verification_name|. Compares the saved printed job pixels with the test 57 // |verification_name|. Compares the saved printed job pixels with the test
60 // data pixels and returns the percentage of different pixels; 0 for success, 58 // data pixels and returns the percentage of different pixels; 0 for success,
61 // ]0, 100] for failure. 59 // [0, 100] for failure.
62 double CompareWithResult(const std::wstring& verification_name) { 60 double CompareWithResult(const std::wstring& verification_name) {
63 FilePath test_result(ScanFiles(verification_name)); 61 FilePath test_result(ScanFiles(verification_name));
64 if (test_result.value().empty()) { 62 if (test_result.value().empty()) {
65 // 100% different, the print job buffer is not there. 63 // 100% different, the print job buffer is not there.
66 return 100.; 64 return 100.;
67 } 65 }
68 66
69 std::wstring verification_file(test_data_directory_.ToWStringHack()); 67 std::wstring verification_file(test_data_directory_.ToWStringHack());
70 file_util::AppendToPath(&verification_file, L"printing"); 68 file_util::AppendToPath(&verification_file, L"printing");
71 file_util::AppendToPath(&verification_file, verification_name); 69 file_util::AppendToPath(&verification_file, verification_name);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 if (diff_png) { 109 if (diff_png) {
112 // Backup the rendered emf file to detect the rendering difference. 110 // Backup the rendered emf file to detect the rendering difference.
113 emf_content.SaveToPng(FilePath(verification_file + L"_rendering.png")); 111 emf_content.SaveToPng(FilePath(verification_file + L"_rendering.png"));
114 } 112 }
115 return std::max(diff_png, diff_emf); 113 return std::max(diff_png, diff_emf);
116 } 114 }
117 } 115 }
118 116
119 // Makes sure the directory exists and is empty. 117 // Makes sure the directory exists and is empty.
120 void CleanupDumpDirectory() { 118 void CleanupDumpDirectory() {
121 // Tries to delete the dumping directory for around 10 seconds. 119 EXPECT_TRUE(file_util::DieFileDie(emf_path(), true));
122 for (int i = 0; i < 100 && file_util::PathExists(emf_path()); ++i) { 120 EXPECT_TRUE(file_util::CreateDirectory(emf_path()));
123 // It's fine fail sometimes because of opened left over .PRN file.
124 // Explanation:
125 // When calling PrintNowTab(), it makes sure the page is rendered and
126 // sent to the spooler. It does *not* wait for the spooler to flush the
127 // job. It is completely unnecessary to wait for that. So the printer
128 // may write the file too late. Since the printer holds an exclusive
129 // access to the file, it can't be deleted until the printer is done.
130 if (file_util::Delete(emf_path(), true)) {
131 break;
132 }
133 PlatformThread::Sleep(100);
134 }
135 file_util::CreateDirectory(emf_path());
136 } 121 }
137 122
138 // Returns if Clear Type is currently enabled. 123 // Returns if Clear Type is currently enabled.
139 static bool IsClearTypeEnabled() { 124 static bool IsClearTypeEnabled() {
140 BOOL ct_enabled = 0; 125 BOOL ct_enabled = 0;
141 if (SystemParametersInfo(SPI_GETCLEARTYPE, 0, &ct_enabled, 0) && ct_enabled) 126 if (SystemParametersInfo(SPI_GETCLEARTYPE, 0, &ct_enabled, 0) && ct_enabled)
142 return true; 127 return true;
143 UINT smoothing = 0; 128 UINT smoothing = 0;
144 if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &smoothing, 0) && 129 if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &smoothing, 0) &&
145 smoothing == FE_FONTSMOOTHINGCLEARTYPE) 130 smoothing == FE_FONTSMOOTHINGCLEARTYPE)
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 429
445 // Force a navigation elsewhere to verify that it's fine with it. 430 // Force a navigation elsewhere to verify that it's fine with it.
446 url = server->TestServerPage("files/printing/test1.html"); 431 url = server->TestServerPage("files/printing/test1.html");
447 EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, 432 EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS,
448 tab_proxy->NavigateToURL(url)); 433 tab_proxy->NavigateToURL(url));
449 } 434 }
450 CloseBrowserAndServer(); 435 CloseBrowserAndServer();
451 436
452 EXPECT_EQ(0., CompareWithResult(L"iframe")) << L"iframe"; 437 EXPECT_EQ(0., CompareWithResult(L"iframe")) << L"iframe";
453 } 438 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_service_uitest.cc ('k') | chrome/browser/process_singleton_linux_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698