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

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: Removed test Created 5 years, 3 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
« no previous file with comments | « no previous file | content/browser/background_sync/background_sync_context_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/task_runner_util.h" 12 #include "base/task_runner_util.h"
13 #include "content/browser/background_sync/background_sync_manager.h" 13 #include "content/browser/background_sync/background_sync_manager.h"
14 #include "content/browser/background_sync/background_sync_registration_handle.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"
19 #include "content/public/browser/storage_partition.h" 20 #include "content/public/browser/storage_partition.h"
20 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
21 #include "content/public/common/content_switches.h" 22 #include "content/public/common/content_switches.h"
22 #include "content/public/test/browser_test_utils.h" 23 #include "content/public/test/browser_test_utils.h"
23 #include "content/public/test/content_browser_test.h" 24 #include "content/public/test/content_browser_test.h"
(...skipping 29 matching lines...) Expand all
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->sync_state() == SYNC_STATE_PENDING);
66 } 67 }
67 68
68 void OneShotPendingDidGetSWRegistration( 69 void OneShotPendingDidGetSWRegistration(
69 const scoped_refptr<BackgroundSyncContext> sync_context, 70 const scoped_refptr<BackgroundSyncContext> sync_context,
70 const std::string& tag, 71 const std::string& tag,
71 const base::Callback<void(bool)>& callback, 72 const base::Callback<void(bool)>& callback,
72 ServiceWorkerStatusCode status, 73 ServiceWorkerStatusCode status,
73 const scoped_refptr<ServiceWorkerRegistration>& registration) { 74 const scoped_refptr<ServiceWorkerRegistration>& registration) {
74 ASSERT_EQ(SERVICE_WORKER_OK, status); 75 ASSERT_EQ(SERVICE_WORKER_OK, status);
75 int64 service_worker_id = registration->id(); 76 int64 service_worker_id = registration->id();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 149
149 void SetOnline(bool online); 150 void SetOnline(bool online);
150 151
151 // Returns true if the one-shot sync with tag is currently pending. Fails 152 // Returns true if the one-shot sync with tag is currently pending. Fails
152 // (assertion failure) if the tag isn't registered. 153 // (assertion failure) if the tag isn't registered.
153 bool OneShotPending(const std::string& tag); 154 bool OneShotPending(const std::string& tag);
154 155
155 bool PopConsole(const std::string& expected_msg); 156 bool PopConsole(const std::string& expected_msg);
156 bool RegisterServiceWorker(); 157 bool RegisterServiceWorker();
157 bool RegisterOneShot(const std::string& tag); 158 bool RegisterOneShot(const std::string& tag);
159 bool UnregisterOneShot(const std::string& tag);
160 bool UnregisterOneShotTwice(const std::string& tag);
158 bool GetRegistrationOneShot(const std::string& tag); 161 bool GetRegistrationOneShot(const std::string& tag);
159 bool GetRegistrationsOneShot(const std::vector<std::string>& expected_tags); 162 bool GetRegistrationsOneShot(const std::vector<std::string>& expected_tags);
160 bool CompleteDelayedOneShot(); 163 bool CompleteDelayedOneShot();
161 bool RejectDelayedOneShot(); 164 bool RejectDelayedOneShot();
162 165
163 private: 166 private:
164 scoped_ptr<net::SpawnedTestServer> https_server_; 167 scoped_ptr<net::SpawnedTestServer> https_server_;
165 Shell* shell_ = nullptr; 168 Shell* shell_ = nullptr;
166 169
167 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncBrowserTest); 170 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"); 219 return script_result == BuildExpectedResult("service worker", "registered");
217 } 220 }
218 221
219 bool BackgroundSyncBrowserTest::RegisterOneShot(const std::string& tag) { 222 bool BackgroundSyncBrowserTest::RegisterOneShot(const std::string& tag) {
220 std::string script_result; 223 std::string script_result;
221 EXPECT_TRUE( 224 EXPECT_TRUE(
222 RunScript(BuildScriptString("registerOneShot", tag), &script_result)); 225 RunScript(BuildScriptString("registerOneShot", tag), &script_result));
223 return script_result == BuildExpectedResult(tag, "registered"); 226 return script_result == BuildExpectedResult(tag, "registered");
224 } 227 }
225 228
229 bool BackgroundSyncBrowserTest::UnregisterOneShot(const std::string& tag) {
230 std::string script_result;
231 EXPECT_TRUE(
232 RunScript(BuildScriptString("unregisterOneShot", tag), &script_result));
233 return script_result == BuildExpectedResult(tag, "unregistered");
234 }
235
236 bool BackgroundSyncBrowserTest::UnregisterOneShotTwice(const std::string& tag) {
237 std::string script_result;
238 EXPECT_TRUE(RunScript(BuildScriptString("unregisterOneShotTwice", tag),
239 &script_result));
240 return script_result ==
241 BuildExpectedResult(tag, "failed to unregister twice");
242 }
243
226 bool BackgroundSyncBrowserTest::GetRegistrationOneShot(const std::string& tag) { 244 bool BackgroundSyncBrowserTest::GetRegistrationOneShot(const std::string& tag) {
227 std::string script_result; 245 std::string script_result;
228 EXPECT_TRUE(RunScript(BuildScriptString("getRegistrationOneShot", tag), 246 EXPECT_TRUE(RunScript(BuildScriptString("getRegistrationOneShot", tag),
229 &script_result)); 247 &script_result));
230 return script_result == BuildExpectedResult(tag, "found"); 248 return script_result == BuildExpectedResult(tag, "found");
231 } 249 }
232 250
233 bool BackgroundSyncBrowserTest::GetRegistrationsOneShot( 251 bool BackgroundSyncBrowserTest::GetRegistrationsOneShot(
234 const std::vector<std::string>& expected_tags) { 252 const std::vector<std::string>& expected_tags) {
235 std::string script_result; 253 std::string script_result;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 SetOnline(false); 385 SetOnline(false);
368 registered_tags.push_back("foo"); 386 registered_tags.push_back("foo");
369 registered_tags.push_back("bar"); 387 registered_tags.push_back("bar");
370 388
371 for (const std::string& tag : registered_tags) 389 for (const std::string& tag : registered_tags)
372 EXPECT_TRUE(RegisterOneShot(tag)); 390 EXPECT_TRUE(RegisterOneShot(tag));
373 391
374 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); 392 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags));
375 } 393 }
376 394
395 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, Unregister) {
396 EXPECT_TRUE(RegisterServiceWorker());
397 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page.
398
399 SetOnline(false);
400 EXPECT_TRUE(RegisterOneShot("foo"));
401 EXPECT_TRUE(UnregisterOneShot("foo"));
402 EXPECT_FALSE(GetRegistrationOneShot("foo"));
403 }
404
405 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, UnregisterTwice) {
406 EXPECT_TRUE(RegisterServiceWorker());
407 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page.
408
409 SetOnline(false);
410 EXPECT_TRUE(RegisterOneShot("foo"));
411 EXPECT_TRUE(UnregisterOneShotTwice("foo"));
412 EXPECT_FALSE(GetRegistrationOneShot("foo"));
413 }
414
415 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, UnregisterMidSync) {
416 EXPECT_TRUE(RegisterServiceWorker());
417 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page.
418
419 EXPECT_TRUE(RegisterOneShot("unregister"));
420 EXPECT_TRUE(PopConsole("ok - unregister completed"));
421 }
422
377 } // namespace 423 } // namespace
378 424
379 } // namespace content 425 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/background_sync/background_sync_context_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698