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