Commit 14dca196 authored by dominickn's avatar dominickn Committed by Commit Bot

Improve add to homescreen data fetcher unit tests.

Existing tests for this component don't work. The service worker
registration is for a different browser context, so the tests never
actuallly verify WebAPK-compatibility properly.

This CL revamps the tests by mocking out InstallableManager instead of
WebContents. This allows precise control over the data returned to the
data fetcher so we can verify more scenarios more accurately.

BUG=721881

Review-Url: https://codereview.chromium.org/2960103002
Cr-Commit-Position: refs/heads/master@{#485505}
parent 251d69bb
...@@ -69,40 +69,15 @@ bool IsParamsForPwaCheck(const InstallableParams& params) { ...@@ -69,40 +69,15 @@ bool IsParamsForPwaCheck(const InstallableParams& params) {
DEFINE_WEB_CONTENTS_USER_DATA_KEY(InstallableManager); DEFINE_WEB_CONTENTS_USER_DATA_KEY(InstallableManager);
struct InstallableManager::ManifestProperty { InstallableManager::IconProperty::IconProperty()
InstallableStatusCode error = NO_ERROR_DETECTED; : error(NO_ERROR_DETECTED), url(), icon(), fetched(false) {}
GURL url;
content::Manifest manifest; InstallableManager::IconProperty::IconProperty(IconProperty&& other) = default;
bool fetched = false;
}; InstallableManager::IconProperty::~IconProperty() {}
struct InstallableManager::ValidManifestProperty { InstallableManager::IconProperty& InstallableManager::IconProperty::operator=(
InstallableStatusCode error = NO_ERROR_DETECTED; InstallableManager::IconProperty&& other) = default;
bool is_valid = false;
bool fetched = false;
};
struct InstallableManager::ServiceWorkerProperty {
InstallableStatusCode error = NO_ERROR_DETECTED;
bool has_worker = false;
bool fetched = false;
};
struct InstallableManager::IconProperty {
IconProperty() :
error(NO_ERROR_DETECTED), url(), icon(), fetched(false) { }
IconProperty(IconProperty&& other) = default;
IconProperty& operator=(IconProperty&& other) = default;
InstallableStatusCode error = NO_ERROR_DETECTED;
GURL url;
std::unique_ptr<SkBitmap> icon;
bool fetched;
private:
// This class contains a std::unique_ptr and therefore must be move-only.
DISALLOW_COPY_AND_ASSIGN(IconProperty);
};
InstallableManager::InstallableManager(content::WebContents* web_contents) InstallableManager::InstallableManager(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents), : content::WebContentsObserver(web_contents),
......
...@@ -137,8 +137,8 @@ class InstallableManager ...@@ -137,8 +137,8 @@ class InstallableManager
// at all if a service worker is never registered). // at all if a service worker is never registered).
// //
// Calls requesting data that is already fetched will return the cached data. // Calls requesting data that is already fetched will return the cached data.
void GetData(const InstallableParams& params, virtual void GetData(const InstallableParams& params,
const InstallableCallback& callback); const InstallableCallback& callback);
// Called via AppBannerManagerAndroid to record metrics on how often the // Called via AppBannerManagerAndroid to record metrics on how often the
// installable check is completed when the menu or add to homescreen menu item // installable check is completed when the menu or add to homescreen menu item
...@@ -153,8 +153,10 @@ class InstallableManager ...@@ -153,8 +153,10 @@ class InstallableManager
virtual void OnWaitingForServiceWorker() {} virtual void OnWaitingForServiceWorker() {}
private: private:
friend class AddToHomescreenDataFetcherTest;
friend class InstallableManagerBrowserTest; friend class InstallableManagerBrowserTest;
friend class InstallableManagerUnitTest; friend class InstallableManagerUnitTest;
friend class TestInstallableManager;
FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest,
ManagerBeginsInEmptyState); ManagerBeginsInEmptyState);
FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, CheckWebapp); FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, CheckWebapp);
...@@ -166,10 +168,41 @@ class InstallableManager ...@@ -166,10 +168,41 @@ class InstallableManager
using Task = std::pair<InstallableParams, InstallableCallback>; using Task = std::pair<InstallableParams, InstallableCallback>;
using IconParams = std::tuple<int, int, content::Manifest::Icon::IconPurpose>; using IconParams = std::tuple<int, int, content::Manifest::Icon::IconPurpose>;
struct ManifestProperty; struct ManifestProperty {
struct ValidManifestProperty; InstallableStatusCode error = NO_ERROR_DETECTED;
struct ServiceWorkerProperty; GURL url;
struct IconProperty; content::Manifest manifest;
bool fetched = false;
};
struct ValidManifestProperty {
InstallableStatusCode error = NO_ERROR_DETECTED;
bool is_valid = false;
bool fetched = false;
};
struct ServiceWorkerProperty {
InstallableStatusCode error = NO_ERROR_DETECTED;
bool has_worker = false;
bool is_waiting = false;
bool fetched = false;
};
struct IconProperty {
IconProperty();
IconProperty(IconProperty&& other);
~IconProperty();
IconProperty& operator=(IconProperty&& other);
InstallableStatusCode error;
GURL url;
std::unique_ptr<SkBitmap> icon;
bool fetched;
private:
// This class contains a std::unique_ptr and therefore must be move-only.
DISALLOW_COPY_AND_ASSIGN(IconProperty);
};
// Returns an IconParams object that queries for a primary icon conforming to // Returns an IconParams object that queries for a primary icon conforming to
// the primary icon size parameters in |params|. // the primary icon size parameters in |params|.
......
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