Commit 2b8b9d49 authored by Luca Hunkeler's avatar Luca Hunkeler Committed by Commit Bot

[Autofill Assistant] Adds missing tests for recently added methods.

Adds tests for CloseCustomTab, OnClientSettingsChanged and OnOverlayColorsChanged.
Also deleted the default implementation of methods in ControllerObserver.

Bug: b/141163294
Change-Id: Idc6439ec7a83a09d34eba92fd3ac7521596d0193
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1831806
Commit-Queue: Luca Hunkeler <hluca@google.com>
Reviewed-by: default avatarClemens Arbesser <arbesser@google.com>
Cr-Commit-Position: refs/heads/master@{#701503}
parent a54f0cf3
...@@ -11,31 +11,4 @@ namespace autofill_assistant { ...@@ -11,31 +11,4 @@ namespace autofill_assistant {
ControllerObserver::ControllerObserver() = default; ControllerObserver::ControllerObserver() = default;
ControllerObserver::~ControllerObserver() = default; ControllerObserver::~ControllerObserver() = default;
void ControllerObserver::OnStateChanged(AutofillAssistantState new_state) {}
void ControllerObserver::OnStatusMessageChanged(const std::string& message) {}
void ControllerObserver::OnBubbleMessageChanged(const std::string& message) {}
void ControllerObserver::CloseCustomTab() {}
void ControllerObserver::OnUserActionsChanged(
const std::vector<UserAction>& user_actions) {}
void ControllerObserver::OnCollectUserDataOptionsChanged(
const CollectUserDataOptions* options) {}
void ControllerObserver::OnUserDataChanged(const UserData* state) {}
void ControllerObserver::OnDetailsChanged(const Details* details) {}
void ControllerObserver::OnInfoBoxChanged(const InfoBox* info_box) {}
void ControllerObserver::OnProgressChanged(int progress) {}
void ControllerObserver::OnProgressVisibilityChanged(bool visible) {}
void ControllerObserver::OnTouchableAreaChanged(
const RectF& visual_viewport,
const std::vector<RectF>& touchable_areas,
const std::vector<RectF>& restricted_areas) {}
void ControllerObserver::OnViewportModeChanged(ViewportMode mode) {}
void ControllerObserver::OnPeekModeChanged(
ConfigureBottomSheetProto::PeekMode peek_mode) {}
void ControllerObserver::OnOverlayColorsChanged(
const UiDelegate::OverlayColors& colors) {}
void ControllerObserver::OnFormChanged(const FormProto* form) {}
void ControllerObserver::OnClientSettingsChanged(
const ClientSettings& settings) {}
} // namespace autofill_assistant } // namespace autofill_assistant
...@@ -31,44 +31,44 @@ class ControllerObserver : public base::CheckedObserver { ...@@ -31,44 +31,44 @@ class ControllerObserver : public base::CheckedObserver {
~ControllerObserver() override; ~ControllerObserver() override;
// Called when the controller has entered a new state. // Called when the controller has entered a new state.
virtual void OnStateChanged(AutofillAssistantState new_state); virtual void OnStateChanged(AutofillAssistantState new_state) = 0;
// Report that the status message has changed. // Report that the status message has changed.
virtual void OnStatusMessageChanged(const std::string& message); virtual void OnStatusMessageChanged(const std::string& message) = 0;
// Report that the bubble / tooltip message has changed. // Report that the bubble / tooltip message has changed.
virtual void OnBubbleMessageChanged(const std::string& message); virtual void OnBubbleMessageChanged(const std::string& message) = 0;
// If the current chrome activity is a custom tab activity, close it. // If the current chrome activity is a custom tab activity, close it.
// Otherwise, do nothing. // Otherwise, do nothing.
virtual void CloseCustomTab(); virtual void CloseCustomTab() = 0;
// Report that the set of user actions has changed. // Report that the set of user actions has changed.
virtual void OnUserActionsChanged( virtual void OnUserActionsChanged(
const std::vector<UserAction>& user_actions); const std::vector<UserAction>& user_actions) = 0;
// Report that the options configuring a CollectUserDataAction have changed. // Report that the options configuring a CollectUserDataAction have changed.
virtual void OnCollectUserDataOptionsChanged( virtual void OnCollectUserDataOptionsChanged(
const CollectUserDataOptions* options); const CollectUserDataOptions* options) = 0;
// Updates the currently selected user data (e.g., contact information). // Updates the currently selected user data (e.g., contact information).
virtual void OnUserDataChanged(const UserData* state); virtual void OnUserDataChanged(const UserData* state) = 0;
// Called when details have changed. Details will be null if they have been // Called when details have changed. Details will be null if they have been
// cleared. // cleared.
virtual void OnDetailsChanged(const Details* details); virtual void OnDetailsChanged(const Details* details) = 0;
// Called when info box has changed. |info_box| will be null if it has been // Called when info box has changed. |info_box| will be null if it has been
// cleared. // cleared.
virtual void OnInfoBoxChanged(const InfoBox* info_box); virtual void OnInfoBoxChanged(const InfoBox* info_box) = 0;
// Called when the current progress has changed. Progress, is expressed as a // Called when the current progress has changed. Progress, is expressed as a
// percentage. // percentage.
virtual void OnProgressChanged(int progress); virtual void OnProgressChanged(int progress) = 0;
// Called when the current progress bar visibility has changed. If |visible| // Called when the current progress bar visibility has changed. If |visible|
// is true, then the bar is now shown. // is true, then the bar is now shown.
virtual void OnProgressVisibilityChanged(bool visible); virtual void OnProgressVisibilityChanged(bool visible) = 0;
// Updates the area of the visible viewport that is accessible when the // Updates the area of the visible viewport that is accessible when the
// overlay state is OverlayState::PARTIAL. // overlay state is OverlayState::PARTIAL.
...@@ -88,22 +88,24 @@ class ControllerObserver : public base::CheckedObserver { ...@@ -88,22 +88,24 @@ class ControllerObserver : public base::CheckedObserver {
virtual void OnTouchableAreaChanged( virtual void OnTouchableAreaChanged(
const RectF& visual_viewport, const RectF& visual_viewport,
const std::vector<RectF>& touchable_areas, const std::vector<RectF>& touchable_areas,
const std::vector<RectF>& restricted_areas); const std::vector<RectF>& restricted_areas) = 0;
// Called when the viewport mode has changed. // Called when the viewport mode has changed.
virtual void OnViewportModeChanged(ViewportMode mode); virtual void OnViewportModeChanged(ViewportMode mode) = 0;
// Called when the peek mode has changed. // Called when the peek mode has changed.
virtual void OnPeekModeChanged(ConfigureBottomSheetProto::PeekMode peek_mode); virtual void OnPeekModeChanged(
ConfigureBottomSheetProto::PeekMode peek_mode) = 0;
// Called when the overlay colors have changed. // Called when the overlay colors have changed.
virtual void OnOverlayColorsChanged(const UiDelegate::OverlayColors& colors); virtual void OnOverlayColorsChanged(
const UiDelegate::OverlayColors& colors) = 0;
// Called when the form has changed. // Called when the form has changed.
virtual void OnFormChanged(const FormProto* form); virtual void OnFormChanged(const FormProto* form) = 0;
// Called when client settings have changed. // Called when client settings have changed.
virtual void OnClientSettingsChanged(const ClientSettings& settings); virtual void OnClientSettingsChanged(const ClientSettings& settings) = 0;
}; };
} // namespace autofill_assistant } // namespace autofill_assistant
#endif // COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_CONTROLLER_OBSERVER_H_ #endif // COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_CONTROLLER_OBSERVER_H_
...@@ -521,6 +521,28 @@ TEST_F(ControllerTest, Stop) { ...@@ -521,6 +521,28 @@ TEST_F(ControllerTest, Stop) {
EXPECT_TRUE(controller_->PerformUserAction(0)); EXPECT_TRUE(controller_->PerformUserAction(0));
} }
TEST_F(ControllerTest, CloseCustomTab) {
SupportsScriptResponseProto script_response;
AddRunnableScript(&script_response, "stop");
SetNextScriptResponse(script_response);
ActionsResponseProto actions_response;
actions_response.add_actions()->mutable_stop()->set_close_cct(true);
std::string actions_response_str;
actions_response.SerializeToString(&actions_response_str);
EXPECT_CALL(*mock_service_, OnGetActions(StrEq("stop"), _, _, _, _, _))
.WillOnce(RunOnceCallback<5>(true, actions_response_str));
Start();
ASSERT_THAT(controller_->GetUserActions(), SizeIs(1));
EXPECT_CALL(mock_observer_, CloseCustomTab()).Times(1);
testing::InSequence seq;
EXPECT_CALL(fake_client_,
Shutdown(Metrics::DropOutReason::CUSTOM_TAB_CLOSED));
EXPECT_TRUE(controller_->PerformUserAction(0));
}
TEST_F(ControllerTest, Reset) { TEST_F(ControllerTest, Reset) {
// 1. Fetch scripts for URL, which in contains a single "reset" script. // 1. Fetch scripts for URL, which in contains a single "reset" script.
SupportsScriptResponseProto script_response; SupportsScriptResponseProto script_response;
...@@ -1574,4 +1596,31 @@ TEST_F(ControllerTest, SetShippingAddress) { ...@@ -1574,4 +1596,31 @@ TEST_F(ControllerTest, SetShippingAddress) {
Eq(0)); Eq(0));
} }
TEST_F(ControllerTest, SetOverlayColors) {
EXPECT_CALL(
mock_observer_,
OnOverlayColorsChanged(AllOf(
Field(&Controller::OverlayColors::background, StrEq("#FF000000")),
Field(&Controller::OverlayColors::highlight_border,
StrEq("#FFFFFFFF")))));
std::map<std::string, std::string> parameters;
parameters["OVERLAY_COLORS"] = "#FF000000:#FFFFFFFF";
auto context = TriggerContext::Create(parameters, "exps");
GURL url("http://a.example.com/path");
controller_->Start(url, std::move(context));
}
TEST_F(ControllerTest, ChangeClientSettings) {
SupportsScriptResponseProto response;
response.mutable_client_settings()->set_periodic_script_check_interval_ms(1);
SetupScripts(response);
EXPECT_CALL(mock_observer_,
OnClientSettingsChanged(
Field(&ClientSettings::periodic_script_check_interval,
base::TimeDelta::FromMilliseconds(1))));
Start();
}
} // namespace autofill_assistant } // namespace autofill_assistant
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "components/autofill_assistant/browser/controller_observer.h" #include "components/autofill_assistant/browser/controller_observer.h"
#include "components/autofill_assistant/browser/metrics.h" #include "components/autofill_assistant/browser/metrics.h"
#include "components/autofill_assistant/browser/script.h" #include "components/autofill_assistant/browser/script.h"
#include "components/autofill_assistant/browser/ui_delegate.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
namespace autofill_assistant { namespace autofill_assistant {
...@@ -24,6 +25,7 @@ class MockControllerObserver : public ControllerObserver { ...@@ -24,6 +25,7 @@ class MockControllerObserver : public ControllerObserver {
MOCK_METHOD1(OnStatusMessageChanged, void(const std::string& message)); MOCK_METHOD1(OnStatusMessageChanged, void(const std::string& message));
MOCK_METHOD1(OnBubbleMessageChanged, void(const std::string& message)); MOCK_METHOD1(OnBubbleMessageChanged, void(const std::string& message));
MOCK_METHOD0(CloseCustomTab, void());
MOCK_METHOD1(OnStateChanged, void(AutofillAssistantState)); MOCK_METHOD1(OnStateChanged, void(AutofillAssistantState));
MOCK_METHOD1(OnUserActionsChanged, MOCK_METHOD1(OnUserActionsChanged,
void(const std::vector<UserAction>& user_actions)); void(const std::vector<UserAction>& user_actions));
...@@ -43,9 +45,10 @@ class MockControllerObserver : public ControllerObserver { ...@@ -43,9 +45,10 @@ class MockControllerObserver : public ControllerObserver {
MOCK_METHOD1(OnViewportModeChanged, void(ViewportMode mode)); MOCK_METHOD1(OnViewportModeChanged, void(ViewportMode mode));
MOCK_METHOD1(OnPeekModeChanged, MOCK_METHOD1(OnPeekModeChanged,
void(ConfigureBottomSheetProto::PeekMode peek_mode)); void(ConfigureBottomSheetProto::PeekMode peek_mode));
MOCK_METHOD1(OnOverlayColorsChanged,
void(const UiDelegate::OverlayColors& colors));
MOCK_METHOD1(OnFormChanged, void(const FormProto* form)); MOCK_METHOD1(OnFormChanged, void(const FormProto* form));
MOCK_METHOD1(OnClientSettingsChanged, void(const ClientSettings& settings));
// TODO(b/141163294): add missing methods and unit tests.
}; };
} // namespace autofill_assistant } // namespace autofill_assistant
......
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