Commit 78622bba authored by nancylingwang's avatar nancylingwang Committed by Commit Bot

Add tests to verify the ARC app icon loading with large number apps.

This CL adds 2 test cases to simulate the ARC app icon loading when the
system start with 500 ARC apps.

1. The test case LoadLargeNumberIcons is used to verify adding 500 ARC
apps with good icons, then the system restarts, re-loading 500 ARC
app icons.

2. The test case LoadLargeNumberIconsWithBadIcon is used to verify
adding 500 ARC apps with good icons, and 10 ARC apps with bad icons,
then the system restarts, re-loading 510 ARC app icons.

Start 20 try jobs below, they both run pass.

BUG=1083331

Change-Id: I4d2f46757577e1db79d4aeb3d2aa497820dd0cf4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2389800
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarLong Cheng <lgcheng@google.com>
Cr-Commit-Position: refs/heads/master@{#805634}
parent 8dc142ad
......@@ -63,6 +63,10 @@ class ArcApps : public KeyedService,
~ArcApps() override;
ArcIconOnceLoader& GetArcIconOnceLoaderForTesting() {
return arc_icon_once_loader_;
}
private:
using AppIdToTaskIds = std::map<std::string, std::set<int>>;
using TaskIdToAppId = std::map<int, std::string>;
......
......@@ -99,11 +99,9 @@ void ArcIconOnceLoader::SizeSpecificLoader::LoadIcon(
break;
}
iter = icons_
.insert(std::make_pair(
app_id, std::make_unique<ArcAppIcon>(
profile_, app_id, size_in_dip_, this, icon_type)))
.first;
auto arc_app_icon = host_.arc_app_icon_factory()->CreateArcAppIcon(
profile_, app_id, size_in_dip_, this, icon_type);
iter = icons_.insert(std::make_pair(app_id, std::move(arc_app_icon))).first;
if (base::FeatureList::IsEnabled(features::kAppServiceAdaptiveIcon)) {
host_.MaybeStartIconRequest(iter->second.get(),
ui::ScaleFactor::NUM_SCALE_FACTORS);
......@@ -187,6 +185,7 @@ void ArcIconOnceLoader::SizeSpecificLoader::OnIconFailed(ArcAppIcon* icon) {
ArcIconOnceLoader::ArcIconOnceLoader(Profile* profile)
: profile_(profile), stop_observing_called_(false) {
ArcAppListPrefs::Get(profile)->AddObserver(this);
arc_app_icon_factory_ = std::make_unique<arc::ArcAppIconFactory>();
}
ArcIconOnceLoader::~ArcIconOnceLoader() {
......@@ -242,6 +241,11 @@ void ArcIconOnceLoader::OnAppIconUpdated(
}
}
void ArcIconOnceLoader::SetArcAppIconFactoryForTesting(
std::unique_ptr<arc::ArcAppIconFactory> arc_app_icon_factory) {
arc_app_icon_factory_ = std::move(arc_app_icon_factory);
}
void ArcIconOnceLoader::MaybeStartIconRequest(ArcAppIcon* arc_app_icon,
ui::ScaleFactor scale_factor) {
DCHECK(arc_app_icon);
......
......@@ -13,6 +13,7 @@
#include "base/callback_forward.h"
#include "base/macros.h"
#include "chrome/browser/ui/app_list/arc/arc_app_icon_descriptor.h"
#include "chrome/browser/ui/app_list/arc/arc_app_icon_factory.h"
#include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
#include "components/services/app_service/public/mojom/types.mojom.h"
......@@ -53,6 +54,13 @@ class ArcIconOnceLoader : public ArcAppListPrefs::Observer {
void OnAppIconUpdated(const std::string& app_id,
const ArcAppIconDescriptor& descriptor) override;
void SetArcAppIconFactoryForTesting(
std::unique_ptr<arc::ArcAppIconFactory> arc_app_icon_factory);
arc::ArcAppIconFactory* arc_app_icon_factory() {
return arc_app_icon_factory_.get();
}
private:
class SizeSpecificLoader;
......@@ -82,6 +90,8 @@ class ArcIconOnceLoader : public ArcAppListPrefs::Observer {
std::map<SizeAndType, std::unique_ptr<SizeSpecificLoader>>
size_specific_loaders_;
std::unique_ptr<arc::ArcAppIconFactory> arc_app_icon_factory_;
// The current icon loading requests.
std::set<ArcAppIcon*> in_flight_requests_;
......
......@@ -1643,6 +1643,8 @@ static_library("ui") {
"app_list/arc/arc_app_icon.h",
"app_list/arc/arc_app_icon_descriptor.cc",
"app_list/arc/arc_app_icon_descriptor.h",
"app_list/arc/arc_app_icon_factory.cc",
"app_list/arc/arc_app_icon_factory.h",
"app_list/arc/arc_app_launcher.cc",
"app_list/arc/arc_app_launcher.h",
"app_list/arc/arc_app_list_prefs.cc",
......
......@@ -41,24 +41,17 @@ bool disable_safe_decoding_for_testing = false;
////////////////////////////////////////////////////////////////////////////////
// ArcAppIcon::ReadResult
struct ArcAppIcon::ReadResult {
ReadResult(bool error,
bool request_to_install,
ui::ScaleFactor scale_factor,
bool resize_allowed,
std::vector<std::string> unsafe_icon_data)
: error(error),
request_to_install(request_to_install),
scale_factor(scale_factor),
resize_allowed(resize_allowed),
unsafe_icon_data(std::move(unsafe_icon_data)) {}
const bool error;
const bool request_to_install;
const ui::ScaleFactor scale_factor;
const bool resize_allowed;
const std::vector<std::string> unsafe_icon_data;
};
ArcAppIcon::ReadResult::ReadResult(bool error,
bool request_to_install,
ui::ScaleFactor scale_factor,
bool resize_allowed,
std::vector<std::string> unsafe_icon_data)
: error(error),
request_to_install(request_to_install),
scale_factor(scale_factor),
resize_allowed(resize_allowed),
unsafe_icon_data(std::move(unsafe_icon_data)) {}
ArcAppIcon::ReadResult::~ReadResult() = default;
////////////////////////////////////////////////////////////////////////////////
// ArcAppIcon::Source
......@@ -287,8 +280,7 @@ ArcAppIcon::ArcAppIcon(content::BrowserContext* context,
}
}
ArcAppIcon::~ArcAppIcon() {
}
ArcAppIcon::~ArcAppIcon() = default;
void ArcAppIcon::LoadSupportedScaleFactors() {
switch (icon_type_) {
......
......@@ -65,12 +65,12 @@ class ArcAppIcon {
int resource_size_in_dip,
Observer* observer,
IconType icon_type = IconType::kUncompressed);
~ArcAppIcon();
virtual ~ArcAppIcon();
// Starts loading the icon at every supported scale factor. The |observer_|
// will be notified as progress is made. "Supported" is in the same sense as
// ui::GetSupportedScaleFactors().
void LoadSupportedScaleFactors();
virtual void LoadSupportedScaleFactors();
// Whether every supported scale factor was successfully loaded. "Supported"
// is in the same sense as ui::GetSupportedScaleFactors().
......@@ -118,13 +118,21 @@ class ArcAppIcon {
static void DisableSafeDecodingForTesting();
static bool IsSafeDecodingDisabledForTesting();
private:
friend class ArcAppIconLoader;
friend class apps::ArcIconOnceLoader;
protected:
struct ReadResult {
ReadResult(bool error,
bool request_to_install,
ui::ScaleFactor scale_factor,
bool resize_allowed,
std::vector<std::string> unsafe_icon_data);
~ReadResult();
class Source;
class DecodeRequest;
struct ReadResult;
const bool error;
const bool request_to_install;
const ui::ScaleFactor scale_factor;
const bool resize_allowed;
const std::vector<std::string> unsafe_icon_data;
};
// Icon loading is performed in several steps. It is initiated by
// LoadImageForScaleFactor request that specifies a required scale factor.
......@@ -141,7 +149,16 @@ class ArcAppIcon {
// install required resource from ARC side. ArcAppListPrefs notifies UI items
// that new icon is available and corresponding item should invoke
// LoadImageForScaleFactor again.
void LoadForScaleFactor(ui::ScaleFactor scale_factor);
virtual void LoadForScaleFactor(ui::ScaleFactor scale_factor);
virtual void OnIconRead(std::unique_ptr<ArcAppIcon::ReadResult> read_result);
private:
friend class ArcAppIconLoader;
friend class apps::ArcIconOnceLoader;
class Source;
class DecodeRequest;
void MaybeRequestIcon(ui::ScaleFactor scale_factor);
static std::unique_ptr<ArcAppIcon::ReadResult> ReadOnBackgroundThread(
......@@ -202,7 +219,6 @@ class ArcAppIcon {
bool resize_allowed,
const base::FilePath& foreground_path,
const base::FilePath& background_path);
void OnIconRead(std::unique_ptr<ArcAppIcon::ReadResult> read_result);
void DecodeImage(
const std::string& unsafe_icon_data,
const ArcAppIconDescriptor& descriptor,
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/app_list/arc/arc_app_icon_factory.h"
#include "content/public/browser/browser_context.h"
namespace arc {
ArcAppIconFactory::ArcAppIconFactory() = default;
ArcAppIconFactory::~ArcAppIconFactory() = default;
std::unique_ptr<ArcAppIcon> ArcAppIconFactory::CreateArcAppIcon(
content::BrowserContext* context,
const std::string& app_id,
int size_in_dip,
ArcAppIcon::Observer* observer,
ArcAppIcon::IconType icon_type) {
return std::make_unique<ArcAppIcon>(context, app_id, size_in_dip, observer,
icon_type);
}
} // namespace arc
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_APP_LIST_ARC_ARC_APP_ICON_FACTORY_H_
#define CHROME_BROWSER_UI_APP_LIST_ARC_ARC_APP_ICON_FACTORY_H_
#include <memory>
#include "chrome/browser/ui/app_list/arc/arc_app_icon.h"
namespace content {
class BrowserContext;
}
namespace arc {
class ArcAppIconFactory {
public:
ArcAppIconFactory();
virtual ~ArcAppIconFactory();
ArcAppIconFactory(const ArcAppIconFactory&) = delete;
ArcAppIconFactory& operator=(const ArcAppIconFactory&) = delete;
virtual std::unique_ptr<ArcAppIcon> CreateArcAppIcon(
content::BrowserContext* context,
const std::string& app_id,
int resource_size_in_dip,
ArcAppIcon::Observer* observer,
ArcAppIcon::IconType icon_type);
};
} // namespace arc
#endif // CHROME_BROWSER_UI_APP_LIST_ARC_ARC_APP_ICON_FACTORY_H_
......@@ -74,6 +74,8 @@ class FakeAppListModelUpdater : public AppListModelUpdater {
void WaitForIconUpdates(size_t expected_updates);
size_t update_image_count() const { return update_image_count_; }
private:
bool search_engine_is_google_ = false;
std::vector<std::unique_ptr<ChromeAppListItem>> items_;
......
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