| 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/files/file.h" | 6 #include "base/files/file.h" |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
| 11 #include "base/memory/ref_counted_memory.h" | 11 #include "base/memory/ref_counted_memory.h" |
| 12 #include "base/memory/scoped_vector.h" |
| 12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "extensions/browser/api/printer_provider/printer_provider_api.h" | 16 #include "extensions/browser/api/printer_provider/printer_provider_api.h" |
| 16 #include "extensions/browser/api/printer_provider/printer_provider_api_factory.h
" | 17 #include "extensions/browser/api/printer_provider/printer_provider_api_factory.h
" |
| 17 #include "extensions/browser/api/printer_provider/printer_provider_print_job.h" | 18 #include "extensions/browser/api/printer_provider/printer_provider_print_job.h" |
| 18 #include "extensions/browser/extension_registry.h" | 19 #include "extensions/browser/extension_registry.h" |
| 19 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
| 21 #include "extensions/common/value_builder.h" |
| 20 #include "extensions/shell/test/shell_apitest.h" | 22 #include "extensions/shell/test/shell_apitest.h" |
| 21 #include "extensions/test/extension_test_message_listener.h" | 23 #include "extensions/test/extension_test_message_listener.h" |
| 22 #include "extensions/test/result_catcher.h" | 24 #include "extensions/test/result_catcher.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 26 |
| 27 namespace extensions { |
| 28 |
| 25 namespace { | 29 namespace { |
| 26 | 30 |
| 27 using extensions::PrinterProviderAPI; | |
| 28 using extensions::PrinterProviderAPIFactory; | |
| 29 | |
| 30 // Callback for PrinterProviderAPI::DispatchGetPrintersRequested calls. | 31 // Callback for PrinterProviderAPI::DispatchGetPrintersRequested calls. |
| 31 // It appends items in |printers| to |*printers_out|. If |done| is set, it runs | 32 // It appends items in |printers| to |*printers_out|. If |done| is set, it runs |
| 32 // |callback|. | 33 // |callback|. |
| 33 void AppendPrintersAndRunCallbackIfDone(base::ListValue* printers_out, | 34 void AppendPrintersAndRunCallbackIfDone(base::ListValue* printers_out, |
| 34 const base::Closure& callback, | 35 const base::Closure& callback, |
| 35 const base::ListValue& printers, | 36 const base::ListValue& printers, |
| 36 bool done) { | 37 bool done) { |
| 37 for (size_t i = 0; i < printers.GetSize(); ++i) { | 38 for (size_t i = 0; i < printers.GetSize(); ++i) { |
| 38 const base::DictionaryValue* printer = NULL; | 39 const base::DictionaryValue* printer = NULL; |
| 39 EXPECT_TRUE(printers.GetDictionary(i, &printer)) | 40 EXPECT_TRUE(printers.GetDictionary(i, &printer)) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 63 void RecordDictAndRunCallback(std::string* result, | 64 void RecordDictAndRunCallback(std::string* result, |
| 64 const base::Closure& callback, | 65 const base::Closure& callback, |
| 65 const base::DictionaryValue& value) { | 66 const base::DictionaryValue& value) { |
| 66 JSONStringValueSerializer serializer(result); | 67 JSONStringValueSerializer serializer(result); |
| 67 EXPECT_TRUE(serializer.Serialize(value)); | 68 EXPECT_TRUE(serializer.Serialize(value)); |
| 68 if (!callback.is_null()) | 69 if (!callback.is_null()) |
| 69 callback.Run(); | 70 callback.Run(); |
| 70 } | 71 } |
| 71 | 72 |
| 72 // Tests for chrome.printerProvider API. | 73 // Tests for chrome.printerProvider API. |
| 73 class PrinterProviderApiTest : public extensions::ShellApiTest { | 74 class PrinterProviderApiTest : public ShellApiTest { |
| 74 public: | 75 public: |
| 75 enum PrintRequestDataType { | 76 enum PrintRequestDataType { |
| 76 PRINT_REQUEST_DATA_TYPE_NOT_SET, | 77 PRINT_REQUEST_DATA_TYPE_NOT_SET, |
| 77 PRINT_REQUEST_DATA_TYPE_FILE, | 78 PRINT_REQUEST_DATA_TYPE_FILE, |
| 78 PRINT_REQUEST_DATA_TYPE_FILE_DELETED, | 79 PRINT_REQUEST_DATA_TYPE_FILE_DELETED, |
| 79 PRINT_REQUEST_DATA_TYPE_BYTES | 80 PRINT_REQUEST_DATA_TYPE_BYTES |
| 80 }; | 81 }; |
| 81 | 82 |
| 82 PrinterProviderApiTest() {} | 83 PrinterProviderApiTest() {} |
| 83 ~PrinterProviderApiTest() override {} | 84 ~PrinterProviderApiTest() override {} |
| 84 | 85 |
| 85 void StartGetPrintersRequest( | 86 void StartGetPrintersRequest( |
| 86 const PrinterProviderAPI::GetPrintersCallback& callback) { | 87 const PrinterProviderAPI::GetPrintersCallback& callback) { |
| 87 PrinterProviderAPIFactory::GetInstance() | 88 PrinterProviderAPIFactory::GetInstance() |
| 88 ->GetForBrowserContext(browser_context()) | 89 ->GetForBrowserContext(browser_context()) |
| 89 ->DispatchGetPrintersRequested(callback); | 90 ->DispatchGetPrintersRequested(callback); |
| 90 } | 91 } |
| 91 | 92 |
| 92 void StartPrintRequestWithNoData( | 93 void StartPrintRequestWithNoData( |
| 93 const std::string& extension_id, | 94 const std::string& extension_id, |
| 94 const PrinterProviderAPI::PrintCallback& callback) { | 95 const PrinterProviderAPI::PrintCallback& callback) { |
| 95 extensions::PrinterProviderPrintJob job; | 96 PrinterProviderPrintJob job; |
| 96 job.printer_id = extension_id + ":printer_id"; | 97 job.printer_id = extension_id + ":printer_id"; |
| 97 job.ticket_json = "{}"; | 98 job.ticket_json = "{}"; |
| 98 job.content_type = "application/pdf"; | 99 job.content_type = "application/pdf"; |
| 99 | 100 |
| 100 PrinterProviderAPIFactory::GetInstance() | 101 PrinterProviderAPIFactory::GetInstance() |
| 101 ->GetForBrowserContext(browser_context()) | 102 ->GetForBrowserContext(browser_context()) |
| 102 ->DispatchPrintRequested(job, callback); | 103 ->DispatchPrintRequested(job, callback); |
| 103 } | 104 } |
| 104 | 105 |
| 105 void StartPrintRequestUsingDocumentBytes( | 106 void StartPrintRequestUsingDocumentBytes( |
| 106 const std::string& extension_id, | 107 const std::string& extension_id, |
| 107 const PrinterProviderAPI::PrintCallback& callback) { | 108 const PrinterProviderAPI::PrintCallback& callback) { |
| 108 extensions::PrinterProviderPrintJob job; | 109 PrinterProviderPrintJob job; |
| 109 job.printer_id = extension_id + ":printer_id"; | 110 job.printer_id = extension_id + ":printer_id"; |
| 110 job.job_title = base::ASCIIToUTF16("Print job"); | 111 job.job_title = base::ASCIIToUTF16("Print job"); |
| 111 job.ticket_json = "{}"; | 112 job.ticket_json = "{}"; |
| 112 job.content_type = "application/pdf"; | 113 job.content_type = "application/pdf"; |
| 113 const unsigned char kDocumentBytes[] = {'b', 'y', 't', 'e', 's'}; | 114 const unsigned char kDocumentBytes[] = {'b', 'y', 't', 'e', 's'}; |
| 114 job.document_bytes = | 115 job.document_bytes = |
| 115 new base::RefCountedBytes(kDocumentBytes, arraysize(kDocumentBytes)); | 116 new base::RefCountedBytes(kDocumentBytes, arraysize(kDocumentBytes)); |
| 116 | 117 |
| 117 PrinterProviderAPIFactory::GetInstance() | 118 PrinterProviderAPIFactory::GetInstance() |
| 118 ->GetForBrowserContext(browser_context()) | 119 ->GetForBrowserContext(browser_context()) |
| 119 ->DispatchPrintRequested(job, callback); | 120 ->DispatchPrintRequested(job, callback); |
| 120 } | 121 } |
| 121 | 122 |
| 122 bool StartPrintRequestUsingFileInfo( | 123 bool StartPrintRequestUsingFileInfo( |
| 123 const std::string& extension_id, | 124 const std::string& extension_id, |
| 124 const PrinterProviderAPI::PrintCallback& callback) { | 125 const PrinterProviderAPI::PrintCallback& callback) { |
| 125 extensions::PrinterProviderPrintJob job; | 126 PrinterProviderPrintJob job; |
| 126 | 127 |
| 127 const char kBytes[] = {'b', 'y', 't', 'e', 's'}; | 128 const char kBytes[] = {'b', 'y', 't', 'e', 's'}; |
| 128 if (!CreateTempFileWithContents(kBytes, static_cast<int>(arraysize(kBytes)), | 129 if (!CreateTempFileWithContents(kBytes, static_cast<int>(arraysize(kBytes)), |
| 129 &job.document_path, &job.file_info)) { | 130 &job.document_path, &job.file_info)) { |
| 130 ADD_FAILURE() << "Failed to create test file."; | 131 ADD_FAILURE() << "Failed to create test file."; |
| 131 return false; | 132 return false; |
| 132 } | 133 } |
| 133 | 134 |
| 134 job.printer_id = extension_id + ":printer_id"; | 135 job.printer_id = extension_id + ":printer_id"; |
| 135 job.job_title = base::ASCIIToUTF16("Print job"); | 136 job.job_title = base::ASCIIToUTF16("Print job"); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 159 // (e.g. registers listener for a chrome.printerProvider event) it will send | 160 // (e.g. registers listener for a chrome.printerProvider event) it will send |
| 160 // message 'ready', at which point the test may be started. | 161 // message 'ready', at which point the test may be started. |
| 161 // If the app is successfully initialized, |*extension_id_out| will be set to | 162 // If the app is successfully initialized, |*extension_id_out| will be set to |
| 162 // the loaded extension's id, otherwise it will remain unchanged. | 163 // the loaded extension's id, otherwise it will remain unchanged. |
| 163 void InitializePrinterProviderTestApp(const std::string& app_path, | 164 void InitializePrinterProviderTestApp(const std::string& app_path, |
| 164 const std::string& test_param, | 165 const std::string& test_param, |
| 165 std::string* extension_id_out) { | 166 std::string* extension_id_out) { |
| 166 ExtensionTestMessageListener loaded_listener("loaded", true); | 167 ExtensionTestMessageListener loaded_listener("loaded", true); |
| 167 ExtensionTestMessageListener ready_listener("ready", false); | 168 ExtensionTestMessageListener ready_listener("ready", false); |
| 168 | 169 |
| 169 const extensions::Extension* extension = LoadApp(app_path); | 170 const Extension* extension = LoadApp(app_path); |
| 170 ASSERT_TRUE(extension); | 171 ASSERT_TRUE(extension); |
| 171 const std::string extension_id = extension->id(); | 172 const std::string extension_id = extension->id(); |
| 172 | 173 |
| 173 loaded_listener.set_extension_id(extension_id); | 174 loaded_listener.set_extension_id(extension_id); |
| 174 ready_listener.set_extension_id(extension_id); | 175 ready_listener.set_extension_id(extension_id); |
| 175 | 176 |
| 176 ASSERT_TRUE(loaded_listener.WaitUntilSatisfied()); | 177 ASSERT_TRUE(loaded_listener.WaitUntilSatisfied()); |
| 177 | 178 |
| 178 loaded_listener.Reply(test_param); | 179 loaded_listener.Reply(test_param); |
| 179 | 180 |
| 180 ASSERT_TRUE(ready_listener.WaitUntilSatisfied()); | 181 ASSERT_TRUE(ready_listener.WaitUntilSatisfied()); |
| 181 | 182 |
| 182 *extension_id_out = extension_id; | 183 *extension_id_out = extension_id; |
| 183 } | 184 } |
| 184 | 185 |
| 185 // Runs a test for chrome.printerProvider.onPrintRequested event. | 186 // Runs a test for chrome.printerProvider.onPrintRequested event. |
| 186 // |test_param|: The test that should be run. | 187 // |test_param|: The test that should be run. |
| 187 // |expected_result|: The print result the app is expected to report. | 188 // |expected_result|: The print result the app is expected to report. |
| 188 void RunPrintRequestTestApp(const std::string& test_param, | 189 void RunPrintRequestTestApp(const std::string& test_param, |
| 189 PrintRequestDataType data_type, | 190 PrintRequestDataType data_type, |
| 190 const std::string& expected_result) { | 191 const std::string& expected_result) { |
| 191 extensions::ResultCatcher catcher; | 192 ResultCatcher catcher; |
| 192 | 193 |
| 193 std::string extension_id; | 194 std::string extension_id; |
| 194 InitializePrinterProviderTestApp("api_test/printer_provider/request_print", | 195 InitializePrinterProviderTestApp("api_test/printer_provider/request_print", |
| 195 test_param, &extension_id); | 196 test_param, &extension_id); |
| 196 if (extension_id.empty()) | 197 if (extension_id.empty()) |
| 197 return; | 198 return; |
| 198 | 199 |
| 199 base::RunLoop run_loop; | 200 base::RunLoop run_loop; |
| 200 bool success; | 201 bool success; |
| 201 std::string print_status; | 202 std::string print_status; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 226 EXPECT_EQ(expected_result, print_status); | 227 EXPECT_EQ(expected_result, print_status); |
| 227 EXPECT_EQ(expected_result == "OK", success); | 228 EXPECT_EQ(expected_result == "OK", success); |
| 228 } | 229 } |
| 229 | 230 |
| 230 // Runs a test for chrome.printerProvider.onGetCapabilityRequested | 231 // Runs a test for chrome.printerProvider.onGetCapabilityRequested |
| 231 // event. | 232 // event. |
| 232 // |test_param|: The test that should be run. | 233 // |test_param|: The test that should be run. |
| 233 // |expected_result|: The printer capability the app is expected to report. | 234 // |expected_result|: The printer capability the app is expected to report. |
| 234 void RunPrinterCapabilitiesRequestTest(const std::string& test_param, | 235 void RunPrinterCapabilitiesRequestTest(const std::string& test_param, |
| 235 const std::string& expected_result) { | 236 const std::string& expected_result) { |
| 236 extensions::ResultCatcher catcher; | 237 ResultCatcher catcher; |
| 237 | 238 |
| 238 std::string extension_id; | 239 std::string extension_id; |
| 239 InitializePrinterProviderTestApp( | 240 InitializePrinterProviderTestApp( |
| 240 "api_test/printer_provider/request_capability", test_param, | 241 "api_test/printer_provider/request_capability", test_param, |
| 241 &extension_id); | 242 &extension_id); |
| 242 if (extension_id.empty()) | 243 if (extension_id.empty()) |
| 243 return; | 244 return; |
| 244 | 245 |
| 245 base::RunLoop run_loop; | 246 base::RunLoop run_loop; |
| 246 std::string result; | 247 std::string result; |
| 247 StartCapabilityRequest( | 248 StartCapabilityRequest( |
| 248 extension_id, | 249 extension_id, |
| 249 base::Bind(&RecordDictAndRunCallback, &result, run_loop.QuitClosure())); | 250 base::Bind(&RecordDictAndRunCallback, &result, run_loop.QuitClosure())); |
| 250 | 251 |
| 251 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 252 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 252 | 253 |
| 253 run_loop.Run(); | 254 run_loop.Run(); |
| 254 EXPECT_EQ(expected_result, result); | 255 EXPECT_EQ(expected_result, result); |
| 255 } | 256 } |
| 256 | 257 |
| 257 bool SimulateExtensionUnload(const std::string& extension_id) { | 258 bool SimulateExtensionUnload(const std::string& extension_id) { |
| 258 extensions::ExtensionRegistry* extension_registry = | 259 ExtensionRegistry* extension_registry = |
| 259 extensions::ExtensionRegistry::Get(browser_context()); | 260 ExtensionRegistry::Get(browser_context()); |
| 260 | 261 |
| 261 const extensions::Extension* extension = | 262 const Extension* extension = extension_registry->GetExtensionById( |
| 262 extension_registry->GetExtensionById( | 263 extension_id, ExtensionRegistry::ENABLED); |
| 263 extension_id, extensions::ExtensionRegistry::ENABLED); | |
| 264 if (!extension) | 264 if (!extension) |
| 265 return false; | 265 return false; |
| 266 | 266 |
| 267 extension_registry->RemoveEnabled(extension_id); | 267 extension_registry->RemoveEnabled(extension_id); |
| 268 extension_registry->TriggerOnUnloaded( | 268 extension_registry->TriggerOnUnloaded( |
| 269 extension, extensions::UnloadedExtensionInfo::REASON_TERMINATE); | 269 extension, UnloadedExtensionInfo::REASON_TERMINATE); |
| 270 return true; | 270 return true; |
| 271 } | 271 } |
| 272 | 272 |
| 273 // Validates that set of printers reported by test apps via | 273 // Validates that set of printers reported by test apps via |
| 274 // chrome.printerProvider.onGetPritersRequested is the same as the set of | 274 // chrome.printerProvider.onGetPritersRequested is the same as the set of |
| 275 // printers in |expected_printers|. |expected_printers| contains list of | 275 // printers in |expected_printers|. |expected_printers| contains list of |
| 276 // printer objects formatted as a JSON string. It is assumed that the values | 276 // printer objects formatted as a JSON string. It is assumed that the values |
| 277 // in |expoected_printers| are unique. | 277 // in |expoected_printers| are unique. |
| 278 void ValidatePrinterListValue( | 278 void ValidatePrinterListValue( |
| 279 const base::ListValue& printers, | 279 const base::ListValue& printers, |
| 280 const std::vector<std::string>& expected_printers) { | 280 const ScopedVector<base::Value>& expected_printers) { |
| 281 ASSERT_EQ(expected_printers.size(), printers.GetSize()); | 281 ASSERT_EQ(expected_printers.size(), printers.GetSize()); |
| 282 for (size_t i = 0; i < expected_printers.size(); ++i) { | 282 for (const base::Value* printer_value : expected_printers) { |
| 283 JSONStringValueDeserializer deserializer(expected_printers[i]); | |
| 284 int error_code; | |
| 285 scoped_ptr<base::Value> printer_value( | |
| 286 deserializer.Deserialize(&error_code, NULL)); | |
| 287 ASSERT_TRUE(printer_value) << "Failed to deserialize " | |
| 288 << expected_printers[i] << ": " | |
| 289 << "error code " << error_code; | |
| 290 EXPECT_TRUE(printers.Find(*printer_value) != printers.end()) | 283 EXPECT_TRUE(printers.Find(*printer_value) != printers.end()) |
| 291 << "Unabe to find " << *printer_value << " in " << printers; | 284 << "Unabe to find " << *printer_value << " in " << printers; |
| 292 } | 285 } |
| 293 } | 286 } |
| 294 | 287 |
| 295 private: | 288 private: |
| 296 // Initializes |data_dir_| if needed and creates a file in it containing | 289 // Initializes |data_dir_| if needed and creates a file in it containing |
| 297 // provided data. | 290 // provided data. |
| 298 bool CreateTempFileWithContents(const char* data, | 291 bool CreateTempFileWithContents(const char* data, |
| 299 int size, | 292 int size, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 RunPrintRequestTestApp("INVALID_VALUE", PRINT_REQUEST_DATA_TYPE_BYTES, | 342 RunPrintRequestTestApp("INVALID_VALUE", PRINT_REQUEST_DATA_TYPE_BYTES, |
| 350 "FAILED"); | 343 "FAILED"); |
| 351 } | 344 } |
| 352 | 345 |
| 353 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, PrintRequestDataNotSet) { | 346 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, PrintRequestDataNotSet) { |
| 354 RunPrintRequestTestApp("IGNORE_CALLBACK", PRINT_REQUEST_DATA_TYPE_NOT_SET, | 347 RunPrintRequestTestApp("IGNORE_CALLBACK", PRINT_REQUEST_DATA_TYPE_NOT_SET, |
| 355 "FAILED"); | 348 "FAILED"); |
| 356 } | 349 } |
| 357 | 350 |
| 358 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, PrintRequestAppUnloaded) { | 351 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, PrintRequestAppUnloaded) { |
| 359 extensions::ResultCatcher catcher; | 352 ResultCatcher catcher; |
| 360 | 353 |
| 361 std::string extension_id; | 354 std::string extension_id; |
| 362 InitializePrinterProviderTestApp("api_test/printer_provider/request_print", | 355 InitializePrinterProviderTestApp("api_test/printer_provider/request_print", |
| 363 "IGNORE_CALLBACK", &extension_id); | 356 "IGNORE_CALLBACK", &extension_id); |
| 364 ASSERT_FALSE(extension_id.empty()); | 357 ASSERT_FALSE(extension_id.empty()); |
| 365 | 358 |
| 366 base::RunLoop run_loop; | 359 base::RunLoop run_loop; |
| 367 bool success = false; | 360 bool success = false; |
| 368 std::string status; | 361 std::string status; |
| 369 StartPrintRequestUsingDocumentBytes( | 362 StartPrintRequestUsingDocumentBytes( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 394 | 387 |
| 395 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, NoCapabilityEventListener) { | 388 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, NoCapabilityEventListener) { |
| 396 RunPrinterCapabilitiesRequestTest("NO_LISTENER", "{}"); | 389 RunPrinterCapabilitiesRequestTest("NO_LISTENER", "{}"); |
| 397 } | 390 } |
| 398 | 391 |
| 399 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, CapabilityInvalidValue) { | 392 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, CapabilityInvalidValue) { |
| 400 RunPrinterCapabilitiesRequestTest("INVALID_VALUE", "{}"); | 393 RunPrinterCapabilitiesRequestTest("INVALID_VALUE", "{}"); |
| 401 } | 394 } |
| 402 | 395 |
| 403 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetCapabilityAppUnloaded) { | 396 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetCapabilityAppUnloaded) { |
| 404 extensions::ResultCatcher catcher; | 397 ResultCatcher catcher; |
| 405 | 398 |
| 406 std::string extension_id; | 399 std::string extension_id; |
| 407 InitializePrinterProviderTestApp( | 400 InitializePrinterProviderTestApp( |
| 408 "api_test/printer_provider/request_capability", "IGNORE_CALLBACK", | 401 "api_test/printer_provider/request_capability", "IGNORE_CALLBACK", |
| 409 &extension_id); | 402 &extension_id); |
| 410 ASSERT_FALSE(extension_id.empty()); | 403 ASSERT_FALSE(extension_id.empty()); |
| 411 | 404 |
| 412 base::RunLoop run_loop; | 405 base::RunLoop run_loop; |
| 413 std::string result; | 406 std::string result; |
| 414 StartCapabilityRequest( | 407 StartCapabilityRequest( |
| 415 extension_id, | 408 extension_id, |
| 416 base::Bind(&RecordDictAndRunCallback, &result, run_loop.QuitClosure())); | 409 base::Bind(&RecordDictAndRunCallback, &result, run_loop.QuitClosure())); |
| 417 | 410 |
| 418 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 411 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 419 | 412 |
| 420 ASSERT_TRUE(SimulateExtensionUnload(extension_id)); | 413 ASSERT_TRUE(SimulateExtensionUnload(extension_id)); |
| 421 run_loop.Run(); | 414 run_loop.Run(); |
| 422 EXPECT_EQ("{}", result); | 415 EXPECT_EQ("{}", result); |
| 423 } | 416 } |
| 424 | 417 |
| 425 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetPrintersSuccess) { | 418 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetPrintersSuccess) { |
| 426 extensions::ResultCatcher catcher; | 419 ResultCatcher catcher; |
| 427 | 420 |
| 428 std::string extension_id; | 421 std::string extension_id; |
| 429 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", | 422 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", |
| 430 "OK", &extension_id); | 423 "OK", &extension_id); |
| 431 ASSERT_FALSE(extension_id.empty()); | 424 ASSERT_FALSE(extension_id.empty()); |
| 432 | 425 |
| 433 base::RunLoop run_loop; | 426 base::RunLoop run_loop; |
| 434 base::ListValue printers; | 427 base::ListValue printers; |
| 435 | 428 |
| 436 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, | 429 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, |
| 437 &printers, run_loop.QuitClosure())); | 430 &printers, run_loop.QuitClosure())); |
| 438 | 431 |
| 439 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 432 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 440 | 433 |
| 441 run_loop.Run(); | 434 run_loop.Run(); |
| 442 | 435 |
| 443 std::vector<std::string> expected_printers; | 436 ScopedVector<base::Value> expected_printers; |
| 444 expected_printers.push_back(base::StringPrintf( | 437 expected_printers.push_back( |
| 445 "{" | 438 DictionaryBuilder() |
| 446 "\"description\":\"Test printer\"," | 439 .Set("description", "Test printer") |
| 447 "\"extensionId\":\"%s\"," | 440 .Set("extensionId", extension_id) |
| 448 "\"extensionName\": \"Test printer provider\"," | 441 .Set("extensionName", "Test printer provider") |
| 449 "\"id\":\"%s:printer1\"," | 442 .Set("id", base::StringPrintf("%s:printer1", extension_id.c_str())) |
| 450 "\"name\":\"Printer 1\"" | 443 .Set("name", "Printer 1") |
| 451 "}", | 444 .Build()); |
| 452 extension_id.c_str(), extension_id.c_str())); | 445 expected_printers.push_back( |
| 453 expected_printers.push_back(base::StringPrintf( | 446 DictionaryBuilder() |
| 454 "{" | 447 .Set("extensionId", extension_id) |
| 455 "\"extensionId\":\"%s\"," | 448 .Set("extensionName", "Test printer provider") |
| 456 "\"extensionName\": \"Test printer provider\"," | 449 .Set("id", |
| 457 "\"id\":\"%s:printerNoDesc\"," | 450 base::StringPrintf("%s:printerNoDesc", extension_id.c_str())) |
| 458 "\"name\":\"Printer 2\"" | 451 .Set("name", "Printer 2") |
| 459 "}", | 452 .Build()); |
| 460 extension_id.c_str(), extension_id.c_str())); | |
| 461 | 453 |
| 462 ValidatePrinterListValue(printers, expected_printers); | 454 ValidatePrinterListValue(printers, expected_printers); |
| 463 } | 455 } |
| 464 | 456 |
| 465 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetPrintersAsyncSuccess) { | 457 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetPrintersAsyncSuccess) { |
| 466 extensions::ResultCatcher catcher; | 458 ResultCatcher catcher; |
| 467 | 459 |
| 468 std::string extension_id; | 460 std::string extension_id; |
| 469 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", | 461 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", |
| 470 "ASYNC_RESPONSE", &extension_id); | 462 "ASYNC_RESPONSE", &extension_id); |
| 471 ASSERT_FALSE(extension_id.empty()); | 463 ASSERT_FALSE(extension_id.empty()); |
| 472 | 464 |
| 473 base::RunLoop run_loop; | 465 base::RunLoop run_loop; |
| 474 base::ListValue printers; | 466 base::ListValue printers; |
| 475 | 467 |
| 476 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, | 468 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, |
| 477 &printers, run_loop.QuitClosure())); | 469 &printers, run_loop.QuitClosure())); |
| 478 | 470 |
| 479 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 471 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 480 | 472 |
| 481 run_loop.Run(); | 473 run_loop.Run(); |
| 482 | 474 |
| 483 std::vector<std::string> expected_printers; | 475 ScopedVector<base::Value> expected_printers; |
| 484 expected_printers.push_back(base::StringPrintf( | 476 expected_printers.push_back( |
| 485 "{" | 477 DictionaryBuilder() |
| 486 "\"description\":\"Test printer\"," | 478 .Set("description", "Test printer") |
| 487 "\"extensionId\":\"%s\"," | 479 .Set("extensionId", extension_id) |
| 488 "\"extensionName\": \"Test printer provider\"," | 480 .Set("extensionName", "Test printer provider") |
| 489 "\"id\":\"%s:printer1\"," | 481 .Set("id", base::StringPrintf("%s:printer1", extension_id.c_str())) |
| 490 "\"name\":\"Printer 1\"" | 482 .Set("name", "Printer 1") |
| 491 "}", | 483 .Build()); |
| 492 extension_id.c_str(), extension_id.c_str())); | |
| 493 | 484 |
| 494 ValidatePrinterListValue(printers, expected_printers); | 485 ValidatePrinterListValue(printers, expected_printers); |
| 495 } | 486 } |
| 496 | 487 |
| 497 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetPrintersTwoExtensions) { | 488 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetPrintersTwoExtensions) { |
| 498 extensions::ResultCatcher catcher; | 489 ResultCatcher catcher; |
| 499 | 490 |
| 500 std::string extension_id_1; | 491 std::string extension_id_1; |
| 501 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", | 492 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", |
| 502 "OK", &extension_id_1); | 493 "OK", &extension_id_1); |
| 503 ASSERT_FALSE(extension_id_1.empty()); | 494 ASSERT_FALSE(extension_id_1.empty()); |
| 504 | 495 |
| 505 std::string extension_id_2; | 496 std::string extension_id_2; |
| 506 InitializePrinterProviderTestApp( | 497 InitializePrinterProviderTestApp( |
| 507 "api_test/printer_provider/request_printers_second", "OK", | 498 "api_test/printer_provider/request_printers_second", "OK", |
| 508 &extension_id_2); | 499 &extension_id_2); |
| 509 ASSERT_FALSE(extension_id_2.empty()); | 500 ASSERT_FALSE(extension_id_2.empty()); |
| 510 | 501 |
| 511 base::RunLoop run_loop; | 502 base::RunLoop run_loop; |
| 512 base::ListValue printers; | 503 base::ListValue printers; |
| 513 | 504 |
| 514 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, | 505 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, |
| 515 &printers, run_loop.QuitClosure())); | 506 &printers, run_loop.QuitClosure())); |
| 516 | 507 |
| 517 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 508 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 518 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 509 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 519 | 510 |
| 520 run_loop.Run(); | 511 run_loop.Run(); |
| 521 | 512 |
| 522 std::vector<std::string> expected_printers; | 513 ScopedVector<base::Value> expected_printers; |
| 523 expected_printers.push_back(base::StringPrintf( | 514 expected_printers.push_back( |
| 524 "{" | 515 DictionaryBuilder() |
| 525 "\"description\":\"Test printer\"," | 516 .Set("description", "Test printer") |
| 526 "\"extensionId\":\"%s\"," | 517 .Set("extensionId", extension_id_1) |
| 527 "\"extensionName\": \"Test printer provider\"," | 518 .Set("extensionName", "Test printer provider") |
| 528 "\"id\":\"%s:printer1\"," | 519 .Set("id", base::StringPrintf("%s:printer1", extension_id_1.c_str())) |
| 529 "\"name\":\"Printer 1\"" | 520 .Set("name", "Printer 1") |
| 530 "}", | 521 .Build()); |
| 531 extension_id_1.c_str(), extension_id_1.c_str())); | 522 expected_printers.push_back( |
| 532 expected_printers.push_back(base::StringPrintf( | 523 DictionaryBuilder() |
| 533 "{" | 524 .Set("extensionId", extension_id_1) |
| 534 "\"extensionId\":\"%s\"," | 525 .Set("extensionName", "Test printer provider") |
| 535 "\"extensionName\": \"Test printer provider\"," | 526 .Set("id", |
| 536 "\"id\":\"%s:printerNoDesc\"," | 527 base::StringPrintf("%s:printerNoDesc", extension_id_1.c_str())) |
| 537 "\"name\":\"Printer 2\"" | 528 .Set("name", "Printer 2") |
| 538 "}", | 529 .Build()); |
| 539 extension_id_1.c_str(), extension_id_1.c_str())); | 530 expected_printers.push_back( |
| 540 expected_printers.push_back(base::StringPrintf( | 531 DictionaryBuilder() |
| 541 "{" | 532 .Set("description", "Test printer") |
| 542 "\"description\":\"Test printer\"," | 533 .Set("extensionId", extension_id_2) |
| 543 "\"extensionId\":\"%s\"," | 534 .Set("extensionName", "Test printer provider") |
| 544 "\"extensionName\": \"Test printer provider\"," | 535 .Set("id", base::StringPrintf("%s:printer1", extension_id_2.c_str())) |
| 545 "\"id\":\"%s:printer1\"," | 536 .Set("name", "Printer 1") |
| 546 "\"name\":\"Printer 1\"" | 537 .Build()); |
| 547 "}", | 538 expected_printers.push_back( |
| 548 extension_id_2.c_str(), extension_id_2.c_str())); | 539 DictionaryBuilder() |
| 549 expected_printers.push_back(base::StringPrintf( | 540 .Set("extensionId", extension_id_2) |
| 550 "{" | 541 .Set("extensionName", "Test printer provider") |
| 551 "\"extensionId\":\"%s\"," | 542 .Set("id", |
| 552 "\"extensionName\": \"Test printer provider\"," | 543 base::StringPrintf("%s:printerNoDesc", extension_id_2.c_str())) |
| 553 "\"id\":\"%s:printerNoDesc\"," | 544 .Set("name", "Printer 2") |
| 554 "\"name\":\"Printer 2\"" | 545 .Build()); |
| 555 "}", | |
| 556 extension_id_2.c_str(), extension_id_2.c_str())); | |
| 557 | 546 |
| 558 ValidatePrinterListValue(printers, expected_printers); | 547 ValidatePrinterListValue(printers, expected_printers); |
| 559 } | 548 } |
| 560 | 549 |
| 561 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, | 550 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, |
| 562 GetPrintersTwoExtensionsBothUnloaded) { | 551 GetPrintersTwoExtensionsBothUnloaded) { |
| 563 extensions::ResultCatcher catcher; | 552 ResultCatcher catcher; |
| 564 | 553 |
| 565 std::string extension_id_1; | 554 std::string extension_id_1; |
| 566 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", | 555 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", |
| 567 "IGNORE_CALLBACK", &extension_id_1); | 556 "IGNORE_CALLBACK", &extension_id_1); |
| 568 ASSERT_FALSE(extension_id_1.empty()); | 557 ASSERT_FALSE(extension_id_1.empty()); |
| 569 | 558 |
| 570 std::string extension_id_2; | 559 std::string extension_id_2; |
| 571 InitializePrinterProviderTestApp( | 560 InitializePrinterProviderTestApp( |
| 572 "api_test/printer_provider/request_printers_second", "IGNORE_CALLBACK", | 561 "api_test/printer_provider/request_printers_second", "IGNORE_CALLBACK", |
| 573 &extension_id_2); | 562 &extension_id_2); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 585 ASSERT_TRUE(SimulateExtensionUnload(extension_id_1)); | 574 ASSERT_TRUE(SimulateExtensionUnload(extension_id_1)); |
| 586 ASSERT_TRUE(SimulateExtensionUnload(extension_id_2)); | 575 ASSERT_TRUE(SimulateExtensionUnload(extension_id_2)); |
| 587 | 576 |
| 588 run_loop.Run(); | 577 run_loop.Run(); |
| 589 | 578 |
| 590 EXPECT_TRUE(printers.empty()); | 579 EXPECT_TRUE(printers.empty()); |
| 591 } | 580 } |
| 592 | 581 |
| 593 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, | 582 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, |
| 594 GetPrintersTwoExtensionsOneFails) { | 583 GetPrintersTwoExtensionsOneFails) { |
| 595 extensions::ResultCatcher catcher; | 584 ResultCatcher catcher; |
| 596 | 585 |
| 597 std::string extension_id_1; | 586 std::string extension_id_1; |
| 598 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", | 587 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", |
| 599 "NOT_ARRAY", &extension_id_1); | 588 "NOT_ARRAY", &extension_id_1); |
| 600 ASSERT_FALSE(extension_id_1.empty()); | 589 ASSERT_FALSE(extension_id_1.empty()); |
| 601 | 590 |
| 602 std::string extension_id_2; | 591 std::string extension_id_2; |
| 603 InitializePrinterProviderTestApp( | 592 InitializePrinterProviderTestApp( |
| 604 "api_test/printer_provider/request_printers_second", "OK", | 593 "api_test/printer_provider/request_printers_second", "OK", |
| 605 &extension_id_2); | 594 &extension_id_2); |
| 606 ASSERT_FALSE(extension_id_2.empty()); | 595 ASSERT_FALSE(extension_id_2.empty()); |
| 607 | 596 |
| 608 base::RunLoop run_loop; | 597 base::RunLoop run_loop; |
| 609 base::ListValue printers; | 598 base::ListValue printers; |
| 610 | 599 |
| 611 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, | 600 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, |
| 612 &printers, run_loop.QuitClosure())); | 601 &printers, run_loop.QuitClosure())); |
| 613 | 602 |
| 614 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 603 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 615 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 604 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 616 | 605 |
| 617 run_loop.Run(); | 606 run_loop.Run(); |
| 618 | 607 |
| 619 std::vector<std::string> expected_printers; | 608 ScopedVector<base::Value> expected_printers; |
| 620 expected_printers.push_back(base::StringPrintf( | 609 expected_printers.push_back( |
| 621 "{" | 610 DictionaryBuilder() |
| 622 "\"description\":\"Test printer\"," | 611 .Set("description", "Test printer") |
| 623 "\"extensionId\":\"%s\"," | 612 .Set("extensionId", extension_id_2) |
| 624 "\"extensionName\": \"Test printer provider\"," | 613 .Set("extensionName", "Test printer provider") |
| 625 "\"id\":\"%s:printer1\"," | 614 .Set("id", base::StringPrintf("%s:printer1", extension_id_2.c_str())) |
| 626 "\"name\":\"Printer 1\"" | 615 .Set("name", "Printer 1") |
| 627 "}", | 616 .Build()); |
| 628 extension_id_2.c_str(), extension_id_2.c_str())); | 617 expected_printers.push_back( |
| 629 expected_printers.push_back(base::StringPrintf( | 618 DictionaryBuilder() |
| 630 "{" | 619 .Set("extensionId", extension_id_2) |
| 631 "\"extensionId\":\"%s\"," | 620 .Set("extensionName", "Test printer provider") |
| 632 "\"extensionName\": \"Test printer provider\"," | 621 .Set("id", |
| 633 "\"id\":\"%s:printerNoDesc\"," | 622 base::StringPrintf("%s:printerNoDesc", extension_id_2.c_str())) |
| 634 "\"name\":\"Printer 2\"" | 623 .Set("name", "Printer 2") |
| 635 "}", | 624 .Build()); |
| 636 extension_id_2.c_str(), extension_id_2.c_str())); | |
| 637 | 625 |
| 638 ValidatePrinterListValue(printers, expected_printers); | 626 ValidatePrinterListValue(printers, expected_printers); |
| 639 } | 627 } |
| 640 | 628 |
| 641 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, | 629 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, |
| 642 GetPrintersTwoExtensionsOneWithNoListener) { | 630 GetPrintersTwoExtensionsOneWithNoListener) { |
| 643 extensions::ResultCatcher catcher; | 631 ResultCatcher catcher; |
| 644 | 632 |
| 645 std::string extension_id_1; | 633 std::string extension_id_1; |
| 646 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", | 634 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", |
| 647 "NO_LISTENER", &extension_id_1); | 635 "NO_LISTENER", &extension_id_1); |
| 648 ASSERT_FALSE(extension_id_1.empty()); | 636 ASSERT_FALSE(extension_id_1.empty()); |
| 649 | 637 |
| 650 std::string extension_id_2; | 638 std::string extension_id_2; |
| 651 InitializePrinterProviderTestApp( | 639 InitializePrinterProviderTestApp( |
| 652 "api_test/printer_provider/request_printers_second", "OK", | 640 "api_test/printer_provider/request_printers_second", "OK", |
| 653 &extension_id_2); | 641 &extension_id_2); |
| 654 ASSERT_FALSE(extension_id_2.empty()); | 642 ASSERT_FALSE(extension_id_2.empty()); |
| 655 | 643 |
| 656 base::RunLoop run_loop; | 644 base::RunLoop run_loop; |
| 657 base::ListValue printers; | 645 base::ListValue printers; |
| 658 | 646 |
| 659 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, | 647 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, |
| 660 &printers, run_loop.QuitClosure())); | 648 &printers, run_loop.QuitClosure())); |
| 661 | 649 |
| 662 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 650 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 663 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 651 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 664 | 652 |
| 665 run_loop.Run(); | 653 run_loop.Run(); |
| 666 | 654 |
| 667 std::vector<std::string> expected_printers; | 655 ScopedVector<base::Value> expected_printers; |
| 668 expected_printers.push_back(base::StringPrintf( | 656 expected_printers.push_back( |
| 669 "{" | 657 DictionaryBuilder() |
| 670 "\"description\":\"Test printer\"," | 658 .Set("description", "Test printer") |
| 671 "\"extensionId\":\"%s\"," | 659 .Set("extensionId", extension_id_2) |
| 672 "\"extensionName\": \"Test printer provider\"," | 660 .Set("extensionName", "Test printer provider") |
| 673 "\"id\":\"%s:printer1\"," | 661 .Set("id", base::StringPrintf("%s:printer1", extension_id_2.c_str())) |
| 674 "\"name\":\"Printer 1\"" | 662 .Set("name", "Printer 1") |
| 675 "}", | 663 .Build()); |
| 676 extension_id_2.c_str(), extension_id_2.c_str())); | 664 expected_printers.push_back( |
| 677 expected_printers.push_back(base::StringPrintf( | 665 DictionaryBuilder() |
| 678 "{" | 666 .Set("extensionId", extension_id_2) |
| 679 "\"extensionId\":\"%s\"," | 667 .Set("extensionName", "Test printer provider") |
| 680 "\"extensionName\": \"Test printer provider\"," | 668 .Set("id", |
| 681 "\"id\":\"%s:printerNoDesc\"," | 669 base::StringPrintf("%s:printerNoDesc", extension_id_2.c_str())) |
| 682 "\"name\":\"Printer 2\"" | 670 .Set("name", "Printer 2") |
| 683 "}", | 671 .Build()); |
| 684 extension_id_2.c_str(), extension_id_2.c_str())); | |
| 685 | 672 |
| 686 ValidatePrinterListValue(printers, expected_printers); | 673 ValidatePrinterListValue(printers, expected_printers); |
| 687 } | 674 } |
| 688 | 675 |
| 689 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetPrintersNoListener) { | 676 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetPrintersNoListener) { |
| 690 extensions::ResultCatcher catcher; | 677 ResultCatcher catcher; |
| 691 | 678 |
| 692 std::string extension_id; | 679 std::string extension_id; |
| 693 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", | 680 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", |
| 694 "NO_LISTENER", &extension_id); | 681 "NO_LISTENER", &extension_id); |
| 695 ASSERT_FALSE(extension_id.empty()); | 682 ASSERT_FALSE(extension_id.empty()); |
| 696 | 683 |
| 697 base::RunLoop run_loop; | 684 base::RunLoop run_loop; |
| 698 base::ListValue printers; | 685 base::ListValue printers; |
| 699 | 686 |
| 700 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, | 687 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, |
| 701 &printers, run_loop.QuitClosure())); | 688 &printers, run_loop.QuitClosure())); |
| 702 | 689 |
| 703 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 690 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 704 | 691 |
| 705 run_loop.Run(); | 692 run_loop.Run(); |
| 706 | 693 |
| 707 EXPECT_TRUE(printers.empty()); | 694 EXPECT_TRUE(printers.empty()); |
| 708 } | 695 } |
| 709 | 696 |
| 710 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetPrintersNotArray) { | 697 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetPrintersNotArray) { |
| 711 extensions::ResultCatcher catcher; | 698 ResultCatcher catcher; |
| 712 | 699 |
| 713 std::string extension_id; | 700 std::string extension_id; |
| 714 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", | 701 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", |
| 715 "NOT_ARRAY", &extension_id); | 702 "NOT_ARRAY", &extension_id); |
| 716 ASSERT_FALSE(extension_id.empty()); | 703 ASSERT_FALSE(extension_id.empty()); |
| 717 | 704 |
| 718 base::RunLoop run_loop; | 705 base::RunLoop run_loop; |
| 719 base::ListValue printers; | 706 base::ListValue printers; |
| 720 | 707 |
| 721 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, | 708 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, |
| 722 &printers, run_loop.QuitClosure())); | 709 &printers, run_loop.QuitClosure())); |
| 723 | 710 |
| 724 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 711 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 725 | 712 |
| 726 run_loop.Run(); | 713 run_loop.Run(); |
| 727 | 714 |
| 728 EXPECT_TRUE(printers.empty()); | 715 EXPECT_TRUE(printers.empty()); |
| 729 } | 716 } |
| 730 | 717 |
| 731 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, | 718 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, |
| 732 GetPrintersInvalidPrinterValueType) { | 719 GetPrintersInvalidPrinterValueType) { |
| 733 extensions::ResultCatcher catcher; | 720 ResultCatcher catcher; |
| 734 | 721 |
| 735 std::string extension_id; | 722 std::string extension_id; |
| 736 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", | 723 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", |
| 737 "INVALID_PRINTER_TYPE", &extension_id); | 724 "INVALID_PRINTER_TYPE", &extension_id); |
| 738 ASSERT_FALSE(extension_id.empty()); | 725 ASSERT_FALSE(extension_id.empty()); |
| 739 | 726 |
| 740 base::RunLoop run_loop; | 727 base::RunLoop run_loop; |
| 741 base::ListValue printers; | 728 base::ListValue printers; |
| 742 | 729 |
| 743 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, | 730 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, |
| 744 &printers, run_loop.QuitClosure())); | 731 &printers, run_loop.QuitClosure())); |
| 745 | 732 |
| 746 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 733 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 747 | 734 |
| 748 run_loop.Run(); | 735 run_loop.Run(); |
| 749 | 736 |
| 750 EXPECT_TRUE(printers.empty()); | 737 EXPECT_TRUE(printers.empty()); |
| 751 } | 738 } |
| 752 | 739 |
| 753 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetPrintersInvalidPrinterValue) { | 740 IN_PROC_BROWSER_TEST_F(PrinterProviderApiTest, GetPrintersInvalidPrinterValue) { |
| 754 extensions::ResultCatcher catcher; | 741 ResultCatcher catcher; |
| 755 | 742 |
| 756 std::string extension_id; | 743 std::string extension_id; |
| 757 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", | 744 InitializePrinterProviderTestApp("api_test/printer_provider/request_printers", |
| 758 "INVALID_PRINTER", &extension_id); | 745 "INVALID_PRINTER", &extension_id); |
| 759 ASSERT_FALSE(extension_id.empty()); | 746 ASSERT_FALSE(extension_id.empty()); |
| 760 | 747 |
| 761 base::RunLoop run_loop; | 748 base::RunLoop run_loop; |
| 762 base::ListValue printers; | 749 base::ListValue printers; |
| 763 | 750 |
| 764 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, | 751 StartGetPrintersRequest(base::Bind(&AppendPrintersAndRunCallbackIfDone, |
| 765 &printers, run_loop.QuitClosure())); | 752 &printers, run_loop.QuitClosure())); |
| 766 | 753 |
| 767 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 754 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 768 | 755 |
| 769 run_loop.Run(); | 756 run_loop.Run(); |
| 770 | 757 |
| 771 EXPECT_TRUE(printers.empty()); | 758 EXPECT_TRUE(printers.empty()); |
| 772 } | 759 } |
| 773 | 760 |
| 774 } // namespace | 761 } // namespace |
| 762 |
| 763 } // namespace extensions |
| OLD | NEW |