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

Side by Side Diff: extensions/browser/api/printer_provider/printer_provider_apitest.cc

Issue 922833004: Make PrinterProviderAPI a pure interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 10 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
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 "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"
11 #include "extensions/browser/api/printer_provider/printer_provider_api_factory.h "
12 #include "extensions/browser/api/printer_provider/printer_provider_print_job.h"
11 #include "extensions/browser/extension_registry.h" 13 #include "extensions/browser/extension_registry.h"
12 #include "extensions/common/extension.h" 14 #include "extensions/common/extension.h"
13 #include "extensions/shell/test/shell_apitest.h" 15 #include "extensions/shell/test/shell_apitest.h"
14 #include "extensions/test/extension_test_message_listener.h" 16 #include "extensions/test/extension_test_message_listener.h"
15 #include "extensions/test/result_catcher.h" 17 #include "extensions/test/result_catcher.h"
16 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
17 19
18 namespace { 20 namespace {
19 21
20 using extensions::PrinterProviderAPI; 22 using extensions::PrinterProviderAPI;
23 using extensions::PrinterProviderAPIFactory;
21 24
22 // Callback for PrinterProviderAPI::DispatchGetPrintersRequested calls. 25 // Callback for PrinterProviderAPI::DispatchGetPrintersRequested calls.
23 // It appends items in |printers| to |*printers_out|. If |done| is set, it runs 26 // It appends items in |printers| to |*printers_out|. If |done| is set, it runs
24 // |callback|. 27 // |callback|.
25 void AppendPrintersAndRunCallbackIfDone(base::ListValue* printers_out, 28 void AppendPrintersAndRunCallbackIfDone(base::ListValue* printers_out,
26 const base::Closure& callback, 29 const base::Closure& callback,
27 const base::ListValue& printers, 30 const base::ListValue& printers,
28 bool done) { 31 bool done) {
29 for (size_t i = 0; i < printers.GetSize(); ++i) { 32 for (size_t i = 0; i < printers.GetSize(); ++i) {
30 const base::DictionaryValue* printer = NULL; 33 const base::DictionaryValue* printer = NULL;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 65 }
63 66
64 // Tests for chrome.printerProvider API. 67 // Tests for chrome.printerProvider API.
65 class PrinterProviderApiTest : public extensions::ShellApiTest { 68 class PrinterProviderApiTest : public extensions::ShellApiTest {
66 public: 69 public:
67 PrinterProviderApiTest() {} 70 PrinterProviderApiTest() {}
68 ~PrinterProviderApiTest() override {} 71 ~PrinterProviderApiTest() override {}
69 72
70 void StartGetPrintersRequest( 73 void StartGetPrintersRequest(
71 const PrinterProviderAPI::GetPrintersCallback& callback) { 74 const PrinterProviderAPI::GetPrintersCallback& callback) {
72 PrinterProviderAPI::GetFactoryInstance() 75 PrinterProviderAPIFactory::GetInstance()
73 ->Get(browser_context()) 76 ->GetForBrowserContext(browser_context())
74 ->DispatchGetPrintersRequested(callback); 77 ->DispatchGetPrintersRequested(callback);
75 } 78 }
76 79
77 void StartPrintRequest(const std::string& extension_id, 80 void StartPrintRequest(const std::string& extension_id,
78 const PrinterProviderAPI::PrintCallback& callback) { 81 const PrinterProviderAPI::PrintCallback& callback) {
79 PrinterProviderAPI::PrintJob job; 82 extensions::PrinterProviderPrintJob job;
80 job.printer_id = extension_id + ":printer_id"; 83 job.printer_id = extension_id + ":printer_id";
81 job.ticket_json = "{}"; 84 job.ticket_json = "{}";
82 job.content_type = "content_type"; 85 job.content_type = "content_type";
83 const unsigned char kDocumentBytes[] = {'b', 'y', 't', 'e', 's', 0}; 86 const unsigned char kDocumentBytes[] = {'b', 'y', 't', 'e', 's', 0};
84 job.document_bytes = 87 job.document_bytes =
85 new base::RefCountedBytes(kDocumentBytes, arraysize(kDocumentBytes)); 88 new base::RefCountedBytes(kDocumentBytes, arraysize(kDocumentBytes));
86 89
87 PrinterProviderAPI::GetFactoryInstance() 90 PrinterProviderAPIFactory::GetInstance()
88 ->Get(browser_context()) 91 ->GetForBrowserContext(browser_context())
89 ->DispatchPrintRequested(job, callback); 92 ->DispatchPrintRequested(job, callback);
90 } 93 }
91 94
92 void StartCapabilityRequest( 95 void StartCapabilityRequest(
93 const std::string& extension_id, 96 const std::string& extension_id,
94 const PrinterProviderAPI::GetCapabilityCallback& callback) { 97 const PrinterProviderAPI::GetCapabilityCallback& callback) {
95 PrinterProviderAPI::GetFactoryInstance() 98 PrinterProviderAPIFactory::GetInstance()
96 ->Get(browser_context()) 99 ->GetForBrowserContext(browser_context())
97 ->DispatchGetCapabilityRequested(extension_id + ":printer_id", 100 ->DispatchGetCapabilityRequested(extension_id + ":printer_id",
98 callback); 101 callback);
99 } 102 }
100 103
101 // Loads chrome.printerProvider test app and initializes is for test 104 // Loads chrome.printerProvider test app and initializes is for test
102 // |test_param|. 105 // |test_param|.
103 // When the app's background page is loaded, the app will send 'loaded' 106 // When the app's background page is loaded, the app will send 'loaded'
104 // message. As a response to the message it will expect string message 107 // message. As a response to the message it will expect string message
105 // specifying the test that should be run. When the app initializes its state 108 // specifying the test that should be run. When the app initializes its state
106 // (e.g. registers listener for a chrome.printerProvider event) it will send 109 // (e.g. registers listener for a chrome.printerProvider event) it will send
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 &printers, run_loop.QuitClosure())); 648 &printers, run_loop.QuitClosure()));
646 649
647 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 650 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
648 651
649 run_loop.Run(); 652 run_loop.Run();
650 653
651 EXPECT_TRUE(printers.empty()); 654 EXPECT_TRUE(printers.empty());
652 } 655 }
653 656
654 } // namespace 657 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698