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

Side by Side Diff: chrome/browser/sync/test/integration/printers_helper.cc

Issue 2799103002: Enable printers sync_integration_tests on chromeos (Closed)
Patch Set: add todo 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 // TODO(sync): crbug.com/709094: Remove all of this once the bug is fixed.
75 // Must wait for ModelTypeStore initialization.
76 // Since PrintersManagerFactory::BuildServiceInstanceFor() uses
77 // content::BrowserThread::GetBlockingPool() to schedule ModelTypeStore
78 // initialization, tests need to wait for initialization to be completed and
79 // sent ModelTypeStore to UI thread.
80 content::BrowserThread::GetBlockingPool()->FlushForTesting();
81 // Wait for UI thread task completion to make sure PrintersSyncBridge received
82 // ModelTypeStore.
83 base::RunLoop().RunUntilIdle();
84
85 return manager;
86 }
87
68 } // namespace 88 } // namespace
69 89
70 void AddPrinter(chromeos::PrintersManager* manager, 90 void AddPrinter(chromeos::PrintersManager* manager,
71 const chromeos::Printer& printer) { 91 const chromeos::Printer& printer) {
72 manager->RegisterPrinter(base::MakeUnique<chromeos::Printer>(printer)); 92 manager->RegisterPrinter(base::MakeUnique<chromeos::Printer>(printer));
73 } 93 }
74 94
75 void RemovePrinter(chromeos::PrintersManager* manager, int index) { 95 void RemovePrinter(chromeos::PrintersManager* manager, int index) {
76 chromeos::Printer testPrinter(CreateTestPrinter(index)); 96 chromeos::Printer testPrinter(CreateTestPrinter(index));
77 manager->RemovePrinter(testPrinter.id()); 97 manager->RemovePrinter(testPrinter.id());
(...skipping 22 matching lines...) Expand all
100 chromeos::Printer CreateTestPrinter(int index) { 120 chromeos::Printer CreateTestPrinter(int index) {
101 chromeos::Printer printer(PrinterId(index)); 121 chromeos::Printer printer(PrinterId(index));
102 printer.set_description("Description"); 122 printer.set_description("Description");
103 printer.set_uri(base::StringPrintf("ipp://192.168.1.%d", index)); 123 printer.set_uri(base::StringPrintf("ipp://192.168.1.%d", index));
104 124
105 return printer; 125 return printer;
106 } 126 }
107 127
108 chromeos::PrintersManager* GetVerifierPrinterStore() { 128 chromeos::PrintersManager* GetVerifierPrinterStore() {
109 chromeos::PrintersManager* manager = 129 chromeos::PrintersManager* manager =
110 chromeos::PrintersManagerFactory::GetForBrowserContext( 130 GetPrinterStore(sync_datatype_helper::test()->verifier());
111 sync_datatype_helper::test()->verifier());
112 // Must wait for ModelTypeStore initialization.
113 base::RunLoop().RunUntilIdle();
114 131
115 return manager; 132 return manager;
116 } 133 }
117 134
118 chromeos::PrintersManager* GetPrinterStore(int index) { 135 chromeos::PrintersManager* GetPrinterStore(int index) {
119 chromeos::PrintersManager* manager = 136 chromeos::PrintersManager* manager =
120 chromeos::PrintersManagerFactory::GetForBrowserContext( 137 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 138
125 return manager; 139 return manager;
126 } 140 }
127 141
128 int GetVerifierPrinterCount() { 142 int GetVerifierPrinterCount() {
129 return GetVerifierPrinterStore()->GetPrinters().size(); 143 return GetVerifierPrinterStore()->GetPrinters().size();
130 } 144 }
131 145
132 int GetPrinterCount(int index) { 146 int GetPrinterCount(int index) {
133 return GetPrinterStore(index)->GetPrinters().size(); 147 return GetPrinterStore(index)->GetPrinters().size();
(...skipping 18 matching lines...) Expand all
152 } 166 }
153 167
154 PrintersMatchChecker::PrintersMatchChecker() 168 PrintersMatchChecker::PrintersMatchChecker()
155 : AwaitMatchStatusChangeChecker( 169 : AwaitMatchStatusChangeChecker(
156 base::Bind(&printers_helper::AllProfilesContainSamePrinters), 170 base::Bind(&printers_helper::AllProfilesContainSamePrinters),
157 "All printers match") {} 171 "All printers match") {}
158 172
159 PrintersMatchChecker::~PrintersMatchChecker() {} 173 PrintersMatchChecker::~PrintersMatchChecker() {}
160 174
161 } // namespace printers_helper 175 } // 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