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

Side by Side Diff: content/browser/background_sync/background_sync_browsertest.cc

Issue 1282013004: BackgroundSyncManager tracks client registrations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up Created 5 years, 4 months 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "background_sync_registration_handle.h"
9 #include "base/command_line.h" 10 #include "base/command_line.h"
10 #include "base/strings/string_split.h" 11 #include "base/strings/string_split.h"
11 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
12 #include "base/task_runner_util.h" 13 #include "base/task_runner_util.h"
13 #include "content/browser/background_sync/background_sync_manager.h" 14 #include "content/browser/background_sync/background_sync_manager.h"
14 #include "content/browser/background_sync/background_sync_status.h" 15 #include "content/browser/background_sync/background_sync_status.h"
15 #include "content/browser/service_worker/service_worker_context_wrapper.h" 16 #include "content/browser/service_worker/service_worker_context_wrapper.h"
16 #include "content/browser/service_worker/service_worker_registration.h" 17 #include "content/browser/service_worker/service_worker_registration.h"
17 #include "content/public/browser/background_sync_context.h" 18 #include "content/public/browser/background_sync_context.h"
18 #include "content/public/browser/browser_context.h" 19 #include "content/public/browser/browser_context.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 54 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
54 bool* result_out, 55 bool* result_out,
55 bool result) { 56 bool result) {
56 *result_out = result; 57 *result_out = result;
57 task_runner->PostTask(FROM_HERE, quit); 58 task_runner->PostTask(FROM_HERE, quit);
58 } 59 }
59 60
60 void OneShotPendingDidGetSyncRegistration( 61 void OneShotPendingDidGetSyncRegistration(
61 const base::Callback<void(bool)>& callback, 62 const base::Callback<void(bool)>& callback,
62 BackgroundSyncStatus error_type, 63 BackgroundSyncStatus error_type,
63 const BackgroundSyncRegistration& registration) { 64 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle) {
64 ASSERT_EQ(BACKGROUND_SYNC_STATUS_OK, error_type); 65 ASSERT_EQ(BACKGROUND_SYNC_STATUS_OK, error_type);
65 callback.Run(registration.sync_state() == SYNC_STATE_PENDING); 66 callback.Run(registration_handle->RegistrationForTests()->sync_state() ==
67 SYNC_STATE_PENDING);
66 } 68 }
67 69
68 void OneShotPendingDidGetSWRegistration( 70 void OneShotPendingDidGetSWRegistration(
69 const scoped_refptr<BackgroundSyncContext> sync_context, 71 const scoped_refptr<BackgroundSyncContext> sync_context,
70 const std::string& tag, 72 const std::string& tag,
71 const base::Callback<void(bool)>& callback, 73 const base::Callback<void(bool)>& callback,
72 ServiceWorkerStatusCode status, 74 ServiceWorkerStatusCode status,
73 const scoped_refptr<ServiceWorkerRegistration>& registration) { 75 const scoped_refptr<ServiceWorkerRegistration>& registration) {
74 ASSERT_EQ(SERVICE_WORKER_OK, status); 76 ASSERT_EQ(SERVICE_WORKER_OK, status);
75 int64 service_worker_id = registration->id(); 77 int64 service_worker_id = registration->id();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 150
149 void SetOnline(bool online); 151 void SetOnline(bool online);
150 152
151 // Returns true if the one-shot sync with tag is currently pending. Fails 153 // Returns true if the one-shot sync with tag is currently pending. Fails
152 // (assertion failure) if the tag isn't registered. 154 // (assertion failure) if the tag isn't registered.
153 bool OneShotPending(const std::string& tag); 155 bool OneShotPending(const std::string& tag);
154 156
155 bool PopConsole(const std::string& expected_msg); 157 bool PopConsole(const std::string& expected_msg);
156 bool RegisterServiceWorker(); 158 bool RegisterServiceWorker();
157 bool RegisterOneShot(const std::string& tag); 159 bool RegisterOneShot(const std::string& tag);
160 bool UnregisterOneShot(const std::string& tag);
161 bool UnregisterOneShotTwice(const std::string& tag);
158 bool GetRegistrationOneShot(const std::string& tag); 162 bool GetRegistrationOneShot(const std::string& tag);
159 bool GetRegistrationsOneShot(const std::vector<std::string>& expected_tags); 163 bool GetRegistrationsOneShot(const std::vector<std::string>& expected_tags);
160 bool CompleteDelayedOneShot(); 164 bool CompleteDelayedOneShot();
161 bool RejectDelayedOneShot(); 165 bool RejectDelayedOneShot();
162 166
163 private: 167 private:
164 scoped_ptr<net::SpawnedTestServer> https_server_; 168 scoped_ptr<net::SpawnedTestServer> https_server_;
165 Shell* shell_ = nullptr; 169 Shell* shell_ = nullptr;
166 170
167 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncBrowserTest); 171 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncBrowserTest);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 return script_result == BuildExpectedResult("service worker", "registered"); 220 return script_result == BuildExpectedResult("service worker", "registered");
217 } 221 }
218 222
219 bool BackgroundSyncBrowserTest::RegisterOneShot(const std::string& tag) { 223 bool BackgroundSyncBrowserTest::RegisterOneShot(const std::string& tag) {
220 std::string script_result; 224 std::string script_result;
221 EXPECT_TRUE( 225 EXPECT_TRUE(
222 RunScript(BuildScriptString("registerOneShot", tag), &script_result)); 226 RunScript(BuildScriptString("registerOneShot", tag), &script_result));
223 return script_result == BuildExpectedResult(tag, "registered"); 227 return script_result == BuildExpectedResult(tag, "registered");
224 } 228 }
225 229
230 bool BackgroundSyncBrowserTest::UnregisterOneShot(const std::string& tag) {
231 std::string script_result;
232 EXPECT_TRUE(
233 RunScript(BuildScriptString("unregisterOneShot", tag), &script_result));
234 return script_result == BuildExpectedResult(tag, "unregistered");
235 }
236
237 bool BackgroundSyncBrowserTest::UnregisterOneShotTwice(const std::string& tag) {
238 std::string script_result;
239 EXPECT_TRUE(RunScript(BuildScriptString("unregisterOneShotTwice", tag),
240 &script_result));
241 return script_result ==
242 BuildExpectedResult(tag, "failed to unregister twice");
243 }
244
226 bool BackgroundSyncBrowserTest::GetRegistrationOneShot(const std::string& tag) { 245 bool BackgroundSyncBrowserTest::GetRegistrationOneShot(const std::string& tag) {
227 std::string script_result; 246 std::string script_result;
228 EXPECT_TRUE(RunScript(BuildScriptString("getRegistrationOneShot", tag), 247 EXPECT_TRUE(RunScript(BuildScriptString("getRegistrationOneShot", tag),
229 &script_result)); 248 &script_result));
230 return script_result == BuildExpectedResult(tag, "found"); 249 return script_result == BuildExpectedResult(tag, "found");
231 } 250 }
232 251
233 bool BackgroundSyncBrowserTest::GetRegistrationsOneShot( 252 bool BackgroundSyncBrowserTest::GetRegistrationsOneShot(
234 const std::vector<std::string>& expected_tags) { 253 const std::vector<std::string>& expected_tags) {
235 std::string script_result; 254 std::string script_result;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 SetOnline(false); 386 SetOnline(false);
368 registered_tags.push_back("foo"); 387 registered_tags.push_back("foo");
369 registered_tags.push_back("bar"); 388 registered_tags.push_back("bar");
370 389
371 for (const std::string& tag : registered_tags) 390 for (const std::string& tag : registered_tags)
372 EXPECT_TRUE(RegisterOneShot(tag)); 391 EXPECT_TRUE(RegisterOneShot(tag));
373 392
374 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); 393 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags));
375 } 394 }
376 395
396 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, Unregister) {
397 EXPECT_TRUE(RegisterServiceWorker());
398 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page.
399
400 SetOnline(false);
401 EXPECT_TRUE(RegisterOneShot("foo"));
402 EXPECT_TRUE(UnregisterOneShot("foo"));
403 EXPECT_FALSE(GetRegistrationOneShot("foo"));
404 }
405
406 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, UnregisterTwice) {
407 EXPECT_TRUE(RegisterServiceWorker());
408 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page.
409
410 SetOnline(false);
411 EXPECT_TRUE(RegisterOneShot("foo"));
412 EXPECT_TRUE(UnregisterOneShotTwice("foo"));
413 EXPECT_FALSE(GetRegistrationOneShot("foo"));
414 }
415
377 } // namespace 416 } // namespace
378 417
379 } // namespace content 418 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698