Commit e99d9c7a authored by Meilin Wang's avatar Meilin Wang Committed by Commit Bot

tast: Fix tests fail due to changes in assistant state change rule.

A new |RUNNING| state was put into use to indicate the assistant service
enabled with UI shown on the screen, while the old |NOT_READY| state is
now narrowed down to only represent assistant service runnning without UI
showed up. This rule change caused the tests running with UI already
shown on screen to fail because we only checked for |NOT_READY| state
before. This change fixed the test failure by adapting to the new rule
and checking for |RUNNING| state as well.

BUG=None.
TEST=tast -verbose run DUT_ip ui.AlssistantSimpleQueries
     ui.AssistantTimeQuery ui.AssistantVolumeQueries

Change-Id: I75427b64604217b1dc6a76ec9585b416e491bcbf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1777107
Commit-Queue: Meilin Wang <meilinw@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarAchuith Bhandarkar <achuith@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695363}
parent 0d2eddfc
...@@ -1637,6 +1637,7 @@ void AutotestPrivateBootstrapMachineLearningServiceFunction::ConnectionError() { ...@@ -1637,6 +1637,7 @@ void AutotestPrivateBootstrapMachineLearningServiceFunction::ConnectionError() {
AutotestPrivateSetAssistantEnabledFunction:: AutotestPrivateSetAssistantEnabledFunction::
AutotestPrivateSetAssistantEnabledFunction() { AutotestPrivateSetAssistantEnabledFunction() {
// |AddObserver| will immediately trigger |OnAssistantStatusChanged|.
ash::AssistantState::Get()->AddObserver(this); ash::AssistantState::Get()->AddObserver(this);
} }
...@@ -1660,19 +1661,23 @@ AutotestPrivateSetAssistantEnabledFunction::Run() { ...@@ -1660,19 +1661,23 @@ AutotestPrivateSetAssistantEnabledFunction::Run() {
if (!err_msg.empty()) if (!err_msg.empty())
return RespondNow(Error(err_msg)); return RespondNow(Error(err_msg));
// |NOT_READY| means service not running // There are three possible states for the voice interaction:
// |STOPPED| means service running but UI not shown // |NOT_READY| means service not running;
auto new_state = params->enabled // |STOPPED| means service running but UI not shown;
? ash::mojom::VoiceInteractionState::STOPPED // |RUNNING| means service running with UI shown on screen.
: ash::mojom::VoiceInteractionState::NOT_READY; // When enabling Assistant, either |STOPPED| or |RUNNING| state could be
// possible depending on whether the UI has been brought up.
if (ash::AssistantState::Get()->voice_interaction_state() == new_state) auto current_state = ash::AssistantState::Get()->voice_interaction_state();
const bool not_ready =
(current_state == ash::mojom::VoiceInteractionState::NOT_READY);
const bool success = (params->enabled != not_ready);
if (success)
return RespondNow(NoArguments()); return RespondNow(NoArguments());
// Assistant service has not responded yet, set up a delayed timer to wait for // Assistant service has not responded yet, set up a delayed timer to wait for
// it and holder a reference to |this|. Also make sure we stop and respond // it and holder a reference to |this|. Also make sure we stop and respond
// when timeout. // when timeout.
expected_state_ = new_state; enabled_ = params->enabled;
timeout_timer_.Start( timeout_timer_.Start(
FROM_HERE, base::TimeDelta::FromMilliseconds(params->timeout_ms), FROM_HERE, base::TimeDelta::FromMilliseconds(params->timeout_ms),
base::BindOnce(&AutotestPrivateSetAssistantEnabledFunction::Timeout, base::BindOnce(&AutotestPrivateSetAssistantEnabledFunction::Timeout,
...@@ -1682,16 +1687,23 @@ AutotestPrivateSetAssistantEnabledFunction::Run() { ...@@ -1682,16 +1687,23 @@ AutotestPrivateSetAssistantEnabledFunction::Run() {
void AutotestPrivateSetAssistantEnabledFunction::OnAssistantStatusChanged( void AutotestPrivateSetAssistantEnabledFunction::OnAssistantStatusChanged(
ash::mojom::VoiceInteractionState state) { ash::mojom::VoiceInteractionState state) {
if (!expected_state_) // Must check if the Optional contains value first to avoid possible
// segmentation fault caused by Respond() below being called before
// RespondLater() in Run(). This will happen due to AddObserver() call
// in the constructor will trigger this function immediately.
if (!enabled_.has_value())
return; return;
// The service could go through |NOT_READY| then to |STOPPED| during enable // The service could go through |NOT_READY| then to |STOPPED| during enable
// flow if this API is called before the initial state is reported. // flow if this API is called before the initial state is reported.
if (expected_state_ != state) const bool not_ready =
(state == ash::mojom::VoiceInteractionState::NOT_READY);
const bool success = (enabled_.value() != not_ready);
if (!success)
return; return;
Respond(NoArguments()); Respond(NoArguments());
expected_state_.reset(); enabled_.reset();
timeout_timer_.AbandonAndStop(); timeout_timer_.AbandonAndStop();
} }
......
...@@ -505,7 +505,7 @@ class AutotestPrivateSetAssistantEnabledFunction ...@@ -505,7 +505,7 @@ class AutotestPrivateSetAssistantEnabledFunction
// will respond with an error. // will respond with an error.
void Timeout(); void Timeout();
base::Optional<ash::mojom::VoiceInteractionState> expected_state_; base::Optional<bool> enabled_;
base::OneShotTimer timeout_timer_; base::OneShotTimer timeout_timer_;
}; };
......
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