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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/data/notifications/platform_notification_service.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <string> 5 #include <string>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/infobars/infobar_service.h" 12 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/browser/notifications/desktop_notification_profile_util.h"
13 #include "chrome/browser/notifications/desktop_notification_service.h" 14 #include "chrome/browser/notifications/desktop_notification_service.h"
14 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 15 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
15 #include "chrome/browser/notifications/notification_test_util.h" 16 #include "chrome/browser/notifications/notification_test_util.h"
16 #include "chrome/browser/notifications/platform_notification_service_impl.h" 17 #include "chrome/browser/notifications/platform_notification_service_impl.h"
17 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" 19 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/test/base/in_process_browser_test.h" 20 #include "chrome/test/base/in_process_browser_test.h"
20 #include "chrome/test/base/ui_test_utils.h" 21 #include "chrome/test/base/ui_test_utils.h"
21 #include "components/infobars/core/confirm_infobar_delegate.h" 22 #include "components/infobars/core/confirm_infobar_delegate.h"
22 #include "components/infobars/core/infobar.h" 23 #include "components/infobars/core/infobar.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 77
77 void InfoBarResponder::Respond(ConfirmInfoBarDelegate* delegate) { 78 void InfoBarResponder::Respond(ConfirmInfoBarDelegate* delegate) {
78 if (accept_) 79 if (accept_)
79 delegate->Accept(); 80 delegate->Accept();
80 else 81 else
81 delegate->Cancel(); 82 delegate->Cancel();
82 } 83 }
83 84
84 // ----------------------------------------------------------------------------- 85 // -----------------------------------------------------------------------------
85 86
87 // Dimensions of the icon.png resource in the notification test data directory.
88 const int kIconWidth = 100;
89 const int kIconHeight = 100;
90
86 class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest { 91 class PlatformNotificationServiceBrowserTest : public InProcessBrowserTest {
87 public: 92 public:
88 PlatformNotificationServiceBrowserTest(); 93 PlatformNotificationServiceBrowserTest();
89 ~PlatformNotificationServiceBrowserTest() override {} 94 ~PlatformNotificationServiceBrowserTest() override {}
90 95
91 // InProcessBrowserTest overrides. 96 // InProcessBrowserTest overrides.
92 void SetUp() override; 97 void SetUp() override;
93 void SetUpOnMainThread() override; 98 void SetUpOnMainThread() override;
94 void TearDown() override; 99 void TearDown() override;
95 100
96 protected: 101 protected:
97 // Returns the Platform Notification Service these unit tests are for. 102 // Returns the Platform Notification Service these unit tests are for.
98 PlatformNotificationServiceImpl* service() const { 103 PlatformNotificationServiceImpl* service() const {
99 return PlatformNotificationServiceImpl::GetInstance(); 104 return PlatformNotificationServiceImpl::GetInstance();
100 } 105 }
101 106
107 // Grants permission to display Web Notifications for origin of the test
108 // page that's being used in this browser test.
109 void GrantNotificationPermissionForTest() const;
110
102 // Returns the UI Manager on which notifications will be displayed. 111 // Returns the UI Manager on which notifications will be displayed.
103 StubNotificationUIManager* ui_manager() const { return ui_manager_.get(); } 112 StubNotificationUIManager* ui_manager() const { return ui_manager_.get(); }
104 113
105 const base::FilePath& server_root() const { return server_root_; } 114 const base::FilePath& server_root() const { return server_root_; }
106 115
107 // Navigates the browser to the test page indicated by |path|. 116 // Navigates the browser to the test page indicated by |path|.
108 void NavigateToTestPage(const std::string& path) const; 117 void NavigateToTestPage(const std::string& path) const;
109 118
110 // Executes |script| and stores the result as a string in |result|. A boolean 119 // Executes |script| and stores the result as a string in |result|. A boolean
111 // will be returned, indicating whether the script was executed successfully. 120 // will be returned, indicating whether the script was executed successfully.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 void PlatformNotificationServiceBrowserTest::SetUpOnMainThread() { 159 void PlatformNotificationServiceBrowserTest::SetUpOnMainThread() {
151 NavigateToTestPage(test_page_url_); 160 NavigateToTestPage(test_page_url_);
152 161
153 InProcessBrowserTest::SetUpOnMainThread(); 162 InProcessBrowserTest::SetUpOnMainThread();
154 } 163 }
155 164
156 void PlatformNotificationServiceBrowserTest::TearDown() { 165 void PlatformNotificationServiceBrowserTest::TearDown() {
157 service()->SetNotificationUIManagerForTesting(nullptr); 166 service()->SetNotificationUIManagerForTesting(nullptr);
158 } 167 }
159 168
169 void PlatformNotificationServiceBrowserTest::
170 GrantNotificationPermissionForTest() const {
171 GURL origin = TestPageUrl().GetOrigin();
172
173 DesktopNotificationProfileUtil::GrantPermission(browser()->profile(), origin);
174 ASSERT_EQ(CONTENT_SETTING_ALLOW,
175 DesktopNotificationProfileUtil::GetContentSetting(
176 browser()->profile(), origin));
177 }
178
160 void PlatformNotificationServiceBrowserTest::NavigateToTestPage( 179 void PlatformNotificationServiceBrowserTest::NavigateToTestPage(
161 const std::string& path) const { 180 const std::string& path) const {
162 ui_test_utils::NavigateToURL(browser(), https_server_->GetURL(path)); 181 ui_test_utils::NavigateToURL(browser(), https_server_->GetURL(path));
163 } 182 }
164 183
165 bool PlatformNotificationServiceBrowserTest::RunScript( 184 bool PlatformNotificationServiceBrowserTest::RunScript(
166 const std::string& script, std::string* result) const { 185 const std::string& script, std::string* result) const {
167 return content::ExecuteScriptAndExtractString( 186 return content::ExecuteScriptAndExtractString(
168 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), 187 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(),
169 script, 188 script,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 258
240 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 259 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
241 260
242 // We don't use or check the notification's direction and language. 261 // We don't use or check the notification's direction and language.
243 const Notification& notification = ui_manager()->GetNotificationAt(0); 262 const Notification& notification = ui_manager()->GetNotificationAt(0);
244 EXPECT_EQ("Title", base::UTF16ToUTF8(notification.title())); 263 EXPECT_EQ("Title", base::UTF16ToUTF8(notification.title()));
245 EXPECT_EQ("Contents", base::UTF16ToUTF8(notification.message())); 264 EXPECT_EQ("Contents", base::UTF16ToUTF8(notification.message()));
246 EXPECT_EQ("replace-id", notification.tag()); 265 EXPECT_EQ("replace-id", notification.tag());
247 EXPECT_FALSE(notification.icon().IsEmpty()); 266 EXPECT_FALSE(notification.icon().IsEmpty());
248 EXPECT_TRUE(notification.silent()); 267 EXPECT_TRUE(notification.silent());
268
269 EXPECT_EQ(kIconWidth, notification.icon().Width());
270 EXPECT_EQ(kIconHeight, notification.icon().Height());
249 } 271 }
250 272
251 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, 273 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
252 CloseDisplayedPersistentNotification) { 274 CloseDisplayedPersistentNotification) {
253 std::string script_result; 275 std::string script_result;
254 276
255 InfoBarResponder accepting_responder(browser(), true); 277 InfoBarResponder accepting_responder(browser(), true);
256 ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); 278 ASSERT_TRUE(RunScript("RequestPermission()", &script_result));
257 EXPECT_EQ("granted", script_result); 279 EXPECT_EQ("granted", script_result);
258 280
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 344
323 InfoBarResponder accepting_responder_file(browser(), true); 345 InfoBarResponder accepting_responder_file(browser(), true);
324 ASSERT_TRUE(RunScript("RequestPermission()", &script_result)); 346 ASSERT_TRUE(RunScript("RequestPermission()", &script_result));
325 EXPECT_EQ("granted", script_result); 347 EXPECT_EQ("granted", script_result);
326 348
327 EXPECT_FALSE(notification_service->IsNotifierEnabled(file_notifier)) 349 EXPECT_FALSE(notification_service->IsNotifierEnabled(file_notifier))
328 << "If this test fails, you may have fixed a bug preventing file origins " 350 << "If this test fails, you may have fixed a bug preventing file origins "
329 << "from sending their origin from Blink; if so you need to update the " 351 << "from sending their origin from Blink; if so you need to update the "
330 << "display function for notification origins to show the file path."; 352 << "display function for notification origins to show the file path.";
331 } 353 }
354
355 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
356 DataUrlAsNotificationImage) {
357 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest());
358
359 std::string script_result;
360 ASSERT_TRUE(RunScript("DisplayPersistentNotificationDataUrlImage()",
361 &script_result));
362 EXPECT_EQ("ok", script_result);
363
364 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
365
366 const Notification& notification = ui_manager()->GetNotificationAt(0);
367 EXPECT_FALSE(notification.icon().IsEmpty());
368
369 EXPECT_EQ("Data URL Title", base::UTF16ToUTF8(notification.title()));
370 EXPECT_EQ(kIconWidth, notification.icon().Width());
371 EXPECT_EQ(kIconHeight, notification.icon().Height());
372 }
373
374 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest,
375 BlobAsNotificationImage) {
376 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest());
377
378 std::string script_result;
379 ASSERT_TRUE(RunScript("DisplayPersistentNotificationBlobImage()",
380 &script_result));
381 EXPECT_EQ("ok", script_result);
382
383 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
384
385 const Notification& notification = ui_manager()->GetNotificationAt(0);
386 EXPECT_FALSE(notification.icon().IsEmpty());
387
388 EXPECT_EQ("Blob Title", base::UTF16ToUTF8(notification.title()));
389 EXPECT_EQ(kIconWidth, notification.icon().Width());
390 EXPECT_EQ(kIconHeight, notification.icon().Height());
391 }
OLDNEW
« 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