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

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

Issue 1292003004: Elide origins displayed on web notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Style nit Created 5 years, 4 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: chrome/browser/notifications/platform_notification_service_unittest.cc
diff --git a/chrome/browser/notifications/platform_notification_service_unittest.cc b/chrome/browser/notifications/platform_notification_service_unittest.cc
index 7c4542a4a2e12ecc2657c5b0ab04b8e45e4ccd84..b4eb2a78528a4e2627148b446c131a4be1125ca2 100644
--- a/chrome/browser/notifications/platform_notification_service_unittest.cc
+++ b/chrome/browser/notifications/platform_notification_service_unittest.cc
@@ -5,6 +5,7 @@
#include "base/strings/utf_string_conversions.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
+#include "chrome/browser/notifications/notification_delegate.h"
#include "chrome/browser/notifications/notification_test_util.h"
#include "chrome/browser/notifications/platform_notification_service_impl.h"
#include "chrome/test/base/testing_profile.h"
@@ -220,57 +221,6 @@ TEST_F(PlatformNotificationServiceTest, DisplayPageNotificationMatches) {
EXPECT_EQ("Button 2", base::UTF16ToUTF8(buttons[1].title));
}
-TEST_F(PlatformNotificationServiceTest, DisplayNameForOrigin) {
- base::string16 display_name =
- service()->DisplayNameForOrigin(profile(), GURL("https://chrome.com/"));
-
- EXPECT_EQ(base::ASCIIToUTF16("chrome.com"), display_name);
-
- // TODO(peter): Include unit tests for the extension-name translation
- // functionality of DisplayNameForOriginInProcessId.
-}
-
-TEST_F(PlatformNotificationServiceTest, TestWebOriginDisplayName) {
- std::string language("en-us");
-
- GURL https_origin("https://mail.google.com/");
- base::string16 expected_display_name = base::ASCIIToUTF16("mail.google.com");
- EXPECT_EQ(expected_display_name,
- PlatformNotificationServiceImpl::WebOriginDisplayName(https_origin,
- language));
-
- GURL https_origin_standard_port("https://mail.google.com:443/");
- expected_display_name = base::ASCIIToUTF16("mail.google.com");
- EXPECT_EQ(expected_display_name,
- PlatformNotificationServiceImpl::WebOriginDisplayName(
- https_origin_standard_port, language));
-
- GURL https_origin_nonstandard_port("https://mail.google.com:444/");
- expected_display_name = base::ASCIIToUTF16("mail.google.com:444");
- EXPECT_EQ(expected_display_name,
- PlatformNotificationServiceImpl::WebOriginDisplayName(
- https_origin_nonstandard_port, language));
-
- GURL http_origin("http://mail.google.com/");
- expected_display_name = base::ASCIIToUTF16("http://mail.google.com");
- EXPECT_EQ(expected_display_name,
- PlatformNotificationServiceImpl::WebOriginDisplayName(http_origin,
- language));
-
- GURL http_origin_standard_port("http://mail.google.com:80/");
- expected_display_name = base::ASCIIToUTF16("http://mail.google.com");
- EXPECT_EQ(expected_display_name,
- PlatformNotificationServiceImpl::WebOriginDisplayName(
- http_origin_standard_port, language));
-
- GURL http_origin_nonstandard_port("http://mail.google.com:81/");
- expected_display_name = base::ASCIIToUTF16("http://mail.google.com:81");
- EXPECT_EQ(expected_display_name,
- PlatformNotificationServiceImpl::WebOriginDisplayName(
- http_origin_nonstandard_port, language));
- // TODO(dewittj): Add file origin once it's supported.
-}
-
TEST_F(PlatformNotificationServiceTest, NotificationPermissionLastUsage) {
// Both page and persistent notifications should update the last usage
// time of the notification permission for the origin.
@@ -299,6 +249,33 @@ TEST_F(PlatformNotificationServiceTest, NotificationPermissionLastUsage) {
#if defined(ENABLE_EXTENSIONS)
+TEST_F(PlatformNotificationServiceTest, DisplayNameForContextMessage) {
+ base::string16 display_name = service()->DisplayNameForContextMessage(
+ profile(), GURL("https://chrome.com/"));
+
+ EXPECT_TRUE(display_name.empty());
+
+ // Create a mocked extension.
+ scoped_refptr<extensions::Extension> extension =
+ extensions::ExtensionBuilder()
+ .SetID("honijodknafkokifofgiaalefdiedpko")
+ .SetManifest(extensions::DictionaryBuilder()
+ .Set("name", "NotificationTest")
+ .Set("version", "1.0")
+ .Set("manifest_version", 2)
+ .Set("description", "Test Extension"))
+ .Build();
+
+ extensions::ExtensionRegistry* registry =
+ extensions::ExtensionRegistry::Get(profile());
+ EXPECT_TRUE(registry->AddEnabled(extension));
+
+ display_name = service()->DisplayNameForContextMessage(
+ profile(),
+ GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"));
+ EXPECT_EQ("NotificationTest", base::UTF16ToUTF8(display_name));
+}
+
TEST_F(PlatformNotificationServiceTest, ExtensionPermissionChecks) {
#if defined(OS_CHROMEOS)
// The ExtensionService on Chrome OS requires these objects to be initialized.
@@ -315,18 +292,19 @@ TEST_F(PlatformNotificationServiceTest, ExtensionPermissionChecks) {
ExtensionService* extension_service =
test_extension_system->CreateExtensionService(
&command_line, base::FilePath() /* install_directory */,
- false /* autoupdate_enabled*/);
+ false /* autoupdate_enabled */);
// Create a mocked extension that has the notifications API permission.
scoped_refptr<extensions::Extension> extension =
- extensions::ExtensionBuilder().SetManifest(
- extensions::DictionaryBuilder()
- .Set("name", "NotificationTest")
- .Set("version", "1.0")
- .Set("manifest_version", 2)
- .Set("description", "Test Extension")
- .Set("permissions",
- extensions::ListBuilder().Append("notifications"))).Build();
+ extensions::ExtensionBuilder()
+ .SetManifest(extensions::DictionaryBuilder()
+ .Set("name", "NotificationTest")
+ .Set("version", "1.0")
+ .Set("manifest_version", 2)
+ .Set("description", "Test Extension")
+ .Set("permissions", extensions::ListBuilder().Append(
+ "notifications")))
+ .Build();
// Install the extension on the faked extension service, and verify that it
// has been added to the extension registry successfully.
@@ -353,4 +331,37 @@ TEST_F(PlatformNotificationServiceTest, ExtensionPermissionChecks) {
kFakeRenderProcessId));
}
+TEST_F(PlatformNotificationServiceTest, CreateNotificationFromData) {
+ content::PlatformNotificationData notification_data;
+ notification_data.title = base::ASCIIToUTF16("My Notification");
+ notification_data.body = base::ASCIIToUTF16("Hello, world!");
+
+ Notification notification = service()->CreateNotificationFromData(
+ profile(), GURL("https://chrome.com/"), SkBitmap(), notification_data,
+ new MockNotificationDelegate("hello"));
+ EXPECT_TRUE(notification.context_message().empty());
+
+ // Create a mocked extension.
+ scoped_refptr<extensions::Extension> extension =
+ extensions::ExtensionBuilder()
+ .SetID("honijodknafkokifofgiaalefdiedpko")
+ .SetManifest(extensions::DictionaryBuilder()
+ .Set("name", "NotificationTest")
+ .Set("version", "1.0")
+ .Set("manifest_version", 2)
+ .Set("description", "Test Extension"))
+ .Build();
+
+ extensions::ExtensionRegistry* registry =
+ extensions::ExtensionRegistry::Get(profile());
+ EXPECT_TRUE(registry->AddEnabled(extension));
+
+ notification = service()->CreateNotificationFromData(
+ profile(),
+ GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"),
+ SkBitmap(), notification_data, new MockNotificationDelegate("hello"));
+ EXPECT_EQ("NotificationTest",
+ base::UTF16ToUTF8(notification.context_message()));
+}
+
#endif // defined(ENABLE_EXTENSIONS)
« no previous file with comments | « chrome/browser/notifications/platform_notification_service_impl.cc ('k') | chrome/browser/search/hotword_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698