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

Unified Diff: chrome/browser/notifications/platform_notification_service_browsertest.cc

Issue 1019803002: Add browser tests for loading notification icons from blob and data URLs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 5 years, 9 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/test/data/notifications/platform_notification_service.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/notifications/platform_notification_service_browsertest.cc
diff --git a/chrome/browser/notifications/platform_notification_service_browsertest.cc b/chrome/browser/notifications/platform_notification_service_browsertest.cc
index 14914a85a1e715d5cc80038bdcb464f6ecd2a47f..0cf8fa190745a180bc3410ba5cc359529bdbf093 100644
--- a/chrome/browser/notifications/platform_notification_service_browsertest.cc
+++ b/chrome/browser/notifications/platform_notification_service_browsertest.cc
@@ -10,6 +10,7 @@
#include "base/path_service.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/infobars/infobar_service.h"
+#include "chrome/browser/notifications/desktop_notification_profile_util.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
#include "chrome/browser/notifications/desktop_notification_service_factory.h"
#include "chrome/browser/notifications/notification_test_util.h"
@@ -83,6 +84,10 @@ void InfoBarResponder::Respond(ConfirmInfoBarDelegate* delegate) {
// -----------------------------------------------------------------------------
+// Dimensions of the icon.png resource in the notification test data directory.
+const int kIconWidth = 100;
+const int kIconHeight = 100;
+
class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest {
public:
PlatformNotificationServiceBrowserTest();
@@ -99,6 +104,10 @@ class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest {
return PlatformNotificationServiceImpl::GetInstance();
}
+ // Grants permission to display Web Notifications for origin of the test
+ // page that's being used in this browser test.
+ void GrantNotificationPermissionForTest() const;
+
// Returns the UI Manager on which notifications will be displayed.
StubNotificationUIManager* ui_manager() const { return ui_manager_.get(); }
@@ -157,6 +166,16 @@ void PlatformNotificationServiceBrowserTest::TearDown() {
service()->SetNotificationUIManagerForTesting(nullptr);
}
+void PlatformNotificationServiceBrowserTest::
+ GrantNotificationPermissionForTest() const {
+ GURL origin = TestPageUrl().GetOrigin();
+
+ DesktopNotificationProfileUtil::GrantPermission(browser()->profile(), origin);
+ ASSERT_EQ(CONTENT_SETTING_ALLOW,
+ DesktopNotificationProfileUtil::GetContentSetting(
+ browser()->profile(), origin));
+}
+
void PlatformNotificationServiceBrowserTest::NavigateToTestPage(
const std::string& path) const {
ui_test_utils::NavigateToURL(browser(), https_server_->GetURL(path));
@@ -246,6 +265,9 @@ IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
EXPECT_EQ("replace-id", notification.tag());
EXPECT_FALSE(notification.icon().IsEmpty());
EXPECT_TRUE(notification.silent());
+
+ EXPECT_EQ(kIconWidth, notification.icon().Width());
+ EXPECT_EQ(kIconHeight, notification.icon().Height());
}
IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
@@ -329,3 +351,41 @@ IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
<< "from sending their origin from Blink; if so you need to update the "
<< "display function for notification origins to show the file path.";
}
+
+IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
+ DataUrlAsNotificationImage) {
+ ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest());
+
+ std::string script_result;
+ ASSERT_TRUE(RunScript("DisplayPersistentNotificationDataUrlImage()",
+ &script_result));
+ EXPECT_EQ("ok", script_result);
+
+ ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
+
+ const Notification& notification = ui_manager()->GetNotificationAt(0);
+ EXPECT_FALSE(notification.icon().IsEmpty());
+
+ EXPECT_EQ("Data URL Title", base::UTF16ToUTF8(notification.title()));
+ EXPECT_EQ(kIconWidth, notification.icon().Width());
+ EXPECT_EQ(kIconHeight, notification.icon().Height());
+}
+
+IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
+ BlobAsNotificationImage) {
+ ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest());
+
+ std::string script_result;
+ ASSERT_TRUE(RunScript("DisplayPersistentNotificationBlobImage()",
+ &script_result));
+ EXPECT_EQ("ok", script_result);
+
+ ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
+
+ const Notification& notification = ui_manager()->GetNotificationAt(0);
+ EXPECT_FALSE(notification.icon().IsEmpty());
+
+ EXPECT_EQ("Blob Title", base::UTF16ToUTF8(notification.title()));
+ EXPECT_EQ(kIconWidth, notification.icon().Width());
+ EXPECT_EQ(kIconHeight, notification.icon().Height());
+}
« no previous file with comments | « no previous file | chrome/test/data/notifications/platform_notification_service.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698