| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 const std::string& argument) { | 50 const std::string& argument) { |
| 51 return base::StringPrintf("%s('%s');", function.c_str(), argument.c_str()); | 51 return base::StringPrintf("%s('%s');", function.c_str(), argument.c_str()); |
| 52 } | 52 } |
| 53 | 53 |
| 54 std::string BuildExpectedResult(const std::string& tag, | 54 std::string BuildExpectedResult(const std::string& tag, |
| 55 const std::string& action) { | 55 const std::string& action) { |
| 56 return base::StringPrintf("%s%s %s", kSuccessfulOperationPrefix, tag.c_str(), | 56 return base::StringPrintf("%s%s %s", kSuccessfulOperationPrefix, tag.c_str(), |
| 57 action.c_str()); | 57 action.c_str()); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void OneShotPendingCallback( | 60 void RegistrationPendingCallback( |
| 61 const base::Closure& quit, | 61 const base::Closure& quit, |
| 62 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 62 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 63 bool* result_out, | 63 bool* result_out, |
| 64 bool result) { | 64 bool result) { |
| 65 *result_out = result; | 65 *result_out = result; |
| 66 task_runner->PostTask(FROM_HERE, quit); | 66 task_runner->PostTask(FROM_HERE, quit); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void OneShotPendingDidGetSyncRegistration( | 69 void RegistrationPendingDidGetSyncRegistration( |
| 70 const base::Callback<void(bool)>& callback, | 70 const base::Callback<void(bool)>& callback, |
| 71 BackgroundSyncStatus error_type, | 71 BackgroundSyncStatus error_type, |
| 72 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle) { | 72 scoped_ptr<BackgroundSyncRegistrationHandle> registration_handle) { |
| 73 ASSERT_EQ(BACKGROUND_SYNC_STATUS_OK, error_type); | 73 ASSERT_EQ(BACKGROUND_SYNC_STATUS_OK, error_type); |
| 74 callback.Run(registration_handle->sync_state() == | 74 callback.Run(registration_handle->sync_state() == |
| 75 BackgroundSyncState::PENDING); | 75 BackgroundSyncState::PENDING); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void OneShotPendingDidGetSWRegistration( | 78 void RegistrationPendingDidGetSWRegistration( |
| 79 const scoped_refptr<BackgroundSyncContext> sync_context, | 79 const scoped_refptr<BackgroundSyncContext> sync_context, |
| 80 const std::string& tag, | 80 const std::string& tag, |
| 81 const base::Callback<void(bool)>& callback, | 81 const base::Callback<void(bool)>& callback, |
| 82 ServiceWorkerStatusCode status, | 82 ServiceWorkerStatusCode status, |
| 83 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 83 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| 84 ASSERT_EQ(SERVICE_WORKER_OK, status); | 84 ASSERT_EQ(SERVICE_WORKER_OK, status); |
| 85 int64_t service_worker_id = registration->id(); | 85 int64_t service_worker_id = registration->id(); |
| 86 BackgroundSyncManager* sync_manager = sync_context->background_sync_manager(); | 86 BackgroundSyncManager* sync_manager = sync_context->background_sync_manager(); |
| 87 sync_manager->GetRegistration( | 87 sync_manager->GetRegistration( |
| 88 service_worker_id, tag, | 88 service_worker_id, tag, |
| 89 base::Bind(&OneShotPendingDidGetSyncRegistration, callback)); | 89 base::Bind(&RegistrationPendingDidGetSyncRegistration, callback)); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void OneShotPendingOnIOThread( | 92 void RegistrationPendingOnIOThread( |
| 93 const scoped_refptr<BackgroundSyncContext> sync_context, | 93 const scoped_refptr<BackgroundSyncContext> sync_context, |
| 94 const scoped_refptr<ServiceWorkerContextWrapper> sw_context, | 94 const scoped_refptr<ServiceWorkerContextWrapper> sw_context, |
| 95 const std::string& tag, | 95 const std::string& tag, |
| 96 const GURL& url, | 96 const GURL& url, |
| 97 const base::Callback<void(bool)>& callback) { | 97 const base::Callback<void(bool)>& callback) { |
| 98 sw_context->FindReadyRegistrationForDocument( | 98 sw_context->FindReadyRegistrationForDocument( |
| 99 url, base::Bind(&OneShotPendingDidGetSWRegistration, sync_context, tag, | 99 url, base::Bind(&RegistrationPendingDidGetSWRegistration, sync_context, |
| 100 callback)); | 100 tag, callback)); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void SetMaxSyncAttemptsOnIOThread( | 103 void SetMaxSyncAttemptsOnIOThread( |
| 104 const scoped_refptr<BackgroundSyncContext>& sync_context, | 104 const scoped_refptr<BackgroundSyncContext>& sync_context, |
| 105 int max_sync_attempts) { | 105 int max_sync_attempts) { |
| 106 BackgroundSyncManager* background_sync_manager = | 106 BackgroundSyncManager* background_sync_manager = |
| 107 sync_context->background_sync_manager(); | 107 sync_context->background_sync_manager(); |
| 108 background_sync_manager->SetMaxSyncAttemptsForTesting(max_sync_attempts); | 108 background_sync_manager->SetMaxSyncAttemptsForTesting(max_sync_attempts); |
| 109 } | 109 } |
| 110 | 110 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 162 |
| 163 bool LoadTestPage(const std::string& path) { | 163 bool LoadTestPage(const std::string& path) { |
| 164 return NavigateToURL(shell_, https_server_->GetURL(path)); | 164 return NavigateToURL(shell_, https_server_->GetURL(path)); |
| 165 } | 165 } |
| 166 | 166 |
| 167 bool RunScript(const std::string& script, std::string* result) { | 167 bool RunScript(const std::string& script, std::string* result) { |
| 168 return content::ExecuteScriptAndExtractString(web_contents(), script, | 168 return content::ExecuteScriptAndExtractString(web_contents(), script, |
| 169 result); | 169 result); |
| 170 } | 170 } |
| 171 | 171 |
| 172 // Returns true if the one-shot sync with tag is currently pending. Fails | 172 // Returns true if the registration with tag |tag| is currently pending. Fails |
| 173 // (assertion failure) if the tag isn't registered. | 173 // (assertion failure) if the tag isn't registered. |
| 174 bool OneShotPending(const std::string& tag); | 174 bool RegistrationPending(const std::string& tag); |
| 175 | 175 |
| 176 // Sets the BackgroundSyncManager's max sync attempts per registration. | 176 // Sets the BackgroundSyncManager's max sync attempts per registration. |
| 177 void SetMaxSyncAttempts(int max_sync_attempts); | 177 void SetMaxSyncAttempts(int max_sync_attempts); |
| 178 | 178 |
| 179 void ClearStoragePartitionData(); | 179 void ClearStoragePartitionData(); |
| 180 | 180 |
| 181 std::string PopConsoleString(); | 181 std::string PopConsoleString(); |
| 182 bool PopConsole(const std::string& expected_msg); | 182 bool PopConsole(const std::string& expected_msg); |
| 183 bool RegisterServiceWorker(); | 183 bool RegisterServiceWorker(); |
| 184 bool RegisterOneShot(const std::string& tag); | 184 bool Register(const std::string& tag); |
| 185 bool RegisterOneShotFromServiceWorker(const std::string& tag); | 185 bool RegisterFromServiceWorker(const std::string& tag); |
| 186 bool GetRegistrationOneShot(const std::string& tag); | 186 bool HasTag(const std::string& tag); |
| 187 bool GetRegistrationOneShotFromServiceWorker(const std::string& tag); | 187 bool HasTagFromServiceWorker(const std::string& tag); |
| 188 bool MatchRegistrations(const std::string& script_result, | 188 bool MatchTags(const std::string& script_result, |
| 189 const std::vector<std::string>& expected_tags); | 189 const std::vector<std::string>& expected_tags); |
| 190 bool GetRegistrationsOneShot(const std::vector<std::string>& expected_tags); | 190 bool GetTags(const std::vector<std::string>& expected_tags); |
| 191 bool GetRegistrationsOneShotFromServiceWorker( | 191 bool GetTagsFromServiceWorker(const std::vector<std::string>& expected_tags); |
| 192 const std::vector<std::string>& expected_tags); | 192 bool CompleteDelayedSyncEvent(); |
| 193 bool CompleteDelayedOneShot(); | 193 bool RejectDelayedSyncEvent(); |
| 194 bool RejectDelayedOneShot(); | |
| 195 | 194 |
| 196 net::EmbeddedTestServer* https_server() { return https_server_.get(); } | 195 net::EmbeddedTestServer* https_server() { return https_server_.get(); } |
| 197 | 196 |
| 198 private: | 197 private: |
| 199 scoped_ptr<net::EmbeddedTestServer> https_server_; | 198 scoped_ptr<net::EmbeddedTestServer> https_server_; |
| 200 Shell* shell_ = nullptr; | 199 Shell* shell_ = nullptr; |
| 201 | 200 |
| 202 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncBrowserTest); | 201 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncBrowserTest); |
| 203 }; | 202 }; |
| 204 | 203 |
| 205 bool BackgroundSyncBrowserTest::OneShotPending(const std::string& tag) { | 204 bool BackgroundSyncBrowserTest::RegistrationPending(const std::string& tag) { |
| 206 bool is_pending; | 205 bool is_pending; |
| 207 base::RunLoop run_loop; | 206 base::RunLoop run_loop; |
| 208 | 207 |
| 209 StoragePartition* storage = GetStorage(); | 208 StoragePartition* storage = GetStorage(); |
| 210 BackgroundSyncContext* sync_context = storage->GetBackgroundSyncContext(); | 209 BackgroundSyncContext* sync_context = storage->GetBackgroundSyncContext(); |
| 211 ServiceWorkerContextWrapper* service_worker_context = | 210 ServiceWorkerContextWrapper* service_worker_context = |
| 212 static_cast<ServiceWorkerContextWrapper*>( | 211 static_cast<ServiceWorkerContextWrapper*>( |
| 213 storage->GetServiceWorkerContext()); | 212 storage->GetServiceWorkerContext()); |
| 214 | 213 |
| 215 base::Callback<void(bool)> callback = | 214 base::Callback<void(bool)> callback = |
| 216 base::Bind(&OneShotPendingCallback, run_loop.QuitClosure(), | 215 base::Bind(&RegistrationPendingCallback, run_loop.QuitClosure(), |
| 217 base::ThreadTaskRunnerHandle::Get(), &is_pending); | 216 base::ThreadTaskRunnerHandle::Get(), &is_pending); |
| 218 | 217 |
| 219 BrowserThread::PostTask( | 218 BrowserThread::PostTask( |
| 220 BrowserThread::IO, FROM_HERE, | 219 BrowserThread::IO, FROM_HERE, |
| 221 base::Bind(&OneShotPendingOnIOThread, make_scoped_refptr(sync_context), | 220 base::Bind(&RegistrationPendingOnIOThread, |
| 221 make_scoped_refptr(sync_context), |
| 222 make_scoped_refptr(service_worker_context), tag, | 222 make_scoped_refptr(service_worker_context), tag, |
| 223 https_server_->GetURL(kDefaultTestURL), callback)); | 223 https_server_->GetURL(kDefaultTestURL), callback)); |
| 224 | 224 |
| 225 run_loop.Run(); | 225 run_loop.Run(); |
| 226 | 226 |
| 227 return is_pending; | 227 return is_pending; |
| 228 } | 228 } |
| 229 | 229 |
| 230 void BackgroundSyncBrowserTest::SetMaxSyncAttempts(int max_sync_attempts) { | 230 void BackgroundSyncBrowserTest::SetMaxSyncAttempts(int max_sync_attempts) { |
| 231 base::RunLoop run_loop; | 231 base::RunLoop run_loop; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 std::string script_result = PopConsoleString(); | 274 std::string script_result = PopConsoleString(); |
| 275 return script_result == expected_msg; | 275 return script_result == expected_msg; |
| 276 } | 276 } |
| 277 | 277 |
| 278 bool BackgroundSyncBrowserTest::RegisterServiceWorker() { | 278 bool BackgroundSyncBrowserTest::RegisterServiceWorker() { |
| 279 std::string script_result; | 279 std::string script_result; |
| 280 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 280 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| 281 return script_result == BuildExpectedResult("service worker", "registered"); | 281 return script_result == BuildExpectedResult("service worker", "registered"); |
| 282 } | 282 } |
| 283 | 283 |
| 284 bool BackgroundSyncBrowserTest::RegisterOneShot(const std::string& tag) { | 284 bool BackgroundSyncBrowserTest::Register(const std::string& tag) { |
| 285 std::string script_result; | 285 std::string script_result; |
| 286 EXPECT_TRUE( | 286 EXPECT_TRUE(RunScript(BuildScriptString("register", tag), &script_result)); |
| 287 RunScript(BuildScriptString("registerOneShot", tag), &script_result)); | |
| 288 return script_result == BuildExpectedResult(tag, "registered"); | 287 return script_result == BuildExpectedResult(tag, "registered"); |
| 289 } | 288 } |
| 290 | 289 |
| 291 bool BackgroundSyncBrowserTest::RegisterOneShotFromServiceWorker( | 290 bool BackgroundSyncBrowserTest::RegisterFromServiceWorker( |
| 292 const std::string& tag) { | 291 const std::string& tag) { |
| 293 std::string script_result; | 292 std::string script_result; |
| 294 EXPECT_TRUE( | 293 EXPECT_TRUE(RunScript(BuildScriptString("registerFromServiceWorker", tag), |
| 295 RunScript(BuildScriptString("registerOneShotFromServiceWorker", tag), | 294 &script_result)); |
| 296 &script_result)); | |
| 297 return script_result == BuildExpectedResult(tag, "register sent to SW"); | 295 return script_result == BuildExpectedResult(tag, "register sent to SW"); |
| 298 } | 296 } |
| 299 | 297 |
| 300 bool BackgroundSyncBrowserTest::GetRegistrationOneShot(const std::string& tag) { | 298 bool BackgroundSyncBrowserTest::HasTag(const std::string& tag) { |
| 301 std::string script_result; | 299 std::string script_result; |
| 302 EXPECT_TRUE(RunScript(BuildScriptString("getRegistrationOneShot", tag), | 300 EXPECT_TRUE(RunScript(BuildScriptString("hasTag", tag), &script_result)); |
| 303 &script_result)); | |
| 304 return script_result == BuildExpectedResult(tag, "found"); | 301 return script_result == BuildExpectedResult(tag, "found"); |
| 305 } | 302 } |
| 306 | 303 |
| 307 bool BackgroundSyncBrowserTest::GetRegistrationOneShotFromServiceWorker( | 304 bool BackgroundSyncBrowserTest::HasTagFromServiceWorker( |
| 308 const std::string& tag) { | 305 const std::string& tag) { |
| 309 std::string script_result; | 306 std::string script_result; |
| 310 EXPECT_TRUE(RunScript( | 307 EXPECT_TRUE(RunScript(BuildScriptString("hasTagFromServiceWorker", tag), |
| 311 BuildScriptString("getRegistrationOneShotFromServiceWorker", tag), | 308 &script_result)); |
| 312 &script_result)); | 309 EXPECT_TRUE(script_result == "ok - hasTag sent to SW"); |
| 313 EXPECT_TRUE(script_result == "ok - getRegistration sent to SW"); | |
| 314 | 310 |
| 315 return PopConsole(BuildExpectedResult(tag, "found")); | 311 return PopConsole(BuildExpectedResult(tag, "found")); |
| 316 } | 312 } |
| 317 | 313 |
| 318 bool BackgroundSyncBrowserTest::MatchRegistrations( | 314 bool BackgroundSyncBrowserTest::MatchTags( |
| 319 const std::string& script_result, | 315 const std::string& script_result, |
| 320 const std::vector<std::string>& expected_tags) { | 316 const std::vector<std::string>& expected_tags) { |
| 321 EXPECT_TRUE(base::StartsWith(script_result, kSuccessfulOperationPrefix, | 317 EXPECT_TRUE(base::StartsWith(script_result, kSuccessfulOperationPrefix, |
| 322 base::CompareCase::INSENSITIVE_ASCII)); | 318 base::CompareCase::INSENSITIVE_ASCII)); |
| 323 std::string tag_string = | 319 std::string tag_string = |
| 324 script_result.substr(strlen(kSuccessfulOperationPrefix)); | 320 script_result.substr(strlen(kSuccessfulOperationPrefix)); |
| 325 std::vector<std::string> result_tags = base::SplitString( | 321 std::vector<std::string> result_tags = base::SplitString( |
| 326 tag_string, ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); | 322 tag_string, ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
| 327 | 323 |
| 328 return std::set<std::string>(expected_tags.begin(), expected_tags.end()) == | 324 return std::set<std::string>(expected_tags.begin(), expected_tags.end()) == |
| 329 std::set<std::string>(result_tags.begin(), result_tags.end()); | 325 std::set<std::string>(result_tags.begin(), result_tags.end()); |
| 330 } | 326 } |
| 331 | 327 |
| 332 bool BackgroundSyncBrowserTest::GetRegistrationsOneShot( | 328 bool BackgroundSyncBrowserTest::GetTags( |
| 333 const std::vector<std::string>& expected_tags) { | 329 const std::vector<std::string>& expected_tags) { |
| 334 std::string script_result; | 330 std::string script_result; |
| 335 EXPECT_TRUE(RunScript("getRegistrationsOneShot()", &script_result)); | 331 EXPECT_TRUE(RunScript("getTags()", &script_result)); |
| 336 | 332 |
| 337 return MatchRegistrations(script_result, expected_tags); | 333 return MatchTags(script_result, expected_tags); |
| 338 } | 334 } |
| 339 | 335 |
| 340 bool BackgroundSyncBrowserTest::GetRegistrationsOneShotFromServiceWorker( | 336 bool BackgroundSyncBrowserTest::GetTagsFromServiceWorker( |
| 341 const std::vector<std::string>& expected_tags) { | 337 const std::vector<std::string>& expected_tags) { |
| 342 std::string script_result; | 338 std::string script_result; |
| 343 EXPECT_TRUE( | 339 EXPECT_TRUE(RunScript("getTagsFromServiceWorker()", &script_result)); |
| 344 RunScript("getRegistrationsOneShotFromServiceWorker()", &script_result)); | 340 EXPECT_TRUE(script_result == "ok - getTags sent to SW"); |
| 345 EXPECT_TRUE(script_result == "ok - getRegistrations sent to SW"); | |
| 346 | 341 |
| 347 return MatchRegistrations(PopConsoleString(), expected_tags); | 342 return MatchTags(PopConsoleString(), expected_tags); |
| 348 } | 343 } |
| 349 | 344 |
| 350 bool BackgroundSyncBrowserTest::CompleteDelayedOneShot() { | 345 bool BackgroundSyncBrowserTest::CompleteDelayedSyncEvent() { |
| 351 std::string script_result; | 346 std::string script_result; |
| 352 EXPECT_TRUE(RunScript("completeDelayedOneShot()", &script_result)); | 347 EXPECT_TRUE(RunScript("completeDelayedSyncEvent()", &script_result)); |
| 353 return script_result == BuildExpectedResult("delay", "completing"); | 348 return script_result == BuildExpectedResult("delay", "completing"); |
| 354 } | 349 } |
| 355 | 350 |
| 356 bool BackgroundSyncBrowserTest::RejectDelayedOneShot() { | 351 bool BackgroundSyncBrowserTest::RejectDelayedSyncEvent() { |
| 357 std::string script_result; | 352 std::string script_result; |
| 358 EXPECT_TRUE(RunScript("rejectDelayedOneShot()", &script_result)); | 353 EXPECT_TRUE(RunScript("rejectDelayedSyncEvent()", &script_result)); |
| 359 return script_result == BuildExpectedResult("delay", "rejecting"); | 354 return script_result == BuildExpectedResult("delay", "rejecting"); |
| 360 } | 355 } |
| 361 | 356 |
| 362 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, OneShotFiresControlled) { | 357 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
| 358 RegisterFromControlledDocument) { |
| 363 EXPECT_TRUE(RegisterServiceWorker()); | 359 EXPECT_TRUE(RegisterServiceWorker()); |
| 364 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 360 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
| 365 | 361 |
| 366 EXPECT_TRUE(RegisterOneShot("foo")); | 362 EXPECT_TRUE(Register("foo")); |
| 367 EXPECT_TRUE(PopConsole("foo fired")); | 363 EXPECT_TRUE(PopConsole("foo fired")); |
| 368 EXPECT_FALSE(GetRegistrationOneShot("foo")); | 364 EXPECT_FALSE(HasTag("foo")); |
| 369 } | 365 } |
| 370 | 366 |
| 371 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, OneShotFiresUncontrolled) { | 367 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
| 368 RegisterFromUncontrolledDocument) { |
| 372 EXPECT_TRUE(RegisterServiceWorker()); | 369 EXPECT_TRUE(RegisterServiceWorker()); |
| 373 | 370 |
| 374 EXPECT_TRUE(RegisterOneShot("foo")); | 371 EXPECT_TRUE(Register("foo")); |
| 375 EXPECT_TRUE(PopConsole("foo fired")); | 372 EXPECT_TRUE(PopConsole("foo fired")); |
| 376 EXPECT_FALSE(GetRegistrationOneShot("foo")); | 373 EXPECT_FALSE(HasTag("foo")); |
| 377 } | 374 } |
| 378 | 375 |
| 379 // Verify that Register works in a service worker | 376 // Verify that Register works in a service worker |
| 380 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, | 377 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, RegisterFromServiceWorker) { |
| 381 OneShotFromServiceWorkerFires) { | |
| 382 EXPECT_TRUE(RegisterServiceWorker()); | 378 EXPECT_TRUE(RegisterServiceWorker()); |
| 383 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 379 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
| 384 | 380 |
| 385 EXPECT_TRUE(RegisterOneShotFromServiceWorker("foo_sw")); | 381 EXPECT_TRUE(RegisterFromServiceWorker("foo_sw")); |
| 386 EXPECT_TRUE(PopConsole("ok - foo_sw registered in SW")); | 382 EXPECT_TRUE(PopConsole("ok - foo_sw registered in SW")); |
| 387 EXPECT_TRUE(PopConsole("foo_sw fired")); | 383 EXPECT_TRUE(PopConsole("foo_sw fired")); |
| 388 EXPECT_FALSE(GetRegistrationOneShot("foo_sw")); | 384 EXPECT_FALSE(HasTag("foo_sw")); |
| 389 } | 385 } |
| 390 | 386 |
| 391 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, OneShotDelaysForNetwork) { | 387 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
| 388 RegistrationDelaysForNetwork) { |
| 392 EXPECT_TRUE(RegisterServiceWorker()); | 389 EXPECT_TRUE(RegisterServiceWorker()); |
| 393 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 390 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
| 394 | 391 |
| 395 // Prevent firing by going offline. | 392 // Prevent firing by going offline. |
| 396 background_sync_test_util::SetOnline(web_contents(), false); | 393 background_sync_test_util::SetOnline(web_contents(), false); |
| 397 EXPECT_TRUE(RegisterOneShot("foo")); | 394 EXPECT_TRUE(Register("foo")); |
| 398 EXPECT_TRUE(GetRegistrationOneShot("foo")); | 395 EXPECT_TRUE(HasTag("foo")); |
| 399 EXPECT_TRUE(OneShotPending("foo")); | 396 EXPECT_TRUE(RegistrationPending("foo")); |
| 400 | 397 |
| 401 // Resume firing by going online. | 398 // Resume firing by going online. |
| 402 background_sync_test_util::SetOnline(web_contents(), true); | 399 background_sync_test_util::SetOnline(web_contents(), true); |
| 403 EXPECT_TRUE(PopConsole("foo fired")); | 400 EXPECT_TRUE(PopConsole("foo fired")); |
| 404 EXPECT_FALSE(GetRegistrationOneShot("foo")); | 401 EXPECT_FALSE(HasTag("foo")); |
| 405 } | 402 } |
| 406 | 403 |
| 407 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, WaitUntil) { | 404 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, WaitUntil) { |
| 408 EXPECT_TRUE(RegisterServiceWorker()); | 405 EXPECT_TRUE(RegisterServiceWorker()); |
| 409 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 406 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
| 410 | 407 |
| 411 background_sync_test_util::SetOnline(web_contents(), true); | 408 background_sync_test_util::SetOnline(web_contents(), true); |
| 412 EXPECT_TRUE(RegisterOneShot("delay")); | 409 EXPECT_TRUE(Register("delay")); |
| 413 | 410 |
| 414 // Verify that it is firing. | 411 // Verify that it is firing. |
| 415 EXPECT_TRUE(GetRegistrationOneShot("delay")); | 412 EXPECT_TRUE(HasTag("delay")); |
| 416 EXPECT_FALSE(OneShotPending("delay")); | 413 EXPECT_FALSE(RegistrationPending("delay")); |
| 417 | 414 |
| 418 // Complete the task. | 415 // Complete the task. |
| 419 EXPECT_TRUE(CompleteDelayedOneShot()); | 416 EXPECT_TRUE(CompleteDelayedSyncEvent()); |
| 420 EXPECT_TRUE(PopConsole("ok - delay completed")); | 417 EXPECT_TRUE(PopConsole("ok - delay completed")); |
| 421 | 418 |
| 422 // Verify that it finished firing. | 419 // Verify that it finished firing. |
| 423 EXPECT_FALSE(GetRegistrationOneShot("delay")); | 420 EXPECT_FALSE(HasTag("delay")); |
| 424 } | 421 } |
| 425 | 422 |
| 426 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, WaitUntilReject) { | 423 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, WaitUntilReject) { |
| 427 EXPECT_TRUE(RegisterServiceWorker()); | 424 EXPECT_TRUE(RegisterServiceWorker()); |
| 428 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 425 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
| 429 | 426 |
| 430 background_sync_test_util::SetOnline(web_contents(), true); | 427 background_sync_test_util::SetOnline(web_contents(), true); |
| 431 EXPECT_TRUE(RegisterOneShot("delay")); | 428 EXPECT_TRUE(Register("delay")); |
| 432 | 429 |
| 433 // Verify that it is firing. | 430 // Verify that it is firing. |
| 434 EXPECT_TRUE(GetRegistrationOneShot("delay")); | 431 EXPECT_TRUE(HasTag("delay")); |
| 435 EXPECT_FALSE(OneShotPending("delay")); | 432 EXPECT_FALSE(RegistrationPending("delay")); |
| 436 | 433 |
| 437 // Complete the task. | 434 // Complete the task. |
| 438 EXPECT_TRUE(RejectDelayedOneShot()); | 435 EXPECT_TRUE(RejectDelayedSyncEvent()); |
| 439 EXPECT_TRUE(PopConsole("ok - delay rejected")); | 436 EXPECT_TRUE(PopConsole("ok - delay rejected")); |
| 440 EXPECT_FALSE(GetRegistrationOneShot("delay")); | 437 EXPECT_FALSE(HasTag("delay")); |
| 441 } | 438 } |
| 442 | 439 |
| 443 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, Incognito) { | 440 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, Incognito) { |
| 444 EXPECT_TRUE(RegisterServiceWorker()); | 441 EXPECT_TRUE(RegisterServiceWorker()); |
| 445 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 442 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
| 446 | 443 |
| 447 background_sync_test_util::SetOnline(web_contents(), false); | 444 background_sync_test_util::SetOnline(web_contents(), false); |
| 448 EXPECT_TRUE(RegisterOneShot("normal")); | 445 EXPECT_TRUE(Register("normal")); |
| 449 EXPECT_TRUE(OneShotPending("normal")); | 446 EXPECT_TRUE(RegistrationPending("normal")); |
| 450 | 447 |
| 451 // Go incognito and verify that incognito doesn't see the registration. | 448 // Go incognito and verify that incognito doesn't see the registration. |
| 452 SetIncognitoMode(true); | 449 SetIncognitoMode(true); |
| 453 | 450 |
| 454 // Tell the new network observer that we're offline (it initializes from | 451 // Tell the new network observer that we're offline (it initializes from |
| 455 // NetworkChangeNotifier::GetCurrentConnectionType() which is not mocked out | 452 // NetworkChangeNotifier::GetCurrentConnectionType() which is not mocked out |
| 456 // in this test). | 453 // in this test). |
| 457 background_sync_test_util::SetOnline(web_contents(), false); | 454 background_sync_test_util::SetOnline(web_contents(), false); |
| 458 | 455 |
| 459 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); | 456 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); |
| 460 EXPECT_TRUE(RegisterServiceWorker()); | 457 EXPECT_TRUE(RegisterServiceWorker()); |
| 461 | 458 |
| 462 EXPECT_FALSE(GetRegistrationOneShot("normal")); | 459 EXPECT_FALSE(HasTag("normal")); |
| 463 | 460 |
| 464 EXPECT_TRUE(RegisterOneShot("incognito")); | 461 EXPECT_TRUE(Register("incognito")); |
| 465 EXPECT_TRUE(OneShotPending("incognito")); | 462 EXPECT_TRUE(RegistrationPending("incognito")); |
| 466 | 463 |
| 467 // Switch back and make sure the registration is still there. | 464 // Switch back and make sure the registration is still there. |
| 468 SetIncognitoMode(false); | 465 SetIncognitoMode(false); |
| 469 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Should be controlled. | 466 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Should be controlled. |
| 470 | 467 |
| 471 EXPECT_TRUE(GetRegistrationOneShot("normal")); | 468 EXPECT_TRUE(HasTag("normal")); |
| 472 EXPECT_FALSE(GetRegistrationOneShot("incognito")); | 469 EXPECT_FALSE(HasTag("incognito")); |
| 473 } | 470 } |
| 474 | 471 |
| 475 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, GetRegistrations) { | 472 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, GetTags) { |
| 476 EXPECT_TRUE(RegisterServiceWorker()); | 473 EXPECT_TRUE(RegisterServiceWorker()); |
| 477 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 474 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
| 478 | 475 |
| 479 std::vector<std::string> registered_tags; | 476 std::vector<std::string> registered_tags; |
| 480 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); | 477 EXPECT_TRUE(GetTags(registered_tags)); |
| 481 | 478 |
| 482 background_sync_test_util::SetOnline(web_contents(), false); | 479 background_sync_test_util::SetOnline(web_contents(), false); |
| 483 registered_tags.push_back("foo"); | 480 registered_tags.push_back("foo"); |
| 484 registered_tags.push_back("bar"); | 481 registered_tags.push_back("bar"); |
| 485 | 482 |
| 486 for (const std::string& tag : registered_tags) | 483 for (const std::string& tag : registered_tags) |
| 487 EXPECT_TRUE(RegisterOneShot(tag)); | 484 EXPECT_TRUE(Register(tag)); |
| 488 | 485 |
| 489 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); | 486 EXPECT_TRUE(GetTags(registered_tags)); |
| 490 } | 487 } |
| 491 | 488 |
| 492 // Verify that GetRegistrations works in a service worker | 489 // Verify that GetRegistrations works in a service worker |
| 493 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, | 490 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
| 494 GetRegistrationsFromServiceWorker) { | 491 GetRegistrationsFromServiceWorker) { |
| 495 EXPECT_TRUE(RegisterServiceWorker()); | 492 EXPECT_TRUE(RegisterServiceWorker()); |
| 496 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 493 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
| 497 | 494 |
| 498 std::vector<std::string> registered_tags; | 495 std::vector<std::string> registered_tags; |
| 499 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); | 496 EXPECT_TRUE(GetTags(registered_tags)); |
| 500 | 497 |
| 501 background_sync_test_util::SetOnline(web_contents(), false); | 498 background_sync_test_util::SetOnline(web_contents(), false); |
| 502 registered_tags.push_back("foo_sw"); | 499 registered_tags.push_back("foo_sw"); |
| 503 registered_tags.push_back("bar_sw"); | 500 registered_tags.push_back("bar_sw"); |
| 504 | 501 |
| 505 for (const std::string& tag : registered_tags) { | 502 for (const std::string& tag : registered_tags) { |
| 506 EXPECT_TRUE(RegisterOneShotFromServiceWorker(tag)); | 503 EXPECT_TRUE(RegisterFromServiceWorker(tag)); |
| 507 EXPECT_TRUE(PopConsole(BuildExpectedResult(tag, "registered in SW"))); | 504 EXPECT_TRUE(PopConsole(BuildExpectedResult(tag, "registered in SW"))); |
| 508 } | 505 } |
| 509 | 506 |
| 510 EXPECT_TRUE(GetRegistrationsOneShotFromServiceWorker(registered_tags)); | 507 EXPECT_TRUE(GetTagsFromServiceWorker(registered_tags)); |
| 511 } | 508 } |
| 512 | 509 |
| 513 // Verify that GetRegistration works in a service worker | 510 // Verify that GetRegistration works in a service worker |
| 514 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, | 511 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, HasTagFromServiceWorker) { |
| 515 GetRegistrationFromServiceWorker) { | |
| 516 EXPECT_TRUE(RegisterServiceWorker()); | 512 EXPECT_TRUE(RegisterServiceWorker()); |
| 517 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 513 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
| 518 | 514 |
| 519 std::vector<std::string> registered_tags; | 515 std::vector<std::string> registered_tags; |
| 520 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); | 516 EXPECT_TRUE(GetTags(registered_tags)); |
| 521 | 517 |
| 522 background_sync_test_util::SetOnline(web_contents(), false); | 518 background_sync_test_util::SetOnline(web_contents(), false); |
| 523 | 519 |
| 524 EXPECT_TRUE(RegisterOneShotFromServiceWorker("foo_sw")); | 520 EXPECT_TRUE(RegisterFromServiceWorker("foo_sw")); |
| 525 EXPECT_TRUE(PopConsole("ok - foo_sw registered in SW")); | 521 EXPECT_TRUE(PopConsole("ok - foo_sw registered in SW")); |
| 526 EXPECT_TRUE(GetRegistrationOneShotFromServiceWorker("foo_sw")); | 522 EXPECT_TRUE(HasTagFromServiceWorker("foo_sw")); |
| 527 } | 523 } |
| 528 | 524 |
| 529 // Verify that a background sync registration is deleted when site data is | 525 // Verify that a background sync registration is deleted when site data is |
| 530 // cleared. | 526 // cleared. |
| 531 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, | 527 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
| 532 SyncRegistrationDeletedWhenClearingSiteData) { | 528 SyncRegistrationDeletedWhenClearingSiteData) { |
| 533 EXPECT_TRUE(RegisterServiceWorker()); | 529 EXPECT_TRUE(RegisterServiceWorker()); |
| 534 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 530 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
| 535 | 531 |
| 536 // Prevent firing by going offline. | 532 // Prevent firing by going offline. |
| 537 background_sync_test_util::SetOnline(web_contents(), false); | 533 background_sync_test_util::SetOnline(web_contents(), false); |
| 538 EXPECT_TRUE(RegisterOneShot("foo")); | 534 EXPECT_TRUE(Register("foo")); |
| 539 EXPECT_TRUE(GetRegistrationOneShot("foo")); | 535 EXPECT_TRUE(HasTag("foo")); |
| 540 EXPECT_TRUE(OneShotPending("foo")); | 536 EXPECT_TRUE(RegistrationPending("foo")); |
| 541 | 537 |
| 542 // Simulate a user clearing site data (including Service Workers, crucially), | 538 // Simulate a user clearing site data (including Service Workers, crucially), |
| 543 // by clearing data from the storage partition. | 539 // by clearing data from the storage partition. |
| 544 ClearStoragePartitionData(); | 540 ClearStoragePartitionData(); |
| 545 | 541 |
| 546 EXPECT_FALSE(GetRegistrationOneShot("foo")); | 542 EXPECT_FALSE(HasTag("foo")); |
| 547 } | 543 } |
| 548 | 544 |
| 549 // Verify that a background sync registration, from a service worker, is deleted | 545 // Verify that a background sync registration, from a service worker, is deleted |
| 550 // when site data is cleared. | 546 // when site data is cleared. |
| 551 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, | 547 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
| 552 SyncRegistrationFromSWDeletedWhenClearingSiteData) { | 548 SyncRegistrationFromSWDeletedWhenClearingSiteData) { |
| 553 EXPECT_TRUE(RegisterServiceWorker()); | 549 EXPECT_TRUE(RegisterServiceWorker()); |
| 554 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 550 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
| 555 | 551 |
| 556 std::vector<std::string> registered_tags; | 552 std::vector<std::string> registered_tags; |
| 557 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); | 553 EXPECT_TRUE(GetTags(registered_tags)); |
| 558 | 554 |
| 559 background_sync_test_util::SetOnline(web_contents(), false); | 555 background_sync_test_util::SetOnline(web_contents(), false); |
| 560 | 556 |
| 561 EXPECT_TRUE(RegisterOneShotFromServiceWorker("foo_sw")); | 557 EXPECT_TRUE(RegisterFromServiceWorker("foo_sw")); |
| 562 EXPECT_TRUE(PopConsole("ok - foo_sw registered in SW")); | 558 EXPECT_TRUE(PopConsole("ok - foo_sw registered in SW")); |
| 563 EXPECT_TRUE(GetRegistrationOneShotFromServiceWorker("foo_sw")); | 559 EXPECT_TRUE(HasTagFromServiceWorker("foo_sw")); |
| 564 | 560 |
| 565 // Simulate a user clearing site data (including Service Workers, crucially), | 561 // Simulate a user clearing site data (including Service Workers, crucially), |
| 566 // by clearing data from the storage partition. | 562 // by clearing data from the storage partition. |
| 567 ClearStoragePartitionData(); | 563 ClearStoragePartitionData(); |
| 568 | 564 |
| 569 EXPECT_FALSE(GetRegistrationOneShotFromServiceWorker("foo")); | 565 EXPECT_FALSE(HasTagFromServiceWorker("foo")); |
| 570 } | 566 } |
| 571 | 567 |
| 572 // Verify that multiple background sync registrations are deleted when site | 568 // Verify that multiple background sync registrations are deleted when site |
| 573 // data is cleared. | 569 // data is cleared. |
| 574 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, | 570 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
| 575 SyncRegistrationsDeletedWhenClearingSiteData) { | 571 SyncRegistrationsDeletedWhenClearingSiteData) { |
| 576 EXPECT_TRUE(RegisterServiceWorker()); | 572 EXPECT_TRUE(RegisterServiceWorker()); |
| 577 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 573 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
| 578 | 574 |
| 579 std::vector<std::string> registered_tags; | 575 std::vector<std::string> registered_tags; |
| 580 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); | 576 EXPECT_TRUE(GetTags(registered_tags)); |
| 581 | 577 |
| 582 background_sync_test_util::SetOnline(web_contents(), false); | 578 background_sync_test_util::SetOnline(web_contents(), false); |
| 583 registered_tags.push_back("foo"); | 579 registered_tags.push_back("foo"); |
| 584 registered_tags.push_back("bar"); | 580 registered_tags.push_back("bar"); |
| 585 | 581 |
| 586 for (const std::string& tag : registered_tags) | 582 for (const std::string& tag : registered_tags) |
| 587 EXPECT_TRUE(RegisterOneShot(tag)); | 583 EXPECT_TRUE(Register(tag)); |
| 588 | 584 |
| 589 EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); | 585 EXPECT_TRUE(GetTags(registered_tags)); |
| 590 | 586 |
| 591 for (const std::string& tag : registered_tags) | 587 for (const std::string& tag : registered_tags) |
| 592 EXPECT_TRUE(OneShotPending(tag)); | 588 EXPECT_TRUE(RegistrationPending(tag)); |
| 593 | 589 |
| 594 // Simulate a user clearing site data (including Service Workers, crucially), | 590 // Simulate a user clearing site data (including Service Workers, crucially), |
| 595 // by clearing data from the storage partition. | 591 // by clearing data from the storage partition. |
| 596 ClearStoragePartitionData(); | 592 ClearStoragePartitionData(); |
| 597 | 593 |
| 598 for (const std::string& tag : registered_tags) | 594 for (const std::string& tag : registered_tags) |
| 599 EXPECT_FALSE(GetRegistrationOneShot(tag)); | 595 EXPECT_FALSE(HasTag(tag)); |
| 600 } | 596 } |
| 601 | 597 |
| 602 // Verify that a sync event that is currently firing is deleted when site | 598 // Verify that a sync event that is currently firing is deleted when site |
| 603 // data is cleared. | 599 // data is cleared. |
| 604 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, | 600 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
| 605 FiringSyncEventDeletedWhenClearingSiteData) { | 601 FiringSyncEventDeletedWhenClearingSiteData) { |
| 606 EXPECT_TRUE(RegisterServiceWorker()); | 602 EXPECT_TRUE(RegisterServiceWorker()); |
| 607 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 603 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
| 608 | 604 |
| 609 background_sync_test_util::SetOnline(web_contents(), true); | 605 background_sync_test_util::SetOnline(web_contents(), true); |
| 610 EXPECT_TRUE(RegisterOneShot("delay")); | 606 EXPECT_TRUE(Register("delay")); |
| 611 | 607 |
| 612 // Verify that it is firing. | 608 // Verify that it is firing. |
| 613 EXPECT_TRUE(GetRegistrationOneShot("delay")); | 609 EXPECT_TRUE(HasTag("delay")); |
| 614 EXPECT_FALSE(OneShotPending("delay")); | 610 EXPECT_FALSE(RegistrationPending("delay")); |
| 615 | 611 |
| 616 // Simulate a user clearing site data (including Service Workers, crucially), | 612 // Simulate a user clearing site data (including Service Workers, crucially), |
| 617 // by clearing data from the storage partition. | 613 // by clearing data from the storage partition. |
| 618 ClearStoragePartitionData(); | 614 ClearStoragePartitionData(); |
| 619 | 615 |
| 620 // Verify that it was deleted. | 616 // Verify that it was deleted. |
| 621 EXPECT_FALSE(GetRegistrationOneShot("delay")); | 617 EXPECT_FALSE(HasTag("delay")); |
| 622 } | 618 } |
| 623 | 619 |
| 624 // Disabled due to flakiness. See https://crbug.com/578952. | 620 // Disabled due to flakiness. See https://crbug.com/578952. |
| 625 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, DISABLED_VerifyRetry) { | 621 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, DISABLED_VerifyRetry) { |
| 626 EXPECT_TRUE(RegisterServiceWorker()); | 622 EXPECT_TRUE(RegisterServiceWorker()); |
| 627 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. | 623 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
| 628 | 624 |
| 629 SetMaxSyncAttempts(2); | 625 SetMaxSyncAttempts(2); |
| 630 | 626 |
| 631 EXPECT_TRUE(RegisterOneShot("delay")); | 627 EXPECT_TRUE(Register("delay")); |
| 632 EXPECT_TRUE(RejectDelayedOneShot()); | 628 EXPECT_TRUE(RejectDelayedSyncEvent()); |
| 633 EXPECT_TRUE(PopConsole("ok - delay rejected")); | 629 EXPECT_TRUE(PopConsole("ok - delay rejected")); |
| 634 | 630 |
| 635 // Verify that the oneshot is still around and waiting to try again. | 631 // Verify that the registration is still around and waiting to try again. |
| 636 EXPECT_TRUE(OneShotPending("delay")); | 632 EXPECT_TRUE(RegistrationPending("delay")); |
| 637 } | 633 } |
| 638 | 634 |
| 639 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, RegisterFromNonMainFrame) { | 635 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, RegisterFromNonMainFrame) { |
| 640 std::string script_result; | 636 std::string script_result; |
| 641 GURL url = https_server()->GetURL(kEmptyURL); | 637 GURL url = https_server()->GetURL(kEmptyURL); |
| 642 EXPECT_TRUE( | 638 EXPECT_TRUE(RunScript(BuildScriptString("registerFromLocalFrame", url.spec()), |
| 643 RunScript(BuildScriptString("registerOneShotFromLocalFrame", url.spec()), | 639 &script_result)); |
| 644 &script_result)); | |
| 645 EXPECT_EQ(BuildExpectedResult("iframe", "failed to register sync"), | 640 EXPECT_EQ(BuildExpectedResult("iframe", "failed to register sync"), |
| 646 script_result); | 641 script_result); |
| 647 } | 642 } |
| 648 | 643 |
| 649 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, | 644 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
| 650 RegisterFromServiceWorkerWithoutMainFrameHost) { | 645 RegisterFromServiceWorkerWithoutMainFrameHost) { |
| 651 // Start a second https server to use as a second origin. | 646 // Start a second https server to use as a second origin. |
| 652 net::EmbeddedTestServer alt_server(net::EmbeddedTestServer::TYPE_HTTPS); | 647 net::EmbeddedTestServer alt_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 653 alt_server.ServeFilesFromSourceDirectory("content/test/data"); | 648 alt_server.ServeFilesFromSourceDirectory("content/test/data"); |
| 654 ASSERT_TRUE(alt_server.Start()); | 649 ASSERT_TRUE(alt_server.Start()); |
| 655 | 650 |
| 656 std::string script_result; | 651 std::string script_result; |
| 657 GURL url = alt_server.GetURL(kRegisterSyncURL); | 652 GURL url = alt_server.GetURL(kRegisterSyncURL); |
| 658 EXPECT_TRUE( | 653 EXPECT_TRUE(RunScript( |
| 659 RunScript(BuildScriptString("registerOneShotFromCrossOriginServiceWorker", | 654 BuildScriptString("registerFromCrossOriginServiceWorker", url.spec()), |
| 660 url.spec()), | 655 &script_result)); |
| 661 &script_result)); | |
| 662 EXPECT_EQ(BuildExpectedResult("worker", "failed to register sync"), | 656 EXPECT_EQ(BuildExpectedResult("worker", "failed to register sync"), |
| 663 script_result); | 657 script_result); |
| 664 } | 658 } |
| 665 | 659 |
| 666 } // namespace content | 660 } // namespace content |
| OLD | NEW |