OLD | NEW |
---|---|
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 Loading... | |
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 void WaitForTaskCompletion() { | |
71 // Since PrintersManagerFactory::BuildServiceInstanceFor() uses | |
72 // content::BrowserThread::GetBlockingPool() to schedule tasks, tests need to | |
skym
2017/04/06 21:03:03
So what if the PrintersManagerFactory schedules ta
Gang Wu
2017/04/06 21:50:56
Done.
| |
73 // Wait for tasks running on content::BrowserThread::GetBlockingPool() to be | |
skym
2017/04/06 21:03:03
Wait shouldn't be capitalized
Gang Wu
2017/04/06 21:50:56
Done.
| |
74 // completed and sent replay to UI thread. | |
75 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | |
76 // Wait for UI thread task completion. | |
skym
2017/04/06 21:03:03
Can you elaborate what's going on here? What's bei
Gang Wu
2017/04/06 21:50:56
Done.
| |
77 base::RunLoop().RunUntilIdle(); | |
78 } | |
79 | |
68 } // namespace | 80 } // namespace |
69 | 81 |
70 void AddPrinter(chromeos::PrintersManager* manager, | 82 void AddPrinter(chromeos::PrintersManager* manager, |
71 const chromeos::Printer& printer) { | 83 const chromeos::Printer& printer) { |
72 manager->RegisterPrinter(base::MakeUnique<chromeos::Printer>(printer)); | 84 manager->RegisterPrinter(base::MakeUnique<chromeos::Printer>(printer)); |
73 } | 85 } |
74 | 86 |
75 void RemovePrinter(chromeos::PrintersManager* manager, int index) { | 87 void RemovePrinter(chromeos::PrintersManager* manager, int index) { |
76 chromeos::Printer testPrinter(CreateTestPrinter(index)); | 88 chromeos::Printer testPrinter(CreateTestPrinter(index)); |
77 manager->RemovePrinter(testPrinter.id()); | 89 manager->RemovePrinter(testPrinter.id()); |
(...skipping 22 matching lines...) Expand all Loading... | |
100 chromeos::Printer CreateTestPrinter(int index) { | 112 chromeos::Printer CreateTestPrinter(int index) { |
101 chromeos::Printer printer(PrinterId(index)); | 113 chromeos::Printer printer(PrinterId(index)); |
102 printer.set_description("Description"); | 114 printer.set_description("Description"); |
103 printer.set_uri(base::StringPrintf("ipp://192.168.1.%d", index)); | 115 printer.set_uri(base::StringPrintf("ipp://192.168.1.%d", index)); |
104 | 116 |
105 return printer; | 117 return printer; |
106 } | 118 } |
107 | 119 |
108 chromeos::PrintersManager* GetVerifierPrinterStore() { | 120 chromeos::PrintersManager* GetVerifierPrinterStore() { |
109 chromeos::PrintersManager* manager = | 121 chromeos::PrintersManager* manager = |
110 chromeos::PrintersManagerFactory::GetForBrowserContext( | 122 chromeos::PrintersManagerFactory::GetForBrowserContext( |
skym
2017/04/06 21:03:03
It seems like there's more stuff that can be moved
Gang Wu
2017/04/06 21:50:56
Done.
| |
111 sync_datatype_helper::test()->verifier()); | 123 sync_datatype_helper::test()->verifier()); |
112 // Must wait for ModelTypeStore initialization. | 124 // Must wait for ModelTypeStore initialization. |
113 base::RunLoop().RunUntilIdle(); | 125 WaitForTaskCompletion(); |
skym
2017/04/06 21:03:03
Does this really need to be called on every GetVer
Gang Wu
2017/04/06 21:50:56
no, just first one. but I think there is no harm t
skym
2017/04/06 22:52:11
I don't think I agree there is no harm done, but I
| |
114 | 126 |
115 return manager; | 127 return manager; |
116 } | 128 } |
117 | 129 |
118 chromeos::PrintersManager* GetPrinterStore(int index) { | 130 chromeos::PrintersManager* GetPrinterStore(int index) { |
119 chromeos::PrintersManager* manager = | 131 chromeos::PrintersManager* manager = |
120 chromeos::PrintersManagerFactory::GetForBrowserContext( | 132 chromeos::PrintersManagerFactory::GetForBrowserContext( |
121 sync_datatype_helper::test()->GetProfile(index)); | 133 sync_datatype_helper::test()->GetProfile(index)); |
122 // Must wait for ModelTypeStore initialization. | 134 // Must wait for ModelTypeStore initialization. |
123 base::RunLoop().RunUntilIdle(); | 135 WaitForTaskCompletion(); |
124 | 136 |
125 return manager; | 137 return manager; |
126 } | 138 } |
127 | 139 |
128 int GetVerifierPrinterCount() { | 140 int GetVerifierPrinterCount() { |
129 return GetVerifierPrinterStore()->GetPrinters().size(); | 141 return GetVerifierPrinterStore()->GetPrinters().size(); |
130 } | 142 } |
131 | 143 |
132 int GetPrinterCount(int index) { | 144 int GetPrinterCount(int index) { |
133 return GetPrinterStore(index)->GetPrinters().size(); | 145 return GetPrinterStore(index)->GetPrinters().size(); |
(...skipping 18 matching lines...) Expand all Loading... | |
152 } | 164 } |
153 | 165 |
154 PrintersMatchChecker::PrintersMatchChecker() | 166 PrintersMatchChecker::PrintersMatchChecker() |
155 : AwaitMatchStatusChangeChecker( | 167 : AwaitMatchStatusChangeChecker( |
156 base::Bind(&printers_helper::AllProfilesContainSamePrinters), | 168 base::Bind(&printers_helper::AllProfilesContainSamePrinters), |
157 "All printers match") {} | 169 "All printers match") {} |
158 | 170 |
159 PrintersMatchChecker::~PrintersMatchChecker() {} | 171 PrintersMatchChecker::~PrintersMatchChecker() {} |
160 | 172 |
161 } // namespace printers_helper | 173 } // namespace printers_helper |
OLD | NEW |