| OLD | NEW |
| 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_status.h" | 14 #include "content/browser/background_sync/background_sync_status.h" |
| 15 #include "content/browser/background_sync/client_background_sync_registration.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" |
| 24 #include "content/public/test/content_browser_test_utils.h" | 25 #include "content/public/test/content_browser_test_utils.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 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<ClientBackgroundSyncRegistration> registration) { |
| 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->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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 |
| 377 } // namespace | 415 } // namespace |
| 378 | 416 |
| 379 } // namespace content | 417 } // namespace content |
| OLD | NEW |