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

Side by Side Diff: chrome/browser/notifications/platform_notification_service_unittest.cc

Issue 1267673003: Plumb Blink notification actions to button UI on desktop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "base/threading/platform_thread.h" 6 #include "base/threading/platform_thread.h"
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "chrome/browser/notifications/notification_test_util.h" 8 #include "chrome/browser/notifications/notification_test_util.h"
9 #include "chrome/browser/notifications/platform_notification_service_impl.h" 9 #include "chrome/browser/notifications/platform_notification_service_impl.h"
10 #include "chrome/test/base/testing_profile.h" 10 #include "chrome/test/base/testing_profile.h"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 TEST_F(PlatformNotificationServiceTest, DisplayPageNotificationMatches) { 180 TEST_F(PlatformNotificationServiceTest, DisplayPageNotificationMatches) {
181 std::vector<int> vibration_pattern( 181 std::vector<int> vibration_pattern(
182 kNotificationVibrationPattern, 182 kNotificationVibrationPattern,
183 kNotificationVibrationPattern + arraysize(kNotificationVibrationPattern)); 183 kNotificationVibrationPattern + arraysize(kNotificationVibrationPattern));
184 184
185 content::PlatformNotificationData notification_data; 185 content::PlatformNotificationData notification_data;
186 notification_data.title = base::ASCIIToUTF16("My notification's title"); 186 notification_data.title = base::ASCIIToUTF16("My notification's title");
187 notification_data.body = base::ASCIIToUTF16("Hello, world!"); 187 notification_data.body = base::ASCIIToUTF16("Hello, world!");
188 notification_data.vibration_pattern = vibration_pattern; 188 notification_data.vibration_pattern = vibration_pattern;
189 notification_data.silent = true; 189 notification_data.silent = true;
190 notification_data.actions.resize(2);
191 notification_data.actions[0].title = "Button 1";
192 notification_data.actions[1].title = "Button 2";
190 193
191 MockDesktopNotificationDelegate* delegate 194 MockDesktopNotificationDelegate* delegate
192 = new MockDesktopNotificationDelegate(); 195 = new MockDesktopNotificationDelegate();
193 service()->DisplayNotification(profile(), 196 service()->DisplayNotification(profile(),
194 GURL("https://chrome.com/"), 197 GURL("https://chrome.com/"),
195 SkBitmap(), 198 SkBitmap(),
196 notification_data, 199 notification_data,
197 make_scoped_ptr(delegate), 200 make_scoped_ptr(delegate),
198 nullptr); 201 nullptr);
199 202
200 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 203 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
201 204
202 const Notification& notification = ui_manager()->GetNotificationAt(0); 205 const Notification& notification = ui_manager()->GetNotificationAt(0);
203 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec()); 206 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec());
204 EXPECT_EQ("My notification's title", 207 EXPECT_EQ("My notification's title",
205 base::UTF16ToUTF8(notification.title())); 208 base::UTF16ToUTF8(notification.title()));
206 EXPECT_EQ("Hello, world!", 209 EXPECT_EQ("Hello, world!",
207 base::UTF16ToUTF8(notification.message())); 210 base::UTF16ToUTF8(notification.message()));
208 211
209 EXPECT_THAT(notification.vibration_pattern(), 212 EXPECT_THAT(notification.vibration_pattern(),
210 testing::ElementsAreArray(kNotificationVibrationPattern)); 213 testing::ElementsAreArray(kNotificationVibrationPattern));
211 214
212 EXPECT_TRUE(notification.silent()); 215 EXPECT_TRUE(notification.silent());
216
217 ASSERT_EQ(2, notification.buttons().size());
218 EXPECT_EQ("Button 1", base::UTF16ToUTF8(notification.buttons()[0].title));
Peter Beverloo 2015/07/30 17:02:05 Could we cache a reference to notification.buttons
johnme 2015/07/31 18:21:31 Done (const auto& buttons)
219 EXPECT_EQ("Button 2", base::UTF16ToUTF8(notification.buttons()[1].title));
213 } 220 }
214 221
215 TEST_F(PlatformNotificationServiceTest, DisplayNameForOrigin) { 222 TEST_F(PlatformNotificationServiceTest, DisplayNameForOrigin) {
216 base::string16 display_name = 223 base::string16 display_name =
217 service()->DisplayNameForOrigin(profile(), GURL("https://chrome.com/")); 224 service()->DisplayNameForOrigin(profile(), GURL("https://chrome.com/"));
218 225
219 EXPECT_EQ(base::ASCIIToUTF16("chrome.com"), display_name); 226 EXPECT_EQ(base::ASCIIToUTF16("chrome.com"), display_name);
220 227
221 // TODO(peter): Include unit tests for the extension-name translation 228 // TODO(peter): Include unit tests for the extension-name translation
222 // functionality of DisplayNameForOriginInProcessId. 229 // functionality of DisplayNameForOriginInProcessId.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 // Verify that the service indicates that permission has been granted. We only 346 // Verify that the service indicates that permission has been granted. We only
340 // check the UI thread-method for now, as that's the one guarding the behavior 347 // check the UI thread-method for now, as that's the one guarding the behavior
341 // in the browser process. 348 // in the browser process.
342 EXPECT_EQ(blink::WebNotificationPermissionAllowed, 349 EXPECT_EQ(blink::WebNotificationPermissionAllowed,
343 service()->CheckPermissionOnUIThread(profile(), 350 service()->CheckPermissionOnUIThread(profile(),
344 extension->url(), 351 extension->url(),
345 kFakeRenderProcessId)); 352 kFakeRenderProcessId));
346 } 353 }
347 354
348 #endif // defined(ENABLE_EXTENSIONS) 355 #endif // defined(ENABLE_EXTENSIONS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698