OLD | NEW |
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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/json/json_string_value_serializer.h" | 6 #include "base/json/json_string_value_serializer.h" |
7 #include "base/memory/ref_counted_memory.h" | 7 #include "base/memory/ref_counted_memory.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "extensions/browser/api/printer_provider/printer_provider_api.h" | 10 #include "extensions/browser/api/printer_provider/printer_provider_api.h" |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 // Validates that set of printers reported by test apps via | 205 // Validates that set of printers reported by test apps via |
206 // chrome.printerProvider.onGetPritersRequested is the same as the set of | 206 // chrome.printerProvider.onGetPritersRequested is the same as the set of |
207 // printers in |expected_printers|. |expected_printers| contains list of | 207 // printers in |expected_printers|. |expected_printers| contains list of |
208 // printer objects formatted as a JSON string. It is assumed that the values | 208 // printer objects formatted as a JSON string. It is assumed that the values |
209 // in |expoected_printers| are unique. | 209 // in |expoected_printers| are unique. |
210 void ValidatePrinterListValue( | 210 void ValidatePrinterListValue( |
211 const base::ListValue& printers, | 211 const base::ListValue& printers, |
212 const std::vector<std::string>& expected_printers) { | 212 const std::vector<std::string>& expected_printers) { |
213 ASSERT_EQ(expected_printers.size(), printers.GetSize()); | 213 ASSERT_EQ(expected_printers.size(), printers.GetSize()); |
214 for (size_t i = 0; i < expected_printers.size(); ++i) { | 214 for (size_t i = 0; i < expected_printers.size(); ++i) { |
215 JSONStringValueSerializer serializer(expected_printers[i]); | 215 JSONStringValueDeserializer deserializer(expected_printers[i]); |
216 int error_code; | 216 int error_code; |
217 scoped_ptr<base::Value> printer_value( | 217 scoped_ptr<base::Value> printer_value( |
218 serializer.Deserialize(&error_code, NULL)); | 218 deserializer.Deserialize(&error_code, NULL)); |
219 ASSERT_TRUE(printer_value) << "Failed to deserialize " | 219 ASSERT_TRUE(printer_value) << "Failed to deserialize " |
220 << expected_printers[i] << ": " | 220 << expected_printers[i] << ": " |
221 << "error code " << error_code; | 221 << "error code " << error_code; |
222 EXPECT_TRUE(printers.Find(*printer_value) != printers.end()) | 222 EXPECT_TRUE(printers.Find(*printer_value) != printers.end()) |
223 << "Unabe to find " << *printer_value << " in " << printers; | 223 << "Unabe to find " << *printer_value << " in " << printers; |
224 } | 224 } |
225 } | 225 } |
226 | 226 |
227 private: | 227 private: |
228 DISALLOW_COPY_AND_ASSIGN(PrinterProviderApiTest); | 228 DISALLOW_COPY_AND_ASSIGN(PrinterProviderApiTest); |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 &printers, run_loop.QuitClosure())); | 648 &printers, run_loop.QuitClosure())); |
649 | 649 |
650 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 650 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
651 | 651 |
652 run_loop.Run(); | 652 run_loop.Run(); |
653 | 653 |
654 EXPECT_TRUE(printers.empty()); | 654 EXPECT_TRUE(printers.empty()); |
655 } | 655 } |
656 | 656 |
657 } // namespace | 657 } // namespace |
OLD | NEW |