Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Unified Diff: chrome/browser/android/webapps/add_to_homescreen_data_fetcher_unittest.cc

Issue 2960103002: Improve add to homescreen data fetcher unit tests. (Closed)
Patch Set: Comments Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/installable/installable_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/webapps/add_to_homescreen_data_fetcher_unittest.cc
diff --git a/chrome/browser/android/webapps/add_to_homescreen_data_fetcher_unittest.cc b/chrome/browser/android/webapps/add_to_homescreen_data_fetcher_unittest.cc
index ebe6b852474512e45d248f019add558b189a8fd1..b14e0a5df281dbb94b3958e349d8975ba8565081 100644
--- a/chrome/browser/android/webapps/add_to_homescreen_data_fetcher_unittest.cc
+++ b/chrome/browser/android/webapps/add_to_homescreen_data_fetcher_unittest.cc
@@ -7,29 +7,18 @@
#include <memory>
#include <string>
-#include "base/callback_forward.h"
-#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
-#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/strings/nullable_string16.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
-#include "base/time/time.h"
#include "chrome/browser/installable/installable_manager.h"
#include "chrome/common/web_application_info.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
-#include "content/browser/service_worker/embedded_worker_test_helper.h"
-#include "content/browser/service_worker/service_worker_context_core.h"
-#include "content/common/service_worker/service_worker_status_code.h"
-#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/manifest.h"
-#include "content/test/test_web_contents.h"
-#include "net/http/http_status_code.h"
#include "third_party/WebKit/public/platform/WebDisplayMode.h"
#include "ui/gfx/image/image_unittest_util.h"
#include "url/gurl.h"
@@ -38,72 +27,15 @@ namespace {
const char* kWebApplicationInfoTitle = "Meta Title";
const char* kDefaultManifestUrl = "https://www.example.com/manifest.json";
+const char* kDefaultIconUrl = "https://www.example.com/icon.png";
const char* kDefaultManifestName = "Default Name";
const char* kDefaultManifestShortName = "Default Short Name";
const char* kDefaultStartUrl = "https://www.example.com/index.html";
const blink::WebDisplayMode kDefaultManifestDisplayMode =
blink::kWebDisplayModeStandalone;
+const int kIconSizePx = 144;
-// WebContents subclass which mocks out image and manifest fetching.
-class MockWebContents : public content::TestWebContents {
- public:
- explicit MockWebContents(content::BrowserContext* browser_context)
- : content::TestWebContents(browser_context),
- should_image_time_out_(false),
- should_manifest_time_out_(false) {}
-
- ~MockWebContents() override {}
-
- void SetManifest(const GURL& manifest_url,
- const content::Manifest& manifest) {
- manifest_url_ = manifest_url;
- manifest_ = manifest;
- }
-
- int DownloadImage(const GURL& url,
- bool is_favicon,
- uint32_t max_bitmap_size,
- bool bypass_cache,
- const ImageDownloadCallback& callback) override {
- if (should_image_time_out_)
- return 0;
-
- const int kIconSizePx = 144;
- SkBitmap icon = gfx::test::CreateBitmap(kIconSizePx, kIconSizePx);
- std::vector<SkBitmap> icons(1u, icon);
- std::vector<gfx::Size> pixel_sizes(1u, gfx::Size(kIconSizePx, kIconSizePx));
- content::BrowserThread::GetTaskRunnerForThread(content::BrowserThread::UI)
- ->PostTask(FROM_HERE, base::Bind(callback, 0, net::HTTP_OK, url, icons,
- pixel_sizes));
- return 0;
- }
-
- void GetManifest(const GetManifestCallback& callback) override {
- if (should_manifest_time_out_)
- return;
-
- content::BrowserThread::GetTaskRunnerForThread(content::BrowserThread::UI)
- ->PostTask(FROM_HERE, base::Bind(callback, manifest_url_, manifest_));
- }
-
- void SetShouldImageTimeOut(bool should_time_out) {
- should_image_time_out_ = should_time_out;
- }
-
- void SetShouldManifestTimeOut(bool should_time_out) {
- should_manifest_time_out_ = should_time_out;
- }
-
- private:
- GURL manifest_url_;
- content::Manifest manifest_;
- bool should_image_time_out_;
- bool should_manifest_time_out_;
-
- DISALLOW_COPY_AND_ASSIGN(MockWebContents);
-};
-
-// Tracks which of the AddToHomescreenDataFetcher::Observer callbacks have been
+// Tracks which of the AddToHomescreenDataFetcher::Observer methods have been
// called.
class ObserverWaiter : public AddToHomescreenDataFetcher::Observer {
public:
@@ -125,12 +57,16 @@ class ObserverWaiter : public AddToHomescreenDataFetcher::Observer {
}
void OnDidDetermineWebApkCompatibility(bool is_webapk_compatible) override {
+ // This should only be called once.
+ EXPECT_FALSE(determined_webapk_compatibility_);
EXPECT_FALSE(title_available_);
determined_webapk_compatibility_ = true;
is_webapk_compatible_ = is_webapk_compatible;
}
void OnUserTitleAvailable(const base::string16& title) override {
+ // This should only be called once.
+ EXPECT_FALSE(title_available_);
EXPECT_FALSE(data_available_);
title_available_ = true;
title_ = title;
@@ -146,6 +82,8 @@ class ObserverWaiter : public AddToHomescreenDataFetcher::Observer {
void OnDataAvailable(const ShortcutInfo& info,
const SkBitmap& primary_icon,
const SkBitmap& badge_icon) override {
+ // This should only be called once.
+ EXPECT_FALSE(data_available_);
EXPECT_TRUE(title_available_);
data_available_ = true;
if (!quit_closure_.is_null())
@@ -175,10 +113,6 @@ base::NullableString16 NullableStringFromUTF8(const std::string& value) {
return base::NullableString16(base::UTF8ToUTF16(value), false);
}
-content::Manifest BuildEmptyManifest() {
- return content::Manifest();
-}
-
// Builds WebAPK compatible content::Manifest.
content::Manifest BuildDefaultManifest() {
content::Manifest manifest;
@@ -191,7 +125,7 @@ content::Manifest BuildDefaultManifest() {
primary_icon.type = base::ASCIIToUTF16("image/png");
primary_icon.sizes.push_back(gfx::Size(144, 144));
primary_icon.purpose.push_back(content::Manifest::Icon::IconPurpose::ANY);
- primary_icon.src = GURL("https://www.google.com/image.png");
+ primary_icon.src = GURL(kDefaultIconUrl);
manifest.icons.push_back(primary_icon);
return manifest;
@@ -199,6 +133,78 @@ content::Manifest BuildDefaultManifest() {
} // anonymous namespace
+class TestInstallableManager : public InstallableManager {
+ public:
+ explicit TestInstallableManager(content::WebContents* web_contents)
+ : InstallableManager(web_contents) {}
+
+ void GetData(const InstallableParams& params,
+ const InstallableCallback& callback) override {
+ if (should_manifest_time_out_ ||
+ (params.check_installable && should_installable_time_out_)) {
+ return;
+ }
+
+ InstallableStatusCode code = code_;
+ if (params.check_installable) {
+ if (!IsManifestValidForWebApp(manifest_))
+ code = valid_manifest_->error;
+ else if (!is_installable_)
+ code = NO_MATCHING_SERVICE_WORKER;
+ }
+
+ callback.Run(
+ {code, GURL(kDefaultManifestUrl), manifest_,
+ params.fetch_valid_primary_icon ? primary_icon_url_ : GURL(),
+ params.fetch_valid_primary_icon ? primary_icon_.get() : nullptr,
+ params.fetch_valid_badge_icon ? badge_icon_url_ : GURL(),
+ params.fetch_valid_badge_icon ? badge_icon_.get() : nullptr,
+ params.check_installable ? is_installable_ : false});
+ }
+
+ void SetInstallable(bool is_installable) { is_installable_ = is_installable; }
+
+ void SetManifest(const content::Manifest& manifest) {
+ manifest_ = manifest;
+
+ if (manifest.icons.empty()) {
+ code_ = NO_ACCEPTABLE_ICON;
+ is_installable_ = false;
+ } else {
+ primary_icon_url_ = manifest_.icons[0].src;
+ primary_icon_.reset(
+ new SkBitmap(gfx::test::CreateBitmap(kIconSizePx, kIconSizePx)));
+
+ badge_icon_url_ = manifest_.icons[0].src;
+ badge_icon_.reset(
+ new SkBitmap(gfx::test::CreateBitmap(kIconSizePx, kIconSizePx)));
+ code_ = NO_ERROR_DETECTED;
+ is_installable_ = true;
+ }
+ }
+
+ void SetShouldManifestTimeOut(bool should_time_out) {
+ should_manifest_time_out_ = should_time_out;
+ }
+
+ void SetShouldInstallableTimeOut(bool should_time_out) {
+ should_installable_time_out_ = should_time_out;
+ }
+
+ private:
+ InstallableStatusCode code_;
+ content::Manifest manifest_;
+ GURL primary_icon_url_;
+ GURL badge_icon_url_;
+ std::unique_ptr<SkBitmap> primary_icon_;
+ std::unique_ptr<SkBitmap> badge_icon_;
+
+ bool is_installable_ = false;
+
+ bool should_manifest_time_out_ = false;
+ bool should_installable_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 ChromeRenderViewHostTestHarness {
@@ -212,23 +218,15 @@ class AddToHomescreenDataFetcherTest : public ChromeRenderViewHostTestHarness {
ASSERT_TRUE(profile()->CreateHistoryService(false, true));
profile()->CreateFaviconService();
- embedded_worker_test_helper_.reset(
- new content::EmbeddedWorkerTestHelper(base::FilePath()));
-
- scoped_refptr<content::SiteInstance> site_instance =
- content::SiteInstance::Create(browser_context());
- site_instance->GetProcess()->Init();
- MockWebContents* mock_web_contents = new MockWebContents(browser_context());
- mock_web_contents->Init(content::WebContents::CreateParams(
- browser_context(), std::move(site_instance)));
- InstallableManager::CreateForWebContents(mock_web_contents);
- SetContents(mock_web_contents);
- NavigateAndCommit(GURL(kDefaultStartUrl));
- }
-
- void TearDown() override {
- embedded_worker_test_helper_.reset();
- ChromeRenderViewHostTestHarness::TearDown();
+ // 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()));
}
scoped_refptr<AddToHomescreenDataFetcher> BuildFetcher(
@@ -238,50 +236,47 @@ class AddToHomescreenDataFetcherTest : public ChromeRenderViewHostTestHarness {
check_webapk_compatible, observer);
}
- // Set the manifest to be returned as a result of WebContents::GetManifest().
- void SetManifest(const GURL& manifest_url,
- const content::Manifest& manifest) {
- MockWebContents* mock_web_contents =
- static_cast<MockWebContents*>(web_contents());
- mock_web_contents->SetManifest(manifest_url, manifest);
+ void RunFetcher(scoped_refptr<AddToHomescreenDataFetcher> fetcher,
+ ObserverWaiter& waiter,
+ const char* expected_title,
+ blink::WebDisplayMode display_mode,
+ bool is_webapk_compatible) {
+ WebApplicationInfo web_application_info;
+ web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle);
+
+ fetcher->OnDidGetWebApplicationInfo(web_application_info);
+ waiter.WaitForDataAvailable();
+
+ EXPECT_EQ(check_webapk_compatibility(),
+ waiter.determined_webapk_compatibility());
+ EXPECT_EQ(is_webapk_compatible, waiter.is_webapk_compatible());
+ EXPECT_TRUE(waiter.title_available());
+ EXPECT_TRUE(base::EqualsASCII(waiter.title(), expected_title));
+ EXPECT_TRUE(
+ base::EqualsASCII(fetcher->shortcut_info().user_title, expected_title));
+ EXPECT_EQ(display_mode, fetcher->shortcut_info().display);
}
- void SetShouldImageTimeOut(bool should_time_out) {
- MockWebContents* mock_web_contents =
- static_cast<MockWebContents*>(web_contents());
- mock_web_contents->SetShouldImageTimeOut(should_time_out);
+ void SetManifest(const content::Manifest& manifest) {
+ installable_manager_->SetManifest(manifest);
}
- void SetShouldManifestTimeOut(bool should_time_out) {
- MockWebContents* mock_web_contents =
- static_cast<MockWebContents*>(web_contents());
- mock_web_contents->SetShouldManifestTimeOut(should_time_out);
+ void SetInstallable(bool is_installable) {
+ installable_manager_->SetInstallable(is_installable);
}
- // Registers service worker at |url|. Blocks till the service worker is
- // registered.
- void RegisterServiceWorker(const GURL& url) {
- base::RunLoop run_loop;
- embedded_worker_test_helper_->context()->RegisterServiceWorker(
- url, GURL(url.spec() + "/service_worker.js"), nullptr,
- base::Bind(&AddToHomescreenDataFetcherTest::OnServiceWorkerRegistered,
- base::Unretained(this), run_loop.QuitClosure()));
+ void SetShouldManifestTimeOut(bool should_time_out) {
+ installable_manager_->SetShouldManifestTimeOut(should_time_out);
}
- private:
- // Callback for RegisterServiceWorker() for when service worker registration
- // has completed.
- void OnServiceWorkerRegistered(const base::Closure& callback,
- content::ServiceWorkerStatusCode status,
- const std::string& status_message,
- int64_t registration_id) {
- ASSERT_EQ(content::SERVICE_WORKER_OK, status)
- << content::ServiceWorkerStatusToString(status);
- callback.Run();
+ void SetShouldInstallableTimeOut(bool should_time_out) {
+ installable_manager_->SetShouldInstallableTimeOut(should_time_out);
}
- std::unique_ptr<content::EmbeddedWorkerTestHelper>
- embedded_worker_test_helper_;
+ virtual bool check_webapk_compatibility() { return true; }
+
+ private:
+ TestInstallableManager* installable_manager_;
DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcherTest);
};
@@ -303,165 +298,259 @@ class AddToHomescreenDataFetcherTestCommon
// The value of |check_webapk_compatible| used when building the
// AddToHomescreenDataFetcher.
- bool check_webapk_compatibility() { return GetParam(); }
+ bool check_webapk_compatibility() override { return GetParam(); }
private:
DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcherTestCommon);
};
-// Checks that AddToHomescreenDataFetcher::Observer::OnUserTitleAvailable() is
-// called when the web manifest returned is empty. The add-to-homescreen dialog
-// makes the dialog's text field editable once OnUserTitleAvailable() is called.
TEST_P(AddToHomescreenDataFetcherTestCommon, EmptyManifest) {
- WebApplicationInfo web_application_info;
- web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle);
+ // Check that an empty manifest has the appropriate methods run.
+ ObserverWaiter waiter;
+ scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
+ RunFetcher(fetcher, waiter, kWebApplicationInfoTitle,
+ blink::kWebDisplayModeBrowser, false);
+ fetcher->set_weak_observer(nullptr);
+}
- SetManifest(GURL(kDefaultManifestUrl), BuildEmptyManifest());
+TEST_P(AddToHomescreenDataFetcherTestCommon, NoIconManifest) {
+ // Test a manifest with no icons. This should use the metadata title and have
pkotwicz 2017/07/05 21:37:43 The AddToHomescreenDataFetcher uses kDefaultManife
dominickn 2017/07/06 01:44:01 Done.
+ // an empty icon in this test runner (in production the empty icon would be
+ // replaced by a favicon or a generated icon).
+ content::Manifest manifest = BuildDefaultManifest();
+ manifest.icons.clear();
+ SetManifest(manifest);
ObserverWaiter waiter;
scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
- fetcher->OnDidGetWebApplicationInfo(web_application_info);
- waiter.WaitForDataAvailable();
+ RunFetcher(fetcher, waiter, kDefaultManifestShortName,
+ blink::kWebDisplayModeStandalone, false);
- EXPECT_EQ(check_webapk_compatibility(),
- waiter.determined_webapk_compatibility());
- EXPECT_FALSE(waiter.is_webapk_compatible());
- EXPECT_TRUE(waiter.title_available());
- EXPECT_TRUE(base::EqualsASCII(waiter.title(), kWebApplicationInfoTitle));
+ EXPECT_TRUE(fetcher->primary_icon().drawsNothing());
+ EXPECT_TRUE(fetcher->shortcut_info().best_primary_icon_url.is_empty());
+ EXPECT_TRUE(fetcher->badge_icon().drawsNothing());
+ EXPECT_TRUE(fetcher->shortcut_info().best_badge_icon_url.is_empty());
fetcher->set_weak_observer(nullptr);
}
-// Test that when the manifest provides Manifest::short_name but not
-// Manifest::name that Manifest::short_name is used as the name instead of
-// WebApplicationInfo::title.
-TEST_P(AddToHomescreenDataFetcherTestCommon,
- ManifestShortNameClobbersWebApplicationName) {
- WebApplicationInfo web_application_info;
- web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle);
+TEST_P(AddToHomescreenDataFetcherTestCommon, ManifestFetchTimesOut) {
+ // 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 an empty icon.
+ SetShouldManifestTimeOut(true);
+ SetManifest(BuildDefaultManifest());
- content::Manifest manifest(BuildDefaultManifest());
- manifest.name = base::NullableString16();
+ {
+ // Check a site with no service worker.
+ ObserverWaiter waiter;
+ scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
+ RunFetcher(fetcher, waiter, kWebApplicationInfoTitle,
+ blink::kWebDisplayModeBrowser, false);
- RegisterServiceWorker(GURL(kDefaultStartUrl));
- SetManifest(GURL(kDefaultManifestUrl), manifest);
+ EXPECT_TRUE(fetcher->primary_icon().drawsNothing());
+ EXPECT_TRUE(fetcher->shortcut_info().best_primary_icon_url.is_empty());
- ObserverWaiter waiter;
- scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
- fetcher->OnDidGetWebApplicationInfo(web_application_info);
- waiter.WaitForDataAvailable();
+ fetcher->set_weak_observer(nullptr);
+ }
- EXPECT_TRUE(base::EqualsASCII(waiter.title(), kDefaultManifestShortName));
- EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().name,
- kDefaultManifestShortName));
+ {
+ // Check with a service worker present.
pkotwicz 2017/07/05 21:37:43 Lines 346-354 are identical to lines 359-367
dominickn 2017/07/06 01:44:01 Done.
+ ObserverWaiter waiter;
+ scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
+ RunFetcher(fetcher, waiter, kWebApplicationInfoTitle,
+ blink::kWebDisplayModeBrowser, false);
- fetcher->set_weak_observer(nullptr);
-}
+ EXPECT_TRUE(fetcher->primary_icon().drawsNothing());
+ EXPECT_TRUE(fetcher->shortcut_info().best_primary_icon_url.is_empty());
-// Test that when the manifest does not provide either Manifest::short_name nor
-// Manifest::name that:
-// - The page is not WebAPK compatible.
-// - WebApplicationInfo::title is used as the "name".
-TEST_P(AddToHomescreenDataFetcherTestCommon, ManifestNoNameNoShortName) {
- WebApplicationInfo web_application_info;
- web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle);
+ fetcher->set_weak_observer(nullptr);
+ }
+}
- content::Manifest manifest(BuildDefaultManifest());
- manifest.name = base::NullableString16();
- manifest.short_name = base::NullableString16();
+TEST_F(AddToHomescreenDataFetcherTest, ServiceWorkerCheckTimesOut) {
+ {
+ // Check that the AddToHomescreenDataFetcher::Observer methods are called
+ // if the service worker check times out on a page that is installable (i.e.
+ // it's taken too long). This should use the short_name and icon from the
+ // manifest, but not be WebAPK-compatible. Only relevant when checking
+ // WebAPK compatibility.
+ SetManifest(BuildDefaultManifest());
+ SetShouldInstallableTimeOut(true);
+
+ ObserverWaiter waiter;
+ scoped_refptr<AddToHomescreenDataFetcher> fetcher(
+ BuildFetcher(true, &waiter));
+ RunFetcher(fetcher, waiter, kDefaultManifestShortName,
+ blink::kWebDisplayModeStandalone, false);
+
+ EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
+ EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url,
+ GURL(kDefaultIconUrl));
+
+ fetcher->set_weak_observer(nullptr);
+ }
- RegisterServiceWorker(GURL(kDefaultStartUrl));
- SetManifest(GURL(kDefaultManifestUrl), manifest);
+ {
+ // Check the case where the service worker check times out because the
+ // service worker doesn't exist.
+ SetInstallable(false);
+ SetShouldInstallableTimeOut(true);
pkotwicz 2017/07/05 21:37:43 Remove call to SetInstallable(false) because SetSh
dominickn 2017/07/06 01:44:01 Done.
- ObserverWaiter waiter;
- scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
- fetcher->OnDidGetWebApplicationInfo(web_application_info);
- waiter.WaitForDataAvailable();
+ ObserverWaiter waiter;
+ scoped_refptr<AddToHomescreenDataFetcher> fetcher(
+ BuildFetcher(true, &waiter));
+ RunFetcher(fetcher, waiter, kDefaultManifestShortName,
+ blink::kWebDisplayModeStandalone, false);
- EXPECT_EQ(check_webapk_compatibility(),
- waiter.determined_webapk_compatibility());
- EXPECT_FALSE(waiter.is_webapk_compatible());
- EXPECT_TRUE(base::EqualsASCII(waiter.title(), kWebApplicationInfoTitle));
- EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().name,
- kWebApplicationInfoTitle));
+ EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
+ EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url,
+ GURL(kDefaultIconUrl));
- fetcher->set_weak_observer(nullptr);
+ fetcher->set_weak_observer(nullptr);
+ }
}
-// Checks that the AddToHomescreenDataFetcher::Observer callbacks are called
-// when the manifest fetch times out.
-TEST_P(AddToHomescreenDataFetcherTestCommon, ManifestFetchTimesOut) {
- WebApplicationInfo web_application_info;
- web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle);
-
- RegisterServiceWorker(GURL(kDefaultStartUrl));
- SetManifest(GURL(kDefaultManifestUrl), BuildDefaultManifest());
- SetShouldManifestTimeOut(true);
- SetShouldImageTimeOut(false);
+TEST_P(AddToHomescreenDataFetcherTestCommon, InstallableManifest) {
+ // Test an installable manifest for a site that has a service worker.
+ content::Manifest manifest(BuildDefaultManifest());
+ SetManifest(manifest);
ObserverWaiter waiter;
scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
- fetcher->OnDidGetWebApplicationInfo(web_application_info);
- waiter.WaitForDataAvailable();
-
- EXPECT_EQ(check_webapk_compatibility(),
- waiter.determined_webapk_compatibility());
- EXPECT_FALSE(waiter.is_webapk_compatible());
- EXPECT_TRUE(base::EqualsASCII(waiter.title(), kWebApplicationInfoTitle));
- EXPECT_TRUE(waiter.title_available());
+ RunFetcher(fetcher, waiter, kDefaultManifestShortName,
+ blink::kWebDisplayModeStandalone, check_webapk_compatibility());
+
+ // There should always be a primary icon. The badge icon should only be
+ // present if we checked for WebAPK compatibility.
+ EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
+ EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url,
+ GURL(kDefaultIconUrl));
+
+ // Check that the badge icon is requested only when AddToHomescreenDataFetcher
+ // checks for WebAPK compatibility.
+ if (check_webapk_compatibility()) {
+ EXPECT_FALSE(fetcher->badge_icon().drawsNothing());
+ EXPECT_EQ(fetcher->shortcut_info().best_badge_icon_url,
+ GURL(kDefaultIconUrl));
+ } else {
+ EXPECT_TRUE(fetcher->badge_icon().drawsNothing());
+ EXPECT_TRUE(fetcher->shortcut_info().best_badge_icon_url.is_empty());
+ }
fetcher->set_weak_observer(nullptr);
}
-// Checks that the AddToHomescreenDataFetcher::Observer callbacks are called
-// when the image fetch times out.
-TEST_P(AddToHomescreenDataFetcherTestCommon, ImageFetchTimesOut) {
- WebApplicationInfo web_application_info;
- web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle);
+TEST_P(AddToHomescreenDataFetcherTestCommon,
+ ManifestNameClobbersWebApplicationName) {
+ // Test that when the manifest provides Manifest::name but not
+ // Manifest::short_name that Manifest::name is used as the title.
+ {
+ // Check the case where we have no icons.
+ content::Manifest manifest = BuildDefaultManifest();
+ manifest.icons.clear();
+ manifest.short_name = base::NullableString16();
+ SetManifest(manifest);
+
+ ObserverWaiter waiter;
+ scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
+ RunFetcher(fetcher, waiter, kDefaultManifestName,
+ blink::kWebDisplayModeStandalone, false);
+
+ EXPECT_TRUE(fetcher->primary_icon().drawsNothing());
+ EXPECT_TRUE(fetcher->shortcut_info().best_primary_icon_url.is_empty());
+ EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().short_name,
+ kDefaultManifestName));
+
+ fetcher->set_weak_observer(nullptr);
+ }
- RegisterServiceWorker(GURL(kDefaultStartUrl));
- SetManifest(GURL(kDefaultManifestUrl), BuildDefaultManifest());
- SetShouldManifestTimeOut(false);
- SetShouldImageTimeOut(true);
+ {
+ // Check a site with no service worker.
+ content::Manifest manifest(BuildDefaultManifest());
+ manifest.short_name = base::NullableString16();
+ SetManifest(manifest);
pkotwicz 2017/07/05 21:37:43 Nit: Can you move the manifest construction out of
dominickn 2017/07/06 01:44:01 Done.
+ SetShouldInstallableTimeOut(true);
+ SetInstallable(false);
pkotwicz 2017/07/05 21:37:43 Nit: Remove call to SetInstallable(false) because
dominickn 2017/07/06 01:44:01 Done.
dominickn 2017/07/06 01:44:01 Done.
+
+ ObserverWaiter waiter;
+ scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
+ RunFetcher(fetcher, waiter, kDefaultManifestName,
+ blink::kWebDisplayModeStandalone, false);
+
+ EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
+ EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url,
+ GURL(kDefaultIconUrl));
+ EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().short_name,
+ kDefaultManifestName));
+
+ fetcher->set_weak_observer(nullptr);
+ }
- ObserverWaiter waiter;
- scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
- fetcher->OnDidGetWebApplicationInfo(web_application_info);
- waiter.WaitForDataAvailable();
+ {
+ // Check a site with a service worker, but the service worker check times
+ // out because its too slow.
+ SetShouldInstallableTimeOut(true);
+ SetInstallable(true);
- EXPECT_EQ(check_webapk_compatibility(),
- waiter.determined_webapk_compatibility());
- EXPECT_FALSE(waiter.is_webapk_compatible());
- EXPECT_TRUE(waiter.title_available());
- EXPECT_TRUE(base::EqualsASCII(waiter.title(), kWebApplicationInfoTitle));
+ ObserverWaiter waiter;
+ scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
+ RunFetcher(fetcher, waiter, kDefaultManifestName,
+ blink::kWebDisplayModeStandalone, false);
- fetcher->set_weak_observer(nullptr);
-}
+ EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
+ EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url,
+ GURL(kDefaultIconUrl));
+ EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().short_name,
+ kDefaultManifestName));
-// Checks that the AddToHomescreenDataFetcher::Observer callbacks are called
-// when the service worker check times out.
-TEST_P(AddToHomescreenDataFetcherTestCommon, ServiceWorkerCheckTimesOut) {
- WebApplicationInfo web_application_info;
- web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle);
+ fetcher->set_weak_observer(nullptr);
+ }
- // Not registering a service worker means we'll wait and time out for the
- // worker.
- SetManifest(GURL(kDefaultManifestUrl), BuildDefaultManifest());
- SetShouldManifestTimeOut(false);
- SetShouldImageTimeOut(false);
+ {
+ // Check a site with a service worker.
+ SetShouldInstallableTimeOut(false);
+ SetInstallable(true);
+ ObserverWaiter waiter;
+ scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
+ RunFetcher(fetcher, waiter, kDefaultManifestName,
+ blink::kWebDisplayModeStandalone, check_webapk_compatibility());
+
+ EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
+ EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url,
+ GURL(kDefaultIconUrl));
+ EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().short_name,
+ kDefaultManifestName));
+
+ fetcher->set_weak_observer(nullptr);
+ }
+}
+TEST_P(AddToHomescreenDataFetcherTestCommon, ManifestNoNameNoShortName) {
+ // Test that when the manifest does not provide either Manifest::short_name
+ // nor Manifest::name that:
+ // - The page is not WebAPK compatible.
+ // - WebApplicationInfo::title is used as the "name".
+ // - We still use the icons from the manifest.
+ content::Manifest manifest(BuildDefaultManifest());
+ manifest.name = base::NullableString16();
+ manifest.short_name = base::NullableString16();
+
+ // Check the case where we don't time out waiting for the service worker.
+ SetManifest(manifest);
+ SetShouldInstallableTimeOut(false);
ObserverWaiter waiter;
scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter));
- fetcher->OnDidGetWebApplicationInfo(web_application_info);
- waiter.WaitForDataAvailable();
-
- EXPECT_EQ(check_webapk_compatibility(),
- waiter.determined_webapk_compatibility());
- EXPECT_FALSE(waiter.is_webapk_compatible());
- EXPECT_TRUE(waiter.title_available());
- EXPECT_TRUE(base::EqualsASCII(waiter.title(), kDefaultManifestShortName));
- EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().user_title,
- kDefaultManifestShortName));
+ RunFetcher(fetcher, waiter, kWebApplicationInfoTitle,
+ blink::kWebDisplayModeStandalone, false);
+
+ EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().name,
+ kWebApplicationInfoTitle));
+ EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().short_name,
+ kWebApplicationInfoTitle));
+ EXPECT_FALSE(fetcher->primary_icon().drawsNothing());
+ EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url,
+ GURL(kDefaultIconUrl));
fetcher->set_weak_observer(nullptr);
}
« no previous file with comments | « no previous file | chrome/browser/installable/installable_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698