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

Unified Diff: third_party/WebKit/Source/modules/notifications/NotificationResourcesLoaderTest.cpp

Issue 1904163002: Move Web Notifications to use Mojo Base URL: https://chromium.googlesource.com/chromium/src.git@skbitmap-blink
Patch Set: it works \o/ Created 4 years, 8 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
Index: third_party/WebKit/Source/modules/notifications/NotificationResourcesLoaderTest.cpp
diff --git a/third_party/WebKit/Source/modules/notifications/NotificationResourcesLoaderTest.cpp b/third_party/WebKit/Source/modules/notifications/NotificationResourcesLoaderTest.cpp
index cd82f45d349dc5c5bd82ba37f3185bce26259372..561352bd37089ddf203c209830c1e345a13fda13 100644
--- a/third_party/WebKit/Source/modules/notifications/NotificationResourcesLoaderTest.cpp
+++ b/third_party/WebKit/Source/modules/notifications/NotificationResourcesLoaderTest.cpp
@@ -6,6 +6,7 @@
#include "core/fetch/MemoryCache.h"
#include "core/testing/DummyPageHolder.h"
+#include "platform/bitmap_type_converters.h"
#include "platform/heap/Heap.h"
#include "platform/testing/URLTestHelpers.h"
#include "platform/weborigin/KURL.h"
@@ -13,8 +14,8 @@
#include "public/platform/WebURL.h"
#include "public/platform/WebURLLoaderMockFactory.h"
#include "public/platform/WebURLResponse.h"
-#include "public/platform/modules/notifications/WebNotificationData.h"
-#include "public/platform/modules/notifications/WebNotificationResources.h"
+#include "public/platform/modules/notifications/notification.mojom-blink.h"
+#include "public/platform/modules/notifications/notification_resources.mojom-blink.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "wtf/Functional.h"
#include "wtf/text/WTFString.h"
@@ -37,7 +38,7 @@ const int kMaxActionIconSizePx = 128;
class NotificationResourcesLoaderTest : public ::testing::Test {
public:
NotificationResourcesLoaderTest()
- : m_page(DummyPageHolder::create()), m_loader(new NotificationResourcesLoader(bind<NotificationResourcesLoader*>(&NotificationResourcesLoaderTest::didFetchResources, this)))
+ : m_page(DummyPageHolder::create()), m_loader(new NotificationResourcesLoader(bind<NotificationResourcesLoader*, mojom::blink::NotificationPtr>(&NotificationResourcesLoaderTest::didFetchResources, this)))
{
}
@@ -49,20 +50,40 @@ public:
}
protected:
+ // Structure for representing the resources loaded by the resource loader as
+ // SkBitmap, as opposed to the Mojo Bitmap type.
+ struct Resources {
+ SkBitmap icon;
+ SkBitmap badge;
+ WTF::Vector<SkBitmap> actionIcons;
+ };
+
ExecutionContext* executionContext() const { return &m_page->document(); }
NotificationResourcesLoader* loader() const { return m_loader.get(); }
- WebNotificationResources* resources() const { return m_resources.get(); }
+ bool hasResources() const { return m_hasResources; }
+
+ const Resources* resources() const { return &m_resources; }
- void didFetchResources(NotificationResourcesLoader* loader)
+ void didFetchResources(NotificationResourcesLoader* loader, mojom::blink::NotificationPtr /* notification */)
{
- m_resources = loader->getResources();
+ mojom::blink::NotificationResourcesPtr resources = loader->getResources();
+ DCHECK(resources);
+
+ m_resources.icon = resources->icon.To<SkBitmap>();
+ m_resources.badge = resources->badge.To<SkBitmap>();
+
+ m_resources.actionIcons.resize(resources->action_icons.size());
+ for (size_t i = 0; i < resources->action_icons.size(); ++i)
+ m_resources.actionIcons[i] = resources->action_icons[i].To<SkBitmap>();
+
+ m_hasResources = true;
}
// Registers a mocked url. When fetched, |fileName| will be loaded from the
// test data directory.
- WebURL registerMockedURL(const String& fileName)
+ String registerMockedURL(const String& fileName)
{
WebURL url(KURL(ParsedURLString, kBaseUrl + fileName));
@@ -72,38 +93,50 @@ protected:
URLTestHelpers::registerMockedURLLoadWithCustomResponse(url, fileName, "notifications/", response);
- return url;
+ return url.string();
}
// Registers a mocked url that will fail to be fetched, with a 404 error.
- WebURL registerMockedErrorURL(const String& fileName)
+ String registerMockedErrorURL(const String& fileName)
{
WebURL url(KURL(ParsedURLString, kBaseUrl + fileName));
URLTestHelpers::registerMockedErrorURLLoad(url);
- return url;
+
+ return url.string();
}
private:
OwnPtr<DummyPageHolder> m_page;
Persistent<NotificationResourcesLoader> m_loader;
- std::unique_ptr<WebNotificationResources> m_resources;
+
+ bool m_hasResources = false;
+ Resources m_resources;
};
+// Creates a Mojo NotificationAction object for an action having the |iconUrl|.
+mojom::blink::NotificationActionPtr createActionWithIcon(String iconUrl) {
+ mojom::blink::NotificationActionPtr action = mojom::blink::NotificationAction::New();
+ action->icon = iconUrl;
+
+ return action;
+}
+
TEST_F(NotificationResourcesLoaderTest, LoadMultipleResources)
{
- WebNotificationData notificationData;
- notificationData.icon = registerMockedURL(kIcon100x100);
- notificationData.badge = registerMockedURL(kIcon48x48);
- notificationData.actions = WebVector<WebNotificationAction>(static_cast<size_t>(2));
- notificationData.actions[0].icon = registerMockedURL(kIcon110x110);
- notificationData.actions[1].icon = registerMockedURL(kIcon120x120);
+ mojom::blink::NotificationPtr notification = mojom::blink::Notification::New();
+ notification->icon = registerMockedURL(kIcon100x100);
+ notification->badge = registerMockedURL(kIcon48x48);
- ASSERT_FALSE(resources());
+ notification->actions.resize(static_cast<size_t>(2));
+ notification->actions[0] = createActionWithIcon(registerMockedURL(kIcon110x110));
+ notification->actions[1] = createActionWithIcon(registerMockedURL(kIcon120x120));
- loader()->start(executionContext(), notificationData);
+ ASSERT_FALSE(hasResources());
+
+ loader()->start(executionContext(), std::move(notification));
Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
- ASSERT_TRUE(resources());
+ ASSERT_TRUE(hasResources());
ASSERT_FALSE(resources()->icon.drawsNothing());
ASSERT_EQ(100, resources()->icon.width());
@@ -120,18 +153,19 @@ TEST_F(NotificationResourcesLoaderTest, LoadMultipleResources)
TEST_F(NotificationResourcesLoaderTest, LargeIconsAreScaledDown)
{
- WebNotificationData notificationData;
- notificationData.icon = registerMockedURL(kIcon500x500);
- notificationData.badge = notificationData.icon;
- notificationData.actions = WebVector<WebNotificationAction>(static_cast<size_t>(1));
- notificationData.actions[0].icon = notificationData.icon;
+ mojom::blink::NotificationPtr notification = mojom::blink::Notification::New();
+ notification->icon = registerMockedURL(kIcon500x500);
+ notification->badge = notification->icon;
+
+ notification->actions.resize(static_cast<size_t>(1));
+ notification->actions[0] = createActionWithIcon(notification->icon);
- ASSERT_FALSE(resources());
+ ASSERT_FALSE(hasResources());
- loader()->start(executionContext(), notificationData);
+ loader()->start(executionContext(), std::move(notification));
Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
- ASSERT_TRUE(resources());
+ ASSERT_TRUE(hasResources());
ASSERT_FALSE(resources()->icon.drawsNothing());
ASSERT_EQ(kMaxIconSizePx, resources()->icon.width());
@@ -150,14 +184,12 @@ TEST_F(NotificationResourcesLoaderTest, LargeIconsAreScaledDown)
TEST_F(NotificationResourcesLoaderTest, EmptyDataYieldsEmptyResources)
{
- WebNotificationData notificationData;
+ ASSERT_FALSE(hasResources());
- ASSERT_FALSE(resources());
-
- loader()->start(executionContext(), notificationData);
+ loader()->start(executionContext(), mojom::blink::Notification::New());
Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
- ASSERT_TRUE(resources());
+ ASSERT_TRUE(hasResources());
ASSERT_TRUE(resources()->icon.drawsNothing());
ASSERT_TRUE(resources()->badge.drawsNothing());
@@ -166,18 +198,19 @@ TEST_F(NotificationResourcesLoaderTest, EmptyDataYieldsEmptyResources)
TEST_F(NotificationResourcesLoaderTest, EmptyResourcesIfAllImagesFailToLoad)
{
- WebNotificationData notificationData;
- notificationData.icon = registerMockedErrorURL(kIcon100x100);
- notificationData.badge = notificationData.icon;
- notificationData.actions = WebVector<WebNotificationAction>(static_cast<size_t>(1));
- notificationData.actions[0].icon = notificationData.icon;
+ mojom::blink::NotificationPtr notification = mojom::blink::Notification::New();
+ notification->icon = registerMockedErrorURL(kIcon100x100);
+ notification->badge = notification->icon;
+
+ notification->actions.resize(static_cast<size_t>(1));
+ notification->actions[0] = createActionWithIcon(notification->icon);
- ASSERT_FALSE(resources());
+ ASSERT_FALSE(hasResources());
- loader()->start(executionContext(), notificationData);
+ loader()->start(executionContext(), std::move(notification));
Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
- ASSERT_TRUE(resources());
+ ASSERT_TRUE(hasResources());
// The test received resources but they are all empty. This ensures that a
// notification can still be shown even if the images fail to load.
@@ -189,16 +222,16 @@ TEST_F(NotificationResourcesLoaderTest, EmptyResourcesIfAllImagesFailToLoad)
TEST_F(NotificationResourcesLoaderTest, OneImageFailsToLoad)
{
- WebNotificationData notificationData;
- notificationData.icon = registerMockedURL(kIcon100x100);
- notificationData.badge = registerMockedErrorURL(kIcon48x48);
+ mojom::blink::NotificationPtr notification = mojom::blink::Notification::New();
+ notification->icon = registerMockedURL(kIcon100x100);
+ notification->badge = registerMockedErrorURL(kIcon48x48);
- ASSERT_FALSE(resources());
+ ASSERT_FALSE(hasResources());
- loader()->start(executionContext(), notificationData);
+ loader()->start(executionContext(), std::move(notification));
Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
- ASSERT_TRUE(resources());
+ ASSERT_TRUE(hasResources());
// The test received resources even though one image failed to load. This
// ensures that a notification can still be shown, though slightly degraded.
@@ -210,20 +243,21 @@ TEST_F(NotificationResourcesLoaderTest, OneImageFailsToLoad)
TEST_F(NotificationResourcesLoaderTest, StopYieldsNoResources)
{
- WebNotificationData notificationData;
- notificationData.icon = registerMockedURL(kIcon100x100);
- notificationData.badge = registerMockedURL(kIcon48x48);
- notificationData.actions = WebVector<WebNotificationAction>(static_cast<size_t>(2));
- notificationData.actions[0].icon = registerMockedURL(kIcon110x110);
- notificationData.actions[1].icon = registerMockedURL(kIcon120x120);
+ mojom::blink::NotificationPtr notification = mojom::blink::Notification::New();
+ notification->icon = registerMockedURL(kIcon100x100);
+ notification->badge = registerMockedURL(kIcon48x48);
+
+ notification->actions.resize(static_cast<size_t>(2));
+ notification->actions[0] = createActionWithIcon(registerMockedURL(kIcon110x110));
+ notification->actions[1] = createActionWithIcon(registerMockedURL(kIcon120x120));
- ASSERT_FALSE(resources());
+ ASSERT_FALSE(hasResources());
- loader()->start(executionContext(), notificationData);
+ loader()->start(executionContext(), std::move(notification));
// Check that starting the loader did not synchronously fail, providing
// empty resources. The requests should be pending now.
- ASSERT_FALSE(resources());
+ ASSERT_FALSE(hasResources());
// The loader would stop e.g. when the execution context is destroyed or
// when the loader is about to be destroyed, as a pre-finalizer.
@@ -233,7 +267,7 @@ TEST_F(NotificationResourcesLoaderTest, StopYieldsNoResources)
// Loading should have been cancelled when |stop| was called so no resources
// should have been received by the test even though
// |serveAsynchronousRequests| was called.
- ASSERT_FALSE(resources());
+ ASSERT_FALSE(hasResources());
}
} // namespace

Powered by Google App Engine
This is Rietveld 408576698