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

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

Issue 9590002: JSONWriter cleanup: integrate pretty print into write options. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix merge conflict 7. Created 8 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/json/json_writer.h" 5 #include "base/json/json_writer.h"
6 #include "base/values.h" 6 #include "base/values.h"
7 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/printing/background_printing_manager.h" 8 #include "chrome/browser/printing/background_printing_manager.h"
9 #include "chrome/browser/printing/print_preview_tab_controller.h" 9 #include "chrome/browser/printing/print_preview_tab_controller.h"
10 #include "chrome/browser/printing/print_preview_unit_test_base.h" 10 #include "chrome/browser/printing/print_preview_unit_test_base.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 // Set the minimal dummy settings to make the HandlePrint() code happy. 123 // Set the minimal dummy settings to make the HandlePrint() code happy.
124 DictionaryValue settings; 124 DictionaryValue settings;
125 settings.SetBoolean(printing::kSettingPreviewModifiable, true); 125 settings.SetBoolean(printing::kSettingPreviewModifiable, true);
126 settings.SetInteger(printing::kSettingColor, printing::COLOR); 126 settings.SetInteger(printing::kSettingColor, printing::COLOR);
127 settings.SetBoolean(printing::kSettingPrintToPDF, false); 127 settings.SetBoolean(printing::kSettingPrintToPDF, false);
128 settings.SetInteger(printing::kSettingMarginsType, 128 settings.SetInteger(printing::kSettingMarginsType,
129 printing::DEFAULT_MARGINS); 129 printing::DEFAULT_MARGINS);
130 130
131 // Put |settings| in to |args| as a JSON string. 131 // Put |settings| in to |args| as a JSON string.
132 std::string json_string; 132 std::string json_string;
133 base::JSONWriter::Write(&settings, false, &json_string); 133 base::JSONWriter::Write(&settings, &json_string);
134 ListValue args; 134 ListValue args;
135 args.Append(new base::StringValue(json_string)); // |args| takes ownership. 135 args.Append(new base::StringValue(json_string)); // |args| takes ownership.
136 preview_ui_->handler_->HandlePrint(&args); 136 preview_ui_->handler_->HandlePrint(&args);
137 } 137 }
138 138
139 void RequestPrintWithCustomMargins( 139 void RequestPrintWithCustomMargins(
140 const double margin_top, const double margin_right, 140 const double margin_top, const double margin_right,
141 const double margin_bottom, const double margin_left) { 141 const double margin_bottom, const double margin_left) {
142 // Set the minimal dummy settings to make the HandlePrint() code happy. 142 // Set the minimal dummy settings to make the HandlePrint() code happy.
143 DictionaryValue settings; 143 DictionaryValue settings;
144 settings.SetBoolean(printing::kSettingPreviewModifiable, true); 144 settings.SetBoolean(printing::kSettingPreviewModifiable, true);
145 settings.SetInteger(printing::kSettingColor, printing::COLOR); 145 settings.SetInteger(printing::kSettingColor, printing::COLOR);
146 settings.SetBoolean(printing::kSettingPrintToPDF, false); 146 settings.SetBoolean(printing::kSettingPrintToPDF, false);
147 settings.SetInteger(printing::kSettingMarginsType, 147 settings.SetInteger(printing::kSettingMarginsType,
148 printing::CUSTOM_MARGINS); 148 printing::CUSTOM_MARGINS);
149 149
150 // Creating custom margins dictionary and nesting it in |settings|. 150 // Creating custom margins dictionary and nesting it in |settings|.
151 DictionaryValue* custom_settings = GetCustomMarginsDictionary( 151 DictionaryValue* custom_settings = GetCustomMarginsDictionary(
152 margin_top, margin_right, margin_bottom, margin_left); 152 margin_top, margin_right, margin_bottom, margin_left);
153 // |settings| takes ownership. 153 // |settings| takes ownership.
154 settings.Set(printing::kSettingMarginsCustom, custom_settings); 154 settings.Set(printing::kSettingMarginsCustom, custom_settings);
155 155
156 // Put |settings| in to |args| as a JSON string. 156 // Put |settings| in to |args| as a JSON string.
157 std::string json_string; 157 std::string json_string;
158 base::JSONWriter::Write(&settings, false, &json_string); 158 base::JSONWriter::Write(&settings, &json_string);
159 ListValue args; 159 ListValue args;
160 args.Append(new base::StringValue(json_string)); // |args| takes ownership. 160 args.Append(new base::StringValue(json_string)); // |args| takes ownership.
161 preview_ui_->handler_->HandlePrint(&args); 161 preview_ui_->handler_->HandlePrint(&args);
162 } 162 }
163 163
164 PrintPreviewUI* preview_ui_; 164 PrintPreviewUI* preview_ui_;
165 165
166 private: 166 private:
167 void ClearStickySettings() { 167 void ClearStickySettings() {
168 PrintPreviewHandler::GetStickySettings()->margins_type_ = 168 PrintPreviewHandler::GetStickySettings()->margins_type_ =
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 double margin_value; 267 double margin_value;
268 EXPECT_FALSE(initial_settings.GetDouble(printing::kSettingMarginTop, 268 EXPECT_FALSE(initial_settings.GetDouble(printing::kSettingMarginTop,
269 &margin_value)); 269 &margin_value));
270 EXPECT_FALSE(initial_settings.GetDouble(printing::kSettingMarginRight, 270 EXPECT_FALSE(initial_settings.GetDouble(printing::kSettingMarginRight,
271 &margin_value)); 271 &margin_value));
272 EXPECT_FALSE(initial_settings.GetDouble(printing::kSettingMarginBottom, 272 EXPECT_FALSE(initial_settings.GetDouble(printing::kSettingMarginBottom,
273 &margin_value)); 273 &margin_value));
274 EXPECT_FALSE(initial_settings.GetDouble(printing::kSettingMarginLeft, 274 EXPECT_FALSE(initial_settings.GetDouble(printing::kSettingMarginLeft,
275 &margin_value)); 275 &margin_value));
276 } 276 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/about_ui.cc ('k') | chrome/browser/ui/webui/tab_modal_confirm_dialog_webui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698