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

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

Issue 666153002: Standardize usage of virtual/override/final in chrome/browser/extensions/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 <set> 5 #include <set>
6 6
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "chrome/browser/extensions/extension_browsertest.h" 9 #include "chrome/browser/extensions/extension_browsertest.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
(...skipping 18 matching lines...) Expand all
29 29
30 class NotificationObserver : public message_center::MessageCenterObserver { 30 class NotificationObserver : public message_center::MessageCenterObserver {
31 public: 31 public:
32 explicit NotificationObserver(const std::string& target_notification) 32 explicit NotificationObserver(const std::string& target_notification)
33 : message_center_(message_center::MessageCenter::Get()), 33 : message_center_(message_center::MessageCenter::Get()),
34 target_notification_id_(target_notification), 34 target_notification_id_(target_notification),
35 waiting_(false) { 35 waiting_(false) {
36 message_center_->AddObserver(this); 36 message_center_->AddObserver(this);
37 } 37 }
38 38
39 virtual ~NotificationObserver() { 39 ~NotificationObserver() override { message_center_->RemoveObserver(this); }
40 message_center_->RemoveObserver(this);
41 }
42 40
43 bool HasReceivedNotification() const { 41 bool HasReceivedNotification() const {
44 return received_notifications_.find(target_notification_id_) != 42 return received_notifications_.find(target_notification_id_) !=
45 received_notifications_.end(); 43 received_notifications_.end();
46 } 44 }
47 45
48 // Runs the message loop and returns true if a notification is received. 46 // Runs the message loop and returns true if a notification is received.
49 // Immediately returns true if a notification has already been received. 47 // Immediately returns true if a notification has already been received.
50 bool WaitForNotification() { 48 bool WaitForNotification() {
51 if (HasReceivedNotification()) 49 if (HasReceivedNotification())
52 return true; 50 return true;
53 51
54 waiting_ = true; 52 waiting_ = true;
55 content::RunMessageLoop(); 53 content::RunMessageLoop();
56 waiting_ = false; 54 waiting_ = false;
57 return HasReceivedNotification(); 55 return HasReceivedNotification();
58 } 56 }
59 57
60 private: 58 private:
61 // MessageCenterObserver implementation: 59 // MessageCenterObserver implementation:
62 virtual void OnNotificationAdded( 60 void OnNotificationAdded(const std::string& notification_id) override {
63 const std::string& notification_id) override {
64 received_notifications_.insert(notification_id); 61 received_notifications_.insert(notification_id);
65 62
66 if (waiting_ && HasReceivedNotification()) 63 if (waiting_ && HasReceivedNotification())
67 base::MessageLoopForUI::current()->Quit(); 64 base::MessageLoopForUI::current()->Quit();
68 } 65 }
69 66
70 message_center::MessageCenter* message_center_; 67 message_center::MessageCenter* message_center_;
71 std::set<std::string> received_notifications_; 68 std::set<std::string> received_notifications_;
72 std::string target_notification_id_; 69 std::string target_notification_id_;
73 bool waiting_; 70 bool waiting_;
74 }; 71 };
75 72
76 } // namespace 73 } // namespace
77 74
78 class ExtensionStorageMonitorTest : public ExtensionBrowserTest { 75 class ExtensionStorageMonitorTest : public ExtensionBrowserTest {
79 public: 76 public:
80 ExtensionStorageMonitorTest() : storage_monitor_(NULL) {} 77 ExtensionStorageMonitorTest() : storage_monitor_(NULL) {}
81 78
82 protected: 79 protected:
83 // ExtensionBrowserTest overrides: 80 // ExtensionBrowserTest overrides:
84 virtual void SetUpOnMainThread() override { 81 void SetUpOnMainThread() override {
85 ExtensionBrowserTest::SetUpOnMainThread(); 82 ExtensionBrowserTest::SetUpOnMainThread();
86 83
87 InitStorageMonitor(); 84 InitStorageMonitor();
88 } 85 }
89 86
90 ExtensionStorageMonitor* monitor() { 87 ExtensionStorageMonitor* monitor() {
91 CHECK(storage_monitor_); 88 CHECK(storage_monitor_);
92 return storage_monitor_; 89 return storage_monitor_;
93 } 90 }
94 91
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 ExtensionStorageMonitor::BUTTON_UNINSTALL); 331 ExtensionStorageMonitor::BUTTON_UNINSTALL);
335 332
336 // Also fake accepting the uninstall. 333 // Also fake accepting the uninstall.
337 TestExtensionRegistryObserver observer(ExtensionRegistry::Get(profile()), 334 TestExtensionRegistryObserver observer(ExtensionRegistry::Get(profile()),
338 extension->id()); 335 extension->id());
339 SimulateUninstallDialogAccept(); 336 SimulateUninstallDialogAccept();
340 observer.WaitForExtensionUninstalled(); 337 observer.WaitForExtensionUninstalled();
341 } 338 }
342 339
343 } // namespace extensions 340 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_storage_monitor.cc ('k') | chrome/browser/extensions/extension_storage_monitor_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698