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..869a24b3786a7559c515c49db9825475e6f82b2e 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,70 +27,13 @@ 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; |
- |
-// 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); |
-}; |
+const int kIconSizePx = 144; |
// Tracks which of the AddToHomescreenDataFetcher::Observer callbacks have been |
// called. |
@@ -175,18 +107,20 @@ 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 BuildNoIconManifest() { |
content::Manifest manifest; |
manifest.name = NullableStringFromUTF8(kDefaultManifestName); |
manifest.short_name = NullableStringFromUTF8(kDefaultManifestShortName); |
manifest.start_url = GURL(kDefaultStartUrl); |
manifest.display = kDefaultManifestDisplayMode; |
+ return manifest; |
+} |
+ |
+// Builds WebAPK compatible content::Manifest. |
+content::Manifest BuildDefaultManifest() { |
+ content::Manifest manifest = BuildNoIconManifest(); |
+ |
content::Manifest::Icon primary_icon; |
primary_icon.type = base::ASCIIToUTF16("image/png"); |
primary_icon.sizes.push_back(gfx::Size(144, 144)); |
@@ -199,6 +133,74 @@ 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, manifest_url_, manifest_, primary_icon_url_, |
+ &primary_icon_, badge_icon_url_, &badge_icon_, |
+ params.check_installable ? is_installable_ : false}); |
pkotwicz
2017/06/28 18:17:02
For the sake of clarity, you should only return a
|
+ } |
+ |
+ void SetStatus(InstallableStatusCode code, bool is_installable) { |
+ code_ = code; |
+ is_installable_ = is_installable; |
+ } |
+ |
+ void SetManifest(const GURL& url, const content::Manifest& manifest) { |
+ manifest_url_ = url; |
+ manifest_ = manifest; |
+ } |
+ |
+ void SetPrimaryIcon(const GURL& url, const SkBitmap& icon) { |
+ primary_icon_url_ = url; |
+ primary_icon_ = icon; |
+ } |
+ |
+ void SetBadgeIcon(const GURL& url, const SkBitmap& icon) { |
+ badge_icon_url_ = url; |
+ badge_icon_ = icon; |
+ } |
+ |
+ 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 manifest_url_; |
+ GURL primary_icon_url_; |
+ GURL badge_icon_url_; |
+ SkBitmap primary_icon_; |
+ 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 +214,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 +232,41 @@ 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 SetManifest(const content::Manifest& manifest) { |
+ installable_manager_->SetManifest(GURL(kDefaultManifestUrl), manifest); |
+ installable_manager_->SetStatus(NO_ERROR_DETECTED, false); |
} |
- void SetShouldImageTimeOut(bool should_time_out) { |
- MockWebContents* mock_web_contents = |
- static_cast<MockWebContents*>(web_contents()); |
- mock_web_contents->SetShouldImageTimeOut(should_time_out); |
+ void SetManifestAndIcons(const content::Manifest& manifest) { |
+ SetManifest(manifest); |
+ installable_manager_->SetPrimaryIcon( |
+ GURL(kDefaultIconUrl), |
+ gfx::test::CreateBitmap(kIconSizePx, kIconSizePx)); |
+ installable_manager_->SetStatus(NO_ERROR_DETECTED, false); |
} |
- void SetShouldManifestTimeOut(bool should_time_out) { |
- MockWebContents* mock_web_contents = |
- static_cast<MockWebContents*>(web_contents()); |
- mock_web_contents->SetShouldManifestTimeOut(should_time_out); |
+ void SetInstallable(const content::Manifest& manifest) { |
+ SetManifestAndIcons(manifest); |
+ installable_manager_->SetStatus(NO_ERROR_DETECTED, true); |
} |
- // 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 SetWebApkInstallable(const content::Manifest& manifest) { |
+ SetInstallable(manifest); |
+ installable_manager_->SetBadgeIcon( |
+ GURL(kDefaultIconUrl), |
+ gfx::test::CreateBitmap(kIconSizePx, kIconSizePx)); |
} |
- 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 SetShouldManifestTimeOut(bool should_time_out) { |
+ installable_manager_->SetShouldManifestTimeOut(should_time_out); |
+ } |
+ |
+ void SetShouldInstallableTimeOut(bool should_time_out) { |
+ installable_manager_->SetShouldInstallableTimeOut(should_time_out); |
} |
- std::unique_ptr<content::EmbeddedWorkerTestHelper> |
- embedded_worker_test_helper_; |
+ private: |
+ TestInstallableManager* installable_manager_; |
DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDataFetcherTest); |
}; |
@@ -316,8 +301,6 @@ TEST_P(AddToHomescreenDataFetcherTestCommon, EmptyManifest) { |
WebApplicationInfo web_application_info; |
web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle); |
- SetManifest(GURL(kDefaultManifestUrl), BuildEmptyManifest()); |
- |
ObserverWaiter waiter; |
scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter)); |
fetcher->OnDidGetWebApplicationInfo(web_application_info); |
@@ -332,110 +315,269 @@ TEST_P(AddToHomescreenDataFetcherTestCommon, EmptyManifest) { |
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) { |
+// Test a manifest with no icons. |
+TEST_P(AddToHomescreenDataFetcherTestCommon, NoIconManifest) { |
WebApplicationInfo web_application_info; |
web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle); |
pkotwicz
2017/06/28 18:17:02
Given that there is only a single caller to BuildN
pkotwicz
2017/06/29 19:22:05
Ping on this comment
dominickn
2017/06/30 02:42:30
Somehow missed this. Done.
|
- content::Manifest manifest(BuildDefaultManifest()); |
- manifest.name = base::NullableString16(); |
- |
- RegisterServiceWorker(GURL(kDefaultStartUrl)); |
- SetManifest(GURL(kDefaultManifestUrl), manifest); |
+ SetManifest(BuildNoIconManifest()); |
ObserverWaiter waiter; |
scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter)); |
fetcher->OnDidGetWebApplicationInfo(web_application_info); |
waiter.WaitForDataAvailable(); |
+ EXPECT_TRUE(waiter.title_available()); |
EXPECT_TRUE(base::EqualsASCII(waiter.title(), kDefaultManifestShortName)); |
- EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().name, |
+ EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().user_title, |
kDefaultManifestShortName)); |
- |
+ EXPECT_TRUE(fetcher->primary_icon().drawsNothing()); |
+ EXPECT_TRUE(fetcher->shortcut_info().best_primary_icon_url.is_empty()); |
+ EXPECT_EQ(check_webapk_compatibility(), |
+ waiter.determined_webapk_compatibility()); |
+ EXPECT_FALSE(waiter.is_webapk_compatible()); |
+ 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 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) { |
+// Test an installable manifest with and without a service worker. |
+TEST_P(AddToHomescreenDataFetcherTestCommon, NonInstallableManifest) { |
WebApplicationInfo web_application_info; |
web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle); |
content::Manifest manifest(BuildDefaultManifest()); |
- manifest.name = base::NullableString16(); |
- manifest.short_name = base::NullableString16(); |
- RegisterServiceWorker(GURL(kDefaultStartUrl)); |
- SetManifest(GURL(kDefaultManifestUrl), manifest); |
+ { |
+ SetManifestAndIcons(manifest); |
+ |
+ ObserverWaiter waiter; |
+ scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter)); |
+ fetcher->OnDidGetWebApplicationInfo(web_application_info); |
+ waiter.WaitForDataAvailable(); |
+ |
+ EXPECT_TRUE(waiter.title_available()); |
+ EXPECT_TRUE(base::EqualsASCII(waiter.title(), kDefaultManifestShortName)); |
+ EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().user_title, |
+ kDefaultManifestShortName)); |
+ EXPECT_FALSE(fetcher->primary_icon().drawsNothing()); |
+ EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url, |
+ GURL(kDefaultIconUrl)); |
+ EXPECT_EQ(check_webapk_compatibility(), |
+ waiter.determined_webapk_compatibility()); |
+ EXPECT_FALSE(waiter.is_webapk_compatible()); |
+ EXPECT_TRUE(fetcher->badge_icon().drawsNothing()); |
+ EXPECT_TRUE(fetcher->shortcut_info().best_badge_icon_url.is_empty()); |
+ fetcher->set_weak_observer(nullptr); |
+ } |
+ |
+ { |
+ SetInstallable(manifest); |
+ |
+ ObserverWaiter waiter; |
+ scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter)); |
+ fetcher->OnDidGetWebApplicationInfo(web_application_info); |
+ waiter.WaitForDataAvailable(); |
+ |
+ EXPECT_TRUE(waiter.title_available()); |
+ EXPECT_TRUE(base::EqualsASCII(waiter.title(), kDefaultManifestShortName)); |
+ EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().user_title, |
+ kDefaultManifestShortName)); |
+ EXPECT_FALSE(fetcher->primary_icon().drawsNothing()); |
+ EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url, |
+ GURL(kDefaultIconUrl)); |
+ EXPECT_EQ(check_webapk_compatibility(), |
+ waiter.determined_webapk_compatibility()); |
+ EXPECT_EQ(check_webapk_compatibility(), waiter.is_webapk_compatible()); |
+ EXPECT_TRUE(fetcher->badge_icon().drawsNothing()); |
+ EXPECT_TRUE(fetcher->shortcut_info().best_badge_icon_url.is_empty()); |
+ fetcher->set_weak_observer(nullptr); |
+ } |
+} |
+ |
+// Test a WebAPK compatible manifest, including badge icon, on an installable |
+// site. |
+TEST_P(AddToHomescreenDataFetcherTestCommon, WebApkCompatibleManifest) { |
+ WebApplicationInfo web_application_info; |
+ web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle); |
+ |
+ content::Manifest manifest(BuildDefaultManifest()); |
+ SetWebApkInstallable(manifest); |
ObserverWaiter waiter; |
scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter)); |
fetcher->OnDidGetWebApplicationInfo(web_application_info); |
waiter.WaitForDataAvailable(); |
+ EXPECT_TRUE(waiter.title_available()); |
+ EXPECT_TRUE(base::EqualsASCII(waiter.title(), kDefaultManifestShortName)); |
+ EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().user_title, |
+ kDefaultManifestShortName)); |
+ EXPECT_FALSE(fetcher->primary_icon().drawsNothing()); |
+ EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url, |
+ GURL(kDefaultIconUrl)); |
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)); |
- |
+ if (check_webapk_compatibility()) { |
+ EXPECT_TRUE(waiter.is_webapk_compatible()); |
+ EXPECT_FALSE(fetcher->badge_icon().drawsNothing()); |
+ EXPECT_EQ(fetcher->shortcut_info().best_badge_icon_url, |
+ GURL(kDefaultIconUrl)); |
+ } |
fetcher->set_weak_observer(nullptr); |
} |
-// Checks that the AddToHomescreenDataFetcher::Observer callbacks are called |
-// when the manifest fetch times out. |
-TEST_P(AddToHomescreenDataFetcherTestCommon, ManifestFetchTimesOut) { |
+// 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); |
- RegisterServiceWorker(GURL(kDefaultStartUrl)); |
- SetManifest(GURL(kDefaultManifestUrl), BuildDefaultManifest()); |
- SetShouldManifestTimeOut(true); |
- SetShouldImageTimeOut(false); |
- |
- ObserverWaiter waiter; |
- scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter)); |
- fetcher->OnDidGetWebApplicationInfo(web_application_info); |
- waiter.WaitForDataAvailable(); |
+ content::Manifest manifest(BuildDefaultManifest()); |
+ manifest.name = base::NullableString16(); |
- 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()); |
+ { |
+ SetManifestAndIcons(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_TRUE(waiter.title_available()); |
+ EXPECT_TRUE(base::EqualsASCII(waiter.title(), kDefaultManifestShortName)); |
+ EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().name, |
+ kDefaultManifestShortName)); |
+ 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); |
+ { |
+ SetInstallable(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_TRUE(waiter.title_available()); |
+ EXPECT_TRUE(base::EqualsASCII(waiter.title(), kDefaultManifestShortName)); |
+ EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().name, |
+ kDefaultManifestShortName)); |
+ EXPECT_FALSE(fetcher->primary_icon().drawsNothing()); |
+ EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url, |
+ GURL(kDefaultIconUrl)); |
+ |
+ fetcher->set_weak_observer(nullptr); |
+ } |
} |
-// Checks that the AddToHomescreenDataFetcher::Observer callbacks are called |
-// when the image fetch times out. |
-TEST_P(AddToHomescreenDataFetcherTestCommon, ImageFetchTimesOut) { |
+// 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. |
+TEST_P(AddToHomescreenDataFetcherTestCommon, ManifestNoNameNoShortName) { |
WebApplicationInfo web_application_info; |
web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle); |
- RegisterServiceWorker(GURL(kDefaultStartUrl)); |
- SetManifest(GURL(kDefaultManifestUrl), BuildDefaultManifest()); |
- SetShouldManifestTimeOut(false); |
- SetShouldImageTimeOut(true); |
+ content::Manifest manifest(BuildDefaultManifest()); |
+ manifest.name = base::NullableString16(); |
+ manifest.short_name = base::NullableString16(); |
- ObserverWaiter waiter; |
- scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter)); |
- fetcher->OnDidGetWebApplicationInfo(web_application_info); |
- waiter.WaitForDataAvailable(); |
+ { |
+ SetManifestAndIcons(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_TRUE(waiter.title_available()); |
+ 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); |
+ } |
- 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)); |
+ { |
+ SetInstallable(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_TRUE(waiter.title_available()); |
+ 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 first call to InstallableManager::GetData times out. |
+TEST_P(AddToHomescreenDataFetcherTestCommon, ManifestFetchTimesOut) { |
+ WebApplicationInfo web_application_info; |
+ web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle); |
+ SetShouldManifestTimeOut(true); |
+ |
+ { |
+ // Check with a site that doesn't have a service worker. |
+ SetManifestAndIcons(BuildDefaultManifest()); |
+ 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_TRUE(waiter.title_available()); |
+ EXPECT_FALSE(waiter.is_webapk_compatible()); |
+ EXPECT_TRUE(base::EqualsASCII(waiter.title(), kWebApplicationInfoTitle)); |
+ |
+ EXPECT_TRUE(fetcher->primary_icon().drawsNothing()); |
+ EXPECT_TRUE(fetcher->shortcut_info().best_primary_icon_url.is_empty()); |
+ fetcher->set_weak_observer(nullptr); |
+ } |
+ |
+ { |
+ // Check with a site that passes the PWA check. |
+ SetInstallable(BuildDefaultManifest()); |
+ 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_TRUE(waiter.title_available()); |
+ EXPECT_FALSE(waiter.is_webapk_compatible()); |
+ EXPECT_TRUE(base::EqualsASCII(waiter.title(), kWebApplicationInfoTitle)); |
+ |
+ EXPECT_TRUE(fetcher->primary_icon().drawsNothing()); |
+ EXPECT_TRUE(fetcher->shortcut_info().best_primary_icon_url.is_empty()); |
+ fetcher->set_weak_observer(nullptr); |
+ } |
} |
// Checks that the AddToHomescreenDataFetcher::Observer callbacks are called |
@@ -444,11 +586,8 @@ TEST_P(AddToHomescreenDataFetcherTestCommon, ServiceWorkerCheckTimesOut) { |
WebApplicationInfo web_application_info; |
web_application_info.title = base::UTF8ToUTF16(kWebApplicationInfoTitle); |
- // Not registering a service worker means we'll wait and time out for the |
- // worker. |
- SetManifest(GURL(kDefaultManifestUrl), BuildDefaultManifest()); |
- SetShouldManifestTimeOut(false); |
- SetShouldImageTimeOut(false); |
+ SetInstallable(BuildDefaultManifest()); |
+ SetShouldInstallableTimeOut(true); |
ObserverWaiter waiter; |
scoped_refptr<AddToHomescreenDataFetcher> fetcher(BuildFetcher(&waiter)); |
@@ -457,12 +596,16 @@ TEST_P(AddToHomescreenDataFetcherTestCommon, ServiceWorkerCheckTimesOut) { |
EXPECT_EQ(check_webapk_compatibility(), |
waiter.determined_webapk_compatibility()); |
- EXPECT_FALSE(waiter.is_webapk_compatible()); |
EXPECT_TRUE(waiter.title_available()); |
+ EXPECT_FALSE(waiter.is_webapk_compatible()); |
EXPECT_TRUE(base::EqualsASCII(waiter.title(), kDefaultManifestShortName)); |
EXPECT_TRUE(base::EqualsASCII(fetcher->shortcut_info().user_title, |
kDefaultManifestShortName)); |
+ EXPECT_FALSE(fetcher->primary_icon().drawsNothing()); |
+ EXPECT_EQ(fetcher->shortcut_info().best_primary_icon_url, |
+ GURL(kDefaultIconUrl)); |
+ |
fetcher->set_weak_observer(nullptr); |
} |