Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / extension_test_notification_observer.h
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_
7
8 #include <string>
9
10 #include "base/compiler_specific.h"
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/location_bar/location_bar.h"
14 #include "content/public/browser/notification_details.h"
15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_types.h"
17
18 namespace content {
19 class WindowedNotificationObserver;
20 }
21
22 // Test helper class for observing extension-related events.
23 class ExtensionTestNotificationObserver : public content::NotificationObserver {
24  public:
25   explicit ExtensionTestNotificationObserver(Browser* browser);
26   virtual ~ExtensionTestNotificationObserver();
27
28   // Wait for the total number of page actions to change to |count|.
29   bool WaitForPageActionCountChangeTo(int count);
30
31   // Wait for the number of visible page actions to change to |count|.
32   bool WaitForPageActionVisibilityChangeTo(int count);
33
34   // Waits until an extension is installed and loaded. Returns true if an
35   // install happened before timeout.
36   bool WaitForExtensionInstall();
37
38   // Wait for an extension install error to be raised. Returns true if an
39   // error was raised.
40   bool WaitForExtensionInstallError();
41
42   // Waits until an extension is loaded and all view have loaded.
43   void WaitForExtensionAndViewLoad();
44
45   // Waits until an extension is loaded.
46   void WaitForExtensionLoad();
47
48   // Waits for an extension load error. Returns true if the error really
49   // happened.
50   bool WaitForExtensionLoadError();
51
52   // Wait for the specified extension to crash. Returns true if it really
53   // crashed.
54   bool WaitForExtensionCrash(const std::string& extension_id);
55
56   // Wait for the crx installer to be done. Returns true if it really is done.
57   bool WaitForCrxInstallerDone();
58
59   // Wait for all extension views to load.
60   bool WaitForExtensionViewsToLoad();
61
62   // Watch for the given event type from the given source.
63   // After calling this method, call Wait() to ensure that RunMessageLoop() is
64   // called appropriately and cleanup is performed.
65   void Watch(int type, const content::NotificationSource& source);
66
67   // After registering one or more event types with Watch(), call
68   // this method to run the message loop and perform cleanup.
69   void Wait();
70
71   const std::string& last_loaded_extension_id() {
72     return last_loaded_extension_id_;
73   }
74   void set_last_loaded_extension_id(
75       const std::string& last_loaded_extension_id) {
76     last_loaded_extension_id_ = last_loaded_extension_id;
77   }
78
79   // content::NotificationObserver
80   virtual void Observe(int type,
81                        const content::NotificationSource& source,
82                        const content::NotificationDetails& details) OVERRIDE;
83
84  private:
85   Profile* GetProfile();
86
87   void WaitForNotification(int notification_type);
88
89   Browser* browser_;
90   Profile* profile_;
91
92   content::NotificationRegistrar registrar_;
93   scoped_ptr<content::WindowedNotificationObserver> observer_;
94
95   std::string last_loaded_extension_id_;
96   int extension_installs_observed_;
97   int extension_load_errors_observed_;
98   int crx_installers_done_observed_;
99 };
100
101 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_NOTIFICATION_OBSERVER_H_