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/sync/test/integration/printers_helper.cc

Issue 2799103002: Enable printers sync_integration_tests on chromeos (Closed)
Patch Set: more comments Created 3 years, 8 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 | « no previous file | chrome/browser/sync/test/integration/single_client_printers_sync_test.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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "chrome/browser/sync/test/integration/printers_helper.h" 5 #include "chrome/browser/sync/test/integration/printers_helper.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <unordered_map> 9 #include <unordered_map>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/threading/sequenced_worker_pool.h"
16 #include "chrome/browser/chromeos/printing/printers_manager.h" 17 #include "chrome/browser/chromeos/printing/printers_manager.h"
17 #include "chrome/browser/chromeos/printing/printers_manager_factory.h" 18 #include "chrome/browser/chromeos/printing/printers_manager_factory.h"
18 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" 19 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
19 #include "chrome/browser/sync/test/integration/sync_test.h" 20 #include "chrome/browser/sync/test/integration/sync_test.h"
21 #include "content/public/browser/browser_thread.h"
20 22
21 using sync_datatype_helper::test; 23 using sync_datatype_helper::test;
22 24
23 namespace printers_helper { 25 namespace printers_helper {
24 26
25 namespace { 27 namespace {
26 28
27 using PrinterList = std::vector<std::unique_ptr<chromeos::Printer>>; 29 using PrinterList = std::vector<std::unique_ptr<chromeos::Printer>>;
28 30
29 // Returns true if Printer#id, Printer#description, and Printer#uri all match. 31 // Returns true if Printer#id, Printer#description, and Printer#uri all match.
(...skipping 28 matching lines...) Expand all
58 map_b.erase(it); 60 map_b.erase(it);
59 } 61 }
60 62
61 return map_b.empty(); 63 return map_b.empty();
62 } 64 }
63 65
64 std::string PrinterId(int index) { 66 std::string PrinterId(int index) {
65 return base::StringPrintf("printer%d", index); 67 return base::StringPrintf("printer%d", index);
66 } 68 }
67 69
70 chromeos::PrintersManager* GetPrinterStore(content::BrowserContext* context) {
71 chromeos::PrintersManager* manager =
72 chromeos::PrintersManagerFactory::GetForBrowserContext(context);
73
74 // Must wait for ModelTypeStore initialization.
skym 2017/04/06 22:52:11 Can you add that we can probably remove all of thi
Gang Wu 2017/04/07 22:02:55 Done.
75 // Since PrintersManagerFactory::BuildServiceInstanceFor() uses
76 // content::BrowserThread::GetBlockingPool() to schedule ModelTypeStore
77 // initialization, tests need to wait for initialization to be completed and
78 // sent ModelTypeStore to UI thread.
79 content::BrowserThread::GetBlockingPool()->FlushForTesting();
80 // Wait for UI thread task completion to make sure PrintersSyncBridge received
81 // ModelTypeStore.
82 base::RunLoop().RunUntilIdle();
83
84 return manager;
85 }
86
68 } // namespace 87 } // namespace
69 88
70 void AddPrinter(chromeos::PrintersManager* manager, 89 void AddPrinter(chromeos::PrintersManager* manager,
71 const chromeos::Printer& printer) { 90 const chromeos::Printer& printer) {
72 manager->RegisterPrinter(base::MakeUnique<chromeos::Printer>(printer)); 91 manager->RegisterPrinter(base::MakeUnique<chromeos::Printer>(printer));
73 } 92 }
74 93
75 void RemovePrinter(chromeos::PrintersManager* manager, int index) { 94 void RemovePrinter(chromeos::PrintersManager* manager, int index) {
76 chromeos::Printer testPrinter(CreateTestPrinter(index)); 95 chromeos::Printer testPrinter(CreateTestPrinter(index));
77 manager->RemovePrinter(testPrinter.id()); 96 manager->RemovePrinter(testPrinter.id());
(...skipping 22 matching lines...) Expand all
100 chromeos::Printer CreateTestPrinter(int index) { 119 chromeos::Printer CreateTestPrinter(int index) {
101 chromeos::Printer printer(PrinterId(index)); 120 chromeos::Printer printer(PrinterId(index));
102 printer.set_description("Description"); 121 printer.set_description("Description");
103 printer.set_uri(base::StringPrintf("ipp://192.168.1.%d", index)); 122 printer.set_uri(base::StringPrintf("ipp://192.168.1.%d", index));
104 123
105 return printer; 124 return printer;
106 } 125 }
107 126
108 chromeos::PrintersManager* GetVerifierPrinterStore() { 127 chromeos::PrintersManager* GetVerifierPrinterStore() {
109 chromeos::PrintersManager* manager = 128 chromeos::PrintersManager* manager =
110 chromeos::PrintersManagerFactory::GetForBrowserContext( 129 GetPrinterStore(sync_datatype_helper::test()->verifier());
111 sync_datatype_helper::test()->verifier());
112 // Must wait for ModelTypeStore initialization.
113 base::RunLoop().RunUntilIdle();
114 130
115 return manager; 131 return manager;
116 } 132 }
117 133
118 chromeos::PrintersManager* GetPrinterStore(int index) { 134 chromeos::PrintersManager* GetPrinterStore(int index) {
119 chromeos::PrintersManager* manager = 135 chromeos::PrintersManager* manager =
120 chromeos::PrintersManagerFactory::GetForBrowserContext( 136 GetPrinterStore(sync_datatype_helper::test()->GetProfile(index));
121 sync_datatype_helper::test()->GetProfile(index));
122 // Must wait for ModelTypeStore initialization.
123 base::RunLoop().RunUntilIdle();
124 137
125 return manager; 138 return manager;
126 } 139 }
127 140
128 int GetVerifierPrinterCount() { 141 int GetVerifierPrinterCount() {
129 return GetVerifierPrinterStore()->GetPrinters().size(); 142 return GetVerifierPrinterStore()->GetPrinters().size();
130 } 143 }
131 144
132 int GetPrinterCount(int index) { 145 int GetPrinterCount(int index) {
133 return GetPrinterStore(index)->GetPrinters().size(); 146 return GetPrinterStore(index)->GetPrinters().size();
(...skipping 18 matching lines...) Expand all
152 } 165 }
153 166
154 PrintersMatchChecker::PrintersMatchChecker() 167 PrintersMatchChecker::PrintersMatchChecker()
155 : AwaitMatchStatusChangeChecker( 168 : AwaitMatchStatusChangeChecker(
156 base::Bind(&printers_helper::AllProfilesContainSamePrinters), 169 base::Bind(&printers_helper::AllProfilesContainSamePrinters),
157 "All printers match") {} 170 "All printers match") {}
158 171
159 PrintersMatchChecker::~PrintersMatchChecker() {} 172 PrintersMatchChecker::~PrintersMatchChecker() {}
160 173
161 } // namespace printers_helper 174 } // namespace printers_helper
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sync/test/integration/single_client_printers_sync_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698