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

Unified Diff: chrome/browser/chromeos/lock_screen_apps/state_controller_unittest.cc

Issue 2848813002: Introduce ash mojo interface for lock screen action handlers (Closed)
Patch Set: add ASH_EXPORTS Created 3 years, 7 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
Index: chrome/browser/chromeos/lock_screen_apps/state_controller_unittest.cc
diff --git a/chrome/browser/chromeos/lock_screen_apps/state_controller_unittest.cc b/chrome/browser/chromeos/lock_screen_apps/state_controller_unittest.cc
index b22474d159a78a20b372c190661f580b85b79cab..67d601e5ea9c7b717fb100d355cd09ea043a2dfe 100644
--- a/chrome/browser/chromeos/lock_screen_apps/state_controller_unittest.cc
+++ b/chrome/browser/chromeos/lock_screen_apps/state_controller_unittest.cc
@@ -2,45 +2,90 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "chrome/browser/chromeos/lock_screen_apps/state_controller.h"
+
#include <memory>
+#include <utility>
+#include <vector>
+#include "ash/public/interfaces/tray_action.mojom.h"
#include "base/memory/ptr_util.h"
+#include "base/run_loop.h"
#include "base/test/scoped_command_line.h"
-#include "chrome/browser/chromeos/lock_screen_apps/state_controller.h"
#include "chrome/browser/chromeos/lock_screen_apps/state_observer.h"
-#include "chrome/browser/chromeos/lock_screen_apps/types.h"
+#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
-namespace {
+using ash::mojom::TrayActionState;
-const lock_screen_apps::Action kTestAction = lock_screen_apps::Action::kNewNote;
+namespace {
class TestStateObserver : public lock_screen_apps::StateObserver {
public:
TestStateObserver() = default;
~TestStateObserver() override = default;
- void OnLockScreenAppsStateChanged(
- lock_screen_apps::Action action,
- lock_screen_apps::ActionState state) override {
- ASSERT_EQ(kTestAction, action);
+ void OnLockScreenNoteStateChanged(TrayActionState state) override {
+ observed_states_.push_back(state);
+ }
- ++state_change_count_;
+ const std::vector<TrayActionState> observed_states() const {
+ return observed_states_;
}
- int state_change_count() const { return state_change_count_; }
+ void ClearObservedStates() { observed_states_.clear(); }
private:
- int state_change_count_ = 0;
+ std::vector<TrayActionState> observed_states_;
DISALLOW_COPY_AND_ASSIGN(TestStateObserver);
};
-class LockScreenAppStateControllerNotSupportedTest : public testing::Test {
+class TestTrayAction : public ash::mojom::TrayAction {
public:
- LockScreenAppStateControllerNotSupportedTest() = default;
+ TestTrayAction() : binding_(this) {}
+
+ ~TestTrayAction() override = default;
- ~LockScreenAppStateControllerNotSupportedTest() override = default;
+ ash::mojom::TrayActionPtr CreateInterfacePtrAndBind() {
+ return binding_.CreateInterfacePtrAndBind();
+ }
+
+ void SetClient(ash::mojom::TrayActionClientPtr client,
+ TrayActionState state) override {
+ client_ = std::move(client);
+ EXPECT_EQ(TrayActionState::kNotAvailable, state);
+ }
+
+ void UpdateLockScreenNoteState(TrayActionState state) override {
+ observed_states_.push_back(state);
+ }
+
+ void SendNewNoteRequest() {
+ ASSERT_TRUE(client_);
+ client_->RequestNewLockScreenNote();
+ }
+
+ const std::vector<TrayActionState>& observed_states() const {
+ return observed_states_;
+ }
+
+ void ClearObservedStates() { observed_states_.clear(); }
+
+ private:
+ mojo::Binding<ash::mojom::TrayAction> binding_;
+ ash::mojom::TrayActionClientPtr client_;
+
+ std::vector<TrayActionState> observed_states_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestTrayAction);
+};
+
+class LockScreenAppStateNotSupportedTest : public testing::Test {
+ public:
+ LockScreenAppStateNotSupportedTest() = default;
+
+ ~LockScreenAppStateNotSupportedTest() override = default;
void SetUp() override {
command_line_ = base::MakeUnique<base::test::ScopedCommandLine>();
@@ -50,65 +95,121 @@ class LockScreenAppStateControllerNotSupportedTest : public testing::Test {
private:
std::unique_ptr<base::test::ScopedCommandLine> command_line_;
- DISALLOW_COPY_AND_ASSIGN(LockScreenAppStateControllerNotSupportedTest);
+ DISALLOW_COPY_AND_ASSIGN(LockScreenAppStateNotSupportedTest);
};
-class LockScreenAppStateControllerTest : public testing::Test {
+class LockScreenAppStateTest : public testing::Test {
public:
- LockScreenAppStateControllerTest() = default;
- ~LockScreenAppStateControllerTest() override = default;
+ LockScreenAppStateTest() = default;
+ ~LockScreenAppStateTest() override = default;
void SetUp() override {
command_line_ = base::MakeUnique<base::test::ScopedCommandLine>();
command_line_->GetProcessCommandLine()->InitFromArgv(
{"", "--enable-lock-screen-apps"});
- state_controller_ = lock_screen_apps::StateController::Get();
- ASSERT_TRUE(state_controller_);
+ ASSERT_TRUE(lock_screen_apps::StateController::IsEnabled());
+
+ state_controller_ = base::MakeUnique<lock_screen_apps::StateController>();
+ state_controller_->SetTrayActionPtrForTesting(
+ tray_action_.CreateInterfacePtrAndBind());
+ state_controller_->Initialize();
+ state_controller_->FlushTrayActionForTesting();
state_controller_->AddObserver(&observer_);
}
- void TearDown() override { state_controller_->RemoveObserver(&observer_); }
+ void TearDown() override {
+ state_controller_->RemoveObserver(&observer_);
+ state_controller_.reset();
+ }
+
+ TestStateObserver* observer() { return &observer_; }
- const TestStateObserver& observer() const { return observer_; }
+ TestTrayAction* tray_action() { return &tray_action_; }
lock_screen_apps::StateController* state_controller() {
- return state_controller_;
+ return state_controller_.get();
}
private:
std::unique_ptr<base::test::ScopedCommandLine> command_line_;
+ content::TestBrowserThreadBundle threads_;
- lock_screen_apps::StateController* state_controller_;
+ std::unique_ptr<lock_screen_apps::StateController> state_controller_;
TestStateObserver observer_;
+ TestTrayAction tray_action_;
- DISALLOW_COPY_AND_ASSIGN(LockScreenAppStateControllerTest);
+ DISALLOW_COPY_AND_ASSIGN(LockScreenAppStateTest);
};
} // namespace
-TEST_F(LockScreenAppStateControllerNotSupportedTest, NoControllerInstance) {
- EXPECT_FALSE(lock_screen_apps::StateController::Get());
+TEST_F(LockScreenAppStateNotSupportedTest, NoInstance) {
+ EXPECT_FALSE(lock_screen_apps::StateController::IsEnabled());
}
-TEST_F(LockScreenAppStateControllerTest, InitialState) {
- EXPECT_EQ(lock_screen_apps::ActionState::kNotSupported,
- state_controller()->GetActionState(kTestAction));
+TEST_F(LockScreenAppStateTest, InitialState) {
+ EXPECT_EQ(TrayActionState::kNotAvailable,
+ state_controller()->GetLockScreenNoteState());
- ASSERT_EQ(0, observer().state_change_count());
+ state_controller()->MoveToBackground();
+
+ EXPECT_EQ(TrayActionState::kNotAvailable,
+ state_controller()->GetLockScreenNoteState());
+
+ EXPECT_EQ(0u, observer()->observed_states().size());
+ EXPECT_EQ(0u, tray_action()->observed_states().size());
+}
+
+TEST_F(LockScreenAppStateTest, MoveToBackgroundFromActive) {
+ state_controller()->SetLockScreenNoteStateForTesting(
+ TrayActionState::kActive);
state_controller()->MoveToBackground();
+ state_controller()->FlushTrayActionForTesting();
+
+ EXPECT_EQ(TrayActionState::kBackground,
+ state_controller()->GetLockScreenNoteState());
+
+ ASSERT_EQ(1u, observer()->observed_states().size());
+ EXPECT_EQ(TrayActionState::kBackground, observer()->observed_states()[0]);
+ ASSERT_EQ(1u, tray_action()->observed_states().size());
+ EXPECT_EQ(TrayActionState::kBackground, tray_action()->observed_states()[0]);
+}
+
+TEST_F(LockScreenAppStateTest, HandleActionWhenNotAvaiable) {
+ ASSERT_EQ(TrayActionState::kNotAvailable,
+ state_controller()->GetLockScreenNoteState());
- EXPECT_EQ(lock_screen_apps::ActionState::kNotSupported,
- state_controller()->GetActionState(kTestAction));
+ tray_action()->SendNewNoteRequest();
+ state_controller()->FlushTrayActionForTesting();
- ASSERT_EQ(0, observer().state_change_count());
+ EXPECT_EQ(0u, observer()->observed_states().size());
+ EXPECT_EQ(0u, tray_action()->observed_states().size());
}
-TEST_F(LockScreenAppStateControllerTest, HandleActionWhenNotAvaiable) {
- ASSERT_EQ(lock_screen_apps::ActionState::kNotSupported,
- state_controller()->GetActionState(kTestAction));
- EXPECT_FALSE(
- state_controller()->HandleAction(lock_screen_apps::Action::kNewNote));
+TEST_F(LockScreenAppStateTest, HandleAction) {
+ state_controller()->SetLockScreenNoteStateForTesting(
+ TrayActionState::kAvailable);
+
+ tray_action()->SendNewNoteRequest();
+ state_controller()->FlushTrayActionForTesting();
+
+ EXPECT_EQ(TrayActionState::kActive,
+ state_controller()->GetLockScreenNoteState());
+ ASSERT_EQ(1u, observer()->observed_states().size());
+ EXPECT_EQ(TrayActionState::kActive, observer()->observed_states()[0]);
+ observer()->ClearObservedStates();
+ ASSERT_EQ(1u, tray_action()->observed_states().size());
+ EXPECT_EQ(TrayActionState::kActive, tray_action()->observed_states()[0]);
+ tray_action()->ClearObservedStates();
+
+ tray_action()->SendNewNoteRequest();
+ state_controller()->FlushTrayActionForTesting();
+
+ // There should be no state change - the state_controller was already in
+ // active state when the request was received.
+ EXPECT_EQ(0u, observer()->observed_states().size());
+ EXPECT_EQ(0u, tray_action()->observed_states().size());
}

Powered by Google App Engine
This is Rietveld 408576698