forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
printing: wait for primary profile in CupsProxyServiceManager
CupsProxyServiceManager spawns CupsProxyService, which depends on the primary profile existing. Before spawning CupsProxyService, check to make sure the primary profile exists. If the primary profile does not exist, CupsProxyServiceManager will continue periodically checking for the primary profile's existence until it reaches an attempt limit, when it will then stop trying to spawn CupsProxyService. Bug: crbug:1424583 Change-Id: I4baecf0387fb066175e7e55c9ae598503293bdd1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4401076 Reviewed-by: Benjamin Gordon <bmgordon@chromium.org> Commit-Queue: Paul Moy <pmoy@chromium.org> Reviewed-by: Hidehiko Abe <hidehiko@chromium.org> Cr-Commit-Position: refs/heads/main@{#1144186}
- Loading branch information
Paul Moy
authored and
Chromium LUCI CQ
committed
May 15, 2023
1 parent
c6b8d36
commit af3bc8d
Showing
6 changed files
with
274 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
chrome/browser/ash/printing/cups_proxy_service_manager_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/ash/printing/cups_proxy_service_manager.h" | ||
|
||
#include <memory> | ||
#include <utility> | ||
|
||
#include "base/test/scoped_feature_list.h" | ||
#include "chrome/common/chrome_features.h" | ||
#include "chrome/services/cups_proxy/cups_proxy_service.h" | ||
#include "chrome/test/base/testing_browser_process.h" | ||
#include "chrome/test/base/testing_profile_manager.h" | ||
#include "chromeos/ash/components/dbus/cups_proxy/cups_proxy_client.h" | ||
#include "components/account_id/account_id.h" | ||
#include "components/user_manager/fake_user_manager.h" | ||
#include "components/user_manager/scoped_user_manager.h" | ||
#include "content/public/test/browser_task_environment.h" | ||
#include "testing/gmock/include/gmock/gmock.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
namespace ash { | ||
|
||
namespace { | ||
|
||
constexpr char kProfileName[] = "user@example.com"; | ||
|
||
} // namespace | ||
|
||
class CupsProxyServiceManagerTest : public testing::Test { | ||
protected: | ||
CupsProxyServiceManagerTest() | ||
: testing_profile_manager_(TestingBrowserProcess::GetGlobal()) {} | ||
CupsProxyServiceManagerTest(const CupsProxyServiceManagerTest&) = delete; | ||
CupsProxyServiceManagerTest& operator=(const CupsProxyServiceManagerTest&) = | ||
delete; | ||
~CupsProxyServiceManagerTest() override = default; | ||
|
||
void SetUp() override { | ||
ASSERT_TRUE(testing_profile_manager_.SetUp()); | ||
|
||
auto fake_user_manager = std::make_unique<user_manager::FakeUserManager>(); | ||
fake_user_manager_ = fake_user_manager.get(); | ||
scoped_user_manager_ = std::make_unique<user_manager::ScopedUserManager>( | ||
std::move(fake_user_manager)); | ||
|
||
CupsProxyClient::InitializeFake(); | ||
} | ||
|
||
void TearDown() override { CupsProxyClient::Shutdown(); } | ||
|
||
void CreatePrimaryProfile() { | ||
AccountId account_id = AccountId::FromUserEmail(kProfileName); | ||
fake_user_manager_->AddUser(account_id); | ||
user_manager::UserManager::Get()->UserLoggedIn( | ||
account_id, | ||
user_manager::FakeUserManager::GetFakeUsernameHash(account_id), | ||
/*browser_restart=*/false, | ||
/*is_child=*/false); | ||
testing_profile_manager_.CreateTestingProfile(kProfileName, | ||
/*is_main_profile=*/true); | ||
} | ||
|
||
content::BrowserTaskEnvironment* task_environment() { | ||
return &task_environment_; | ||
} | ||
|
||
base::test::ScopedFeatureList* scoped_feature_list() { | ||
return &scoped_feature_list_; | ||
} | ||
|
||
user_manager::FakeUserManager* fake_user_manager() { | ||
return fake_user_manager_; | ||
} | ||
|
||
private: | ||
content::BrowserTaskEnvironment task_environment_; | ||
base::test::ScopedFeatureList scoped_feature_list_; | ||
TestingProfileManager testing_profile_manager_; | ||
// Owned by `scoped_user_manager_`. | ||
user_manager::FakeUserManager* fake_user_manager_ = nullptr; | ||
std::unique_ptr<user_manager::ScopedUserManager> scoped_user_manager_; | ||
}; | ||
|
||
TEST_F(CupsProxyServiceManagerTest, FeatureNotEnabled) { | ||
scoped_feature_list()->InitAndDisableFeature(features::kPluginVm); | ||
|
||
CupsProxyServiceManager manager; | ||
|
||
EXPECT_EQ(nullptr, cups_proxy::CupsProxyService::GetInstance()); | ||
} | ||
|
||
TEST_F(CupsProxyServiceManagerTest, PrimaryProfileAlreadyCreated) { | ||
scoped_feature_list()->InitAndEnableFeature(features::kPluginVm); | ||
CreatePrimaryProfile(); | ||
|
||
CupsProxyServiceManager manager; | ||
|
||
task_environment()->RunUntilIdle(); | ||
|
||
EXPECT_NE(nullptr, cups_proxy::CupsProxyService::GetInstance()); | ||
} | ||
|
||
TEST_F(CupsProxyServiceManagerTest, PrimaryProfileCreatedLater) { | ||
scoped_feature_list()->InitAndEnableFeature(features::kPluginVm); | ||
|
||
// Before the primary profile has been created, we don't expect | ||
// CupsProxyService to have been spawned. | ||
CupsProxyServiceManager manager; | ||
|
||
task_environment()->RunUntilIdle(); | ||
|
||
EXPECT_EQ(nullptr, cups_proxy::CupsProxyService::GetInstance()); | ||
|
||
CreatePrimaryProfile(); | ||
|
||
task_environment()->RunUntilIdle(); | ||
|
||
EXPECT_NE(nullptr, cups_proxy::CupsProxyService::GetInstance()); | ||
} | ||
|
||
} // namespace ash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters