Commit a8ecad2d authored by Muhammad Hasan Khan's avatar Muhammad Hasan Khan Committed by Commit Bot

login: add a test for reentrancy of ArcInstanceStopped event

In this change we're adding a test that simulates the same condition
that was addressed in https://crrev.com/c/2381050 i.e. we ensure that
ArcInstanceStopped is not called on new instances of arc_container_client_adapter
if they're created during handling of ArcInstanceStopped event.

BUG=b:164816080
TEST=components_unittests --gtest_filter='ArcContainerClientAdapterTest*'
TEST=revert the fix and ensure that the test fails

Change-Id: Ibe4911664be8b81a16c6c25a282121f4d83323bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2459528
Commit-Queue: Muhammad Hasan Khan <mhasank@chromium.org>
Reviewed-by: default avatarRyo Hashimoto <hashimoto@chromium.org>
Reviewed-by: default avatarYusuke Sato <yusukes@chromium.org>
Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817065}
parent d9e68559
......@@ -397,6 +397,7 @@ source_set("unit_tests") {
"pay/arc_payment_app_bridge_unittest.cc",
"power/arc_power_bridge_unittest.cc",
"property/arc_property_bridge_unittest.cc",
"session/arc_container_client_adapter_unittest.cc",
"session/arc_data_remover_unittest.cc",
"session/arc_property_util_unittest.cc",
"session/arc_session_impl_unittest.cc",
......
// Copyright 2020 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 <memory>
#include "base/callback_helpers.h"
#include "chromeos/dbus/session_manager/fake_session_manager_client.h"
#include "components/arc/session/arc_container_client_adapter.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace arc {
class ArcContainerClientAdapterTest : public testing::Test {
public:
ArcContainerClientAdapterTest() = default;
~ArcContainerClientAdapterTest() override = default;
ArcContainerClientAdapterTest(const ArcContainerClientAdapterTest&) = delete;
ArcContainerClientAdapterTest& operator=(
const ArcContainerClientAdapterTest&) = delete;
void SetUp() override {
chromeos::SessionManagerClient::InitializeFake();
client_adapter_ = CreateArcContainerClientAdapter();
}
void TearDown() override {
client_adapter_ = nullptr;
chromeos::SessionManagerClient::Shutdown();
}
protected:
ArcClientAdapter* client_adapter() { return client_adapter_.get(); }
private:
std::unique_ptr<ArcClientAdapter> client_adapter_;
};
// b/164816080 This test ensures that a new container instance that is
// created while handling the shutting down of the previous instance,
// doesn't incorrectly receive the shutdown event as well.
TEST_F(ArcContainerClientAdapterTest,
DoesNotGetArcInstanceStoppedOnNestedInstance) {
class Observer : public ArcClientAdapter::Observer {
public:
explicit Observer(Observer* child_observer)
: child_observer_(child_observer) {}
Observer(const Observer&) = delete;
Observer& operator=(const Observer&) = delete;
~Observer() override {
if (child_observer_ && nested_client_adapter_)
nested_client_adapter_->RemoveObserver(child_observer_);
}
bool stopped_called() const { return stopped_called_; }
// ArcClientAdapter::Observer:
void ArcInstanceStopped() override {
stopped_called_ = true;
if (child_observer_) {
nested_client_adapter_ = CreateArcContainerClientAdapter();
nested_client_adapter_->AddObserver(child_observer_);
}
}
private:
Observer* const child_observer_;
std::unique_ptr<ArcClientAdapter> nested_client_adapter_;
bool stopped_called_ = false;
};
Observer child_observer(nullptr);
Observer parent_observer(&child_observer);
client_adapter()->AddObserver(&parent_observer);
base::ScopedClosureRunner teardown(base::BindOnce(
[](ArcClientAdapter* client_adapter, Observer* parent_observer) {
client_adapter->RemoveObserver(parent_observer);
},
client_adapter(), &parent_observer));
chromeos::FakeSessionManagerClient::Get()->NotifyArcInstanceStopped();
EXPECT_TRUE(parent_observer.stopped_called());
EXPECT_FALSE(child_observer.stopped_called());
}
} // namespace arc
......@@ -258,8 +258,6 @@ void ArcSessionRunner::SetRestartDelayForTesting(
restart_delay_ = restart_delay;
}
// TODO(b/164816080) add a test to ensure OnSessionStopped is not called
// when starting ARC session after failed attempt
void ArcSessionRunner::StartArcSession() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(!restart_timer_.IsRunning());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment