1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
|
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/webapps/browser/android/add_to_homescreen_data_fetcher.h"
#include <memory>
#include <string>
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/run_loop.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/cancelable_task_tracker.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "components/favicon/content/large_favicon_provider_getter.h"
#include "components/favicon/core/large_favicon_provider.h"
#include "components/favicon_base/favicon_types.h"
#include "components/webapps/browser/features.h"
#include "components/webapps/browser/installable/installable_data.h"
#include "components/webapps/browser/installable/installable_logging.h"
#include "components/webapps/browser/installable/installable_manager.h"
#include "components/webapps/browser/installable/installable_metrics.h"
#include "components/webapps/common/web_page_metadata.mojom.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/web_contents_tester.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/blink/public/common/manifest/manifest_util.h"
#include "third_party/blink/public/mojom/favicon/favicon_url.mojom.h"
#include "third_party/blink/public/mojom/manifest/display_mode.mojom.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom.h"
#include "ui/gfx/image/image_unittest_util.h"
#include "url/gurl.h"
namespace webapps {
namespace {
const std::u16string kWebAppInstallInfoTitle = u"Meta Title";
const std::u16string kDefaultManifestName = u"Default Name";
const std::u16string kDefaultManifestShortName = u"Default Short Name";
const char* kDefaultManifestUrl = "https://www.example.com/manifest.json";
const char* kDefaultIconUrl = "https://www.example.com/icon.png";
const char* kDefaultStartUrl = "https://www.example.com/index.html";
const blink::mojom::DisplayMode kDefaultManifestDisplayMode =
blink::mojom::DisplayMode::kStandalone;
const int kIconSizePx = 144;
// Tracks which of the AddToHomescreenDataFetcher::Observer methods have been
// called.
class ObserverWaiter : public AddToHomescreenDataFetcher::Observer {
public:
ObserverWaiter()
: is_webapk_compatible_(false),
title_available_(false),
data_available_(false) {}
ObserverWaiter(const ObserverWaiter&) = delete;
ObserverWaiter& operator=(const ObserverWaiter&) = delete;
~ObserverWaiter() override {}
// Waits till the OnDataAvailable() callback is called.
void WaitForDataAvailable() {
if (data_available_)
return;
base::RunLoop run_loop;
quit_closure_ = run_loop.QuitClosure();
run_loop.Run();
}
void OnUserTitleAvailable(const std::u16string& title,
const GURL& url,
bool is_webapk_compatible) override {
// This should only be called once.
EXPECT_FALSE(title_available_);
EXPECT_FALSE(data_available_);
title_available_ = true;
title_ = title;
is_webapk_compatible_ = is_webapk_compatible;
}
void OnDataAvailable(
const ShortcutInfo& info,
const SkBitmap& primary_icon,
const InstallableStatusCode installable_status) override {
// This should only be called once.
EXPECT_FALSE(data_available_);
EXPECT_TRUE(title_available_);
data_available_ = true;
installable_status_ = installable_status;
if (quit_closure_)
quit_closure_.Run();
}
std::u16string title() const { return title_; }
bool is_webapk_compatible() const { return is_webapk_compatible_; }
bool title_available() const { return title_available_; }
InstallableStatusCode installable_status() const {
return installable_status_;
}
private:
std::u16string title_;
bool is_webapk_compatible_;
bool title_available_;
bool data_available_;
InstallableStatusCode installable_status_;
base::RepeatingClosure quit_closure_;
};
// Builds blink::WebPageMetadata.
mojom::WebPageMetadataPtr BuildDefaultMetadata() {
auto metadata = mojom::WebPageMetadata::New();
metadata->application_name = kWebAppInstallInfoTitle;
return metadata;
}
// Builds WebAPK compatible blink::Manifest.
blink::mojom::ManifestPtr BuildDefaultManifest() {
auto manifest = blink::mojom::Manifest::New();
manifest->name = kDefaultManifestName;
manifest->short_name = kDefaultManifestShortName;
manifest->start_url = GURL(kDefaultStartUrl);
manifest->id = GURL(kDefaultStartUrl);
manifest->display = kDefaultManifestDisplayMode;
blink::Manifest::ImageResource primary_icon;
primary_icon.type = u"image/png";
primary_icon.sizes.push_back(gfx::Size(144, 144));
primary_icon.purpose.push_back(
blink::mojom::ManifestImageResource_Purpose::ANY);
primary_icon.src = GURL(kDefaultIconUrl);
manifest->icons.push_back(primary_icon);
return manifest;
}
} // anonymous namespace
class TestInstallableManager : public InstallableManager {
public:
explicit TestInstallableManager(content::WebContents* web_contents)
: InstallableManager(web_contents) {}
// Mock out the GetData API so we can control exactly what is returned to the
// data fetcher. The order of errors matches | InstallableManager::GetErrors|.
void GetData(const InstallableParams& params,
InstallableCallback callback) override {
if (should_manifest_time_out_) {
return;
}
InitPageData();
// Do not check if in secure content in unittest.
InstallableParams test_params = params;
test_params.check_eligibility = false;
InstallableManager::GetData(test_params, std::move(callback));
}
void SetWebPageMetadata(mojom::WebPageMetadataPtr metadata) {
page_data_->OnPageMetadataFetched(std::move(metadata));
}
void SetManifest(blink::mojom::ManifestPtr manifest) {
if (!manifest->icons.empty()) {
SetPrimaryIcon(manifest->icons[0].src);
}
page_data_->OnManifestFetched(std::move(manifest),
GURL(kDefaultManifestUrl));
}
void SetPrimaryIcon(const GURL& icon_url) {
page_data_->OnPrimaryIconFetched(
icon_url, blink::mojom::ManifestImageResource_Purpose::ANY,
gfx::test::CreateBitmap(kIconSizePx, kIconSizePx));
}
void SetShouldManifestTimeOut(bool should_time_out) {
should_manifest_time_out_ = should_time_out;
}
private:
void InitPageData() {
// Initialize all default values and set "fetched" to be true so the
// installable fetcher won't try to fetch the real data.
if (!page_data_->manifest_fetched()) {
page_data_->OnManifestFetched(blink::mojom::Manifest::New(), GURL(),
MANIFEST_EMPTY);
}
if (!page_data_->web_page_metadata_fetched()) {
page_data_->OnPageMetadataFetched(BuildDefaultMetadata());
}
if (!page_data_->primary_icon_fetched()) {
page_data_->OnPrimaryIconFetchedError(NO_ACCEPTABLE_ICON);
}
if (!page_data_->is_screenshots_fetch_complete()) {
page_data_->OnScreenshotsDownloaded(std::vector<Screenshot>());
}
}
bool should_manifest_time_out_ = false;
};
// Tests AddToHomescreenDataFetcher. These tests should be browser tests but
// Android does not support browser tests yet (crbug.com/611756).
class AddToHomescreenDataFetcherTest
: public content::RenderViewHostTestHarness {
public:
AddToHomescreenDataFetcherTest() {}
AddToHomescreenDataFetcherTest(const AddToHomescreenDataFetcherTest&) =
delete;
AddToHomescreenDataFetcherTest& operator=(
const AddToHomescreenDataFetcherTest&) = delete;
~AddToHomescreenDataFetcherTest() override {}
void SetUp() override {
content::RenderViewHostTestHarness::SetUp();
// Manually inject the TestInstallableManager as a "InstallableManager"
// WebContentsUserData. We can't directly call ::CreateForWebContents due to
// typing issues since TestInstallableManager doesn't directly inherit from
// WebContentsUserData.
web_contents()->SetUserData(
TestInstallableManager::UserDataKey(),
base::WrapUnique(new TestInstallableManager(web_contents())));
installable_manager_ = static_cast<TestInstallableManager*>(
web_contents()->GetUserData(TestInstallableManager::UserDataKey()));
favicon::SetLargeFaviconProviderGetter(base::BindRepeating(
[](favicon::LargeFaviconProvider* provider,
content::BrowserContext* context) { return provider; },
&null_large_favicon_provider_));
NavigateAndCommit(GURL(kDefaultStartUrl));
}
protected:
content::WebContentsTester* web_contents_tester() {
return content::WebContentsTester::For(web_contents());
}
std::unique_ptr<AddToHomescreenDataFetcher> BuildFetcher(
AddToHomescreenDataFetcher::Observer* observer) {
return std::make_unique<AddToHomescreenDataFetcher>(web_contents(), 500,
observer);
}
void RunFetcher(AddToHomescreenDataFetcher* fetcher,
ObserverWaiter& waiter,
const std::u16string& expected_user_title,
const std::u16string& expected_name,
blink::mojom::DisplayMode display_mode,
bool is_webapk_compatible,
InstallableStatusCode status_code) {
waiter.WaitForDataAvailable();
EXPECT_EQ(is_webapk_compatible, waiter.is_webapk_compatible());
EXPECT_TRUE(waiter.title_available());
if (is_webapk_compatible)
EXPECT_EQ(waiter.title(), expected_name);
else
EXPECT_EQ(waiter.title(), expected_user_title);
EXPECT_EQ(fetcher->shortcut_info().user_title, expected_user_title);
EXPECT_EQ(display_mode, fetcher->shortcut_info().display);
EXPECT_EQ(status_code, waiter.installable_status());
}
void RunFetcher(AddToHomescreenDataFetcher* fetcher,
ObserverWaiter& waiter,
const std::u16string& expected_title,
blink::mojom::DisplayMode display_mode,
bool is_webapk_compatible,
InstallableStatusCode status_code) {
RunFetcher(fetcher, waiter, expected_title, expected_title, display_mode,
is_webapk_compatible, status_code);
}
void CheckHistograms(base::HistogramTester& histograms) {
histograms.ExpectTotalCount("Webapp.AddToHomescreenDialog.Timeout", 1);
}
void SetManifest(blink::mojom::ManifestPtr manifest) {
installable_manager_->SetManifest(std::move(manifest));
}
void SetWebPageMetadata(mojom::WebPageMetadataPtr metadata) {
installable_manager_->SetWebPageMetadata(std::move(metadata));
}
void SetPrimaryIcon(const GURL& icon_url) {
installable_manager_->SetPrimaryIcon(icon_url);
}
void SetShouldManifestTimeOut(bool should_time_out) {
installable_manager_->SetShouldManifestTimeOut(should_time_out);
}
base::test::ScopedFeatureList scoped_feature_list_;
private:
class NullLargeFaviconProvider : public favicon::LargeFaviconProvider {
public:
NullLargeFaviconProvider() = default;
virtual ~NullLargeFaviconProvider() = default;
MOCK_METHOD5(GetLargeIconRawBitmapOrFallbackStyleForPageUrl,
base::CancelableTaskTracker::TaskId(
const GURL& page_url,
int min_source_size_in_pixel,
int desired_size_in_pixel,
favicon_base::LargeIconCallback callback,
base::CancelableTaskTracker* tracker));
MOCK_METHOD5(GetLargeIconImageOrFallbackStyleForPageUrl,
base::CancelableTaskTracker::TaskId(
const GURL& page_url,
int min_source_size_in_pixel,
int desired_size_in_pixel,
favicon_base::LargeIconImageCallback callback,
base::CancelableTaskTracker* tracker));
base::CancelableTaskTracker::TaskId GetLargeIconRawBitmapForPageUrl(
const GURL& page_url,
int min_source_size_in_pixel,
favicon_base::FaviconRawBitmapCallback callback,
base::CancelableTaskTracker* tracker) override {
content::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(std::move(callback),
favicon_base::FaviconRawBitmapResult()));
return base::CancelableTaskTracker::kBadTaskId;
}
};
raw_ptr<TestInstallableManager> installable_manager_;
NullLargeFaviconProvider null_large_favicon_provider_;
};
TEST_F(AddToHomescreenDataFetcherTest, EmptyManifest) {
// Check that an empty manifest has the appropriate methods run.
base::HistogramTester histograms;
ObserverWaiter waiter;
std::unique_ptr<AddToHomescreenDataFetcher> fetcher = BuildFetcher(&waiter);
RunFetcher(fetcher.get(), waiter, kWebAppInstallInfoTitle,
blink::mojom::DisplayMode::kBrowser, false,
InstallableStatusCode::MANIFEST_EMPTY);
CheckHistograms(histograms);
}
TEST_F(AddToHomescreenDataFetcherTest, NoIconManifest) {
// Test a manifest with no icons. This should use the short name and have
// a generated icon (empty icon url).
blink::mojom::ManifestPtr manifest = BuildDefaultManifest();
manifest->icons.clear();
SetManifest(std::move(manifest));
base::HistogramTester histograms;
ObserverWaiter waiter;
std::unique_ptr<AddToHomescreenDataFetcher> fetcher = BuildFetcher(&waiter);
RunFetcher(fetcher.get(), waiter, kDefaultManifestShortName,
blink::mojom::DisplayMode::kStandalone, false,
InstallableStatusCode::NO_ACCEPTABLE_ICON);
CheckHistograms(histograms);
EXPECT_TRUE(fetcher->shortcut_info().best_primary_icon_url.is_empty());
EXPECT_TRUE(fetcher->shortcut_info().splash_image_url.is_empty());
}
// Check that the AddToHomescreenDataFetcher::Observer methods are called
// if the first call to InstallableManager::GetData() times out. This should
// fall back to the metadata title and have a non-empty icon (taken from the
// favicon).
TEST_F(AddToHomescreenDataFetcherTest, ManifestFetchTimesOutPwa) {
SetShouldManifestTimeOut(true);
SetManifest(BuildDefaultManifest());
// Check a site where InstallableManager finishes working after the time out
// and determines PWA-ness. This is only relevant when checking WebAPK
// compatibility.
base::HistogramTester histograms;
ObserverWaiter waiter;
std::unique_ptr<AddToHomescreenDataFetcher> fetcher = BuildFetcher(&waiter);
RunFetcher(fetcher.get(), waiter, web_contents()->GetTitle(),
blink::mojom::DisplayMode::kBrowser, false,
InstallableStatusCode::DATA_TIMED_OUT);
CheckHistograms(histograms);
EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
EXPECT_TRUE(fetcher->shortcut_info().best_primary_icon_url.is_empty());
}
TEST_F(AddToHomescreenDataFetcherTest, ManifestFetchTimesOutNonPwa) {
SetShouldManifestTimeOut(true);
SetManifest(BuildDefaultManifest());
// Check where InstallableManager finishes working after the time out and
// determines non-PWA-ness.
base::HistogramTester histograms;
ObserverWaiter waiter;
std::unique_ptr<AddToHomescreenDataFetcher> fetcher = BuildFetcher(&waiter);
RunFetcher(fetcher.get(), waiter, web_contents()->GetTitle(),
blink::mojom::DisplayMode::kBrowser, false,
InstallableStatusCode::DATA_TIMED_OUT);
CheckHistograms(histograms);
EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
EXPECT_TRUE(fetcher->shortcut_info().best_primary_icon_url.is_empty());
}
TEST_F(AddToHomescreenDataFetcherTest, ManifestFetchTimesOutUnknown) {
SetShouldManifestTimeOut(true);
SetManifest(BuildDefaultManifest());
// Check where InstallableManager doesn't finish working after the time out.
base::HistogramTester histograms;
ObserverWaiter waiter;
std::unique_ptr<AddToHomescreenDataFetcher> fetcher = BuildFetcher(&waiter);
RunFetcher(fetcher.get(), waiter, web_contents()->GetTitle(),
blink::mojom::DisplayMode::kBrowser, false,
InstallableStatusCode::DATA_TIMED_OUT);
NavigateAndCommit(GURL("about:blank"));
CheckHistograms(histograms);
EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
EXPECT_TRUE(fetcher->shortcut_info().best_primary_icon_url.is_empty());
}
TEST_F(AddToHomescreenDataFetcherTest, InstallableManifest) {
// Test a site that has valid manifest.
SetManifest(BuildDefaultManifest());
base::HistogramTester histograms;
ObserverWaiter waiter;
std::unique_ptr<AddToHomescreenDataFetcher> fetcher = BuildFetcher(&waiter);
RunFetcher(fetcher.get(), waiter, kDefaultManifestShortName,
kDefaultManifestName, blink::mojom::DisplayMode::kStandalone, true,
InstallableStatusCode::NO_ERROR_DETECTED);
// There should always be a primary icon.
EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url,
GURL(kDefaultIconUrl));
// Check that splash icon url has been selected.
EXPECT_EQ(fetcher->shortcut_info().splash_image_url, GURL(kDefaultIconUrl));
CheckHistograms(histograms);
}
TEST_F(AddToHomescreenDataFetcherTest, ManifestNoNameNoShortName) {
scoped_feature_list_.InitAndDisableFeature(
features::kUniversalInstallManifest);
// Test that when the manifest does not provide either Manifest::short_name
// nor Manifest::name that:
// - The page is not WebAPK compatible.
// - WebAppInstallInfo::title is used as the "name".
// - We still use the icons from the manifest.
blink::mojom::ManifestPtr manifest = BuildDefaultManifest();
manifest->name = absl::nullopt;
manifest->short_name = absl::nullopt;
SetManifest(std::move(manifest));
ObserverWaiter waiter;
std::unique_ptr<AddToHomescreenDataFetcher> fetcher = BuildFetcher(&waiter);
RunFetcher(fetcher.get(), waiter, kWebAppInstallInfoTitle,
blink::mojom::DisplayMode::kStandalone, false,
InstallableStatusCode::MANIFEST_MISSING_NAME_OR_SHORT_NAME);
EXPECT_EQ(fetcher->shortcut_info().name, kWebAppInstallInfoTitle);
EXPECT_EQ(fetcher->shortcut_info().short_name, kWebAppInstallInfoTitle);
EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url,
GURL(kDefaultIconUrl));
}
TEST_F(AddToHomescreenDataFetcherTest,
UniversalInstallManifestNoNameNoShortName) {
scoped_feature_list_.InitAndEnableFeature(
features::kUniversalInstallManifest);
// Test that when the manifest does not provide either Manifest::short_name
// nor Manifest::name but web page metadata provides a application-name.
blink::mojom::ManifestPtr manifest = BuildDefaultManifest();
manifest->name = absl::nullopt;
manifest->short_name = absl::nullopt;
SetManifest(std::move(manifest));
mojom::WebPageMetadataPtr metadata = BuildDefaultMetadata();
SetWebPageMetadata(std::move(metadata));
ObserverWaiter waiter;
std::unique_ptr<AddToHomescreenDataFetcher> fetcher = BuildFetcher(&waiter);
RunFetcher(fetcher.get(), waiter, kWebAppInstallInfoTitle,
blink::mojom::DisplayMode::kStandalone, true,
InstallableStatusCode::NO_ERROR_DETECTED);
EXPECT_EQ(fetcher->shortcut_info().name, kWebAppInstallInfoTitle);
EXPECT_EQ(fetcher->shortcut_info().short_name, kWebAppInstallInfoTitle);
EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url,
GURL(kDefaultIconUrl));
}
TEST_F(AddToHomescreenDataFetcherTest, UniversalInstallNoManifestIcons) {
scoped_feature_list_.InitWithFeatures(
{features::kUniversalInstallManifest, features::kUniversalInstallIcon},
{});
// Test that when the manifest does not provide any icon, we fallback to use
// favicon.
blink::mojom::ManifestPtr manifest = BuildDefaultManifest();
manifest->icons.clear();
SetManifest(std::move(manifest));
std::vector<blink::mojom::FaviconURLPtr> favicon_urls;
favicon_urls.push_back(blink::mojom::FaviconURL::New(
GURL{"http://www.google.com/favicon.ico"},
blink::mojom::FaviconIconType::kFavicon, std::vector<gfx::Size>(),
/*is_default_icon=*/false));
web_contents_tester()->TestSetFaviconURL(mojo::Clone(favicon_urls));
// Fake that |InstallableIconFetcher| fetched the icon correctly.
SetPrimaryIcon(GURL(kDefaultIconUrl));
ObserverWaiter waiter;
std::unique_ptr<AddToHomescreenDataFetcher> fetcher = BuildFetcher(&waiter);
RunFetcher(fetcher.get(), waiter, kDefaultManifestShortName,
kDefaultManifestName, blink::mojom::DisplayMode::kStandalone, true,
InstallableStatusCode::NO_ERROR_DETECTED);
EXPECT_EQ(fetcher->shortcut_info().name, kDefaultManifestName);
EXPECT_EQ(fetcher->shortcut_info().short_name, kDefaultManifestShortName);
EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url,
GURL(kDefaultIconUrl));
}
TEST_F(AddToHomescreenDataFetcherTest, UniversalManifestDisplay) {
scoped_feature_list_.InitAndEnableFeature(
features::kUniversalInstallManifest);
// Test that when the manifest does not provide display mode, we fallback to
// install with DisplayMode::kMinimalUi.
blink::mojom::ManifestPtr manifest = BuildDefaultManifest();
manifest->display = blink::mojom::DisplayMode::kUndefined;
SetManifest(std::move(manifest));
mojom::WebPageMetadataPtr metadata = BuildDefaultMetadata();
SetWebPageMetadata(std::move(metadata));
ObserverWaiter waiter;
std::unique_ptr<AddToHomescreenDataFetcher> fetcher = BuildFetcher(&waiter);
RunFetcher(fetcher.get(), waiter, kDefaultManifestShortName,
kDefaultManifestName, blink::mojom::DisplayMode::kMinimalUi, true,
InstallableStatusCode::NO_ERROR_DETECTED);
EXPECT_EQ(fetcher->shortcut_info().name, kDefaultManifestName);
EXPECT_EQ(fetcher->shortcut_info().short_name, kDefaultManifestShortName);
EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url,
GURL(kDefaultIconUrl));
}
} // namespace webapps
|