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/chrome_notification_display_service.h" | |
14 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 15 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
15 #include "chrome/browser/notifications/notification.h" | 16 #include "chrome/browser/notifications/notification.h" |
16 #include "chrome/browser/notifications/notification_permission_context.h" | 17 #include "chrome/browser/notifications/notification_permission_context.h" |
17 #include "chrome/browser/notifications/notification_permission_context_factory.h " | 18 #include "chrome/browser/notifications/notification_permission_context_factory.h " |
18 #include "chrome/browser/notifications/notification_test_util.h" | 19 #include "chrome/browser/notifications/notification_test_util.h" |
19 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 20 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
20 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
22 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 23 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
23 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 std::string RequestAndRespondToPermission( | 87 std::string RequestAndRespondToPermission( |
87 PermissionBubbleManager::AutoResponseType bubble_response); | 88 PermissionBubbleManager::AutoResponseType bubble_response); |
88 | 89 |
89 content::WebContents* GetActiveWebContents(Browser* browser) { | 90 content::WebContents* GetActiveWebContents(Browser* browser) { |
90 return browser->tab_strip_model()->GetActiveWebContents(); | 91 return browser->tab_strip_model()->GetActiveWebContents(); |
91 } | 92 } |
92 | 93 |
93 const base::FilePath server_root_; | 94 const base::FilePath server_root_; |
94 const std::string test_page_url_; | 95 const std::string test_page_url_; |
95 scoped_ptr<StubNotificationUIManager> ui_manager_; | 96 scoped_ptr<StubNotificationUIManager> ui_manager_; |
97 scoped_ptr<ChromeNotificationDisplayService> display_service_; | |
96 scoped_ptr<net::EmbeddedTestServer> https_server_; | 98 scoped_ptr<net::EmbeddedTestServer> https_server_; |
97 }; | 99 }; |
98 | 100 |
99 // ----------------------------------------------------------------------------- | 101 // ----------------------------------------------------------------------------- |
100 | 102 |
101 namespace { | 103 namespace { |
102 const char kTestFileName[] = "notifications/platform_notification_service.html"; | 104 const char kTestFileName[] = "notifications/platform_notification_service.html"; |
103 } | 105 } |
104 | 106 |
105 PlatformNotificationServiceBrowserTest::PlatformNotificationServiceBrowserTest() | 107 PlatformNotificationServiceBrowserTest::PlatformNotificationServiceBrowserTest() |
106 : server_root_(FILE_PATH_LITERAL("chrome/test/data")), | 108 : server_root_(FILE_PATH_LITERAL("chrome/test/data")), |
107 // The test server has a base directory that doesn't exist in the | 109 // The test server has a base directory that doesn't exist in the |
108 // filesystem. | 110 // filesystem. |
109 test_page_url_(std::string("/") + kTestFileName) {} | 111 test_page_url_(std::string("/") + kTestFileName) {} |
110 | 112 |
111 void PlatformNotificationServiceBrowserTest::SetUpCommandLine( | 113 void PlatformNotificationServiceBrowserTest::SetUpCommandLine( |
112 base::CommandLine* command_line) { | 114 base::CommandLine* command_line) { |
113 command_line->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures); | 115 command_line->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures); |
114 command_line->AppendSwitch(switches::kEnableNotificationActionIcons); | 116 command_line->AppendSwitch(switches::kEnableNotificationActionIcons); |
115 | 117 |
116 InProcessBrowserTest::SetUpCommandLine(command_line); | 118 InProcessBrowserTest::SetUpCommandLine(command_line); |
117 } | 119 } |
118 | 120 |
119 void PlatformNotificationServiceBrowserTest::SetUp() { | 121 void PlatformNotificationServiceBrowserTest::SetUp() { |
120 ui_manager_.reset(new StubNotificationUIManager); | 122 ui_manager_.reset(new StubNotificationUIManager); |
121 https_server_.reset( | 123 https_server_.reset( |
122 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); | 124 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); |
123 https_server_->ServeFilesFromSourceDirectory(server_root_); | 125 https_server_->ServeFilesFromSourceDirectory(server_root_); |
124 ASSERT_TRUE(https_server_->Start()); | 126 ASSERT_TRUE(https_server_->Start()); |
125 | |
126 service()->SetNotificationUIManagerForTesting(ui_manager_.get()); | |
127 | |
128 InProcessBrowserTest::SetUp(); | 127 InProcessBrowserTest::SetUp(); |
129 } | 128 } |
130 | 129 |
131 void PlatformNotificationServiceBrowserTest::SetUpOnMainThread() { | 130 void PlatformNotificationServiceBrowserTest::SetUpOnMainThread() { |
132 NavigateToTestPage(test_page_url_); | 131 NavigateToTestPage(test_page_url_); |
133 | 132 display_service_.reset(new ChromeNotificationDisplayService( |
133 browser()->profile(), ui_manager_.get())); | |
134 service()->SetNotificationDisplayServiceForTesting(display_service_.get()); | |
Peter Beverloo
2016/04/18 14:57:10
Why can't we use KeyedServiceFactory::SetTestingFa
Miguel Garcia
2016/04/19 14:24:58
Looked into it, we can for the unit test but the b
| |
134 InProcessBrowserTest::SetUpOnMainThread(); | 135 InProcessBrowserTest::SetUpOnMainThread(); |
135 } | 136 } |
136 | 137 |
137 void PlatformNotificationServiceBrowserTest::TearDown() { | 138 void PlatformNotificationServiceBrowserTest::TearDown() { |
138 service()->SetNotificationUIManagerForTesting(nullptr); | 139 service()->SetNotificationDisplayServiceForTesting(nullptr); |
139 } | 140 } |
140 | 141 |
141 void PlatformNotificationServiceBrowserTest:: | 142 void PlatformNotificationServiceBrowserTest:: |
142 GrantNotificationPermissionForTest() const { | 143 GrantNotificationPermissionForTest() const { |
143 GURL origin = TestPageUrl().GetOrigin(); | 144 GURL origin = TestPageUrl().GetOrigin(); |
144 | 145 |
145 DesktopNotificationProfileUtil::GrantPermission(browser()->profile(), origin); | 146 DesktopNotificationProfileUtil::GrantPermission(browser()->profile(), origin); |
146 ASSERT_EQ(CONTENT_SETTING_ALLOW, | 147 ASSERT_EQ(CONTENT_SETTING_ALLOW, |
147 DesktopNotificationProfileUtil::GetContentSetting( | 148 DesktopNotificationProfileUtil::GetContentSetting( |
148 browser()->profile(), origin)); | 149 browser()->profile(), origin)); |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
487 EXPECT_EQ("actionTitle2", base::UTF16ToUTF8(notification.buttons()[1].title)); | 488 EXPECT_EQ("actionTitle2", base::UTF16ToUTF8(notification.buttons()[1].title)); |
488 | 489 |
489 notification.delegate()->ButtonClick(0); | 490 notification.delegate()->ButtonClick(0); |
490 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 491 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
491 EXPECT_EQ("action_button_click actionId1", script_result); | 492 EXPECT_EQ("action_button_click actionId1", script_result); |
492 | 493 |
493 notification.delegate()->ButtonClick(1); | 494 notification.delegate()->ButtonClick(1); |
494 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); | 495 ASSERT_TRUE(RunScript("GetMessageFromWorker()", &script_result)); |
495 EXPECT_EQ("action_button_click actionId2", script_result); | 496 EXPECT_EQ("action_button_click actionId2", script_result); |
496 } | 497 } |
OLD | NEW |