| OLD | NEW |
| 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 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 14 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
| 15 #include "chrome/browser/notifications/notification.h" | 15 #include "chrome/browser/notifications/notification.h" |
| 16 #include "chrome/browser/notifications/notification_permission_context.h" | |
| 17 #include "chrome/browser/notifications/notification_permission_context_factory.h
" | |
| 18 #include "chrome/browser/notifications/notification_test_util.h" | 16 #include "chrome/browser/notifications/notification_test_util.h" |
| 19 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 17 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 18 #include "chrome/browser/permissions/permission_manager.h" |
| 20 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 22 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 21 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
| 23 #include "chrome/grit/generated_resources.h" | 22 #include "chrome/grit/generated_resources.h" |
| 24 #include "chrome/test/base/in_process_browser_test.h" | 23 #include "chrome/test/base/in_process_browser_test.h" |
| 25 #include "chrome/test/base/ui_test_utils.h" | 24 #include "chrome/test/base/ui_test_utils.h" |
| 25 #include "content/public/browser/permission_type.h" |
| 26 #include "content/public/common/content_switches.h" | 26 #include "content/public/common/content_switches.h" |
| 27 #include "content/public/test/browser_test_utils.h" | 27 #include "content/public/test/browser_test_utils.h" |
| 28 #include "net/base/filename_util.h" | 28 #include "net/base/filename_util.h" |
| 29 #include "net/test/embedded_test_server/embedded_test_server.h" | 29 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 32 | 33 |
| 33 // ----------------------------------------------------------------------------- | 34 // ----------------------------------------------------------------------------- |
| 34 | 35 |
| 35 // Dimensions of the icon.png resource in the notification test data directory. | 36 // Dimensions of the icon.png resource in the notification test data directory. |
| 36 const int kIconWidth = 100; | 37 const int kIconWidth = 100; |
| 37 const int kIconHeight = 100; | 38 const int kIconHeight = 100; |
| 38 | 39 |
| 39 // The maximum width and height of badges. Oversized images are scaled down to | 40 // The maximum width and height of badges. Oversized images are scaled down to |
| 40 // these values. | 41 // these values. |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 notification.origin_url().spec()); | 394 notification.origin_url().spec()); |
| 394 } | 395 } |
| 395 | 396 |
| 396 // TODO(felt): This DCHECKs when bubbles are enabled, when the file_url is | 397 // TODO(felt): This DCHECKs when bubbles are enabled, when the file_url is |
| 397 // persisted. crbug.com/502057 | 398 // persisted. crbug.com/502057 |
| 398 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | 399 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| 399 DISABLED_CheckFilePermissionNotGranted) { | 400 DISABLED_CheckFilePermissionNotGranted) { |
| 400 // This case should succeed because a normal page URL is used. | 401 // This case should succeed because a normal page URL is used. |
| 401 std::string script_result; | 402 std::string script_result; |
| 402 | 403 |
| 403 NotificationPermissionContext* permission_context = | 404 PermissionManager* permission_manager = |
| 404 NotificationPermissionContextFactory::GetForProfile(browser()->profile()); | 405 PermissionManager::Get(browser()->profile()); |
| 405 ASSERT_TRUE(permission_context); | |
| 406 | 406 |
| 407 EXPECT_EQ(CONTENT_SETTING_ASK, | 407 EXPECT_EQ(blink::mojom::PermissionStatus::ASK, |
| 408 permission_context->GetPermissionStatus(TestPageUrl(), | 408 permission_manager->GetPermissionStatus( |
| 409 TestPageUrl())); | 409 content::PermissionType::NOTIFICATIONS, TestPageUrl(), |
| 410 TestPageUrl())); |
| 410 | 411 |
| 411 RequestAndAcceptPermission(); | 412 RequestAndAcceptPermission(); |
| 412 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 413 EXPECT_EQ(blink::mojom::PermissionStatus::GRANTED, |
| 413 permission_context->GetPermissionStatus(TestPageUrl(), | 414 permission_manager->GetPermissionStatus( |
| 414 TestPageUrl())); | 415 content::PermissionType::NOTIFICATIONS, TestPageUrl(), |
| 416 TestPageUrl())); |
| 415 | 417 |
| 416 // This case should fail because a file URL is used. | 418 // This case should fail because a file URL is used. |
| 417 base::FilePath dir_source_root; | 419 base::FilePath dir_source_root; |
| 418 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &dir_source_root)); | 420 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &dir_source_root)); |
| 419 base::FilePath full_file_path = | 421 base::FilePath full_file_path = |
| 420 dir_source_root.Append(server_root()).AppendASCII(kTestFileName); | 422 dir_source_root.Append(server_root()).AppendASCII(kTestFileName); |
| 421 GURL file_url(net::FilePathToFileURL(full_file_path)); | 423 GURL file_url(net::FilePathToFileURL(full_file_path)); |
| 422 | 424 |
| 423 ui_test_utils::NavigateToURL(browser(), file_url); | 425 ui_test_utils::NavigateToURL(browser(), file_url); |
| 424 | 426 |
| 425 EXPECT_EQ(CONTENT_SETTING_ASK, | 427 EXPECT_EQ(blink::mojom::PermissionStatus::ASK, |
| 426 permission_context->GetPermissionStatus(file_url, file_url)); | 428 permission_manager->GetPermissionStatus( |
| 429 content::PermissionType::NOTIFICATIONS, file_url, file_url)); |
| 427 | 430 |
| 428 RequestAndAcceptPermission(); | 431 RequestAndAcceptPermission(); |
| 429 EXPECT_EQ(CONTENT_SETTING_ASK, | 432 EXPECT_EQ(blink::mojom::PermissionStatus::ASK, |
| 430 permission_context->GetPermissionStatus(file_url, file_url)) | 433 permission_manager->GetPermissionStatus( |
| 434 content::PermissionType::NOTIFICATIONS, file_url, file_url)) |
| 431 << "If this test fails, you may have fixed a bug preventing file origins " | 435 << "If this test fails, you may have fixed a bug preventing file origins " |
| 432 << "from sending their origin from Blink; if so you need to update the " | 436 << "from sending their origin from Blink; if so you need to update the " |
| 433 << "display function for notification origins to show the file path."; | 437 << "display function for notification origins to show the file path."; |
| 434 } | 438 } |
| 435 | 439 |
| 436 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, | 440 IN_PROC_BROWSER_TEST_F(PlatformNotificationServiceBrowserTest, |
| 437 DataUrlAsNotificationImage) { | 441 DataUrlAsNotificationImage) { |
| 438 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); | 442 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest()); |
| 439 | 443 |
| 440 std::string script_result; | 444 std::string script_result; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 EXPECT_EQ("actionTitle2", base::UTF16ToUTF8(notification.buttons()[1].title)); | 491 EXPECT_EQ("actionTitle2", base::UTF16ToUTF8(notification.buttons()[1].title)); |
| 488 | 492 |
| 489 notification.delegate()->ButtonClick(0); | 493 notification.delegate()->ButtonClick(0); |
| 490 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 494 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
| 491 EXPECT_EQ("action_button_click actionId1", script_result); | 495 EXPECT_EQ("action_button_click actionId1", script_result); |
| 492 | 496 |
| 493 notification.delegate()->ButtonClick(1); | 497 notification.delegate()->ButtonClick(1); |
| 494 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 498 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
| 495 EXPECT_EQ("action_button_click actionId2", script_result); | 499 EXPECT_EQ("action_button_click actionId2", script_result); |
| 496 } | 500 } |
| OLD | NEW |