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

Unified Diff: chromeos/dbus/fake_cups_client_unittest.cc

Issue 2232203003: Implement a dbus client for CupsTool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« chromeos/dbus/fake_cups_client.h ('K') | « chromeos/dbus/fake_cups_client.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« chromeos/dbus/fake_cups_client.h ('K') | « chromeos/dbus/fake_cups_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698