Durable Storage: Refactor browser test and test the basic "deny" flow.
[chromium-blink-merge.git] / chrome / test / base / extension_load_waiter_one_shot.h
blob15cae651a97b8fad4600d65d82647af8887f59d0
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
3 // found in the LICENSE file.
5 #ifndef CHROME_TEST_BASE_EXTENSION_LOAD_WAITER_ONE_SHOT_H_
6 #define CHROME_TEST_BASE_EXTENSION_LOAD_WAITER_ONE_SHOT_H_
8 #include "base/callback_forward.h"
9 #include "content/public/browser/notification_observer.h"
10 #include "content/public/browser/notification_registrar.h"
11 #include "content/public/test/test_utils.h"
13 namespace content {
14 class BrowserContext;
15 } // namespace content
17 // A class used to wait for an extension to load. Callers provide a load
18 // callback and can block until the extension loads.
19 class ExtensionLoadWaiterOneShot : public content::NotificationObserver {
20 public:
21 ExtensionLoadWaiterOneShot();
22 ~ExtensionLoadWaiterOneShot() override;
24 // Waits for extension with |extension_id| to load. The id should be a pointer
25 // to a static char array.
26 void WaitForExtension(const char* extension_id, const base::Closure& load_cb);
28 // content::NotificationObserver overrides.
29 void Observe(int type,
30 const content::NotificationSource& source,
31 const content::NotificationDetails& details) override;
33 // Get the browser context associated with the loaded extension. Returns
34 // NULL if |WaitForExtension| was not previously called.
35 content::BrowserContext* browser_context() { return browser_context_; }
37 // Get the id of the loaded extension.
38 const char* extension_id() { return extension_id_; }
40 private:
41 content::NotificationRegistrar registrar_;
42 scoped_refptr<content::MessageLoopRunner> load_looper_;
43 const char* extension_id_;
44 content::BrowserContext* browser_context_;
46 DISALLOW_COPY_AND_ASSIGN(ExtensionLoadWaiterOneShot);
49 #endif // CHROME_TEST_BASE_EXTENSION_LOAD_WAITER_ONE_SHOT_H_