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

Unified Diff: chrome/test/base/extension_load_waiter.cc

Issue 320753002: Support javascript gtests in an extension background page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixup comment Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/base/extension_load_waiter.cc
diff --git a/chrome/test/base/extension_load_waiter.cc b/chrome/test/base/extension_load_waiter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c4923a6182027e461b0755f6388dd98c119f42ea
--- /dev/null
+++ b/chrome/test/base/extension_load_waiter.cc
@@ -0,0 +1,52 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/test/base/extension_load_waiter.h"
+
+#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/common/extensions/extension_constants.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/browser/notification_service.h"
+#include "extensions/browser/extension_host.h"
+
+ExtensionLoadWaiter::ExtensionLoadWaiter()
+ : load_looper_(NULL), extension_id_(""), browser_context_(NULL) {
Peter Lundblad 2014/06/11 16:45:05 No need to initialize scoped_refptr with NULL, set
Peter Lundblad 2014/06/11 16:45:05 No need to initialize scoped_refptr with NULL, set
Peter Lundblad 2014/06/11 16:45:06 No need to initialize scoped_refptr with NULL, set
David Tseng 2014/06/11 17:52:54 Done.
+}
+
+ExtensionLoadWaiter::~ExtensionLoadWaiter() {
+}
+
+void ExtensionLoadWaiter::WaitFor(const char* extension_id) {
+ Reset();
Peter Lundblad 2014/06/11 16:45:05 Suggestion: make this so that you can only wait on
Peter Lundblad 2014/06/11 16:45:06 Suggestion: make this so that you can only wait on
Peter Lundblad 2014/06/11 16:45:06 Suggestion: make this so that you can only wait on
David Tseng 2014/06/11 17:52:54 Done.
+ extension_id_ = extension_id;
+ load_looper_ = new content::MessageLoopRunner();
+ registrar_.Add(this,
+ chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
+ content::NotificationService::AllSources());
+ load_looper_->Run();
+}
+
+void ExtensionLoadWaiter::Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ switch (type) {
+ case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: {
+ extensions::ExtensionHost* host =
+ content::Details<extensions::ExtensionHost>(details).ptr();
+ if (host->extension_id() == extension_id_) {
+ browser_context_ = host->browser_context();
+ registrar_.Remove(this,
+ chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
+ content::NotificationService::AllSources());
+ load_looper_->Quit();
+ }
+ break;
+ }
+ }
+}
+void ExtensionLoadWaiter::Reset() {
dmazzoni 2014/06/10 16:06:16 Nit: blank line before
David Tseng 2014/06/10 20:14:25 Done.
Peter Lundblad 2014/06/11 16:45:05 nit: add blank line.
Peter Lundblad 2014/06/11 16:45:06 nit: add blank line.
Peter Lundblad 2014/06/11 16:45:06 nit: add blank line.
David Tseng 2014/06/11 17:52:54 Already done.
+ extension_id_ = "";
+ load_looper_ = NULL;
+ browser_context_ = NULL;
+}

Powered by Google App Engine
This is Rietveld 408576698