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_network_observer.h" | 14 #include "content/browser/background_sync/background_sync_network_observer.h" |
15 #include "content/browser/background_sync/background_sync_registration_handle.h" | 15 #include "content/browser/background_sync/background_sync_registration_handle.h" |
16 #include "content/browser/background_sync/background_sync_status.h" | 16 #include "content/browser/background_sync/background_sync_status.h" |
17 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 17 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
18 #include "content/browser/service_worker/service_worker_registration.h" | 18 #include "content/browser/service_worker/service_worker_registration.h" |
19 #include "content/public/browser/background_sync_context.h" | 19 #include "content/public/browser/background_sync_context.h" |
20 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
21 #include "content/public/browser/storage_partition.h" | 21 #include "content/public/browser/storage_partition.h" |
22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
23 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
| 24 #include "content/public/test/background_sync_test_util.h" |
24 #include "content/public/test/browser_test_utils.h" | 25 #include "content/public/test/browser_test_utils.h" |
25 #include "content/public/test/content_browser_test.h" | 26 #include "content/public/test/content_browser_test.h" |
26 #include "content/public/test/content_browser_test_utils.h" | 27 #include "content/public/test/content_browser_test_utils.h" |
27 #include "content/public/test/test_utils.h" | 28 #include "content/public/test/test_utils.h" |
28 #include "content/shell/browser/shell.h" | 29 #include "content/shell/browser/shell.h" |
29 #include "net/base/network_change_notifier.h" | 30 #include "net/base/network_change_notifier.h" |
30 #include "net/test/embedded_test_server/embedded_test_server.h" | 31 #include "net/test/embedded_test_server/embedded_test_server.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
32 | 33 |
33 using net::NetworkChangeNotifier; | 34 using net::NetworkChangeNotifier; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 } | 104 } |
104 | 105 |
105 } // namespace | 106 } // namespace |
106 | 107 |
107 class BackgroundSyncBrowserTest : public ContentBrowserTest { | 108 class BackgroundSyncBrowserTest : public ContentBrowserTest { |
108 public: | 109 public: |
109 BackgroundSyncBrowserTest() {} | 110 BackgroundSyncBrowserTest() {} |
110 ~BackgroundSyncBrowserTest() override {} | 111 ~BackgroundSyncBrowserTest() override {} |
111 | 112 |
112 void SetUp() override { | 113 void SetUp() override { |
113 BackgroundSyncNetworkObserver::SetIgnoreNetworkChangeNotifierForTests(true); | 114 BackgroundSyncTestUtil::SetIgnoreNetworkChangeNotifier(true); |
| 115 |
114 ContentBrowserTest::SetUp(); | 116 ContentBrowserTest::SetUp(); |
115 } | 117 } |
116 | 118 |
117 void SetIncognitoMode(bool incognito) { | 119 void SetIncognitoMode(bool incognito) { |
118 shell_ = incognito ? CreateOffTheRecordBrowser() : shell(); | 120 shell_ = incognito ? CreateOffTheRecordBrowser() : shell(); |
119 } | 121 } |
120 | 122 |
121 StoragePartition* GetStorage() { | 123 StoragePartition* GetStorage() { |
122 WebContents* web_contents = shell_->web_contents(); | 124 WebContents* web_contents = shell_->web_contents(); |
123 return BrowserContext::GetStoragePartition( | 125 return BrowserContext::GetStoragePartition( |
124 web_contents->GetBrowserContext(), web_contents->GetSiteInstance()); | 126 web_contents->GetBrowserContext(), web_contents->GetSiteInstance()); |
125 } | 127 } |
126 | 128 |
127 BackgroundSyncContext* GetSyncContext() { | 129 BackgroundSyncContext* GetSyncContext() { |
128 return GetStorage()->GetBackgroundSyncContext(); | 130 return GetStorage()->GetBackgroundSyncContext(); |
129 } | 131 } |
130 | 132 |
| 133 WebContents* web_contents() { return shell_->web_contents(); } |
| 134 |
131 void SetUpCommandLine(base::CommandLine* command_line) override { | 135 void SetUpCommandLine(base::CommandLine* command_line) override { |
132 // TODO(jkarlin): Remove this once background sync is no longer | 136 // TODO(jkarlin): Remove this once background sync is no longer |
133 // experimental. | 137 // experimental. |
134 command_line->AppendSwitch( | 138 command_line->AppendSwitch( |
135 switches::kEnableExperimentalWebPlatformFeatures); | 139 switches::kEnableExperimentalWebPlatformFeatures); |
136 } | 140 } |
137 | 141 |
138 void SetUpOnMainThread() override { | 142 void SetUpOnMainThread() override { |
139 https_server_.reset( | 143 https_server_.reset( |
140 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); | 144 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); |
141 https_server_->ServeFilesFromSourceDirectory("content/test/data"); | 145 https_server_->ServeFilesFromSourceDirectory("content/test/data"); |
142 ASSERT_TRUE(https_server_->Start()); | 146 ASSERT_TRUE(https_server_->Start()); |
143 | 147 |
144 SetIncognitoMode(false); | 148 SetIncognitoMode(false); |
145 SetMaxSyncAttempts(1); | 149 SetMaxSyncAttempts(1); |
146 SetOnline(true); | 150 BackgroundSyncTestUtil::SetOnline(web_contents(), true); |
147 ASSERT_TRUE(LoadTestPage(kDefaultTestURL)); | 151 ASSERT_TRUE(LoadTestPage(kDefaultTestURL)); |
148 | 152 |
149 ContentBrowserTest::SetUpOnMainThread(); | 153 ContentBrowserTest::SetUpOnMainThread(); |
150 } | 154 } |
151 | 155 |
152 void TearDownOnMainThread() override { https_server_.reset(); } | 156 void TearDownOnMainThread() override { https_server_.reset(); } |
153 | 157 |
154 bool LoadTestPage(const std::string& path) { | 158 bool LoadTestPage(const std::string& path) { |
155 return NavigateToURL(shell_, https_server_->GetURL(path)); | 159 return NavigateToURL(shell_, https_server_->GetURL(path)); |
156 } | 160 } |
157 | 161 |
158 bool RunScript(const std::string& script, std::string* result) { | 162 bool RunScript(const std::string& script, std::string* result) { |
159 return content::ExecuteScriptAndExtractString(shell_->web_contents(), | 163 return content::ExecuteScriptAndExtractString(web_contents(), script, |
160 script, result); | 164 result); |
161 } | 165 } |
162 | 166 |
163 // This runs asynchronously on the IO thread, but we don't need to wait for it | |
164 // to complete before running a background sync operation, since those also | |
165 // run on the IO thread. | |
166 void SetOnline(bool online); | |
167 void SetOnlineOnIOThread( | |
168 const scoped_refptr<BackgroundSyncContext>& sync_context, | |
169 bool online); | |
170 | |
171 // Returns true if the one-shot sync with tag is currently pending. Fails | 167 // Returns true if the one-shot sync with tag is currently pending. Fails |
172 // (assertion failure) if the tag isn't registered. | 168 // (assertion failure) if the tag isn't registered. |
173 bool OneShotPending(const std::string& tag); | 169 bool OneShotPending(const std::string& tag); |
174 | 170 |
175 // Sets the BackgroundSyncManager's max sync attempts per registration. | 171 // Sets the BackgroundSyncManager's max sync attempts per registration. |
176 void SetMaxSyncAttempts(int max_sync_attempts); | 172 void SetMaxSyncAttempts(int max_sync_attempts); |
177 | 173 |
178 void ClearStoragePartitionData(); | 174 void ClearStoragePartitionData(); |
179 | 175 |
180 std::string PopConsoleString(); | 176 std::string PopConsoleString(); |
(...skipping 16 matching lines...) Expand all Loading... |
197 bool NotifyWhenFinishedImmediateOneShot(const std::string& expected_msg); | 193 bool NotifyWhenFinishedImmediateOneShot(const std::string& expected_msg); |
198 bool StoreRegistrationOneShot(const std::string& tag); | 194 bool StoreRegistrationOneShot(const std::string& tag); |
199 | 195 |
200 private: | 196 private: |
201 scoped_ptr<net::EmbeddedTestServer> https_server_; | 197 scoped_ptr<net::EmbeddedTestServer> https_server_; |
202 Shell* shell_ = nullptr; | 198 Shell* shell_ = nullptr; |
203 | 199 |
204 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncBrowserTest); | 200 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncBrowserTest); |
205 }; | 201 }; |
206 | 202 |
207 void BackgroundSyncBrowserTest::SetOnline(bool online) { | |
208 ASSERT_TRUE(shell_); | |
209 BrowserThread::PostTask( | |
210 BrowserThread::IO, FROM_HERE, | |
211 base::Bind(&BackgroundSyncBrowserTest::SetOnlineOnIOThread, | |
212 base::Unretained(this), base::Unretained(GetSyncContext()), | |
213 online)); | |
214 base::RunLoop().RunUntilIdle(); | |
215 } | |
216 | |
217 void BackgroundSyncBrowserTest::SetOnlineOnIOThread( | |
218 const scoped_refptr<BackgroundSyncContext>& sync_context, | |
219 bool online) { | |
220 BackgroundSyncManager* sync_manager = sync_context->background_sync_manager(); | |
221 BackgroundSyncNetworkObserver* network_observer = | |
222 sync_manager->GetNetworkObserverForTesting(); | |
223 if (online) { | |
224 network_observer->NotifyManagerIfNetworkChangedForTesting( | |
225 NetworkChangeNotifier::CONNECTION_WIFI); | |
226 } else { | |
227 network_observer->NotifyManagerIfNetworkChangedForTesting( | |
228 NetworkChangeNotifier::CONNECTION_NONE); | |
229 } | |
230 } | |
231 | |
232 bool BackgroundSyncBrowserTest::OneShotPending(const std::string& tag) { | 203 bool BackgroundSyncBrowserTest::OneShotPending(const std::string& tag) { |
233 bool is_pending; | 204 bool is_pending; |
234 base::RunLoop run_loop; | 205 base::RunLoop run_loop; |
235 | 206 |
236 StoragePartition* storage = GetStorage(); | 207 StoragePartition* storage = GetStorage(); |
237 BackgroundSyncContext* sync_context = storage->GetBackgroundSyncContext(); | 208 BackgroundSyncContext* sync_context = storage->GetBackgroundSyncContext(); |
238 ServiceWorkerContextWrapper* service_worker_context = | 209 ServiceWorkerContextWrapper* service_worker_context = |
239 static_cast<ServiceWorkerContextWrapper*>( | 210 static_cast<ServiceWorkerContextWrapper*>( |
240 storage->GetServiceWorkerContext()); | 211 storage->GetServiceWorkerContext()); |
241 | 212 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 | 367 |
397 bool BackgroundSyncBrowserTest::RejectDelayedOneShot() { | 368 bool BackgroundSyncBrowserTest::RejectDelayedOneShot() { |
398 std::string script_result; | 369 std::string script_result; |
399 EXPECT_TRUE(RunScript("rejectDelayedOneShot()", &script_result)); | 370 EXPECT_TRUE(RunScript("rejectDelayedOneShot()", &script_result)); |
400 return script_result == BuildExpectedResult("delay", "rejecting"); | 371 return script_result == BuildExpectedResult("delay", "rejecting"); |
401 } | 372 } |
402 | 373 |
403 bool BackgroundSyncBrowserTest::NotifyWhenFinishedOneShot( | 374 bool BackgroundSyncBrowserTest::NotifyWhenFinishedOneShot( |
404 const std::string& tag) { | 375 const std::string& tag) { |
405 EXPECT_TRUE(content::ExecuteScript( | 376 EXPECT_TRUE(content::ExecuteScript( |
406 shell_->web_contents(), | 377 web_contents(), BuildScriptString("notifyWhenFinishedOneShot", tag))); |
407 BuildScriptString("notifyWhenFinishedOneShot", tag))); | |
408 return PopConsole(BuildExpectedResult(tag, "finished")); | 378 return PopConsole(BuildExpectedResult(tag, "finished")); |
409 } | 379 } |
410 | 380 |
411 bool BackgroundSyncBrowserTest::NotifyWhenFinishedImmediateOneShot( | 381 bool BackgroundSyncBrowserTest::NotifyWhenFinishedImmediateOneShot( |
412 const std::string& expected_msg) { | 382 const std::string& expected_msg) { |
413 std::string script_result; | 383 std::string script_result; |
414 EXPECT_TRUE( | 384 EXPECT_TRUE( |
415 RunScript("notifyWhenFinishedImmediateOneShot()", &script_result)); | 385 RunScript("notifyWhenFinishedImmediateOneShot()", &script_result)); |
416 return script_result == expected_msg; | 386 return script_result == expected_msg; |
417 } | 387 } |
(...skipping 25 matching lines...) Expand all Loading... |
443 EXPECT_TRUE(PopConsole("ok - foo_sw registered in SW")); | 413 EXPECT_TRUE(PopConsole("ok - foo_sw registered in SW")); |
444 EXPECT_TRUE(PopConsole("foo_sw fired")); | 414 EXPECT_TRUE(PopConsole("foo_sw fired")); |
445 EXPECT_FALSE(GetRegistrationOneShot("foo_sw")); | 415 EXPECT_FALSE(GetRegistrationOneShot("foo_sw")); |
446 } | 416 } |
447 | 417 |
448 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, OneShotDelaysForNetwork) { | 418 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, OneShotDelaysForNetwork) { |
449 EXPECT_TRUE(RegisterServiceWorker()); | 419 EXPECT_TRUE(RegisterServiceWorker()); |
450 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 420 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
451 | 421 |
452 // Prevent firing by going offline. | 422 // Prevent firing by going offline. |
453 SetOnline(false); | 423 BackgroundSyncTestUtil::SetOnline(web_contents(), false); |
454 EXPECT_TRUE(RegisterOneShot("foo")); | 424 EXPECT_TRUE(RegisterOneShot("foo")); |
455 EXPECT_TRUE(GetRegistrationOneShot("foo")); | 425 EXPECT_TRUE(GetRegistrationOneShot("foo")); |
456 EXPECT_TRUE(OneShotPending("foo")); | 426 EXPECT_TRUE(OneShotPending("foo")); |
457 | 427 |
458 // Resume firing by going online. | 428 // Resume firing by going online. |
459 SetOnline(true); | 429 BackgroundSyncTestUtil::SetOnline(web_contents(), true); |
460 EXPECT_TRUE(PopConsole("foo fired")); | 430 EXPECT_TRUE(PopConsole("foo fired")); |
461 EXPECT_FALSE(GetRegistrationOneShot("foo")); | 431 EXPECT_FALSE(GetRegistrationOneShot("foo")); |
462 } | 432 } |
463 | 433 |
464 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, WaitUntil) { | 434 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, WaitUntil) { |
465 EXPECT_TRUE(RegisterServiceWorker()); | 435 EXPECT_TRUE(RegisterServiceWorker()); |
466 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 436 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
467 | 437 |
468 SetOnline(true); | 438 BackgroundSyncTestUtil::SetOnline(web_contents(), true); |
469 EXPECT_TRUE(RegisterOneShot("delay")); | 439 EXPECT_TRUE(RegisterOneShot("delay")); |
470 | 440 |
471 // Verify that it is firing. | 441 // Verify that it is firing. |
472 EXPECT_TRUE(GetRegistrationOneShot("delay")); | 442 EXPECT_TRUE(GetRegistrationOneShot("delay")); |
473 EXPECT_FALSE(OneShotPending("delay")); | 443 EXPECT_FALSE(OneShotPending("delay")); |
474 | 444 |
475 // Complete the task. | 445 // Complete the task. |
476 EXPECT_TRUE(CompleteDelayedOneShot()); | 446 EXPECT_TRUE(CompleteDelayedOneShot()); |
477 EXPECT_TRUE(PopConsole("ok - delay completed")); | 447 EXPECT_TRUE(PopConsole("ok - delay completed")); |
478 | 448 |
479 // Verify that it finished firing. | 449 // Verify that it finished firing. |
480 // TODO(jkarlin): Use registration.finished to verify that the event actually | 450 // TODO(jkarlin): Use registration.finished to verify that the event actually |
481 // completed successfully. | 451 // completed successfully. |
482 EXPECT_FALSE(GetRegistrationOneShot("delay")); | 452 EXPECT_FALSE(GetRegistrationOneShot("delay")); |
483 } | 453 } |
484 | 454 |
485 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, WaitUntilReject) { | 455 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, WaitUntilReject) { |
486 EXPECT_TRUE(RegisterServiceWorker()); | 456 EXPECT_TRUE(RegisterServiceWorker()); |
487 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 457 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
488 | 458 |
489 SetOnline(true); | 459 BackgroundSyncTestUtil::SetOnline(web_contents(), true); |
490 EXPECT_TRUE(RegisterOneShot("delay")); | 460 EXPECT_TRUE(RegisterOneShot("delay")); |
491 | 461 |
492 // Verify that it is firing. | 462 // Verify that it is firing. |
493 EXPECT_TRUE(GetRegistrationOneShot("delay")); | 463 EXPECT_TRUE(GetRegistrationOneShot("delay")); |
494 EXPECT_FALSE(OneShotPending("delay")); | 464 EXPECT_FALSE(OneShotPending("delay")); |
495 | 465 |
496 // Complete the task. | 466 // Complete the task. |
497 EXPECT_TRUE(RejectDelayedOneShot()); | 467 EXPECT_TRUE(RejectDelayedOneShot()); |
498 EXPECT_TRUE(PopConsole("ok - delay rejected")); | 468 EXPECT_TRUE(PopConsole("ok - delay rejected")); |
499 EXPECT_FALSE(GetRegistrationOneShot("delay")); | 469 EXPECT_FALSE(GetRegistrationOneShot("delay")); |
500 } | 470 } |
501 | 471 |
502 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, Incognito) { | 472 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, Incognito) { |
503 EXPECT_TRUE(RegisterServiceWorker()); | 473 EXPECT_TRUE(RegisterServiceWorker()); |
504 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 474 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
505 | 475 |
506 SetOnline(false); | 476 BackgroundSyncTestUtil::SetOnline(web_contents(), false); |
507 EXPECT_TRUE(RegisterOneShot("normal")); | 477 EXPECT_TRUE(RegisterOneShot("normal")); |
508 EXPECT_TRUE(OneShotPending("normal")); | 478 EXPECT_TRUE(OneShotPending("normal")); |
509 | 479 |
510 // Go incognito and verify that incognito doesn't see the registration. | 480 // Go incognito and verify that incognito doesn't see the registration. |
511 SetIncognitoMode(true); | 481 SetIncognitoMode(true); |
512 | 482 |
513 // Tell the new network observer that we're offline (it initializes from | 483 // Tell the new network observer that we're offline (it initializes from |
514 // NetworkChangeNotifier::GetCurrentConnectionType() which is not mocked out | 484 // NetworkChangeNotifier::GetCurrentConnectionType() which is not mocked out |
515 // in this test). | 485 // in this test). |
516 SetOnline(false); | 486 BackgroundSyncTestUtil::SetOnline(web_contents(), false); |
517 | 487 |
518 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); | 488 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); |
519 EXPECT_TRUE(RegisterServiceWorker()); | 489 EXPECT_TRUE(RegisterServiceWorker()); |
520 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 490 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
521 | 491 |
522 EXPECT_FALSE(GetRegistrationOneShot("normal")); | 492 EXPECT_FALSE(GetRegistrationOneShot("normal")); |
523 | 493 |
524 EXPECT_TRUE(RegisterOneShot("incognito")); | 494 EXPECT_TRUE(RegisterOneShot("incognito")); |
525 EXPECT_TRUE(OneShotPending("incognito")); | 495 EXPECT_TRUE(OneShotPending("incognito")); |
526 | 496 |
527 // Switch back and make sure the registration is still there. | 497 // Switch back and make sure the registration is still there. |
528 SetIncognitoMode(false); | 498 SetIncognitoMode(false); |
529 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Should be controlled. | 499 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Should be controlled. |
530 | 500 |
531 EXPECT_TRUE(GetRegistrationOneShot("normal")); | 501 EXPECT_TRUE(GetRegistrationOneShot("normal")); |
532 EXPECT_FALSE(GetRegistrationOneShot("incognito")); | 502 EXPECT_FALSE(GetRegistrationOneShot("incognito")); |
533 } | 503 } |
534 | 504 |
535 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, GetRegistrations) { | 505 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, GetRegistrations) { |
536 EXPECT_TRUE(RegisterServiceWorker()); | 506 EXPECT_TRUE(RegisterServiceWorker()); |
537 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 507 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
538 | 508 |
539 std::vector<std::string> registered_tags; | 509 std::vector<std::string> registered_tags; |
540 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); | 510 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); |
541 | 511 |
542 SetOnline(false); | 512 BackgroundSyncTestUtil::SetOnline(web_contents(), false); |
543 registered_tags.push_back("foo"); | 513 registered_tags.push_back("foo"); |
544 registered_tags.push_back("bar"); | 514 registered_tags.push_back("bar"); |
545 | 515 |
546 for (const std::string& tag : registered_tags) | 516 for (const std::string& tag : registered_tags) |
547 EXPECT_TRUE(RegisterOneShot(tag)); | 517 EXPECT_TRUE(RegisterOneShot(tag)); |
548 | 518 |
549 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); | 519 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); |
550 } | 520 } |
551 | 521 |
552 // Verify that GetRegistrations works in a service worker | 522 // Verify that GetRegistrations works in a service worker |
553 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, | 523 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
554 GetRegistrationsFromServiceWorker) { | 524 GetRegistrationsFromServiceWorker) { |
555 EXPECT_TRUE(RegisterServiceWorker()); | 525 EXPECT_TRUE(RegisterServiceWorker()); |
556 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 526 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
557 | 527 |
558 std::vector<std::string> registered_tags; | 528 std::vector<std::string> registered_tags; |
559 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); | 529 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); |
560 | 530 |
561 SetOnline(false); | 531 BackgroundSyncTestUtil::SetOnline(web_contents(), false); |
562 registered_tags.push_back("foo_sw"); | 532 registered_tags.push_back("foo_sw"); |
563 registered_tags.push_back("bar_sw"); | 533 registered_tags.push_back("bar_sw"); |
564 | 534 |
565 for (const std::string& tag : registered_tags) { | 535 for (const std::string& tag : registered_tags) { |
566 EXPECT_TRUE(RegisterOneShotFromServiceWorker(tag)); | 536 EXPECT_TRUE(RegisterOneShotFromServiceWorker(tag)); |
567 EXPECT_TRUE(PopConsole(BuildExpectedResult(tag, "registered in SW"))); | 537 EXPECT_TRUE(PopConsole(BuildExpectedResult(tag, "registered in SW"))); |
568 } | 538 } |
569 | 539 |
570 EXPECT_TRUE(GetRegistrationsOneShotFromServiceWorker(registered_tags)); | 540 EXPECT_TRUE(GetRegistrationsOneShotFromServiceWorker(registered_tags)); |
571 } | 541 } |
572 | 542 |
573 // Verify that GetRegistration works in a service worker | 543 // Verify that GetRegistration works in a service worker |
574 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, | 544 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
575 GetRegistrationFromServiceWorker) { | 545 GetRegistrationFromServiceWorker) { |
576 EXPECT_TRUE(RegisterServiceWorker()); | 546 EXPECT_TRUE(RegisterServiceWorker()); |
577 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 547 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
578 | 548 |
579 std::vector<std::string> registered_tags; | 549 std::vector<std::string> registered_tags; |
580 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); | 550 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); |
581 | 551 |
582 SetOnline(false); | 552 BackgroundSyncTestUtil::SetOnline(web_contents(), false); |
583 | 553 |
584 EXPECT_TRUE(RegisterOneShotFromServiceWorker("foo_sw")); | 554 EXPECT_TRUE(RegisterOneShotFromServiceWorker("foo_sw")); |
585 EXPECT_TRUE(PopConsole("ok - foo_sw registered in SW")); | 555 EXPECT_TRUE(PopConsole("ok - foo_sw registered in SW")); |
586 EXPECT_TRUE(GetRegistrationOneShotFromServiceWorker("foo_sw")); | 556 EXPECT_TRUE(GetRegistrationOneShotFromServiceWorker("foo_sw")); |
587 } | 557 } |
588 | 558 |
589 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, Unregister) { | 559 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, Unregister) { |
590 EXPECT_TRUE(RegisterServiceWorker()); | 560 EXPECT_TRUE(RegisterServiceWorker()); |
591 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 561 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
592 | 562 |
593 SetOnline(false); | 563 BackgroundSyncTestUtil::SetOnline(web_contents(), false); |
594 EXPECT_TRUE(RegisterOneShot("foo")); | 564 EXPECT_TRUE(RegisterOneShot("foo")); |
595 EXPECT_TRUE(UnregisterOneShot("foo")); | 565 EXPECT_TRUE(UnregisterOneShot("foo")); |
596 EXPECT_FALSE(GetRegistrationOneShot("foo")); | 566 EXPECT_FALSE(GetRegistrationOneShot("foo")); |
597 } | 567 } |
598 | 568 |
599 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, UnregisterTwice) { | 569 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, UnregisterTwice) { |
600 EXPECT_TRUE(RegisterServiceWorker()); | 570 EXPECT_TRUE(RegisterServiceWorker()); |
601 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 571 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
602 | 572 |
603 SetOnline(false); | 573 BackgroundSyncTestUtil::SetOnline(web_contents(), false); |
604 EXPECT_TRUE(RegisterOneShot("foo")); | 574 EXPECT_TRUE(RegisterOneShot("foo")); |
605 EXPECT_TRUE(UnregisterOneShotTwice("foo")); | 575 EXPECT_TRUE(UnregisterOneShotTwice("foo")); |
606 EXPECT_FALSE(GetRegistrationOneShot("foo")); | 576 EXPECT_FALSE(GetRegistrationOneShot("foo")); |
607 } | 577 } |
608 | 578 |
609 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, UnregisterMidSync) { | 579 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, UnregisterMidSync) { |
610 EXPECT_TRUE(RegisterServiceWorker()); | 580 EXPECT_TRUE(RegisterServiceWorker()); |
611 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 581 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
612 | 582 |
613 EXPECT_TRUE(RegisterOneShot("unregister")); | 583 EXPECT_TRUE(RegisterOneShot("unregister")); |
614 EXPECT_TRUE(PopConsole("ok - unregister completed")); | 584 EXPECT_TRUE(PopConsole("ok - unregister completed")); |
615 } | 585 } |
616 | 586 |
617 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, | 587 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
618 CallFinishedBeforeSyncSucceeds) { | 588 CallFinishedBeforeSyncSucceeds) { |
619 EXPECT_TRUE(RegisterServiceWorker()); | 589 EXPECT_TRUE(RegisterServiceWorker()); |
620 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 590 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
621 | 591 |
622 SetOnline(false); | 592 BackgroundSyncTestUtil::SetOnline(web_contents(), false); |
623 EXPECT_TRUE(RegisterOneShot("foo")); | 593 EXPECT_TRUE(RegisterOneShot("foo")); |
624 EXPECT_TRUE(NotifyWhenFinishedOneShot("foo")); | 594 EXPECT_TRUE(NotifyWhenFinishedOneShot("foo")); |
625 | 595 |
626 SetOnline(true); | 596 BackgroundSyncTestUtil::SetOnline(web_contents(), true); |
627 // The ordering of PopConsole messages tells us that the event fired | 597 // The ordering of PopConsole messages tells us that the event fired |
628 // before finished resolved. | 598 // before finished resolved. |
629 EXPECT_TRUE(PopConsole("foo fired")); | 599 EXPECT_TRUE(PopConsole("foo fired")); |
630 EXPECT_TRUE(PopConsole("foo finished result: true")); | 600 EXPECT_TRUE(PopConsole("foo finished result: true")); |
631 } | 601 } |
632 | 602 |
633 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, CallFinishedBeforeSyncFails) { | 603 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, CallFinishedBeforeSyncFails) { |
634 EXPECT_TRUE(RegisterServiceWorker()); | 604 EXPECT_TRUE(RegisterServiceWorker()); |
635 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 605 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
636 | 606 |
637 SetOnline(true); | 607 BackgroundSyncTestUtil::SetOnline(web_contents(), true); |
638 EXPECT_TRUE(RegisterOneShot("delay")); | 608 EXPECT_TRUE(RegisterOneShot("delay")); |
639 EXPECT_FALSE(OneShotPending("delay")); | 609 EXPECT_FALSE(OneShotPending("delay")); |
640 EXPECT_TRUE(NotifyWhenFinishedOneShot("delay")); | 610 EXPECT_TRUE(NotifyWhenFinishedOneShot("delay")); |
641 | 611 |
642 EXPECT_TRUE(RejectDelayedOneShot()); | 612 EXPECT_TRUE(RejectDelayedOneShot()); |
643 // The ordering of PopConsole messages tells us that the event fired | 613 // The ordering of PopConsole messages tells us that the event fired |
644 // before finished resolved. | 614 // before finished resolved. |
645 EXPECT_TRUE(PopConsole("ok - delay rejected")); | 615 EXPECT_TRUE(PopConsole("ok - delay rejected")); |
646 EXPECT_TRUE(PopConsole("delay finished result: false")); | 616 EXPECT_TRUE(PopConsole("delay finished result: false")); |
647 } | 617 } |
648 | 618 |
649 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, | 619 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
650 CallFinishedAfterSyncSucceeds) { | 620 CallFinishedAfterSyncSucceeds) { |
651 EXPECT_TRUE(RegisterServiceWorker()); | 621 EXPECT_TRUE(RegisterServiceWorker()); |
652 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 622 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
653 | 623 |
654 SetOnline(false); | 624 BackgroundSyncTestUtil::SetOnline(web_contents(), false); |
655 EXPECT_TRUE(RegisterOneShot("foo")); | 625 EXPECT_TRUE(RegisterOneShot("foo")); |
656 EXPECT_TRUE(StoreRegistrationOneShot("foo")); | 626 EXPECT_TRUE(StoreRegistrationOneShot("foo")); |
657 | 627 |
658 SetOnline(true); | 628 BackgroundSyncTestUtil::SetOnline(web_contents(), true); |
659 EXPECT_TRUE(PopConsole("foo fired")); | 629 EXPECT_TRUE(PopConsole("foo fired")); |
660 EXPECT_FALSE(GetRegistrationOneShot("foo")); | 630 EXPECT_FALSE(GetRegistrationOneShot("foo")); |
661 EXPECT_TRUE(NotifyWhenFinishedImmediateOneShot("ok - foo result: true")); | 631 EXPECT_TRUE(NotifyWhenFinishedImmediateOneShot("ok - foo result: true")); |
662 } | 632 } |
663 | 633 |
664 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, | 634 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
665 CallFinishedAfterSyncUnregistered) { | 635 CallFinishedAfterSyncUnregistered) { |
666 EXPECT_TRUE(RegisterServiceWorker()); | 636 EXPECT_TRUE(RegisterServiceWorker()); |
667 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 637 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
668 | 638 |
669 SetOnline(false); | 639 BackgroundSyncTestUtil::SetOnline(web_contents(), false); |
670 EXPECT_TRUE(RegisterOneShot("foo")); | 640 EXPECT_TRUE(RegisterOneShot("foo")); |
671 EXPECT_TRUE(StoreRegistrationOneShot("foo")); | 641 EXPECT_TRUE(StoreRegistrationOneShot("foo")); |
672 EXPECT_TRUE(UnregisterOneShot("foo")); | 642 EXPECT_TRUE(UnregisterOneShot("foo")); |
673 EXPECT_FALSE(GetRegistrationOneShot("foo")); | 643 EXPECT_FALSE(GetRegistrationOneShot("foo")); |
674 EXPECT_TRUE(NotifyWhenFinishedImmediateOneShot("ok - foo result: false")); | 644 EXPECT_TRUE(NotifyWhenFinishedImmediateOneShot("ok - foo result: false")); |
675 } | 645 } |
676 | 646 |
677 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, CallFinishedAfterSyncFails) { | 647 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, CallFinishedAfterSyncFails) { |
678 EXPECT_TRUE(RegisterServiceWorker()); | 648 EXPECT_TRUE(RegisterServiceWorker()); |
679 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 649 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
680 | 650 |
681 SetOnline(true); | 651 BackgroundSyncTestUtil::SetOnline(web_contents(), true); |
682 EXPECT_TRUE(RegisterOneShot("delay")); | 652 EXPECT_TRUE(RegisterOneShot("delay")); |
683 EXPECT_FALSE(OneShotPending("delay")); | 653 EXPECT_FALSE(OneShotPending("delay")); |
684 EXPECT_TRUE(StoreRegistrationOneShot("delay")); | 654 EXPECT_TRUE(StoreRegistrationOneShot("delay")); |
685 | 655 |
686 EXPECT_TRUE(RejectDelayedOneShot()); | 656 EXPECT_TRUE(RejectDelayedOneShot()); |
687 EXPECT_TRUE(PopConsole("ok - delay rejected")); | 657 EXPECT_TRUE(PopConsole("ok - delay rejected")); |
688 EXPECT_TRUE(NotifyWhenFinishedImmediateOneShot("ok - delay result: false")); | 658 EXPECT_TRUE(NotifyWhenFinishedImmediateOneShot("ok - delay result: false")); |
689 } | 659 } |
690 | 660 |
691 // Verify that a background sync registration is deleted when site data is | 661 // Verify that a background sync registration is deleted when site data is |
692 // cleared. | 662 // cleared. |
693 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, | 663 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
694 SyncRegistrationDeletedWhenClearingSiteData) { | 664 SyncRegistrationDeletedWhenClearingSiteData) { |
695 EXPECT_TRUE(RegisterServiceWorker()); | 665 EXPECT_TRUE(RegisterServiceWorker()); |
696 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 666 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
697 | 667 |
698 // Prevent firing by going offline. | 668 // Prevent firing by going offline. |
699 SetOnline(false); | 669 BackgroundSyncTestUtil::SetOnline(web_contents(), false); |
700 EXPECT_TRUE(RegisterOneShot("foo")); | 670 EXPECT_TRUE(RegisterOneShot("foo")); |
701 EXPECT_TRUE(GetRegistrationOneShot("foo")); | 671 EXPECT_TRUE(GetRegistrationOneShot("foo")); |
702 EXPECT_TRUE(OneShotPending("foo")); | 672 EXPECT_TRUE(OneShotPending("foo")); |
703 | 673 |
704 // Simulate a user clearing site data (including Service Workers, crucially), | 674 // Simulate a user clearing site data (including Service Workers, crucially), |
705 // by clearing data from the storage partition. | 675 // by clearing data from the storage partition. |
706 ClearStoragePartitionData(); | 676 ClearStoragePartitionData(); |
707 | 677 |
708 EXPECT_FALSE(GetRegistrationOneShot("foo")); | 678 EXPECT_FALSE(GetRegistrationOneShot("foo")); |
709 } | 679 } |
710 | 680 |
711 // Verify that a background sync registration, from a service worker, is deleted | 681 // Verify that a background sync registration, from a service worker, is deleted |
712 // when site data is cleared. | 682 // when site data is cleared. |
713 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, | 683 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
714 SyncRegistrationFromSWDeletedWhenClearingSiteData) { | 684 SyncRegistrationFromSWDeletedWhenClearingSiteData) { |
715 EXPECT_TRUE(RegisterServiceWorker()); | 685 EXPECT_TRUE(RegisterServiceWorker()); |
716 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 686 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
717 | 687 |
718 std::vector<std::string> registered_tags; | 688 std::vector<std::string> registered_tags; |
719 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); | 689 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); |
720 | 690 |
721 SetOnline(false); | 691 BackgroundSyncTestUtil::SetOnline(web_contents(), false); |
722 | 692 |
723 EXPECT_TRUE(RegisterOneShotFromServiceWorker("foo_sw")); | 693 EXPECT_TRUE(RegisterOneShotFromServiceWorker("foo_sw")); |
724 EXPECT_TRUE(PopConsole("ok - foo_sw registered in SW")); | 694 EXPECT_TRUE(PopConsole("ok - foo_sw registered in SW")); |
725 EXPECT_TRUE(GetRegistrationOneShotFromServiceWorker("foo_sw")); | 695 EXPECT_TRUE(GetRegistrationOneShotFromServiceWorker("foo_sw")); |
726 | 696 |
727 // Simulate a user clearing site data (including Service Workers, crucially), | 697 // Simulate a user clearing site data (including Service Workers, crucially), |
728 // by clearing data from the storage partition. | 698 // by clearing data from the storage partition. |
729 ClearStoragePartitionData(); | 699 ClearStoragePartitionData(); |
730 | 700 |
731 EXPECT_FALSE(GetRegistrationOneShotFromServiceWorker("foo")); | 701 EXPECT_FALSE(GetRegistrationOneShotFromServiceWorker("foo")); |
732 } | 702 } |
733 | 703 |
734 // Verify that multiple background sync registrations are deleted when site | 704 // Verify that multiple background sync registrations are deleted when site |
735 // data is cleared. | 705 // data is cleared. |
736 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, | 706 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
737 SyncRegistrationsDeletedWhenClearingSiteData) { | 707 SyncRegistrationsDeletedWhenClearingSiteData) { |
738 EXPECT_TRUE(RegisterServiceWorker()); | 708 EXPECT_TRUE(RegisterServiceWorker()); |
739 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 709 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
740 | 710 |
741 std::vector<std::string> registered_tags; | 711 std::vector<std::string> registered_tags; |
742 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); | 712 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); |
743 | 713 |
744 SetOnline(false); | 714 BackgroundSyncTestUtil::SetOnline(web_contents(), false); |
745 registered_tags.push_back("foo"); | 715 registered_tags.push_back("foo"); |
746 registered_tags.push_back("bar"); | 716 registered_tags.push_back("bar"); |
747 | 717 |
748 for (const std::string& tag : registered_tags) | 718 for (const std::string& tag : registered_tags) |
749 EXPECT_TRUE(RegisterOneShot(tag)); | 719 EXPECT_TRUE(RegisterOneShot(tag)); |
750 | 720 |
751 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); | 721 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); |
752 | 722 |
753 for (const std::string& tag : registered_tags) | 723 for (const std::string& tag : registered_tags) |
754 EXPECT_TRUE(OneShotPending(tag)); | 724 EXPECT_TRUE(OneShotPending(tag)); |
755 | 725 |
756 // Simulate a user clearing site data (including Service Workers, crucially), | 726 // Simulate a user clearing site data (including Service Workers, crucially), |
757 // by clearing data from the storage partition. | 727 // by clearing data from the storage partition. |
758 ClearStoragePartitionData(); | 728 ClearStoragePartitionData(); |
759 | 729 |
760 for (const std::string& tag : registered_tags) | 730 for (const std::string& tag : registered_tags) |
761 EXPECT_FALSE(GetRegistrationOneShot(tag)); | 731 EXPECT_FALSE(GetRegistrationOneShot(tag)); |
762 } | 732 } |
763 | 733 |
764 // Verify that a sync event that is currently firing is deleted when site | 734 // Verify that a sync event that is currently firing is deleted when site |
765 // data is cleared. | 735 // data is cleared. |
766 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, | 736 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
767 FiringSyncEventDeletedWhenClearingSiteData) { | 737 FiringSyncEventDeletedWhenClearingSiteData) { |
768 EXPECT_TRUE(RegisterServiceWorker()); | 738 EXPECT_TRUE(RegisterServiceWorker()); |
769 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 739 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
770 | 740 |
771 SetOnline(true); | 741 BackgroundSyncTestUtil::SetOnline(web_contents(), true); |
772 EXPECT_TRUE(RegisterOneShot("delay")); | 742 EXPECT_TRUE(RegisterOneShot("delay")); |
773 | 743 |
774 // Verify that it is firing. | 744 // Verify that it is firing. |
775 EXPECT_TRUE(GetRegistrationOneShot("delay")); | 745 EXPECT_TRUE(GetRegistrationOneShot("delay")); |
776 EXPECT_FALSE(OneShotPending("delay")); | 746 EXPECT_FALSE(OneShotPending("delay")); |
777 | 747 |
778 // Simulate a user clearing site data (including Service Workers, crucially), | 748 // Simulate a user clearing site data (including Service Workers, crucially), |
779 // by clearing data from the storage partition. | 749 // by clearing data from the storage partition. |
780 ClearStoragePartitionData(); | 750 ClearStoragePartitionData(); |
781 | 751 |
782 // Verify that it was deleted. | 752 // Verify that it was deleted. |
783 EXPECT_FALSE(GetRegistrationOneShot("delay")); | 753 EXPECT_FALSE(GetRegistrationOneShot("delay")); |
784 } | 754 } |
785 | 755 |
786 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, VerifyRetry) { | 756 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, VerifyRetry) { |
787 EXPECT_TRUE(RegisterServiceWorker()); | 757 EXPECT_TRUE(RegisterServiceWorker()); |
788 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 758 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
789 | 759 |
790 SetMaxSyncAttempts(2); | 760 SetMaxSyncAttempts(2); |
791 | 761 |
792 EXPECT_TRUE(RegisterOneShot("delay")); | 762 EXPECT_TRUE(RegisterOneShot("delay")); |
793 EXPECT_TRUE(RejectDelayedOneShot()); | 763 EXPECT_TRUE(RejectDelayedOneShot()); |
794 EXPECT_TRUE(PopConsole("ok - delay rejected")); | 764 EXPECT_TRUE(PopConsole("ok - delay rejected")); |
795 | 765 |
796 // Verify that the oneshot is still around and waiting to try again. | 766 // Verify that the oneshot is still around and waiting to try again. |
797 EXPECT_TRUE(OneShotPending("delay")); | 767 EXPECT_TRUE(OneShotPending("delay")); |
798 } | 768 } |
799 | 769 |
800 } // namespace content | 770 } // namespace content |
OLD | NEW |