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

Side by Side Diff: extensions/test/extension_test_notification_observer.h

Issue 2393343002: Split ExtensionTestObserver and move to //extensions. (Closed)
Patch Set: Created 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_ 5 #ifndef EXTENSIONS_TEST_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_ 6 #define EXTENSIONS_TEST_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/callback_list.h"
11 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
12 #include "chrome/browser/chrome_notification_types.h" 13 #include "base/scoped_observer.h"
13 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/location_bar/location_bar.h"
16 #include "content/public/browser/notification_details.h" 14 #include "content/public/browser/notification_details.h"
Devlin 2016/10/06 15:52:17 Not all of these are needed, either.
Rahul Chaturvedi 2016/10/11 20:12:35 Done.
17 #include "content/public/browser/notification_observer.h" 15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h"
18 #include "content/public/browser/notification_types.h" 17 #include "content/public/browser/notification_types.h"
18 #include "extensions/browser/process_manager.h"
19 #include "extensions/browser/process_manager_observer.h"
19 20
20 namespace content { 21 namespace content {
22 class BrowserContext;
21 class WindowedNotificationObserver; 23 class WindowedNotificationObserver;
22 } 24 }
23 25
24 // Test helper class for observing extension-related events. 26 // Test helper class for observing extension-related events.
Devlin 2016/10/06 15:52:17 extensions:: namespace?
Rahul Chaturvedi 2016/10/11 20:12:35 This is moved code, I would like to keep the origi
25 class ExtensionTestNotificationObserver 27 class ExtensionTestNotificationObserver : public content::NotificationObserver {
26 : public content::NotificationObserver,
27 public extensions::ExtensionActionAPI::Observer {
28 public: 28 public:
29 explicit ExtensionTestNotificationObserver(Browser* browser); 29 explicit ExtensionTestNotificationObserver(content::BrowserContext*);
Devlin 2016/10/06 15:52:17 variable name
Rahul Chaturvedi 2016/10/11 20:12:35 Done.
30 ~ExtensionTestNotificationObserver() override; 30 ~ExtensionTestNotificationObserver() override;
31 31
32 // Wait for the number of visible page actions to change to |count|.
33 bool WaitForPageActionVisibilityChangeTo(int count);
34
35 // Wait for an extension install error to be raised. Returns true if an 32 // Wait for an extension install error to be raised. Returns true if an
36 // error was raised. 33 // error was raised.
37 bool WaitForExtensionInstallError(); 34 bool WaitForExtensionInstallError();
38 35
39 // Waits until an extension is loaded and all view have loaded.
40 void WaitForExtensionAndViewLoad();
41
42 // Waits until an extension is loaded. 36 // Waits until an extension is loaded.
43 void WaitForExtensionLoad(); 37 void WaitForExtensionLoad();
44 38
45 // Waits for an extension load error. Returns true if the error really 39 // Waits for an extension load error. Returns true if the error really
46 // happened. 40 // happened.
47 bool WaitForExtensionLoadError(); 41 bool WaitForExtensionLoadError();
48 42
49 // Wait for the specified extension to crash. Returns true if it really 43 // Wait for the specified extension to crash. Returns true if it really
50 // crashed. 44 // crashed.
51 bool WaitForExtensionCrash(const std::string& extension_id); 45 bool WaitForExtensionCrash(const std::string& extension_id);
52 46
53 // Wait for the crx installer to be done. Returns true if it really is done. 47 // Wait for the crx installer to be done. Returns true if it really is done.
54 bool WaitForCrxInstallerDone(); 48 bool WaitForCrxInstallerDone();
55 49
56 // Wait for all extension views to load.
57 bool WaitForExtensionViewsToLoad();
58
59 // Wait for extension to be idle.
60 bool WaitForExtensionIdle(const std::string& extension_id);
61
62 // Wait for extension to be not idle.
63 bool WaitForExtensionNotIdle(const std::string& extension_id);
64
65 // Watch for the given event type from the given source. 50 // Watch for the given event type from the given source.
66 // After calling this method, call Wait() to ensure that RunMessageLoop() is 51 // After calling this method, call Wait() to ensure that RunMessageLoop() is
67 // called appropriately and cleanup is performed. 52 // called appropriately and cleanup is performed.
68 void Watch(int type, const content::NotificationSource& source); 53 void Watch(int type, const content::NotificationSource& source);
69 54
70 // After registering one or more event types with Watch(), call 55 // After registering one or more event types with Watch(), call
71 // this method to run the message loop and perform cleanup. 56 // this method to run the message loop and perform cleanup.
72 void Wait(); 57 void Wait();
73 58
74 const std::string& last_loaded_extension_id() { 59 const std::string& last_loaded_extension_id() {
75 return last_loaded_extension_id_; 60 return last_loaded_extension_id_;
76 } 61 }
77 void set_last_loaded_extension_id( 62 void set_last_loaded_extension_id(
78 const std::string& last_loaded_extension_id) { 63 const std::string& last_loaded_extension_id) {
79 last_loaded_extension_id_ = last_loaded_extension_id; 64 last_loaded_extension_id_ = last_loaded_extension_id;
80 } 65 }
81 66
82 // content::NotificationObserver 67 // content::NotificationObserver
83 void Observe(int type, 68 void Observe(int type,
84 const content::NotificationSource& source, 69 const content::NotificationSource& source,
85 const content::NotificationDetails& details) override; 70 const content::NotificationDetails& details) override;
86 71
87 private: 72 protected:
88 class NotificationSet; 73 class NotificationSet : public content::NotificationObserver,
74 public extensions::ProcessManagerObserver {
75 public:
76 NotificationSet();
77 ~NotificationSet() override;
89 78
90 Profile* GetProfile(); 79 void Add(int type, const content::NotificationSource& source);
80 void Add(int type);
81 void AddExtensionFrameUnregistration(extensions::ProcessManager* manager);
91 82
92 void WaitForNotification(int notification_type); 83 // Notified any time an Add()ed notification is received.
84 // The details of the notification are dropped.
85 base::CallbackList<void()>& callback_list() { return callback_list_; }
Devlin 2016/10/06 15:52:17 non-const & return values are discouraged by style
Rahul Chaturvedi 2016/10/11 20:12:35 Moved code.
86
87 private:
88 // content::NotificationObserver:
89 void Observe(int type,
90 const content::NotificationSource& source,
91 const content::NotificationDetails& details) override;
92
93 // extensions::ProcessManagerObserver:
94 void OnExtensionFrameUnregistered(
95 const std::string& extension_id,
96 content::RenderFrameHost* render_frame_host) override;
97
98 content::NotificationRegistrar notification_registrar_;
99 base::CallbackList<void()> callback_list_;
100 ScopedObserver<extensions::ProcessManager,
101 extensions::ProcessManagerObserver>
102 process_manager_observer_;
Devlin 2016/10/06 15:52:17 DISALLOW_COPY_AND_ASSIGN?
Rahul Chaturvedi 2016/10/11 20:12:35 Done.
103 };
93 104
94 // Wait for |condition_| to be met. |notification_set| is the set of 105 // Wait for |condition_| to be met. |notification_set| is the set of
95 // notifications to wait for and to check |condition| when observing. This 106 // notifications to wait for and to check |condition| when observing. This
96 // can be NULL if we are instead waiting for a different observer method, like 107 // can be NULL if we are instead waiting for a different observer method, like
97 // OnPageActionsUpdated(). 108 // OnPageActionsUpdated().
98 void WaitForCondition(const base::Callback<bool(void)>& condition, 109 void WaitForCondition(const base::Callback<bool(void)>& condition,
99 NotificationSet* notification_set); 110 NotificationSet* notification_set);
100 111
112 void WaitForNotification(int notification_type);
113
101 // Quits the message loop if |condition_| is met. 114 // Quits the message loop if |condition_| is met.
102 void MaybeQuit(); 115 void MaybeQuit();
103 116
104 // extensions::ExtensionActionAPI::Observer: 117 content::BrowserContext* context_;
105 void OnPageActionsUpdated(content::WebContents* contents) override;
106 118
107 Browser* browser_; 119 private:
108 Profile* profile_;
109
110 content::NotificationRegistrar registrar_; 120 content::NotificationRegistrar registrar_;
111 std::unique_ptr<content::WindowedNotificationObserver> observer_; 121 std::unique_ptr<content::WindowedNotificationObserver> observer_;
112 122
113 std::string last_loaded_extension_id_; 123 std::string last_loaded_extension_id_;
114 int extension_installs_observed_; 124 int extension_installs_observed_;
115 int extension_load_errors_observed_; 125 int extension_load_errors_observed_;
116 int crx_installers_done_observed_; 126 int crx_installers_done_observed_;
117 127
118 // The condition for which we are waiting. This should be checked in any 128 // The condition for which we are waiting. This should be checked in any
119 // observing methods that could trigger it. 129 // observing methods that could trigger it.
120 base::Callback<bool(void)> condition_; 130 base::Callback<bool(void)> condition_;
121 131
122 // The closure to quit the currently-running message loop. 132 // The closure to quit the currently-running message loop.
123 base::Closure quit_closure_; 133 base::Closure quit_closure_;
Devlin 2016/10/06 15:52:17 DISALLOW_COPY_AND_ASSIGN?
Rahul Chaturvedi 2016/10/11 20:12:35 Done.
124 }; 134 };
125 135
126 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_ 136 #endif // EXTENSIONS_TEST_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698