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

Side by Side Diff: chrome/browser/ui/webui/print_preview_handler_unittest.cc

Issue 8665006: Build & run unit tests on Aura. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years 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
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/json/json_writer.h" 6 #include "base/json/json_writer.h"
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/printing/background_printing_manager.h" 9 #include "chrome/browser/printing/background_printing_manager.h"
10 #include "chrome/browser/printing/print_preview_tab_controller.h" 10 #include "chrome/browser/printing/print_preview_tab_controller.h"
11 #include "chrome/browser/ui/browser_list.h" 11 #include "chrome/browser/ui/browser_list.h"
12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
13 #include "chrome/browser/ui/webui/print_preview_handler.h" 13 #include "chrome/browser/ui/webui/print_preview_handler.h"
14 #include "chrome/browser/ui/webui/print_preview_ui.h" 14 #include "chrome/browser/ui/webui/print_preview_ui.h"
15 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/test/base/browser_with_test_window_test.h" 16 #include "chrome/test/base/browser_with_test_window_test.h"
17 #include "printing/page_size_margins.h" 17 #include "printing/page_size_margins.h"
18 #include "printing/print_job_constants.h" 18 #include "printing/print_job_constants.h"
19 19
20 // Test crashes on Aura due to initiator tab's native view having no parent.
21 // http://crbug.com/104284
22 #if defined(USE_AURA)
23 #define MAYBE_StickyMarginsCustom DISABLED_StickyMarginsCustom
24 #define MAYBE_StickyMarginsDefault DISABLED_StickyMarginsDefault
25 #define MAYBE_StickyMarginsCustomThenDefault \
26 DISABLED_StickyMarginsCustomThenDefault
27 #define MAYBE_GetLastUsedMarginSettingsCustom \
28 DISABLED_GetLastUsedMarginSettingsCustom
29 #define MAYBE_GetLastUsedMarginSettingsDefault \
30 DISABLED_GetLastUsedMarginSettingsDefault
31 #else
32 #define MAYBE_StickyMarginsCustom StickyMarginsCustom
33 #define MAYBE_StickyMarginsDefault StickyMarginsDefault
34 #define MAYBE_StickyMarginsCustomThenDefault StickyMarginsCustomThenDefault
35 #define MAYBE_GetLastUsedMarginSettingsCustom GetLastUsedMarginSettingsCustom
36 #define MAYBE_GetLastUsedMarginSettingsDefault GetLastUsedMarginSettingsDefault
37 #endif
38
20 namespace { 39 namespace {
21 40
22 DictionaryValue* GetCustomMarginsDictionary( 41 DictionaryValue* GetCustomMarginsDictionary(
23 const double margin_top, const double margin_right, 42 const double margin_top, const double margin_right,
24 const double margin_bottom, const double margin_left) { 43 const double margin_bottom, const double margin_left) {
25 base::DictionaryValue* custom_settings = new base::DictionaryValue(); 44 base::DictionaryValue* custom_settings = new base::DictionaryValue();
26 custom_settings->SetDouble(printing::kSettingMarginTop, margin_top); 45 custom_settings->SetDouble(printing::kSettingMarginTop, margin_top);
27 custom_settings->SetDouble(printing::kSettingMarginRight, margin_right); 46 custom_settings->SetDouble(printing::kSettingMarginRight, margin_right);
28 custom_settings->SetDouble(printing::kSettingMarginBottom, margin_bottom); 47 custom_settings->SetDouble(printing::kSettingMarginBottom, margin_bottom);
29 custom_settings->SetDouble(printing::kSettingMarginLeft, margin_left); 48 custom_settings->SetDouble(printing::kSettingMarginLeft, margin_left);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 PrintPreviewUI* preview_ui_; 159 PrintPreviewUI* preview_ui_;
141 160
142 private: 161 private:
143 void ClearStickySettings() { 162 void ClearStickySettings() {
144 PrintPreviewHandler::last_used_margins_type_ = printing::DEFAULT_MARGINS; 163 PrintPreviewHandler::last_used_margins_type_ = printing::DEFAULT_MARGINS;
145 delete PrintPreviewHandler::last_used_page_size_margins_; 164 delete PrintPreviewHandler::last_used_page_size_margins_;
146 PrintPreviewHandler::last_used_page_size_margins_ = NULL; 165 PrintPreviewHandler::last_used_page_size_margins_ = NULL;
147 } 166 }
148 }; 167 };
149 168
150 // Test crashs on TouchUI due to initiator tab's native view having no parent.
151 // http://crbug.com/104284
152 #if defined(TOUCH_UI)
153 #define MAYBE_StickyMarginsCustom DISABLED_StickyMarginsCustom
154 #else
155 #define MAYBE_StickyMarginsCustom StickyMarginsCustom
156 #endif
157 // Tests that margin settings are saved correctly when printing with custom 169 // Tests that margin settings are saved correctly when printing with custom
158 // margins selected. 170 // margins selected.
159 TEST_F(PrintPreviewHandlerTest, MAYBE_StickyMarginsCustom) { 171 TEST_F(PrintPreviewHandlerTest, MAYBE_StickyMarginsCustom) {
160 const double kMarginTop = 25.5; 172 const double kMarginTop = 25.5;
161 const double kMarginRight = 26.5; 173 const double kMarginRight = 26.5;
162 const double kMarginBottom = 27.5; 174 const double kMarginBottom = 27.5;
163 const double kMarginLeft = 28.5; 175 const double kMarginLeft = 28.5;
164 RequestPrintWithCustomMargins( 176 RequestPrintWithCustomMargins(
165 kMarginTop, kMarginRight, kMarginBottom, kMarginLeft); 177 kMarginTop, kMarginRight, kMarginBottom, kMarginLeft);
166 EXPECT_EQ(1, browser()->tab_count()); 178 EXPECT_EQ(1, browser()->tab_count());
167 179
168 // Checking that sticky settings were saved correctly. 180 // Checking that sticky settings were saved correctly.
169 EXPECT_EQ(PrintPreviewHandler::last_used_color_model_, printing::COLOR); 181 EXPECT_EQ(PrintPreviewHandler::last_used_color_model_, printing::COLOR);
170 EXPECT_EQ(PrintPreviewHandler::last_used_margins_type_, 182 EXPECT_EQ(PrintPreviewHandler::last_used_margins_type_,
171 printing::CUSTOM_MARGINS); 183 printing::CUSTOM_MARGINS);
172 ASSERT_TRUE(PrintPreviewHandler::last_used_page_size_margins_); 184 ASSERT_TRUE(PrintPreviewHandler::last_used_page_size_margins_);
173 CheckCustomMargins(kMarginTop, kMarginRight, kMarginBottom, kMarginLeft); 185 CheckCustomMargins(kMarginTop, kMarginRight, kMarginBottom, kMarginLeft);
174 } 186 }
175 187
176 // http://crbug.com/104284
177 #if defined(TOUCH_UI)
178 #define MAYBE_StickyMarginsDefault DISABLED_StickyMarginsDefault
179 #else
180 #define MAYBE_StickyMarginsDefault StickyMarginsDefault
181 #endif
182 // Tests that margin settings are saved correctly when printing with default 188 // Tests that margin settings are saved correctly when printing with default
183 // margins selected. 189 // margins selected.
184 TEST_F(PrintPreviewHandlerTest, MAYBE_StickyMarginsDefault) { 190 TEST_F(PrintPreviewHandlerTest, MAYBE_StickyMarginsDefault) {
185 RequestPrintWithDefaultMargins(); 191 RequestPrintWithDefaultMargins();
186 EXPECT_EQ(1, browser()->tab_count()); 192 EXPECT_EQ(1, browser()->tab_count());
187 193
188 // Checking that sticky settings were saved correctly. 194 // Checking that sticky settings were saved correctly.
189 EXPECT_EQ(PrintPreviewHandler::last_used_color_model_, printing::COLOR); 195 EXPECT_EQ(PrintPreviewHandler::last_used_color_model_, printing::COLOR);
190 EXPECT_EQ(PrintPreviewHandler::last_used_margins_type_, 196 EXPECT_EQ(PrintPreviewHandler::last_used_margins_type_,
191 printing::DEFAULT_MARGINS); 197 printing::DEFAULT_MARGINS);
192 ASSERT_FALSE(PrintPreviewHandler::last_used_page_size_margins_); 198 ASSERT_FALSE(PrintPreviewHandler::last_used_page_size_margins_);
193 } 199 }
194 200
195 // http://crbug.com/104284
196 #if defined(TOUCH_UI)
197 #define MAYBE_StickyMarginsCustomThenDefault \
198 DISABLED_StickyMarginsCustomThenDefault
199 #else
200 #define MAYBE_StickyMarginsCustomThenDefault StickyMarginsCustomThenDefault
201 #endif
202 // Tests that margin settings are saved correctly when printing with custom 201 // Tests that margin settings are saved correctly when printing with custom
203 // margins selected and then again with default margins selected. 202 // margins selected and then again with default margins selected.
204 TEST_F(PrintPreviewHandlerTest, MAYBE_StickyMarginsCustomThenDefault) { 203 TEST_F(PrintPreviewHandlerTest, MAYBE_StickyMarginsCustomThenDefault) {
205 const double kMarginTop = 125.5; 204 const double kMarginTop = 125.5;
206 const double kMarginRight = 126.5; 205 const double kMarginRight = 126.5;
207 const double kMarginBottom = 127.5; 206 const double kMarginBottom = 127.5;
208 const double kMarginLeft = 128.5; 207 const double kMarginLeft = 128.5;
209 RequestPrintWithCustomMargins( 208 RequestPrintWithCustomMargins(
210 kMarginTop, kMarginRight, kMarginBottom, kMarginLeft); 209 kMarginTop, kMarginRight, kMarginBottom, kMarginLeft);
211 EXPECT_EQ(1, browser()->tab_count()); 210 EXPECT_EQ(1, browser()->tab_count());
212 DeletePrintPreviewTab(); 211 DeletePrintPreviewTab();
213 EXPECT_EQ(PrintPreviewHandler::last_used_margins_type_, 212 EXPECT_EQ(PrintPreviewHandler::last_used_margins_type_,
214 printing::CUSTOM_MARGINS); 213 printing::CUSTOM_MARGINS);
215 ASSERT_TRUE(PrintPreviewHandler::last_used_page_size_margins_); 214 ASSERT_TRUE(PrintPreviewHandler::last_used_page_size_margins_);
216 CheckCustomMargins(kMarginTop, kMarginRight, kMarginBottom, kMarginLeft); 215 CheckCustomMargins(kMarginTop, kMarginRight, kMarginBottom, kMarginLeft);
217 216
218 OpenPrintPreviewTab(); 217 OpenPrintPreviewTab();
219 RequestPrintWithDefaultMargins(); 218 RequestPrintWithDefaultMargins();
220 219
221 // Checking that sticky settings were saved correctly. 220 // Checking that sticky settings were saved correctly.
222 EXPECT_EQ(PrintPreviewHandler::last_used_color_model_, printing::COLOR); 221 EXPECT_EQ(PrintPreviewHandler::last_used_color_model_, printing::COLOR);
223 EXPECT_EQ(PrintPreviewHandler::last_used_margins_type_, 222 EXPECT_EQ(PrintPreviewHandler::last_used_margins_type_,
224 printing::DEFAULT_MARGINS); 223 printing::DEFAULT_MARGINS);
225 ASSERT_TRUE(PrintPreviewHandler::last_used_page_size_margins_); 224 ASSERT_TRUE(PrintPreviewHandler::last_used_page_size_margins_);
226 CheckCustomMargins(kMarginTop, kMarginRight, kMarginBottom, kMarginLeft); 225 CheckCustomMargins(kMarginTop, kMarginRight, kMarginBottom, kMarginLeft);
227 } 226 }
228 227
229 // http://crbug.com/104284
230 #if defined(TOUCH_UI)
231 #define MAYBE_GetLastUsedMarginSettingsCustom \
232 DISABLED_GetLastUsedMarginSettingsCustom
233 #else
234 #define MAYBE_GetLastUsedMarginSettingsCustom GetLastUsedMarginSettingsCustom
235 #endif
236 // Tests that margin settings are retrieved correctly after printing with custom 228 // Tests that margin settings are retrieved correctly after printing with custom
237 // margins. 229 // margins.
238 TEST_F(PrintPreviewHandlerTest, MAYBE_GetLastUsedMarginSettingsCustom) { 230 TEST_F(PrintPreviewHandlerTest, MAYBE_GetLastUsedMarginSettingsCustom) {
239 const double kMarginTop = 125.5; 231 const double kMarginTop = 125.5;
240 const double kMarginRight = 126.5; 232 const double kMarginRight = 126.5;
241 const double kMarginBottom = 127.5; 233 const double kMarginBottom = 127.5;
242 const double kMarginLeft = 128.5; 234 const double kMarginLeft = 128.5;
243 RequestPrintWithCustomMargins( 235 RequestPrintWithCustomMargins(
244 kMarginTop, kMarginRight, kMarginBottom, kMarginLeft); 236 kMarginTop, kMarginRight, kMarginBottom, kMarginLeft);
245 base::DictionaryValue initial_settings; 237 base::DictionaryValue initial_settings;
(...skipping 10 matching lines...) Expand all
256 &margin_value)); 248 &margin_value));
257 EXPECT_EQ(kMarginRight, margin_value); 249 EXPECT_EQ(kMarginRight, margin_value);
258 EXPECT_TRUE(initial_settings.GetDouble(printing::kSettingMarginBottom, 250 EXPECT_TRUE(initial_settings.GetDouble(printing::kSettingMarginBottom,
259 &margin_value)); 251 &margin_value));
260 EXPECT_EQ(kMarginBottom, margin_value); 252 EXPECT_EQ(kMarginBottom, margin_value);
261 EXPECT_TRUE(initial_settings.GetDouble(printing::kSettingMarginLeft, 253 EXPECT_TRUE(initial_settings.GetDouble(printing::kSettingMarginLeft,
262 &margin_value)); 254 &margin_value));
263 EXPECT_EQ(kMarginLeft, margin_value); 255 EXPECT_EQ(kMarginLeft, margin_value);
264 } 256 }
265 257
266 // http://crbug.com/104284
267 #if defined(TOUCH_UI)
268 #define MAYBE_GetLastUsedMarginSettingsDefault \
269 DISABLED_GetLastUsedMarginSettingsDefault
270 #else
271 #define MAYBE_GetLastUsedMarginSettingsDefault GetLastUsedMarginSettingsDefault
272 #endif
273 // Tests that margin settings are retrieved correctly after printing with 258 // Tests that margin settings are retrieved correctly after printing with
274 // default margins. 259 // default margins.
275 TEST_F(PrintPreviewHandlerTest, MAYBE_GetLastUsedMarginSettingsDefault) { 260 TEST_F(PrintPreviewHandlerTest, MAYBE_GetLastUsedMarginSettingsDefault) {
276 RequestPrintWithDefaultMargins(); 261 RequestPrintWithDefaultMargins();
277 base::DictionaryValue initial_settings; 262 base::DictionaryValue initial_settings;
278 preview_ui_->handler_->GetLastUsedMarginSettings(&initial_settings); 263 preview_ui_->handler_->GetLastUsedMarginSettings(&initial_settings);
279 int margins_type; 264 int margins_type;
280 EXPECT_TRUE(initial_settings.GetInteger(printing::kSettingMarginsType, 265 EXPECT_TRUE(initial_settings.GetInteger(printing::kSettingMarginsType,
281 &margins_type)); 266 &margins_type));
282 EXPECT_EQ(margins_type, printing::DEFAULT_MARGINS); 267 EXPECT_EQ(margins_type, printing::DEFAULT_MARGINS);
283 double margin_value; 268 double margin_value;
284 EXPECT_FALSE(initial_settings.GetDouble(printing::kSettingMarginTop, 269 EXPECT_FALSE(initial_settings.GetDouble(printing::kSettingMarginTop,
285 &margin_value)); 270 &margin_value));
286 EXPECT_FALSE(initial_settings.GetDouble(printing::kSettingMarginRight, 271 EXPECT_FALSE(initial_settings.GetDouble(printing::kSettingMarginRight,
287 &margin_value)); 272 &margin_value));
288 EXPECT_FALSE(initial_settings.GetDouble(printing::kSettingMarginBottom, 273 EXPECT_FALSE(initial_settings.GetDouble(printing::kSettingMarginBottom,
289 &margin_value)); 274 &margin_value));
290 EXPECT_FALSE(initial_settings.GetDouble(printing::kSettingMarginLeft, 275 EXPECT_FALSE(initial_settings.GetDouble(printing::kSettingMarginLeft,
291 &margin_value)); 276 &margin_value));
292 } 277 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/select_file_dialog_unittest.cc ('k') | chrome/browser/ui/webui/print_preview_ui_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698