From 4f8a17f23a0bba7da7654c147ca377e271abe0db Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 22 Mar 2016 16:01:47 -0500 Subject: add tests for not showing snap decisions in greeter mode --- tests/integration/usb-manager-test.cpp | 34 +++++++++++++++++++++++++++++++--- tests/utils/adbd-server.h | 8 ++++---- 2 files changed, 35 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/integration/usb-manager-test.cpp b/tests/integration/usb-manager-test.cpp index 3ce79d0..03c80c7 100644 --- a/tests/integration/usb-manager-test.cpp +++ b/tests/integration/usb-manager-test.cpp @@ -87,7 +87,7 @@ protected: QtDBusMock::DBusMock dbusMock; std::shared_ptr m_tmpdir; std::shared_ptr m_usb_monitor; - std::shared_ptr m_greeter; + std::shared_ptr m_greeter; }; TEST_F(UsbManagerFixture, Allow) @@ -157,7 +157,7 @@ TEST_F(UsbManagerFixture, Allow) EXPECT_EQ(public_key, lines[0]); } -TEST_F(UsbManagerFixture, AndroidInterruptus) +TEST_F(UsbManagerFixture, USBDisconnectedDuringPrompt) { const std::shared_ptr socket_path {new std::string{*m_tmpdir+"/socket"}, file_deleter}; const std::shared_ptr public_keys_path {new std::string{*m_tmpdir+"/adb_keys"}, file_deleter}; @@ -171,7 +171,6 @@ TEST_F(UsbManagerFixture, AndroidInterruptus) for (int i=0; i<3; i++) { -g_message("i %d", i); // add a signal spy to listen to the notification daemon QSignalSpy notificationsSpy( ¬ificationsMockInterface(), @@ -196,3 +195,32 @@ g_message("i %d", i); notificationsSpy.clear(); } } + +TEST_F(UsbManagerFixture, Greeter) +{ + const std::shared_ptr socket_path {new std::string{*m_tmpdir+"/socket"}, file_deleter}; + const std::shared_ptr public_keys_path {new std::string{*m_tmpdir+"/adb_keys"}, file_deleter}; + + // start a mock AdbdServer ready to submit a request + const std::string public_key {"public_key"}; + auto adbd_server = std::make_shared(*socket_path, std::vector{"PK"+public_key}); + + // set up a UsbManager to process the request + m_greeter->m_is_active.set(true); + auto usb_manager = std::make_shared(*socket_path, *public_keys_path, m_usb_monitor, m_greeter); + + // add a signal spy to listen to the notification daemon + QSignalSpy notificationsSpy( + ¬ificationsMockInterface(), + SIGNAL(MethodCalled(const QString &, const QVariantList &)) + ); + + // the greeter is active, so the notification should not appear + EXPECT_FALSE(notificationsSpy.wait(2000)); + + // disable the greeter, the notification should appear + m_greeter->m_is_active.set(false); + wait_for_signals(notificationsSpy, 1); + EXPECT_EQ("Notify", notificationsSpy.at(0).at(0)); + notificationsSpy.clear(); +} diff --git a/tests/utils/adbd-server.h b/tests/utils/adbd-server.h index 968c1f0..5e66379 100644 --- a/tests/utils/adbd-server.h +++ b/tests/utils/adbd-server.h @@ -73,7 +73,7 @@ private: auto client_socket = g_socket_accept(server_socket, m_cancellable, &error); if (error != nullptr) { if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning("GAdbdServer: Error accepting socket connection: %s", error->message); + g_message("GAdbdServer: Error accepting socket connection: %s", error->message); g_clear_error(&error); break; } @@ -90,7 +90,7 @@ private: &error); if (error != nullptr) { if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning("GAdbdServer: Error sending request: %s", error->message); + g_message("GAdbdServer: Error sending request: %s", error->message); g_clear_error(&error); g_clear_object(&client_socket); break; @@ -106,10 +106,10 @@ private: &error); if (error != nullptr) { if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_warning("GAdbdServer: Error reading response: %s", error->message); + g_message("GAdbdServer: Error reading response: %s", error->message); g_clear_error(&error); g_clear_object(&client_socket); - break; + continue; } const std::string response(buf, std::string::size_type(n_bytes)); g_message("server got response: %s", response.c_str()); -- cgit v1.2.3