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

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

Issue 925783002: Split ValueSerializer into separate Serializer and Deserializer classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed cpplint warnings. Created 5 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
« no previous file with comments | « chrome/browser/ui/webui/nacl_ui.cc ('k') | chrome/common/extensions/extension_test_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 ++(*call_count); 158 ++(*call_count);
159 *success_out = success; 159 *success_out = success;
160 *status_out = status; 160 *status_out = status;
161 } 161 }
162 162
163 // Converts JSON string to base::ListValue object. 163 // Converts JSON string to base::ListValue object.
164 // On failure, returns NULL and fills |*error| string. 164 // On failure, returns NULL and fills |*error| string.
165 scoped_ptr<base::ListValue> GetJSONAsListValue(const std::string& json, 165 scoped_ptr<base::ListValue> GetJSONAsListValue(const std::string& json,
166 std::string* error) { 166 std::string* error) {
167 scoped_ptr<base::Value> deserialized( 167 scoped_ptr<base::Value> deserialized(
168 JSONStringValueSerializer(json).Deserialize(NULL, error)); 168 JSONStringValueDeserializer(json).Deserialize(NULL, error));
169 if (!deserialized) 169 if (!deserialized)
170 return scoped_ptr<base::ListValue>(); 170 return scoped_ptr<base::ListValue>();
171 base::ListValue* list = nullptr; 171 base::ListValue* list = nullptr;
172 if (!deserialized->GetAsList(&list)) { 172 if (!deserialized->GetAsList(&list)) {
173 *error = "Value is not a list."; 173 *error = "Value is not a list.";
174 return scoped_ptr<base::ListValue>(); 174 return scoped_ptr<base::ListValue>();
175 } 175 }
176 return scoped_ptr<base::ListValue>(list->DeepCopy()); 176 return scoped_ptr<base::ListValue>(list->DeepCopy());
177 } 177 }
178 178
179 // Converts JSON string to base::DictionaryValue object. 179 // Converts JSON string to base::DictionaryValue object.
180 // On failure, returns NULL and fills |*error| string. 180 // On failure, returns NULL and fills |*error| string.
181 scoped_ptr<base::DictionaryValue> GetJSONAsDictionaryValue( 181 scoped_ptr<base::DictionaryValue> GetJSONAsDictionaryValue(
182 const std::string& json, 182 const std::string& json,
183 std::string* error) { 183 std::string* error) {
184 scoped_ptr<base::Value> deserialized( 184 scoped_ptr<base::Value> deserialized(
185 JSONStringValueSerializer(json).Deserialize(NULL, error)); 185 JSONStringValueDeserializer(json).Deserialize(NULL, error));
186 if (!deserialized) 186 if (!deserialized)
187 return scoped_ptr<base::DictionaryValue>(); 187 return scoped_ptr<base::DictionaryValue>();
188 base::DictionaryValue* dictionary; 188 base::DictionaryValue* dictionary;
189 if (!deserialized->GetAsDictionary(&dictionary)) { 189 if (!deserialized->GetAsDictionary(&dictionary)) {
190 *error = "Value is not a dictionary."; 190 *error = "Value is not a dictionary.";
191 return scoped_ptr<base::DictionaryValue>(); 191 return scoped_ptr<base::DictionaryValue>();
192 } 192 }
193 return scoped_ptr<base::DictionaryValue>(dictionary->DeepCopy()); 193 return scoped_ptr<base::DictionaryValue>(dictionary->DeepCopy());
194 } 194 }
195 195
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 extension_printer_handler_->StartPrint( 762 extension_printer_handler_->StartPrint(
763 kPrinterId, kPWGRasterOnlyPrinterSimpleDescription, kEmptyPrintTicket, 763 kPrinterId, kPWGRasterOnlyPrinterSimpleDescription, kEmptyPrintTicket,
764 gfx::Size(100, 100), print_data, 764 gfx::Size(100, 100), print_data,
765 base::Bind(&RecordPrintResult, &call_count, &success, &status)); 765 base::Bind(&RecordPrintResult, &call_count, &success, &status));
766 766
767 EXPECT_EQ(1u, call_count); 767 EXPECT_EQ(1u, call_count);
768 768
769 EXPECT_FALSE(success); 769 EXPECT_FALSE(success);
770 EXPECT_EQ("INVALID_DATA", status); 770 EXPECT_EQ("INVALID_DATA", status);
771 } 771 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/nacl_ui.cc ('k') | chrome/common/extensions/extension_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698