Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chromeos/dbus/fake_cups_client.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace chromeos { | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 const char kPrinterName[] = "the magic printer"; | |
| 16 | |
| 17 void RecordBooleanResult(bool* called, bool* success, bool result) { | |
| 18 if (called == nullptr || success == nullptr) | |
|
hashimoto
2016/09/07 05:53:17
Is this null check needed?
If not, please remove i
skau
2016/09/09 15:25:33
Acknowledged.
| |
| 19 return; | |
| 20 | |
| 21 *called = true; | |
| 22 *success = result; | |
| 23 } | |
| 24 | |
| 25 void ErrorStub(bool* called) { | |
| 26 if (!called) | |
|
hashimoto
2016/09/07 05:53:17
ditto.
skau
2016/09/09 15:25:32
Acknowledged.
| |
| 27 return; | |
| 28 | |
| 29 *called = true; | |
| 30 } | |
| 31 | |
| 32 } // namespace | |
| 33 | |
| 34 TEST(FakeCupsClientTest, AddPrinterCallsCallback) { | |
| 35 base::MessageLoop message_loop; | |
| 36 FakeCupsClient fake_cups; | |
| 37 | |
| 38 bool called = false; | |
| 39 bool success; | |
| 40 fake_cups.AddPrinter(kPrinterName, "", "", false, | |
| 41 base::Bind(&RecordBooleanResult, &called, &success), | |
| 42 base::Bind(&ErrorStub, nullptr)); | |
| 43 | |
| 44 message_loop.RunUntilIdle(); | |
| 45 | |
| 46 ASSERT_TRUE(called); | |
| 47 EXPECT_TRUE(success); | |
| 48 } | |
| 49 | |
| 50 TEST(FakeCupsClientTest, RemoveMissingPrinterReturnsFalse) { | |
| 51 base::MessageLoop message_loop; | |
| 52 | |
| 53 bool called = false; | |
| 54 bool success; | |
| 55 | |
| 56 FakeCupsClient fake_cups; | |
| 57 fake_cups.RemovePrinter(kPrinterName, | |
| 58 base::Bind(&RecordBooleanResult, &called, &success), | |
| 59 base::Bind(&ErrorStub, nullptr)); | |
| 60 | |
| 61 message_loop.RunUntilIdle(); | |
| 62 | |
| 63 ASSERT_TRUE(called); | |
| 64 EXPECT_FALSE(success); | |
| 65 } | |
| 66 | |
| 67 TEST(FakeCupsClientTest, RemoveExistingPrinterReturnsTrue) { | |
| 68 base::MessageLoop message_loop; | |
| 69 | |
| 70 FakeCupsClient fake_cups; | |
| 71 fake_cups.AddPrinter(kPrinterName, "", "", false, | |
| 72 base::Bind(&RecordBooleanResult, nullptr, nullptr), | |
| 73 base::Bind(&ErrorStub, nullptr)); | |
| 74 | |
| 75 bool called = false; | |
| 76 bool success; | |
| 77 fake_cups.RemovePrinter(kPrinterName, | |
| 78 base::Bind(&RecordBooleanResult, &called, &success), | |
| 79 base::Bind(&ErrorStub, nullptr)); | |
| 80 | |
| 81 message_loop.RunUntilIdle(); | |
| 82 | |
| 83 ASSERT_TRUE(called); | |
| 84 EXPECT_TRUE(success); | |
| 85 } | |
| 86 | |
| 87 } // namespace chromeos | |
| OLD | NEW |