Chromium Code Reviews| Index: chrome/browser/services/gcm/push_messaging_browsertest.cc |
| diff --git a/chrome/browser/services/gcm/push_messaging_browsertest.cc b/chrome/browser/services/gcm/push_messaging_browsertest.cc |
| index 2e603b64118180a01f83463fbd346bf14b49ffe7..ff13ef25b5fa6086ce957ba339fcb3b7f87d2158 100644 |
| --- a/chrome/browser/services/gcm/push_messaging_browsertest.cc |
| +++ b/chrome/browser/services/gcm/push_messaging_browsertest.cc |
| @@ -15,6 +15,7 @@ |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| #include "chrome/test/base/in_process_browser_test.h" |
| #include "chrome/test/base/ui_test_utils.h" |
| +#include "components/gcm_driver/gcm_client.h" |
| #include "components/infobars/core/confirm_infobar_delegate.h" |
| #include "components/infobars/core/infobar.h" |
| #include "components/infobars/core/infobar_manager.h" |
| @@ -92,12 +93,16 @@ class PushMessagingBrowserTest : public InProcessBrowserTest { |
| browser()->profile(), &FakeGCMProfileService::Build)); |
| gcm_service_->set_collect(true); |
| - ui_test_utils::NavigateToURL( |
| - browser(), https_server_->GetURL("files/push_messaging/test.html")); |
| + loadTestPage(); |
| InProcessBrowserTest::SetUpOnMainThread(); |
| } |
| + void loadTestPage() { |
| + ui_test_utils::NavigateToURL( |
| + browser(), https_server_->GetURL("files/push_messaging/test.html")); |
| + } |
| + |
| bool RunScript(const std::string& script, std::string* result) { |
| return content::ExecuteScriptAndExtractString( |
| browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), |
| @@ -105,18 +110,15 @@ class PushMessagingBrowserTest : public InProcessBrowserTest { |
| result); |
| } |
| - bool RegisterServiceWorker(std::string* result) { |
| - return RunScript("registerServiceWorker()", result); |
| - } |
| - |
| - bool RegisterPush(std::string* result) { |
| - return RunScript("registerPush('1234567890')", result); |
| - } |
| - |
| net::SpawnedTestServer* https_server() const { return https_server_.get(); } |
| FakeGCMProfileService* gcm_service() const { return gcm_service_; } |
| + PushMessagingServiceImpl* push_service() { |
| + return static_cast<PushMessagingServiceImpl*>( |
| + gcm_service_->push_messaging_service()); |
| + } |
| + |
| private: |
| scoped_ptr<net::SpawnedTestServer> https_server_; |
| FakeGCMProfileService* gcm_service_; |
| @@ -125,32 +127,62 @@ class PushMessagingBrowserTest : public InProcessBrowserTest { |
| }; |
| IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterSuccess) { |
| - std::string register_worker_result; |
| - ASSERT_TRUE(RegisterServiceWorker(®ister_worker_result)); |
| - ASSERT_EQ("ok", register_worker_result); |
| + std::string script_result; |
| + |
| + ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| + ASSERT_EQ("ok - service worker registered", script_result); |
| InfoBarResponder accepting_responder(browser(), true); |
| - std::string register_push_result; |
| - ASSERT_TRUE(RegisterPush(®ister_push_result)); |
| - EXPECT_EQ(std::string(kPushMessagingEndpoint) + " - 1", register_push_result); |
| + ASSERT_TRUE(RunScript("registerPush('1234567890')", &script_result)); |
| + EXPECT_EQ(std::string(kPushMessagingEndpoint) + " - 1", script_result); |
| - PushMessagingApplicationId expected_id(https_server()->GetURL(""), 0L); |
| - EXPECT_EQ(expected_id.ToString(), gcm_service()->last_registered_app_id()); |
| + PushMessagingApplicationId app_id(https_server()->GetURL(""), 0L); |
| + EXPECT_EQ(app_id.ToString(), gcm_service()->last_registered_app_id()); |
| EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| } |
| IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterFailureNoPermission) { |
| - std::string register_worker_result; |
| - ASSERT_TRUE(RegisterServiceWorker(®ister_worker_result)); |
| - ASSERT_EQ("ok", register_worker_result); |
| + std::string script_result; |
| + |
| + ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| + ASSERT_EQ("ok - service worker registered", script_result); |
| InfoBarResponder cancelling_responder(browser(), false); |
| - std::string register_push_result; |
| - ASSERT_TRUE(RegisterPush(®ister_push_result)); |
| + ASSERT_TRUE(RunScript("registerPush('1234567890')", &script_result)); |
| EXPECT_EQ("AbortError - Registration failed - permission denied", |
| - register_push_result); |
| + script_result); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) { |
| + std::string script_result; |
| + |
| + ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| + ASSERT_EQ("ok - service worker registered", script_result); |
| + |
| + InfoBarResponder accepting_responder(browser(), true); |
| + |
| + ASSERT_TRUE(RunScript("registerPush('1234567890')", &script_result)); |
| + EXPECT_EQ(std::string(kPushMessagingEndpoint) + " - 1", script_result); |
| + |
| + PushMessagingApplicationId app_id(https_server()->GetURL(""), 0L); |
| + EXPECT_EQ(app_id.ToString(), gcm_service()->last_registered_app_id()); |
| + EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
| + |
| + ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| + ASSERT_EQ("false - is not controlled", script_result); |
| + |
| + loadTestPage(); // Reload to become controlled. |
| + |
| + ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
| + ASSERT_EQ("true - is controlled", script_result); |
| + |
| + GCMClient::IncomingMessage message; |
| + message.data = {{"data", "testdata"}}; |
|
fgorski
2014/10/24 17:09:24
Just noticed C++11.
Nice. And since it is not bann
fgorski
2014/10/24 21:53:48
although having second look at http://chromium-cpp
Michael van Ouwerkerk
2014/10/27 15:14:30
Done.
Michael van Ouwerkerk
2014/10/27 15:14:30
Acknowledged.
|
| + push_service()->OnMessage(app_id.ToString(), message); |
| + ASSERT_TRUE(RunScript("asyncData.getData('push')", &script_result)); |
| + EXPECT_EQ("testdata", script_result); |
| } |
| } // namespace gcm |