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

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

Issue 2539623002: [Extensions] Move [Chrome]ExtensionTestNotificationObserver into extensions:: (Closed)
Patch Set: Created 4 years 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 2016 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 #include <chrome/browser/extensions/chrome_extension_test_notification_observer. h> 5 #include <chrome/browser/extensions/chrome_extension_test_notification_observer. h>
6 #include "base/scoped_observer.h" 6 #include "base/scoped_observer.h"
7 #include "chrome/browser/extensions/extension_action_test_util.h" 7 #include "chrome/browser/extensions/extension_action_test_util.h"
8 #include "chrome/browser/extensions/extension_util.h" 8 #include "chrome/browser/extensions/extension_util.h"
9 #include "chrome/browser/profiles/profile_manager.h" 9 #include "chrome/browser/profiles/profile_manager.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "content/public/browser/browser_context.h" 12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
14 #include "extensions/browser/notification_types.h" 14 #include "extensions/browser/notification_types.h"
15 #include "extensions/browser/process_manager.h" 15 #include "extensions/browser/process_manager.h"
16 #include "extensions/common/extension.h" 16 #include "extensions/common/extension.h"
17 17
18 using extensions::Extension; 18 namespace extensions {
19 19
20 namespace { 20 namespace {
21 21
22 // A callback that returns true if the condition has been met and takes no 22 // A callback that returns true if the condition has been met and takes no
23 // arguments. 23 // arguments.
24 using ConditionCallback = base::Callback<bool(void)>; 24 using ConditionCallback = base::Callback<bool(void)>;
25 25
26 bool HasPageActionVisibilityReachedTarget( 26 bool HasPageActionVisibilityReachedTarget(
27 Browser* browser, 27 Browser* browser,
28 size_t target_visible_page_action_count) { 28 size_t target_visible_page_action_count) {
29 return extensions::extension_action_test_util::GetVisiblePageActionCount( 29 return extension_action_test_util::GetVisiblePageActionCount(
30 browser->tab_strip_model()->GetActiveWebContents()) == 30 browser->tab_strip_model()->GetActiveWebContents()) ==
31 target_visible_page_action_count; 31 target_visible_page_action_count;
32 } 32 }
33 33
34 bool HaveAllExtensionRenderFrameHostsFinishedLoading( 34 bool HaveAllExtensionRenderFrameHostsFinishedLoading(ProcessManager* manager) {
35 extensions::ProcessManager* manager) { 35 ProcessManager::FrameSet all_views = manager->GetAllFrames();
36 extensions::ProcessManager::FrameSet all_views = manager->GetAllFrames();
37 for (content::RenderFrameHost* host : manager->GetAllFrames()) { 36 for (content::RenderFrameHost* host : manager->GetAllFrames()) {
38 if (content::WebContents::FromRenderFrameHost(host)->IsLoading()) 37 if (content::WebContents::FromRenderFrameHost(host)->IsLoading())
39 return false; 38 return false;
40 } 39 }
41 return true; 40 return true;
42 } 41 }
43 42
44 } // namespace 43 } // namespace
45 44
46 //////////////////////////////////////////////////////////////////////////////// 45 ////////////////////////////////////////////////////////////////////////////////
(...skipping 18 matching lines...) Expand all
65 context_ = browser_->profile(); 64 context_ = browser_->profile();
66 else 65 else
67 context_ = ProfileManager::GetActiveUserProfile(); 66 context_ = ProfileManager::GetActiveUserProfile();
68 } 67 }
69 return context_; 68 return context_;
70 } 69 }
71 70
72 bool ChromeExtensionTestNotificationObserver:: 71 bool ChromeExtensionTestNotificationObserver::
73 WaitForPageActionVisibilityChangeTo(int count) { 72 WaitForPageActionVisibilityChangeTo(int count) {
74 DCHECK(browser_); 73 DCHECK(browser_);
75 ScopedObserver<extensions::ExtensionActionAPI, 74 ScopedObserver<ExtensionActionAPI, ExtensionActionAPI::Observer> observer(
76 extensions::ExtensionActionAPI::Observer> 75 this);
77 observer(this); 76 observer.Add(ExtensionActionAPI::Get(GetBrowserContext()));
78 observer.Add(extensions::ExtensionActionAPI::Get(GetBrowserContext()));
79 WaitForCondition( 77 WaitForCondition(
80 base::Bind(&HasPageActionVisibilityReachedTarget, browser_, count), NULL); 78 base::Bind(&HasPageActionVisibilityReachedTarget, browser_, count), NULL);
81 return true; 79 return true;
82 } 80 }
83 81
84 bool ChromeExtensionTestNotificationObserver::WaitForExtensionViewsToLoad() { 82 bool ChromeExtensionTestNotificationObserver::WaitForExtensionViewsToLoad() {
85 extensions::ProcessManager* manager = 83 ProcessManager* manager = ProcessManager::Get(GetBrowserContext());
86 extensions::ProcessManager::Get(GetBrowserContext());
87 NotificationSet notification_set; 84 NotificationSet notification_set;
88 notification_set.Add(content::NOTIFICATION_WEB_CONTENTS_DESTROYED); 85 notification_set.Add(content::NOTIFICATION_WEB_CONTENTS_DESTROYED);
89 notification_set.Add(content::NOTIFICATION_LOAD_STOP); 86 notification_set.Add(content::NOTIFICATION_LOAD_STOP);
90 notification_set.AddExtensionFrameUnregistration(manager); 87 notification_set.AddExtensionFrameUnregistration(manager);
91 WaitForCondition( 88 WaitForCondition(
92 base::Bind(&HaveAllExtensionRenderFrameHostsFinishedLoading, manager), 89 base::Bind(&HaveAllExtensionRenderFrameHostsFinishedLoading, manager),
93 &notification_set); 90 &notification_set);
94 return true; 91 return true;
95 } 92 }
96 93
97 bool ChromeExtensionTestNotificationObserver::WaitForExtensionIdle( 94 bool ChromeExtensionTestNotificationObserver::WaitForExtensionIdle(
98 const std::string& extension_id) { 95 const std::string& extension_id) {
99 NotificationSet notification_set; 96 NotificationSet notification_set;
100 notification_set.Add(content::NOTIFICATION_RENDERER_PROCESS_TERMINATED); 97 notification_set.Add(content::NOTIFICATION_RENDERER_PROCESS_TERMINATED);
101 WaitForCondition(base::Bind(&extensions::util::IsExtensionIdle, extension_id, 98 WaitForCondition(
102 GetBrowserContext()), 99 base::Bind(&util::IsExtensionIdle, extension_id, GetBrowserContext()),
103 &notification_set); 100 &notification_set);
104 return true; 101 return true;
105 } 102 }
106 103
107 bool ChromeExtensionTestNotificationObserver::WaitForExtensionNotIdle( 104 bool ChromeExtensionTestNotificationObserver::WaitForExtensionNotIdle(
108 const std::string& extension_id) { 105 const std::string& extension_id) {
109 NotificationSet notification_set; 106 NotificationSet notification_set;
110 notification_set.Add(content::NOTIFICATION_LOAD_STOP); 107 notification_set.Add(content::NOTIFICATION_LOAD_STOP);
111 WaitForCondition(base::Bind( 108 WaitForCondition(base::Bind(
112 [](const std::string& extension_id, 109 [](const std::string& extension_id,
113 content::BrowserContext* context) -> bool { 110 content::BrowserContext* context) -> bool {
114 return !extensions::util::IsExtensionIdle(extension_id, 111 return !util::IsExtensionIdle(extension_id, context);
115 context);
116 }, 112 },
117 extension_id, GetBrowserContext()), 113 extension_id, GetBrowserContext()),
118 &notification_set); 114 &notification_set);
119 return true; 115 return true;
120 } 116 }
121 117
122 void ChromeExtensionTestNotificationObserver::WaitForExtensionAndViewLoad() { 118 void ChromeExtensionTestNotificationObserver::WaitForExtensionAndViewLoad() {
123 WaitForExtensionLoad(); 119 WaitForExtensionLoad();
124 WaitForExtensionViewsToLoad(); 120 WaitForExtensionViewsToLoad();
125 } 121 }
126 122
127 void ChromeExtensionTestNotificationObserver::OnPageActionsUpdated( 123 void ChromeExtensionTestNotificationObserver::OnPageActionsUpdated(
128 content::WebContents* web_contents) { 124 content::WebContents* web_contents) {
129 MaybeQuit(); 125 MaybeQuit();
130 } 126 }
127
128 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698