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

Side by Side Diff: chrome/browser/services/gcm/push_messaging_browsertest.cc

Issue 673783003: BrowserTest for delivering push message to service worker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@PushIntegrationTest2
Patch Set: Use generic data requesting class in js. Created 6 years, 1 month 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
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 "chrome/browser/infobars/infobar_service.h" 8 #include "chrome/browser/infobars/infobar_service.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" 10 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h"
11 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" 11 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
12 #include "chrome/browser/services/gcm/push_messaging_application_id.h" 12 #include "chrome/browser/services/gcm/push_messaging_application_id.h"
13 #include "chrome/browser/services/gcm/push_messaging_constants.h" 13 #include "chrome/browser/services/gcm/push_messaging_constants.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/test/base/in_process_browser_test.h" 16 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
18 #include "components/gcm_driver/gcm_client.h"
18 #include "components/infobars/core/confirm_infobar_delegate.h" 19 #include "components/infobars/core/confirm_infobar_delegate.h"
19 #include "components/infobars/core/infobar.h" 20 #include "components/infobars/core/infobar.h"
20 #include "components/infobars/core/infobar_manager.h" 21 #include "components/infobars/core/infobar_manager.h"
21 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
22 #include "content/public/common/content_switches.h" 23 #include "content/public/common/content_switches.h"
23 #include "content/public/test/browser_test_utils.h" 24 #include "content/public/test/browser_test_utils.h"
24 25
25 namespace gcm { 26 namespace gcm {
26 27
27 namespace { 28 namespace {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 InProcessBrowserTest::SetUp(); 86 InProcessBrowserTest::SetUp();
86 } 87 }
87 88
88 // InProcessBrowserTest: 89 // InProcessBrowserTest:
89 virtual void SetUpOnMainThread() override { 90 virtual void SetUpOnMainThread() override {
90 gcm_service_ = static_cast<FakeGCMProfileService*>( 91 gcm_service_ = static_cast<FakeGCMProfileService*>(
91 GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( 92 GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse(
92 browser()->profile(), &FakeGCMProfileService::Build)); 93 browser()->profile(), &FakeGCMProfileService::Build));
93 gcm_service_->set_collect(true); 94 gcm_service_->set_collect(true);
94 95
96 loadTestPage();
97
98 InProcessBrowserTest::SetUpOnMainThread();
99 }
100
101 void loadTestPage() {
95 ui_test_utils::NavigateToURL( 102 ui_test_utils::NavigateToURL(
96 browser(), https_server_->GetURL("files/push_messaging/test.html")); 103 browser(), https_server_->GetURL("files/push_messaging/test.html"));
97
98 InProcessBrowserTest::SetUpOnMainThread();
99 } 104 }
100 105
101 bool RunScript(const std::string& script, std::string* result) { 106 bool RunScript(const std::string& script, std::string* result) {
102 return content::ExecuteScriptAndExtractString( 107 return content::ExecuteScriptAndExtractString(
103 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), 108 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(),
104 script, 109 script,
105 result); 110 result);
106 } 111 }
107 112
108 bool RegisterServiceWorker(std::string* result) {
109 return RunScript("registerServiceWorker()", result);
110 }
111
112 bool RegisterPush(std::string* result) {
113 return RunScript("registerPush('1234567890')", result);
114 }
115
116 net::SpawnedTestServer* https_server() const { return https_server_.get(); } 113 net::SpawnedTestServer* https_server() const { return https_server_.get(); }
117 114
118 FakeGCMProfileService* gcm_service() const { return gcm_service_; } 115 FakeGCMProfileService* gcm_service() const { return gcm_service_; }
119 116
117 PushMessagingServiceImpl* push_service() {
118 return static_cast<PushMessagingServiceImpl*>(
119 gcm_service_->push_messaging_service());
120 }
121
120 private: 122 private:
121 scoped_ptr<net::SpawnedTestServer> https_server_; 123 scoped_ptr<net::SpawnedTestServer> https_server_;
122 FakeGCMProfileService* gcm_service_; 124 FakeGCMProfileService* gcm_service_;
123 125
124 DISALLOW_COPY_AND_ASSIGN(PushMessagingBrowserTest); 126 DISALLOW_COPY_AND_ASSIGN(PushMessagingBrowserTest);
125 }; 127 };
126 128
127 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterSuccess) { 129 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterSuccess) {
128 std::string register_worker_result; 130 std::string script_result;
129 ASSERT_TRUE(RegisterServiceWorker(&register_worker_result)); 131
130 ASSERT_EQ("ok", register_worker_result); 132 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
133 ASSERT_EQ("ok - service worker registered", script_result);
131 134
132 InfoBarResponder accepting_responder(browser(), true); 135 InfoBarResponder accepting_responder(browser(), true);
133 136
134 std::string register_push_result; 137 ASSERT_TRUE(RunScript("registerPush('1234567890')", &script_result));
135 ASSERT_TRUE(RegisterPush(&register_push_result)); 138 EXPECT_EQ(std::string(kPushMessagingEndpoint) + " - 1", script_result);
136 EXPECT_EQ(std::string(kPushMessagingEndpoint) + " - 1", register_push_result);
137 139
138 PushMessagingApplicationId expected_id(https_server()->GetURL(""), 0L); 140 PushMessagingApplicationId app_id(https_server()->GetURL(""), 0L);
139 EXPECT_EQ(expected_id.ToString(), gcm_service()->last_registered_app_id()); 141 EXPECT_EQ(app_id.ToString(), gcm_service()->last_registered_app_id());
140 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); 142 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]);
141 } 143 }
142 144
143 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterFailureNoPermission) { 145 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterFailureNoPermission) {
144 std::string register_worker_result; 146 std::string script_result;
145 ASSERT_TRUE(RegisterServiceWorker(&register_worker_result)); 147
146 ASSERT_EQ("ok", register_worker_result); 148 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
149 ASSERT_EQ("ok - service worker registered", script_result);
147 150
148 InfoBarResponder cancelling_responder(browser(), false); 151 InfoBarResponder cancelling_responder(browser(), false);
149 152
150 std::string register_push_result; 153 ASSERT_TRUE(RunScript("registerPush('1234567890')", &script_result));
151 ASSERT_TRUE(RegisterPush(&register_push_result));
152 EXPECT_EQ("AbortError - Registration failed - permission denied", 154 EXPECT_EQ("AbortError - Registration failed - permission denied",
153 register_push_result); 155 script_result);
156 }
157
158 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) {
159 std::string script_result;
160
161 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
162 ASSERT_EQ("ok - service worker registered", script_result);
163
164 InfoBarResponder accepting_responder(browser(), true);
165
166 ASSERT_TRUE(RunScript("registerPush('1234567890')", &script_result));
167 EXPECT_EQ(std::string(kPushMessagingEndpoint) + " - 1", script_result);
168
169 PushMessagingApplicationId app_id(https_server()->GetURL(""), 0L);
170 EXPECT_EQ(app_id.ToString(), gcm_service()->last_registered_app_id());
171 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]);
172
173 ASSERT_TRUE(RunScript("isControlled()", &script_result));
174 ASSERT_EQ("false - is not controlled", script_result);
175
176 loadTestPage(); // Reload to become controlled.
177
178 ASSERT_TRUE(RunScript("isControlled()", &script_result));
179 ASSERT_EQ("true - is controlled", script_result);
180
181 GCMClient::IncomingMessage message;
182 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.
183 push_service()->OnMessage(app_id.ToString(), message);
184 ASSERT_TRUE(RunScript("asyncData.getData('push')", &script_result));
185 EXPECT_EQ("testdata", script_result);
154 } 186 }
155 187
156 } // namespace gcm 188 } // namespace gcm
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/push_messaging/service_worker.js » ('j') | chrome/test/data/push_messaging/service_worker.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698