Chromium Code Reviews| Index: chromeos/dbus/fake_cups_client_unittest.cc |
| diff --git a/chromeos/dbus/fake_cups_client_unittest.cc b/chromeos/dbus/fake_cups_client_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a3e8b7917d3ec52b169db1ed84ebee5158192439 |
| --- /dev/null |
| +++ b/chromeos/dbus/fake_cups_client_unittest.cc |
| @@ -0,0 +1,87 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chromeos/dbus/fake_cups_client.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace chromeos { |
| + |
| +namespace { |
| + |
| +const char kPrinterName[] = "the magic printer"; |
| + |
| +void RecordBooleanResult(bool* called, bool* success, bool result) { |
| + 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.
|
| + return; |
| + |
| + *called = true; |
| + *success = result; |
| +} |
| + |
| +void ErrorStub(bool* called) { |
| + if (!called) |
|
hashimoto
2016/09/07 05:53:17
ditto.
skau
2016/09/09 15:25:32
Acknowledged.
|
| + return; |
| + |
| + *called = true; |
| +} |
| + |
| +} // namespace |
| + |
| +TEST(FakeCupsClientTest, AddPrinterCallsCallback) { |
| + base::MessageLoop message_loop; |
| + FakeCupsClient fake_cups; |
| + |
| + bool called = false; |
| + bool success; |
| + fake_cups.AddPrinter(kPrinterName, "", "", false, |
| + base::Bind(&RecordBooleanResult, &called, &success), |
| + base::Bind(&ErrorStub, nullptr)); |
| + |
| + message_loop.RunUntilIdle(); |
| + |
| + ASSERT_TRUE(called); |
| + EXPECT_TRUE(success); |
| +} |
| + |
| +TEST(FakeCupsClientTest, RemoveMissingPrinterReturnsFalse) { |
| + base::MessageLoop message_loop; |
| + |
| + bool called = false; |
| + bool success; |
| + |
| + FakeCupsClient fake_cups; |
| + fake_cups.RemovePrinter(kPrinterName, |
| + base::Bind(&RecordBooleanResult, &called, &success), |
| + base::Bind(&ErrorStub, nullptr)); |
| + |
| + message_loop.RunUntilIdle(); |
| + |
| + ASSERT_TRUE(called); |
| + EXPECT_FALSE(success); |
| +} |
| + |
| +TEST(FakeCupsClientTest, RemoveExistingPrinterReturnsTrue) { |
| + base::MessageLoop message_loop; |
| + |
| + FakeCupsClient fake_cups; |
| + fake_cups.AddPrinter(kPrinterName, "", "", false, |
| + base::Bind(&RecordBooleanResult, nullptr, nullptr), |
| + base::Bind(&ErrorStub, nullptr)); |
| + |
| + bool called = false; |
| + bool success; |
| + fake_cups.RemovePrinter(kPrinterName, |
| + base::Bind(&RecordBooleanResult, &called, &success), |
| + base::Bind(&ErrorStub, nullptr)); |
| + |
| + message_loop.RunUntilIdle(); |
| + |
| + ASSERT_TRUE(called); |
| + EXPECT_TRUE(success); |
| +} |
| + |
| +} // namespace chromeos |