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

Side by Side Diff: content/browser/service_worker/service_worker_job_unittest.cc

Issue 2746783002: [ServiceWorker] Mojofy InstallEvent of Service Worker (Closed)
Patch Set: Fix the test failure Created 3 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include <tuple> 6 #include <tuple>
7 7
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 ASSERT_NE(registration1, registration2); 288 ASSERT_NE(registration1, registration2);
289 } 289 }
290 290
291 // Make sure basic registration is working. 291 // Make sure basic registration is working.
292 TEST_F(ServiceWorkerJobTest, Register) { 292 TEST_F(ServiceWorkerJobTest, Register) {
293 scoped_refptr<ServiceWorkerRegistration> registration = 293 scoped_refptr<ServiceWorkerRegistration> registration =
294 RunRegisterJob(GURL("http://www.example.com/"), 294 RunRegisterJob(GURL("http://www.example.com/"),
295 GURL("http://www.example.com/service_worker.js")); 295 GURL("http://www.example.com/service_worker.js"));
296 296
297 ASSERT_NE(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); 297 ASSERT_NE(scoped_refptr<ServiceWorkerRegistration>(NULL), registration);
298 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( 298 EXPECT_EQ(EmbeddedWorkerTestHelper::Event::Install,
299 ServiceWorkerMsg_InstallEvent::ID)); 299 helper_->dispatched_events()->at(0));
300 } 300 }
301 301
302 // Make sure registrations are cleaned up when they are unregistered. 302 // Make sure registrations are cleaned up when they are unregistered.
303 TEST_F(ServiceWorkerJobTest, Unregister) { 303 TEST_F(ServiceWorkerJobTest, Unregister) {
304 GURL pattern("http://www.example.com/"); 304 GURL pattern("http://www.example.com/");
305 305
306 scoped_refptr<ServiceWorkerRegistration> registration = 306 scoped_refptr<ServiceWorkerRegistration> registration =
307 RunRegisterJob(pattern, GURL("http://www.example.com/service_worker.js")); 307 RunRegisterJob(pattern, GURL("http://www.example.com/service_worker.js"));
308 308
309 RunUnregisterJob(pattern); 309 RunUnregisterJob(pattern);
(...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, third_version->status()); 1464 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, third_version->status());
1465 } 1465 }
1466 1466
1467 class EventCallbackHelper : public EmbeddedWorkerTestHelper { 1467 class EventCallbackHelper : public EmbeddedWorkerTestHelper {
1468 public: 1468 public:
1469 EventCallbackHelper() 1469 EventCallbackHelper()
1470 : EmbeddedWorkerTestHelper(base::FilePath()), 1470 : EmbeddedWorkerTestHelper(base::FilePath()),
1471 install_event_result_(blink::kWebServiceWorkerEventResultCompleted), 1471 install_event_result_(blink::kWebServiceWorkerEventResultCompleted),
1472 activate_event_result_(blink::kWebServiceWorkerEventResultCompleted) {} 1472 activate_event_result_(blink::kWebServiceWorkerEventResultCompleted) {}
1473 1473
1474 void OnInstallEvent(int embedded_worker_id, 1474 void OnInstallEvent(
1475 int request_id) override { 1475 mojom::ServiceWorkerEventDispatcher::DispatchInstallEventCallback
1476 callback) override {
1476 if (!install_callback_.is_null()) 1477 if (!install_callback_.is_null())
1477 install_callback_.Run(); 1478 install_callback_.Run();
1478 SimulateSend(new ServiceWorkerHostMsg_InstallEventFinished( 1479 dispatched_events()->push_back(Event::Install);
xiaofengzhang 2017/04/28 07:14:24 Delete it because it's useless for the tests that
1479 embedded_worker_id, request_id, install_event_result_, 1480 std::move(callback).Run(EventResultToStatus(install_event_result_),
1480 has_fetch_handler_, base::Time::Now())); 1481 has_fetch_handler_, base::Time::Now());
1481 } 1482 }
1482 1483
1483 void OnActivateEvent( 1484 void OnActivateEvent(
1484 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback 1485 mojom::ServiceWorkerEventDispatcher::DispatchActivateEventCallback
1485 callback) override { 1486 callback) override {
1486 std::move(callback).Run(EventResultToStatus(activate_event_result_), 1487 std::move(callback).Run(EventResultToStatus(activate_event_result_),
1487 base::Time::Now()); 1488 base::Time::Now());
1488 } 1489 }
1489 1490
1490 void set_install_callback(const base::Closure& callback) { 1491 void set_install_callback(const base::Closure& callback) {
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 // should not be promoted to ACTIVATED because failure occur 1750 // should not be promoted to ACTIVATED because failure occur
1750 // during shutdown. 1751 // during shutdown.
1751 runner->RunUntilIdle(); 1752 runner->RunUntilIdle();
1752 base::RunLoop().RunUntilIdle(); 1753 base::RunLoop().RunUntilIdle();
1753 EXPECT_EQ(new_version.get(), registration->active_version()); 1754 EXPECT_EQ(new_version.get(), registration->active_version());
1754 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status()); 1755 EXPECT_EQ(ServiceWorkerVersion::ACTIVATING, new_version->status());
1755 registration->RemoveListener(update_helper); 1756 registration->RemoveListener(update_helper);
1756 } 1757 }
1757 1758
1758 } // namespace content 1759 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698