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

Side by Side Diff: chrome/browser/extensions/extension_gcm_app_handler_unittest.cc

Issue 913943002: Unregister from GCM when the only GCM app is removed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test Created 5 years, 10 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 | « chrome/browser/extensions/extension_gcm_app_handler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/extensions/extension_gcm_app_handler.h" 5 #include "chrome/browser/extensions/extension_gcm_app_handler.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 const gcm::GCMClient::IncomingMessage& message) override {} 141 const gcm::GCMClient::IncomingMessage& message) override {}
142 142
143 void OnMessagesDeleted(const std::string& app_id) override {} 143 void OnMessagesDeleted(const std::string& app_id) override {}
144 144
145 void OnSendError( 145 void OnSendError(
146 const std::string& app_id, 146 const std::string& app_id,
147 const gcm::GCMClient::SendErrorDetails& send_error_details) override {} 147 const gcm::GCMClient::SendErrorDetails& send_error_details) override {}
148 148
149 void OnUnregisterCompleted(const std::string& app_id, 149 void OnUnregisterCompleted(const std::string& app_id,
150 gcm::GCMClient::Result result) override { 150 gcm::GCMClient::Result result) override {
151 ExtensionGCMAppHandler::OnUnregisterCompleted(app_id, result);
151 unregistration_result_ = result; 152 unregistration_result_ = result;
152 waiter_->SignalCompleted(); 153 waiter_->SignalCompleted();
153 } 154 }
154 155
155 void RemoveAppHandler(const std::string& app_id) override { 156 void RemoveAppHandler(const std::string& app_id) override {
156 ExtensionGCMAppHandler::RemoveAppHandler(app_id); 157 ExtensionGCMAppHandler::RemoveAppHandler(app_id);
157 if (!GetGCMDriver()->app_handlers().size()) 158 if (!GetGCMDriver()->app_handlers().size())
158 app_handler_count_drop_to_zero_ = true; 159 app_handler_count_drop_to_zero_ = true;
159 } 160 }
160 161
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 waiter()->PumpUILoop(); 396 waiter()->PumpUILoop();
396 EXPECT_FALSE(HasAppHandlers(extension->id())); 397 EXPECT_FALSE(HasAppHandlers(extension->id()));
397 398
398 // App handler is added when extension is reloaded. 399 // App handler is added when extension is reloaded.
399 EnableExtension(extension.get()); 400 EnableExtension(extension.get());
400 waiter()->PumpUILoop(); 401 waiter()->PumpUILoop();
401 EXPECT_TRUE(HasAppHandlers(extension->id())); 402 EXPECT_TRUE(HasAppHandlers(extension->id()));
402 403
403 // App handler is removed when extension is uninstalled. 404 // App handler is removed when extension is uninstalled.
404 UninstallExtension(extension.get()); 405 UninstallExtension(extension.get());
405 waiter()->PumpUILoop(); 406 waiter()->WaitUntilCompleted();
406 EXPECT_FALSE(HasAppHandlers(extension->id())); 407 EXPECT_FALSE(HasAppHandlers(extension->id()));
407 } 408 }
408 409
409 TEST_F(ExtensionGCMAppHandlerTest, UnregisterOnExtensionUninstall) { 410 TEST_F(ExtensionGCMAppHandlerTest, UnregisterOnExtensionUninstall) {
410 scoped_refptr<Extension> extension(CreateExtension()); 411 scoped_refptr<Extension> extension(CreateExtension());
411 LoadExtension(extension.get()); 412 LoadExtension(extension.get());
412 413
413 // Kick off registration. 414 // Kick off registration.
414 std::vector<std::string> sender_ids; 415 std::vector<std::string> sender_ids;
415 sender_ids.push_back("sender1"); 416 sender_ids.push_back("sender1");
416 Register(extension->id(), sender_ids); 417 Register(extension->id(), sender_ids);
417 waiter()->WaitUntilCompleted(); 418 waiter()->WaitUntilCompleted();
418 EXPECT_EQ(gcm::GCMClient::SUCCESS, registration_result()); 419 EXPECT_EQ(gcm::GCMClient::SUCCESS, registration_result());
419 420
420 // Add another app handler in order to prevent the GCM service from being
421 // stopped when the extension is uninstalled. This is needed because otherwise
422 // we are not able to receive the unregistration result.
423 GetGCMDriver()->AddAppHandler("Foo", gcm_app_handler());
424
425 // Unregistration should be triggered when the extension is uninstalled. 421 // Unregistration should be triggered when the extension is uninstalled.
426 UninstallExtension(extension.get()); 422 UninstallExtension(extension.get());
427 waiter()->WaitUntilCompleted(); 423 waiter()->WaitUntilCompleted();
428 EXPECT_EQ(gcm::GCMClient::SUCCESS, 424 EXPECT_EQ(gcm::GCMClient::SUCCESS,
429 gcm_app_handler()->unregistration_result()); 425 gcm_app_handler()->unregistration_result());
430
431 // Clean up.
432 GetGCMDriver()->RemoveAppHandler("Foo");
433 } 426 }
434 427
435 TEST_F(ExtensionGCMAppHandlerTest, UpdateExtensionWithGcmPermissionKept) { 428 TEST_F(ExtensionGCMAppHandlerTest, UpdateExtensionWithGcmPermissionKept) {
436 scoped_refptr<Extension> extension(CreateExtension()); 429 scoped_refptr<Extension> extension(CreateExtension());
437 430
438 // App handler is added when the extension is loaded. 431 // App handler is added when the extension is loaded.
439 LoadExtension(extension.get()); 432 LoadExtension(extension.get());
440 waiter()->PumpUILoop(); 433 waiter()->PumpUILoop();
441 EXPECT_TRUE(HasAppHandlers(extension->id())); 434 EXPECT_TRUE(HasAppHandlers(extension->id()));
442 435
(...skipping 14 matching lines...) Expand all
457 450
458 // App handler is removed when the extension is updated to the version that 451 // App handler is removed when the extension is updated to the version that
459 // has GCM permission removed. 452 // has GCM permission removed.
460 UpdateExtension(extension.get(), "good2.crx"); 453 UpdateExtension(extension.get(), "good2.crx");
461 waiter()->PumpUILoop(); 454 waiter()->PumpUILoop();
462 EXPECT_TRUE(gcm_app_handler()->app_handler_count_drop_to_zero()); 455 EXPECT_TRUE(gcm_app_handler()->app_handler_count_drop_to_zero());
463 EXPECT_FALSE(HasAppHandlers(extension->id())); 456 EXPECT_FALSE(HasAppHandlers(extension->id()));
464 } 457 }
465 458
466 } // namespace extensions 459 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_gcm_app_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698