Chromium Code Reviews| 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 <map> | 5 #include <map> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 gcm_service_ = static_cast<FakeGCMProfileService*>( | 134 gcm_service_ = static_cast<FakeGCMProfileService*>( |
| 135 GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 135 GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 136 browser()->profile(), &FakeGCMProfileService::Build)); | 136 browser()->profile(), &FakeGCMProfileService::Build)); |
| 137 gcm_service_->set_collect(true); | 137 gcm_service_->set_collect(true); |
| 138 | 138 |
| 139 loadTestPage(); | 139 loadTestPage(); |
| 140 | 140 |
| 141 InProcessBrowserTest::SetUpOnMainThread(); | 141 InProcessBrowserTest::SetUpOnMainThread(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void loadTestPage() { | 144 virtual void loadTestPage() { |
| 145 ui_test_utils::NavigateToURL( | 145 ui_test_utils::NavigateToURL( |
| 146 browser(), https_server_->GetURL("files/push_messaging/test.html")); | 146 browser(), https_server_->GetURL("files/push_messaging/test.html")); |
| 147 } | 147 } |
| 148 | 148 |
| 149 bool RunScript(const std::string& script, std::string* result) { | 149 bool RunScript(const std::string& script, std::string* result) { |
| 150 return content::ExecuteScriptAndExtractString( | 150 return content::ExecuteScriptAndExtractString( |
| 151 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), | 151 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), |
| 152 script, | 152 script, |
| 153 result); | 153 result); |
| 154 } | 154 } |
| 155 | 155 |
| 156 net::SpawnedTestServer* https_server() const { return https_server_.get(); } | 156 net::SpawnedTestServer* https_server() const { return https_server_.get(); } |
| 157 | 157 |
| 158 FakeGCMProfileService* gcm_service() const { return gcm_service_; } | 158 FakeGCMProfileService* gcm_service() const { return gcm_service_; } |
| 159 | 159 |
| 160 PushMessagingServiceImpl* push_service() { | 160 PushMessagingServiceImpl* push_service() { |
| 161 return static_cast<PushMessagingServiceImpl*>( | 161 return static_cast<PushMessagingServiceImpl*>( |
| 162 gcm_service_->push_messaging_service()); | 162 gcm_service_->push_messaging_service()); |
| 163 } | 163 } |
| 164 | 164 |
| 165 private: | 165 protected: |
|
Michael van Ouwerkerk
2014/12/10 18:36:33
This should still be private. We have public gette
Miguel Garcia
2014/12/11 11:37:08
Done.
| |
| 166 scoped_ptr<net::SpawnedTestServer> https_server_; | 166 scoped_ptr<net::SpawnedTestServer> https_server_; |
| 167 FakeGCMProfileService* gcm_service_; | 167 FakeGCMProfileService* gcm_service_; |
| 168 | 168 |
| 169 DISALLOW_COPY_AND_ASSIGN(PushMessagingBrowserTest); | 169 DISALLOW_COPY_AND_ASSIGN(PushMessagingBrowserTest); |
| 170 }; | 170 }; |
| 171 | 171 |
| 172 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterSuccess) { | 172 class PushMessagingBadManifestBrowserTest : public PushMessagingBrowserTest { |
| 173 void loadTestPage() override { | |
|
Michael van Ouwerkerk
2014/12/10 18:36:33
Instead of subclassing, you could add a loadTestPa
Miguel Garcia
2014/12/11 11:37:08
mm not sure I agree here, the way this is structur
| |
| 174 ui_test_utils::NavigateToURL( | |
| 175 browser(), | |
| 176 https_server_->GetURL("files/push_messaging/test_bad_manifest.html")); | |
| 177 }; | |
| 178 }; | |
| 179 | |
| 180 IN_PROC_BROWSER_TEST_F(PushMessagingBadManifestBrowserTest, | |
| 181 RegisterFailsNotVisibleMessages) { | |
| 173 std::string script_result; | 182 std::string script_result; |
| 174 | 183 |
| 175 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 184 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 185 ASSERT_EQ("ok - service worker registered", script_result); | |
| 186 ASSERT_TRUE(RunScript("registerPush()", &script_result)); | |
| 187 EXPECT_EQ("AbortError - Registration failed - permission denied", | |
| 188 script_result); | |
| 189 } | |
| 190 | |
| 191 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | |
| 192 RegisterSuccessNotificationsGranted) { | |
| 193 std::string script_result; | |
| 194 | |
| 195 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | |
| 176 ASSERT_EQ("ok - service worker registered", script_result); | 196 ASSERT_EQ("ok - service worker registered", script_result); |
| 177 | 197 |
| 178 InfoBarResponder accepting_responder(browser(), true); | 198 InfoBarResponder accepting_responder(browser(), true); |
| 179 ASSERT_TRUE(RunScript("requestNotificationPermission()", &script_result)); | 199 ASSERT_TRUE(RunScript("requestNotificationPermission()", &script_result)); |
| 180 ASSERT_EQ("permission status - granted", script_result); | 200 ASSERT_EQ("permission status - granted", script_result); |
| 181 | 201 |
| 182 ASSERT_TRUE(RunScript("registerPush()", &script_result)); | 202 ASSERT_TRUE(RunScript("registerPush()", &script_result)); |
| 183 EXPECT_EQ(std::string(kPushMessagingEndpoint) + " - 1", script_result); | 203 EXPECT_EQ(std::string(kPushMessagingEndpoint) + " - 1", script_result); |
| 184 | 204 |
| 185 PushMessagingApplicationId app_id(https_server()->GetURL(""), 0L); | 205 PushMessagingApplicationId app_id(https_server()->GetURL(""), 0L); |
| 186 EXPECT_EQ(app_id.ToString(), gcm_service()->last_registered_app_id()); | 206 EXPECT_EQ(app_id.ToString(), gcm_service()->last_registered_app_id()); |
| 187 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 207 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| 188 } | 208 } |
| 189 | 209 |
| 190 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 210 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 191 RegisterFailureNoPushPermission) { | 211 RegisterSuccessNotificationsPrompt) { |
| 192 std::string script_result; | 212 std::string script_result; |
| 193 | 213 |
| 194 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 214 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 195 ASSERT_EQ("ok - service worker registered", script_result); | 215 ASSERT_EQ("ok - service worker registered", script_result); |
| 196 | 216 |
| 217 InfoBarResponder accepting_responder(browser(), true); | |
| 197 ASSERT_TRUE(RunScript("registerPush()", &script_result)); | 218 ASSERT_TRUE(RunScript("registerPush()", &script_result)); |
| 198 EXPECT_EQ("AbortError - Registration failed - permission denied", | 219 EXPECT_EQ(std::string(kPushMessagingEndpoint) + " - 1", script_result); |
| 199 script_result); | 220 |
| 221 PushMessagingApplicationId app_id(https_server()->GetURL(""), 0L); | |
| 222 EXPECT_EQ(app_id.ToString(), gcm_service()->last_registered_app_id()); | |
| 223 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | |
| 200 } | 224 } |
| 201 | 225 |
| 202 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 226 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| 203 RegisterFailureNotificationsBlocked) { | 227 RegisterFailureNotificationsBlocked) { |
| 204 std::string script_result; | 228 std::string script_result; |
| 205 | 229 |
| 206 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 230 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 207 ASSERT_EQ("ok - service worker registered", script_result); | 231 ASSERT_EQ("ok - service worker registered", script_result); |
| 208 | 232 |
| 209 InfoBarResponder cancelling_responder(browser(), false); | 233 InfoBarResponder cancelling_responder(browser(), false); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 | 428 |
| 405 ASSERT_TRUE(RunScript("registerPush()", &script_result)); | 429 ASSERT_TRUE(RunScript("registerPush()", &script_result)); |
| 406 EXPECT_EQ("AbortError - Registration failed - permission denied", | 430 EXPECT_EQ("AbortError - Registration failed - permission denied", |
| 407 script_result); | 431 script_result); |
| 408 | 432 |
| 409 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); | 433 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); |
| 410 EXPECT_EQ("permission status - denied", script_result); | 434 EXPECT_EQ("permission status - denied", script_result); |
| 411 } | 435 } |
| 412 | 436 |
| 413 } // namespace gcm | 437 } // namespace gcm |
| OLD | NEW |