Commit da5b445c authored by Josh Pratt's avatar Josh Pratt Committed by Commit Bot

Skip VM uninstallation steps if Crostini was not fully installed.

This CL skips parts of the uninstall flow if the Termina VM was not
installed. This occurs if installation and uninstallation occurs
offline.

BUG=884284

Change-Id: I7e669605844b0914948bde792f67891e55ad0e7a
Reviewed-on: https://chromium-review.googlesource.com/1233016Reviewed-by: default avatarTimothy Loh <timloh@chromium.org>
Reviewed-by: default avatarNicholas Verne <nverne@chromium.org>
Commit-Queue: Josh Pratt <jopra@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593787}
parent ac216a9d
...@@ -35,8 +35,14 @@ CrostiniRemover::~CrostiniRemover() = default; ...@@ -35,8 +35,14 @@ CrostiniRemover::~CrostiniRemover() = default;
void CrostiniRemover::RemoveCrostini() { void CrostiniRemover::RemoveCrostini() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
CrostiniManager::GetForProfile(profile_)->InstallTerminaComponent( if (CrostiniManager::GetForProfile(profile_)->IsCrosTerminaInstalled()) {
base::BindOnce(&CrostiniRemover::OnComponentLoaded, this)); CrostiniManager::GetForProfile(profile_)->InstallTerminaComponent(
base::BindOnce(&CrostiniRemover::OnComponentLoaded, this));
} else {
// Crostini installation didn't install the component. Concierge should not
// be running, nor should there be any VMs.
CrostiniRemover::StopConciergeFinished(true);
}
} }
void CrostiniRemover::OnComponentLoaded(ConciergeClientResult result) { void CrostiniRemover::OnComponentLoaded(ConciergeClientResult result) {
...@@ -85,6 +91,7 @@ void CrostiniRemover::DestroyDiskImageFinished(ConciergeClientResult result) { ...@@ -85,6 +91,7 @@ void CrostiniRemover::DestroyDiskImageFinished(ConciergeClientResult result) {
} }
void CrostiniRemover::StopConciergeFinished(bool is_successful) { void CrostiniRemover::StopConciergeFinished(bool is_successful) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// The is_successful parameter is never set by debugd. // The is_successful parameter is never set by debugd.
auto* cros_component_manager = auto* cros_component_manager =
g_browser_process->platform_part()->cros_component_manager(); g_browser_process->platform_part()->cros_component_manager();
......
...@@ -73,16 +73,7 @@ void CrostiniDialogBrowserTest::CreatedBrowserMainParts( ...@@ -73,16 +73,7 @@ void CrostiniDialogBrowserTest::CreatedBrowserMainParts(
} }
void CrostiniDialogBrowserTest::SetUp() { void CrostiniDialogBrowserTest::SetUp() {
base::FilePath component_user_dir; InitCrosTermina();
ASSERT_TRUE(base::PathService::Get(component_updater::DIR_COMPONENT_USER,
&component_user_dir));
ASSERT_TRUE(cros_termina_resources_.Set(
component_user_dir.Append("cros-components")
.Append(imageloader::kTerminaComponentName)));
image_loader_client_->SetMountPathForComponent(
imageloader::kTerminaComponentName, cros_termina_resources_.GetPath());
SetCrostiniUIAllowedForTesting(true); SetCrostiniUIAllowedForTesting(true);
DialogBrowserTest::SetUp(); DialogBrowserTest::SetUp();
} }
...@@ -99,6 +90,18 @@ void CrostiniDialogBrowserTest::SetUpOnMainThread() { ...@@ -99,6 +90,18 @@ void CrostiniDialogBrowserTest::SetUpOnMainThread() {
cros_termina_resources_.GetPath().value(), base::DoNothing()); cros_termina_resources_.GetPath().value(), base::DoNothing());
} }
void CrostiniDialogBrowserTest::InitCrosTermina() {
base::FilePath component_user_dir;
ASSERT_TRUE(base::PathService::Get(component_updater::DIR_COMPONENT_USER,
&component_user_dir));
ASSERT_TRUE(cros_termina_resources_.Set(
component_user_dir.Append("cros-components")
.Append(imageloader::kTerminaComponentName)));
image_loader_client_->SetMountPathForComponent(
imageloader::kTerminaComponentName, cros_termina_resources_.GetPath());
}
void CrostiniDialogBrowserTest::SetConnectionType( void CrostiniDialogBrowserTest::SetConnectionType(
net::NetworkChangeNotifier::ConnectionType connection_type) { net::NetworkChangeNotifier::ConnectionType connection_type) {
extra_parts_->network_change_notifier()->SetConnectionType(connection_type); extra_parts_->network_change_notifier()->SetConnectionType(connection_type);
......
...@@ -27,6 +27,7 @@ class CrostiniDialogBrowserTest : public DialogBrowserTest { ...@@ -27,6 +27,7 @@ class CrostiniDialogBrowserTest : public DialogBrowserTest {
content::BrowserMainParts* browser_main_parts) override; content::BrowserMainParts* browser_main_parts) override;
void SetUp() override; void SetUp() override;
void SetUpOnMainThread() override; void SetUpOnMainThread() override;
virtual void InitCrosTermina();
void SetConnectionType( void SetConnectionType(
net::NetworkChangeNotifier::ConnectionType connection_type); net::NetworkChangeNotifier::ConnectionType connection_type);
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/chromeos/crostini/crostini_manager.h" #include "chrome/browser/chromeos/crostini/crostini_manager.h"
#include "chrome/browser/chromeos/crostini/crostini_pref_names.h"
#include "chrome/browser/chromeos/crostini/crostini_util.h" #include "chrome/browser/chromeos/crostini/crostini_util.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_list_client_impl.h" #include "chrome/browser/ui/app_list/app_list_client_impl.h"
...@@ -20,6 +21,7 @@ ...@@ -20,6 +21,7 @@
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_concierge_client.h" #include "chromeos/dbus/fake_concierge_client.h"
#include "components/crx_file/id_util.h" #include "components/crx_file/id_util.h"
#include "components/prefs/pref_service.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/window/dialog_client_view.h" #include "ui/views/window/dialog_client_view.h"
...@@ -83,10 +85,28 @@ class CrostiniUninstallerViewBrowserTest : public CrostiniDialogBrowserTest { ...@@ -83,10 +85,28 @@ class CrostiniUninstallerViewBrowserTest : public CrostiniDialogBrowserTest {
WaitingFakeConciergeClient* waiting_fake_concierge_client_; WaitingFakeConciergeClient* waiting_fake_concierge_client_;
private: private:
DISALLOW_COPY_AND_ASSIGN(CrostiniUninstallerViewBrowserTest); DISALLOW_COPY_AND_ASSIGN(CrostiniUninstallerViewBrowserTest);
}; };
class CrostiniUninstalledUninstallerViewBrowserTest
: public CrostiniUninstallerViewBrowserTest {
public:
CrostiniUninstalledUninstallerViewBrowserTest() = default;
void SetUpOnMainThread() override {
browser()->profile()->GetPrefs()->SetBoolean(
crostini::prefs::kCrostiniEnabled, true);
// Skips installing the Cros-Termina component.
}
void InitCrosTermina() override {
// Skips setting up the Cros-Termina component.
}
private:
DISALLOW_COPY_AND_ASSIGN(CrostiniUninstalledUninstallerViewBrowserTest);
};
// Test the dialog is actually launched from the app launcher. // Test the dialog is actually launched from the app launcher.
IN_PROC_BROWSER_TEST_F(CrostiniUninstallerViewBrowserTest, InvokeUi_default) { IN_PROC_BROWSER_TEST_F(CrostiniUninstallerViewBrowserTest, InvokeUi_default) {
ShowAndVerifyUi(); ShowAndVerifyUi();
...@@ -117,6 +137,33 @@ IN_PROC_BROWSER_TEST_F(CrostiniUninstallerViewBrowserTest, UninstallFlow) { ...@@ -117,6 +137,33 @@ IN_PROC_BROWSER_TEST_F(CrostiniUninstallerViewBrowserTest, UninstallFlow) {
1); 1);
} }
IN_PROC_BROWSER_TEST_F(CrostiniUninstalledUninstallerViewBrowserTest,
OfflineUninstallFlowWithoutTermina) {
base::HistogramTester histogram_tester;
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_NONE);
base::RunLoop().RunUntilIdle();
ShowUi("default");
EXPECT_NE(nullptr, ActiveView());
EXPECT_FALSE(ActiveView()->GetWidget()->IsClosed());
EXPECT_EQ(ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
ActiveView()->GetDialogButtons());
EXPECT_TRUE(HasAcceptButton());
EXPECT_TRUE(HasCancelButton());
ActiveView()->GetDialogClientView()->AcceptWindow();
WaitForViewDestroyed();
histogram_tester.ExpectBucketCount(
"Crostini.UninstallResult",
static_cast<base::HistogramBase::Sample>(
CrostiniUninstallerView::UninstallResult::kSuccess),
1);
}
IN_PROC_BROWSER_TEST_F(CrostiniUninstallerViewBrowserTest, Cancel) { IN_PROC_BROWSER_TEST_F(CrostiniUninstallerViewBrowserTest, Cancel) {
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
......
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