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) {
DEFINE_WEB_CONTENTS_USER_DATA_KEY(InstallableManager);
struct InstallableManager::ManifestProperty {
InstallableStatusCode error = NO_ERROR_DETECTED;
GURL url;
content::Manifest manifest;
bool fetched = false;
};
struct InstallableManager::ValidManifestProperty {
InstallableStatusCode error = NO_ERROR_DETECTED;
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::IconProperty::IconProperty()
: error(NO_ERROR_DETECTED), url(), icon(), fetched(false) {}
InstallableManager::IconProperty::IconProperty(IconProperty&& other) = default;
InstallableManager::IconProperty::~IconProperty() {}
InstallableManager::IconProperty& InstallableManager::IconProperty::operator=(
InstallableManager::IconProperty&& other) = default;
InstallableManager::InstallableManager(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
......
......@@ -137,8 +137,8 @@ class InstallableManager
// at all if a service worker is never registered).
//
// Calls requesting data that is already fetched will return the cached data.
void GetData(const InstallableParams& params,
const InstallableCallback& callback);
virtual void GetData(const InstallableParams& params,
const InstallableCallback& callback);
// Called via AppBannerManagerAndroid to record metrics on how often the
// installable check is completed when the menu or add to homescreen menu item
......@@ -153,8 +153,10 @@ class InstallableManager
virtual void OnWaitingForServiceWorker() {}
private:
friend class AddToHomescreenDataFetcherTest;
friend class InstallableManagerBrowserTest;
friend class InstallableManagerUnitTest;
friend class TestInstallableManager;
FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest,
ManagerBeginsInEmptyState);
FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, CheckWebapp);
......@@ -166,10 +168,41 @@ class InstallableManager
using Task = std::pair<InstallableParams, InstallableCallback>;
using IconParams = std::tuple<int, int, content::Manifest::Icon::IconPurpose>;
struct ManifestProperty;
struct ValidManifestProperty;
struct ServiceWorkerProperty;
struct IconProperty;
struct ManifestProperty {
InstallableStatusCode error = NO_ERROR_DETECTED;
GURL url;
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
// 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