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

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

Issue 1344843003: [BackgroundSync] Add browser side support for SyncRegistration.done (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ncn_max
Patch Set: Address comments from PS7 Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/background_sync/background_sync_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 156
157 bool PopConsole(const std::string& expected_msg); 157 bool PopConsole(const std::string& expected_msg);
158 bool RegisterServiceWorker(); 158 bool RegisterServiceWorker();
159 bool RegisterOneShot(const std::string& tag); 159 bool RegisterOneShot(const std::string& tag);
160 bool UnregisterOneShot(const std::string& tag); 160 bool UnregisterOneShot(const std::string& tag);
161 bool UnregisterOneShotTwice(const std::string& tag); 161 bool UnregisterOneShotTwice(const std::string& tag);
162 bool GetRegistrationOneShot(const std::string& tag); 162 bool GetRegistrationOneShot(const std::string& tag);
163 bool GetRegistrationsOneShot(const std::vector<std::string>& expected_tags); 163 bool GetRegistrationsOneShot(const std::vector<std::string>& expected_tags);
164 bool CompleteDelayedOneShot(); 164 bool CompleteDelayedOneShot();
165 bool RejectDelayedOneShot(); 165 bool RejectDelayedOneShot();
166 bool NotifyWhenDoneOneShot(const std::string& tag);
167 bool NotifyWhenDoneImmediateOneShot(const std::string& expected_msg);
168 bool StoreRegistrationOneShot(const std::string& tag);
166 169
167 private: 170 private:
168 scoped_ptr<net::SpawnedTestServer> https_server_; 171 scoped_ptr<net::SpawnedTestServer> https_server_;
169 Shell* shell_ = nullptr; 172 Shell* shell_ = nullptr;
170 173
171 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncBrowserTest); 174 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncBrowserTest);
172 }; 175 };
173 176
174 void BackgroundSyncBrowserTest::SetOnline(bool online) { 177 void BackgroundSyncBrowserTest::SetOnline(bool online) {
175 if (online) { 178 if (online) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 EXPECT_TRUE(RunScript("completeDelayedOneShot()", &script_result)); 272 EXPECT_TRUE(RunScript("completeDelayedOneShot()", &script_result));
270 return script_result == BuildExpectedResult("delay", "completing"); 273 return script_result == BuildExpectedResult("delay", "completing");
271 } 274 }
272 275
273 bool BackgroundSyncBrowserTest::RejectDelayedOneShot() { 276 bool BackgroundSyncBrowserTest::RejectDelayedOneShot() {
274 std::string script_result; 277 std::string script_result;
275 EXPECT_TRUE(RunScript("rejectDelayedOneShot()", &script_result)); 278 EXPECT_TRUE(RunScript("rejectDelayedOneShot()", &script_result));
276 return script_result == BuildExpectedResult("delay", "rejecting"); 279 return script_result == BuildExpectedResult("delay", "rejecting");
277 } 280 }
278 281
282 bool BackgroundSyncBrowserTest::NotifyWhenDoneOneShot(const std::string& tag) {
283 EXPECT_TRUE(content::ExecuteScript(
284 shell_->web_contents(), BuildScriptString("notifyWhenDoneOneShot", tag)));
285 return PopConsole(BuildExpectedResult(tag, "done"));
286 }
287
288 bool BackgroundSyncBrowserTest::NotifyWhenDoneImmediateOneShot(
289 const std::string& expected_msg) {
290 std::string script_result;
291 EXPECT_TRUE(RunScript("notifyWhenDoneImmediateOneShot()", &script_result));
292 return script_result == expected_msg;
293 }
294
295 bool BackgroundSyncBrowserTest::StoreRegistrationOneShot(
296 const std::string& tag) {
297 std::string script_result;
298 EXPECT_TRUE(
299 RunScript(BuildScriptString("storeRegistration", tag), &script_result));
300 return script_result == BuildExpectedResult(tag, "stored");
301 }
302
279 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, OneShotFires) { 303 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, OneShotFires) {
280 EXPECT_TRUE(RegisterServiceWorker()); 304 EXPECT_TRUE(RegisterServiceWorker());
281 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. 305 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page.
282 306
283 EXPECT_TRUE(RegisterOneShot("foo")); 307 EXPECT_TRUE(RegisterOneShot("foo"));
284 EXPECT_TRUE(PopConsole("foo fired")); 308 EXPECT_TRUE(PopConsole("foo fired"));
285 EXPECT_FALSE(GetRegistrationOneShot("foo")); 309 EXPECT_FALSE(GetRegistrationOneShot("foo"));
286 } 310 }
287 311
288 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, OneShotDelaysForNetwork) { 312 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, OneShotDelaysForNetwork) {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 } 438 }
415 439
416 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, UnregisterMidSync) { 440 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, UnregisterMidSync) {
417 EXPECT_TRUE(RegisterServiceWorker()); 441 EXPECT_TRUE(RegisterServiceWorker());
418 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. 442 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page.
419 443
420 EXPECT_TRUE(RegisterOneShot("unregister")); 444 EXPECT_TRUE(RegisterOneShot("unregister"));
421 EXPECT_TRUE(PopConsole("ok - unregister completed")); 445 EXPECT_TRUE(PopConsole("ok - unregister completed"));
422 } 446 }
423 447
448 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, CallDoneBeforeSyncSucceeds) {
449 EXPECT_TRUE(RegisterServiceWorker());
450 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page.
451
452 SetOnline(false);
453 EXPECT_TRUE(RegisterOneShot("foo"));
454 EXPECT_TRUE(NotifyWhenDoneOneShot("foo"));
455
456 SetOnline(true);
457 // The ordering of PopConsole messages tells us that the event fired
458 // before done resolved.
459 EXPECT_TRUE(PopConsole("foo fired"));
460 EXPECT_TRUE(PopConsole("foo done result: true"));
461 }
462
463 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, CallDoneBeforeSyncFails) {
464 EXPECT_TRUE(RegisterServiceWorker());
465 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page.
466
467 SetOnline(true);
468 EXPECT_TRUE(RegisterOneShot("delay"));
469 EXPECT_FALSE(OneShotPending("delay"));
470 EXPECT_TRUE(NotifyWhenDoneOneShot("delay"));
471
472 EXPECT_TRUE(RejectDelayedOneShot());
473 // The ordering of PopConsole messages tells us that the event fired
474 // before done resolved.
475 EXPECT_TRUE(PopConsole("ok - delay rejected"));
476 EXPECT_TRUE(PopConsole("delay done result: false"));
477 }
478
479 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, CallDoneAfterSyncSuceeds) {
480 EXPECT_TRUE(RegisterServiceWorker());
481 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page.
482
483 SetOnline(false);
484 EXPECT_TRUE(RegisterOneShot("foo"));
485 EXPECT_TRUE(StoreRegistrationOneShot("foo"));
486
487 SetOnline(true);
488 EXPECT_TRUE(PopConsole("foo fired"));
489 EXPECT_FALSE(GetRegistrationOneShot("foo"));
490 EXPECT_TRUE(NotifyWhenDoneImmediateOneShot("ok - foo result: true"));
491 }
492
493 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest,
494 CallDoneAfterSyncUnregistered) {
495 EXPECT_TRUE(RegisterServiceWorker());
496 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page.
497
498 SetOnline(false);
499 EXPECT_TRUE(RegisterOneShot("foo"));
500 EXPECT_TRUE(StoreRegistrationOneShot("foo"));
501 EXPECT_TRUE(UnregisterOneShot("foo"));
502 EXPECT_FALSE(GetRegistrationOneShot("foo"));
503 EXPECT_TRUE(NotifyWhenDoneImmediateOneShot("ok - foo result: false"));
504 }
505
506 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, CallDoneAfterSyncFails) {
507 EXPECT_TRUE(RegisterServiceWorker());
508 EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page.
509
510 SetOnline(true);
511 EXPECT_TRUE(RegisterOneShot("delay"));
512 EXPECT_FALSE(OneShotPending("delay"));
513 EXPECT_TRUE(StoreRegistrationOneShot("delay"));
514
515 EXPECT_TRUE(RejectDelayedOneShot());
516 EXPECT_TRUE(PopConsole("ok - delay rejected"));
517 EXPECT_TRUE(NotifyWhenDoneImmediateOneShot("ok - delay result: false"));
518 }
519
424 } // namespace 520 } // namespace
425 521
426 } // namespace content 522 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/background_sync/background_sync_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698